Bläddra i källkod

Fixed reachability computation

Yentl Van Tendeloo 8 år sedan
förälder
incheckning
13e63f5c85
2 ändrade filer med 209 tillägg och 10 borttagningar
  1. 16 9
      integration/code/reachability.alc
  2. 193 1
      integration/test_mvc.py

+ 16 - 9
integration/code/reachability.alc

@@ -31,6 +31,7 @@ Element function reachability_graph(params : Element, output_mms : Element):
 	Boolean possible
 	Element all_places
 	Element dict_repr
+	Element new_dict_repr
 	Element work_unit
 
 	result = create_node()
@@ -43,6 +44,7 @@ Element function reachability_graph(params : Element, output_mms : Element):
 	all_transitions = allInstances(in_model, "Transition")
 	while (read_nr_out(all_transitions) > 0):
 		transition = set_pop(all_transitions)
+		log("Consider transition " + transition)
 
 		tv = create_node()
 		links = allIncomingAssociationInstances(in_model, transition, "P2T")
@@ -102,6 +104,9 @@ Element function reachability_graph(params : Element, output_mms : Element):
 		all_transitions = set_copy(all_transitions_original)
 		while (read_nr_out(all_transitions) > 0):
 			transition = set_pop(all_transitions)
+
+			log("Test transition: " + cast_v2s(read_attribute(in_model, transition, "name")))
+
 			keys = dict_keys(transition_vectors_consume[transition])
 			possible = True
 			while (read_nr_out(keys) > 0):
@@ -111,22 +116,24 @@ Element function reachability_graph(params : Element, output_mms : Element):
 				if (integer_lt(dict_repr[key], transition_vectors_consume[transition][key])):
 					// Impossible transition, so discard this one
 					possible = False
+					log("Not applicable!")
 					break!
 
 			if (possible):
-				dict_repr = dict_copy(dict_repr)
+				log("Applicable!")
+				new_dict_repr = dict_copy(dict_repr)
 				// Transition can execute, so compute and add the new state based on the consume/produce vectors
-				log("Before transition: " + dict_to_string(dict_repr))
+				log("Before transition: " + dict_to_string(new_dict_repr))
 				keys = dict_keys(transition_vectors_consume[transition])
 				while (read_nr_out(keys) > 0):
 					key = set_pop(keys)
-					dict_overwrite(dict_repr, key, integer_subtraction(dict_repr[key], transition_vectors_consume[transition][key]))
+					dict_overwrite(new_dict_repr, key, integer_subtraction(new_dict_repr[key], transition_vectors_consume[transition][key]))
 
 				keys = dict_keys(transition_vectors_produce[transition])
 				while (read_nr_out(keys) > 0):
 					key = set_pop(keys)
-					dict_overwrite(dict_repr, key, integer_addition(dict_repr[key], transition_vectors_produce[transition][key]))
-				log("After transition: " + dict_to_string(dict_repr))
+					dict_overwrite(new_dict_repr, key, integer_addition(new_dict_repr[key], transition_vectors_produce[transition][key]))
+				log("After transition: " + dict_to_string(new_dict_repr))
 
 				// Check if this state already has an associated ID
 				Integer other_state_id
@@ -137,7 +144,7 @@ Element function reachability_graph(params : Element, output_mms : Element):
 				while (read_nr_out(keys) > 0):
 					other_state_id = set_pop(keys)
 
-					if (dict_eq(reachable_states[other_state_id], dict_repr)):
+					if (dict_eq(reachable_states[other_state_id], new_dict_repr)):
 						target_id = other_state_id
 						break!
 
@@ -147,7 +154,7 @@ Element function reachability_graph(params : Element, output_mms : Element):
 					next_id = next_id + 1
 
 					// Add to all data structures
-					dict_add(reachable_states, target_id, dict_repr)
+					dict_add(reachable_states, target_id, new_dict_repr)
 					dict_add(mappings, target_id, create_node())
 					set_add(workset, target_id)
 
@@ -155,12 +162,12 @@ Element function reachability_graph(params : Element, output_mms : Element):
 					state = instantiate_node(out_model, "State", cast_i2s(target_id))
 					instantiate_attribute(out_model, state, "name", cast_i2s(target_id))
 
-					keys = dict_keys(dict_repr)
+					keys = dict_keys(new_dict_repr)
 					while (read_nr_out(keys) > 0):
 						key = set_pop(keys)
 						place = instantiate_node(out_model, "Place", "")
 						instantiate_attribute(out_model, place, "name", read_attribute(in_model, key, "name"))
-						instantiate_attribute(out_model, place, "tokens", dict_repr[key])
+						instantiate_attribute(out_model, place, "tokens", new_dict_repr[key])
 						instantiate_link(out_model, "Contains", "", state, place)
 
 				// Anyway, we have found a transition, which we should store

+ 193 - 1
integration/test_mvc.py

@@ -1880,7 +1880,7 @@ class TestModelverseCore(unittest.TestCase):
             ]))
     """
 
-    def test_process_model(self):
+    def test_process_model_trivial_pn(self):
         self.assertTrue(run_file(all_files,
             [ "root", "root", "root", 
                 "model_add",
@@ -2131,3 +2131,195 @@ class TestModelverseCore(unittest.TestCase):
                      ]),
                 "Ready for command...",
             ]))
+
+    def test_process_model_simple_pn(self):
+        self.assertTrue(run_file(all_files,
+            [ "root", "root", "root", 
+                "model_add",
+                    "SimpleClassDiagrams",
+                    "PetriNet",
+                    ] + get_model_constructor(open("integration/code/pn_design.mvc", "r").read()) + [
+                "model_add",
+                    "SimpleClassDiagrams",
+                    "ReachabilityGraph",
+                    ] + get_model_constructor(open("integration/code/reachability_graph.mvc", "r").read()) + [
+                "model_list",
+                "transformation_add_MT_language",
+                "PetriNet",
+                "",
+                "PetriNet_RAM",
+                "transformation_add_MT_language",
+                "ReachabilityGraph",
+                "",
+                "ReachabilityGraph_RAM",
+                "transformation_add_MT",
+                    "PetriNet_RAM",
+                    "",
+                    "PetriNet",
+                    "",
+                    "initialize_PN",
+                    ] + get_model_constructor(open("integration/code/initialize_PN.mvc", "r").read()) + [
+                "transformation_add_MANUAL",
+                    "PetriNet",
+                    "",
+                    "PetriNet",
+                    "",
+                    "refine_PN",
+                "transformation_add_AL",
+                    "PetriNet",
+                    "",
+                    "ReachabilityGraph",
+                    "",
+                    "reachability",
+                    ] + get_constructor(open("integration/code/reachability.alc", "r").read()) + [
+                "transformation_add_MT",
+                    "ReachabilityGraph_RAM",
+                    "ReachabilityGraph",
+                    "",
+                    "",
+                    "reachability_print",
+                    ] + get_model_constructor(open("integration/code/reachabilitygraph_print.mvc", "r").read()) + [
+                "model_add",
+                    "ProcessModel",
+                    "pn_reachability",
+                    ] + get_model_constructor(open("integration/code/pm_pn_reachability.mvc", "r").read()) + [
+                "model_list",
+                "process_execute",
+                "pn_reachability",
+                "my_",
+                    "instantiate",
+                        "PetriNet/Place",
+                        "crit_1",
+                        "attr_add",
+                            "crit_1",
+                            "name",
+                            "crit_1",
+                        "attr_add",
+                            "crit_1",
+                            "tokens",
+                            0,
+                    "instantiate",
+                        "PetriNet/Place",
+                        "crit_2",
+                        "attr_add",
+                            "crit_2",
+                            "name",
+                            "crit_2",
+                        "attr_add",
+                            "crit_2",
+                            "tokens",
+                            0,
+                    "instantiate",
+                        "PetriNet/Place",
+                        "free",
+                        "attr_add",
+                            "free",
+                            "name",
+                            "free",
+                        "attr_add",
+                            "free",
+                            "tokens",
+                            1,
+                    "instantiate",
+                        "PetriNet/Transition",
+                        "acq_1",
+                        "attr_add",
+                            "acq_1",
+                            "name",
+                            "acq_1",
+                    "instantiate",
+                        "PetriNet/Transition",
+                        "acq_2",
+                        "attr_add",
+                            "acq_2",
+                            "name",
+                            "acq_2",
+                    "instantiate",
+                        "PetriNet/Transition",
+                        "rel_1",
+                        "attr_add",
+                            "rel_1",
+                            "name",
+                            "rel_1",
+                    "instantiate",
+                        "PetriNet/Transition",
+                        "rel_2",
+                        "attr_add",
+                            "rel_2",
+                            "name",
+                            "rel_2",
+                    "instantiate",
+                        "PetriNet/P2T",
+                        "a1i",
+                        "free",
+                        "acq_1",
+                        "attr_add",
+                            "a1i",
+                            "weight",
+                            1,
+                    "instantiate",
+                        "PetriNet/T2P",
+                        "a1o",
+                        "acq_1",
+                        "crit_1",
+                        "attr_add",
+                            "a1o",
+                            "weight",
+                            1,
+                    "instantiate",
+                        "PetriNet/P2T",
+                        "a2i",
+                        "free",
+                        "acq_2",
+                        "attr_add",
+                            "a2i",
+                            "weight",
+                            1,
+                    "instantiate",
+                        "PetriNet/T2P",
+                        "a2o",
+                        "acq_2",
+                        "crit_2",
+                        "attr_add",
+                            "a2o",
+                            "weight",
+                            1,
+                    "instantiate",
+                        "PetriNet/P2T",
+                        "r1i",
+                        "crit_1",
+                        "rel_1",
+                        "attr_add",
+                            "r1i",
+                            "weight",
+                            1,
+                    "instantiate",
+                        "PetriNet/T2P",
+                        "r1o",
+                        "rel_1",
+                        "free",
+                        "attr_add",
+                            "r1o",
+                            "weight",
+                            1,
+                    "instantiate",
+                        "PetriNet/P2T",
+                        "r2i",
+                        "crit_2",
+                        "rel_2",
+                        "attr_add",
+                            "r2i",
+                            "weight",
+                            1,
+                    "instantiate",
+                        "PetriNet/T2P",
+                        "r2o",
+                        "rel_2",
+                        "free",
+                        "attr_add",
+                            "r2o",
+                            "weight",
+                            1,
+                    "exit",
+                "model_list",
+            ], None))