浏览代码

Added a test for PM execution (and reachability graph construction)

Yentl Van Tendeloo 8 年之前
父节点
当前提交
348fe8d0d3

+ 9 - 0
bootstrap/primitives.alc

@@ -316,3 +316,12 @@ Element function set_to_list(s : Element):
 		list_append(result, set_pop(tmp))
 		list_append(result, set_pop(tmp))
 
 
 	return result!
 	return result!
+
+Void function dict_overwrite(d : Element, key : Element, value : Element):
+	if (dict_in(d, key)):
+		dict_delete(d, key)
+	if (dict_in_node(d, key)):
+		dict_delete_node(d, key)
+	dict_add(d, key, value)
+
+	return !

+ 30 - 9
integration/code/reachability.alc

@@ -2,14 +2,37 @@ include "primitives.alh"
 include "modelling.alh"
 include "modelling.alh"
 include "object_operations.alh"
 include "object_operations.alh"
 
 
-Element function reachability_graph(params : Element, output : Element):
+Element function reachability_graph(params : Element, output_mms : Element):
 	Element result
 	Element result
 	Element model
 	Element model
 	Element workset
 	Element workset
+	Element out_model
+	Element in_model
+	Element transition_vectors_produce
+	Element transition_vectors_consume
+	Element all_transitions
+	Element vector
+	Element tv
+	Element links
+	Element mappings
+	Element reachable_states
+	Element keys
+	String transition
 	String state
 	String state
+	String name
+	String link
+	String place
+	String key
+	Integer link_weight
+	Integer initial
+	Integer state_id
+	Boolean possible
+	Element all_places
+	Element dict_repr
+	Element work_unit
 
 
 	result = create_node()
 	result = create_node()
-	out_model = instantiate_node(output["ReachabilityGraph"])
+	out_model = instantiate_model(output_mms["ReachabilityGraph"])
 	in_model = params["PetriNets"]
 	in_model = params["PetriNets"]
 
 
 	// Create a dictionary representation for each transition
 	// Create a dictionary representation for each transition
@@ -47,9 +70,7 @@ Element function reachability_graph(params : Element, output : Element):
 		place = set_pop(all_places)
 		place = set_pop(all_places)
 		dict_add(dict_repr, read_attribute(in_model, place, "name"), read_attribute(in_model, place, "tokens"))
 		dict_add(dict_repr, read_attribute(in_model, place, "name"), read_attribute(in_model, place, "tokens"))
 
 
-	initial = 0
-
-	set_add(workset, create_tuple(initial, dict_repr))
+	set_add(workset, dict_repr)
 	mappings = create_node()
 	mappings = create_node()
 
 
 	while (read_nr_out(workset) > 0):
 	while (read_nr_out(workset) > 0):
@@ -68,22 +89,22 @@ Element function reachability_graph(params : Element, output : Element):
 				key = set_pop(keys)
 				key = set_pop(keys)
 
 
 				// Compare the values in the state with those consumed by the transition
 				// Compare the values in the state with those consumed by the transition
-				if (dict_repr[key] < transition_vectors_consume[name][key]):
+				if (integer_lt(dict_repr[key], transition_vectors_consume[name][key])):
 					// Impossible transition, so discard this one
 					// Impossible transition, so discard this one
 					possible = False
 					possible = False
 					break!
 					break!
 
 
 			if (possible):
 			if (possible):
-				dict_repr = dict_copy(work_unit[1])
+				dict_repr = dict_copy(dict_repr)
 				// Transition can execute, so compute and add the new state based on the consume/produce vectors
 				// Transition can execute, so compute and add the new state based on the consume/produce vectors
 				keys = dict_keys(transition_vectors_consume[name])
 				keys = dict_keys(transition_vectors_consume[name])
 				while (read_nr_out(keys) > 0):
 				while (read_nr_out(keys) > 0):
 					key = set_pop(keys)
 					key = set_pop(keys)
-					dict_overwrite(dict_repr, key, dict_repr[key] - transition_vectors_consume[name][key])
+					dict_overwrite(dict_repr, key, integer_subtraction(dict_repr[key], transition_vectors_consume[name][key]))
 				keys = dict_keys(transition_vectors_produce[name])
 				keys = dict_keys(transition_vectors_produce[name])
 				while (read_nr_out(keys) > 0):
 				while (read_nr_out(keys) > 0):
 					key = set_pop(keys)
 					key = set_pop(keys)
-					dict_overwrite(dict_repr, key, dict_repr[key] + transition_vectors_produce[name][key])
+					dict_overwrite(dict_repr, key, integer_addition(dict_repr[key], transition_vectors_produce[name][key]))
 
 
 				// Add the target to workset
 				// Add the target to workset
 				set_add(workset, dict_repr)
 				set_add(workset, dict_repr)

+ 78 - 30
integration/test_mvc.py

@@ -1878,34 +1878,55 @@ class TestModelverseCore(unittest.TestCase):
                 "OK",
                 "OK",
                 "Ready for command...",
                 "Ready for command...",
             ]))
             ]))
+    """
 
 
-    def test_transform_add_MT_pn_reachability(self):
+    def test_process_model(self):
         self.assertTrue(run_file(all_files,
         self.assertTrue(run_file(all_files,
             [ "root", "root", "root", 
             [ "root", "root", "root", 
                 "model_add",
                 "model_add",
                     "SimpleClassDiagrams",
                     "SimpleClassDiagrams",
-                    "PetriNets",
+                    "PetriNet",
                     ] + get_model_constructor(open("integration/code/pn_design.mvc", "r").read()) + [
                     ] + get_model_constructor(open("integration/code/pn_design.mvc", "r").read()) + [
                 "model_add",
                 "model_add",
                     "SimpleClassDiagrams",
                     "SimpleClassDiagrams",
                     "ReachabilityGraph",
                     "ReachabilityGraph",
                     ] + get_model_constructor(open("integration/code/reachability_graph.mvc", "r").read()) + [
                     ] + get_model_constructor(open("integration/code/reachability_graph.mvc", "r").read()) + [
-                "model_add",
-                    "PetriNets",
-                    "my_pn",
-                    ] + get_model_constructor(open("integration/code/pn_design_model_larger.mvc", "r").read()) + [
                 "model_list",
                 "model_list",
+                "transformation_add_MT_language",
+                "PetriNet",
+                "",
+                "PetriNet_RAM",
+                "transformation_add_MT_language",
+                "ReachabilityGraph",
+                "",
+                "ReachabilityGraph_RAM",
+                "transformation_add_MT",
+                    "",
+                    "PetriNet",
+                    "",
+                    "initialize_PN",
+                "transformation_add_MANUAL",
+                    "PetriNet",
+                    "",
+                    "PetriNet",
+                    "",
+                    "refine_PN",
                 "transformation_add_AL",
                 "transformation_add_AL",
-                    "PetriNets",
+                    "PetriNet",
                     "",
                     "",
                     "ReachabilityGraph",
                     "ReachabilityGraph",
                     "",
                     "",
-                    "pn_reachability",
+                    "reachability",
                     ] + get_constructor(open("integration/code/reachability.alc", "r").read()) + [
                     ] + get_constructor(open("integration/code/reachability.alc", "r").read()) + [
-                "transformation_execute",
-                "pn_reachability",
-                "my_pn",
-                "my_pn_reachability",
+                "transformation_add_MT",
+                    "ReachabilityGraph",
+                    "",
+                    "",
+                    "reachability_print",
+                "model_add",
+                    "ProcessModel",
+                    "pn_reachability",
+                    ] + get_model_constructor(open("integration/code/pm_pn_reachability.mvc", "r").read()) + [
                 "model_list",
                 "model_list",
             ],
             ],
             [   # bootup phase
             [   # bootup phase
@@ -1930,19 +1951,37 @@ class TestModelverseCore(unittest.TestCase):
                 "Waiting for model constructors...",
                 "Waiting for model constructors...",
                 "Model upload success!",
                 "Model upload success!",
                 "Ready for command...",
                 "Ready for command...",
-                # model_add
-                "Creating new model!",
-                "Model type?",
-                "Model name?",
-                "Waiting for model constructors...",
-                "Model upload success!",
-                "Ready for command...",
                 # model_list
                 # model_list
                 model_list |
                 model_list |
                 set([
                 set([
-                     "  PetriNets : SimpleClassDiagrams",
-                     "  ReachabilityGraph : SimpleClassDiagrams",
-                     "  my_pn : PetriNets",]),
+                     "  PetriNet : SimpleClassDiagrams",
+                     "  ReachabilityGraph : SimpleClassDiagrams",]),
+                "Ready for command...",
+                # transformation_add_MT_language
+                "Formalisms to include (terminate with empty string)?",
+                "Name of the RAMified transformation metamodel?",
+                "Ready for command...",
+                # transformation_add_MT_language
+                "Formalisms to include (terminate with empty string)?",
+                "Name of the RAMified transformation metamodel?",
+                "Ready for command...",
+                # transformation_add_MT
+                "RAMified metamodel to use?",
+                "Supported metamodels:",
+                set(["  PetriNet",]),
+                "",
+                "Which ones do you want to use as source (empty string to finish)?",
+                "Which ones do you want to use as target (empty string to finish)?",
+                "Model added as target",
+                "Name of new transformation?",
+                "Waiting for model constructors...",
+                "Ready for command...",
+                # transformation_add_MANUAL
+                "Which metamodels do you want to use as source for the manual operation (empty string to finish)?",
+                "Model added as source",
+                "Which metamodels do you want to use as target for the manual operation (empty string to finish)?",
+                "Model added as target",
+                "Name of Manual operation model?",
                 "Ready for command...",
                 "Ready for command...",
                 # transformation_add_AL
                 # transformation_add_AL
                 "Which metamodels do you want to use as source for the action code (empty string to finish)?",
                 "Which metamodels do you want to use as source for the action code (empty string to finish)?",
@@ -1952,17 +1991,26 @@ class TestModelverseCore(unittest.TestCase):
                 "Name of Action Language model?",
                 "Name of Action Language model?",
                 "Waiting for model constructors...",
                 "Waiting for model constructors...",
                 "Ready for command...",
                 "Ready for command...",
-                # transformation_execute (pn_reachability)
-                "Which transformation do you want to execute?",
-                "Which model to bind for source element PetriNets",
-                "Which model to create for target element ReachabilityGraph",
+                # transformation_add_MT
+                "RAMified metamodel to use?",
+                "Supported metamodels:",
+                set(["  ReachabilityGraph",]),
+                "",
+                "Which ones do you want to use as source (empty string to finish)?",
+                "Model added as source",
+                "Which ones do you want to use as target (empty string to finish)?",
+                "Name of new transformation?",
+                "Waiting for model constructors...",
                 "Ready for command...",
                 "Ready for command...",
                 # model_list
                 # model_list
                 model_list |
                 model_list |
                 set([
                 set([
-                     "  PetriNets : SimpleClassDiagrams",
+                     "  PetriNet : SimpleClassDiagrams",
                      "  ReachabilityGraph : SimpleClassDiagrams",
                      "  ReachabilityGraph : SimpleClassDiagrams",
-                     "  my_pn_reachability : ReachabilityGraph",
-                     "  my_pn : PetriNets",]),
+                     "  initialize_PN : PetriNet_RAM",
+                     "  refine_PN : ManualOperation",
+                     "  reachability : ActionLanguage",
+                     "  reachability_print : ReachabilityGraph_RAM",
+                     "  pn_reachability : ProcessModel",
+                     ]),
             ]))
             ]))
-    """

+ 1 - 1
interface/HUTN/hutn_compiler/primitives_visitor.py

@@ -238,7 +238,7 @@ class PrimitivesVisitor(Visitor):
             name_node = self.value(arg_name)
             name_node = self.value(arg_name)
             self.dict(arg_node, "name", name_node)
             self.dict(arg_node, "name", name_node)
 
 
-            # print expressions[i].get_text()
+            #print expressions[i].get_text()
             value_node = self.get_primitive(expressions[i])
             value_node = self.get_primitive(expressions[i])
             self.dict(arg_node, "value", value_node)
             self.dict(arg_node, "value", value_node)
 
 

+ 1 - 0
interface/HUTN/includes/primitives.alh

@@ -106,3 +106,4 @@ Element function set_equality(sa : Element, sb : Element)
 Element function dict_copy(dict : Element)
 Element function dict_copy(dict : Element)
 Element function set_to_list(s : Element)
 Element function set_to_list(s : Element)
 Element function create_tuple(a : Element, b : Element)
 Element function create_tuple(a : Element, b : Element)
+Void function dict_overwrite(a : Element, b : Element, c : Element)