Ver código fonte

Reordered things a bit to make reachability graph into a test

Yentl Van Tendeloo 8 anos atrás
pai
commit
4d44712bfd

+ 3 - 1
integration/code/pn_design.mvc

@@ -8,7 +8,9 @@ SimpleClassDiagrams PetriNets_Design{
         tokens : Natural
         name : String
     }
-    Class Transition {}
+    Class Transition {
+        name : String
+    }
     Association P2T (Place, Transition) {
         weight : Natural
     }

+ 12 - 4
integration/code/pn_design_model_larger.mvc

@@ -14,10 +14,18 @@ PetriNets pn {
         name = "lock_available"
     }
 
-    Transition release_section_1 {}
-    Transition release_section_2 {}
-    Transition acquire_section_1 {}
-    Transition acquire_section_2 {}
+    Transition release_section_1 {
+        name = "release_section_1"
+    }
+    Transition release_section_2 {
+        name = "release_section_2"
+    }
+    Transition acquire_section_1 {
+        name = "acquire_section_1"
+    }
+    Transition acquire_section_2 {
+        name = "acquire_section_2"
+    }
 
     P2T (critical_section_1, release_section_1) {
         weight = 1

+ 2 - 1
integration/code/pn_runtime.mvc

@@ -6,10 +6,11 @@ SimpleClassDiagrams PetriNets_Runtime{
     SimpleAttribute String {}
 
     Class Place {
-        tokens : Natural
         name : String
+        tokens : Natural
     }
     Class Transition {
+        name : String
         executing : Boolean
     }
     Association P2T (Place, Transition) {

+ 1 - 0
integration/code/pn_runtime_model.mvc

@@ -15,6 +15,7 @@ PetriNets_Runtime pn {
 	}
 	Transition t1 {
 		executing = False
+        name = "t1"
 	}
 	P2T (p1, t1) {
 		weight = 1

+ 13 - 14
integration/code/coverability.alc

@@ -2,14 +2,14 @@ include "primitives.alh"
 include "modelling.alh"
 include "object_operations.alh"
 
-Element function coverability_graph(params : Element, output : Element):
+Element function reachability_graph(params : Element, output : Element):
 	Element result
 	Element model
 	Element workset
 	String state
 
 	result = create_node()
-	out_model = instantiate_node(output["CoverabilityGraph"])
+	out_model = instantiate_node(output["ReachabilityGraph"])
 	in_model = params["PetriNets"]
 
 	// Create a dictionary representation for each transition
@@ -40,24 +40,22 @@ Element function coverability_graph(params : Element, output : Element):
 			dict_add(tv, name, link_weight)
 
 	workset = create_node()
-	initial = instantiate_node(out_model, "InitialState", "")
 
 	all_places = allInstances(in_model, "Place")
 	dict_repr = create_node()
 	while (read_nr_out(all_places) > 0):
 		place = set_pop(all_places)
-		state_config = instantiate_node(out_model, "Place", "")
-		instantiate_attribute(out_model, state_config, "name", read_attribute(in_model, place, "name"))
-		instantiate_attribute(out_model, state_config, "tokens", read_attribute(in_model, place, "tokens"))
-		instantiate_link(out_model, "", "", initial, state_config)
 		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))
+	mappings = create_node()
 
 	while (read_nr_out(workset) > 0):
-		work_unit = set_pop(workset)
-		state = work_unit[0]
-		dict_repr = dict_copy(work_unit[1])
+		dict_repr = set_pop(workset)
+		// TODO check if dict_repr is already in the set of reachable states
+		set_add(reachable_states, dict_repr)
 
 		// Compute how the PN behaves with this specific state
 		// For this, we fetch all transitions and check if they are enabled
@@ -73,9 +71,10 @@ Element function coverability_graph(params : Element, output : Element):
 				if (dict_repr[key] < transition_vectors_consume[name][key]):
 					// Impossible transition, so discard this one
 					possible = False
-					continue!
+					break!
 
 			if (possible):
+				dict_repr = dict_copy(work_unit[1])
 				// Transition can execute, so compute and add the new state based on the consume/produce vectors
 				keys = dict_keys(transition_vectors_consume[name])
 				while (read_nr_out(keys) > 0):
@@ -86,8 +85,8 @@ Element function coverability_graph(params : Element, output : Element):
 					key = set_pop(keys)
 					dict_overwrite(dict_repr, key, dict_repr[key] + transition_vectors_produce[name][key])
 
-				// Now write out the dictionary representation to a model!
-				// TODO
+				// Add the target to workset
+				set_add(workset, dict_repr)
 
-	dict_add(result, "CoverabilityGraph", out_model)
+	dict_add(result, "ReachabilityGraph", out_model)
 	return result!

+ 7 - 3
integration/code/coverability_graph.mvc

@@ -1,4 +1,8 @@
-SimpleClassDiagrams CoverabilityGraph {
+include "primitives.alh"
+include "object_operations.alh"
+include "modelling.alh"
+
+SimpleClassDiagrams ReachabilityGraph {
     Class State {}
     Class Place {
         name : String
@@ -11,7 +15,7 @@ SimpleClassDiagrams CoverabilityGraph {
 
     GlobalConstraint {
         global_constraint = $
-            String constraint(model : Element):
+            String function constraint(model : Element):
                 Element states
                 Element places
                 String state
@@ -39,7 +43,7 @@ SimpleClassDiagrams CoverabilityGraph {
                         place = set_pop(places)
                         set_add(got, read_attribute(model, place, "name"))
 
-                    if (bool_not(set_equals(got, expected))):
+                    if (bool_not(set_equality(got, expected))):
                         return "States don't all agree on the set of places"!
                 
                 return "OK"!

+ 91 - 0
integration/test_mvc.py

@@ -1538,3 +1538,94 @@ class TestModelverseCore(unittest.TestCase):
                 "OK",
                 "Ready for command...",
             ]))
+
+    def test_transform_add_MT_pn_reachability(self):
+        self.assertTrue(run_file(all_files,
+            [ "root", "root", "root", 
+                "model_add",
+                    "SimpleClassDiagrams",
+                    "PetriNets",
+                    ] + 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_add",
+                    "PetriNets",
+                    "my_pn",
+                    ] + get_model_constructor(open("integration/code/pn_design_model_larger.mvc", "r").read()) + [
+                "model_list",
+                "transformation_add_AL",
+                    "PetriNets",
+                    "",
+                    "ReachabilityGraph",
+                    "",
+                    "pn_reachability",
+                    ] + get_constructor(open("integration/code/reachability.alc", "r").read()) + [
+                "transformation_execute",
+                "pn_reachability",
+                "my_pn",
+                "my_pn_reachability",
+                "model_list",
+            ],
+            [   # bootup phase
+                "Desired username for admin user?",
+                "Desired password for admin user?",
+                "Please repeat the password",
+                "Passwords match!",
+                "Welcome to the Model Management Interface v2.0!",
+                "Use the 'help' command for a list of possible commands",
+                "Ready for command...",
+                # model_add
+                "Creating new model!",
+                "Model type?",
+                "Model name?",
+                "Waiting for model constructors...",
+                "Model upload success!",
+                "Ready for command...",
+                # model_add
+                "Creating new model!",
+                "Model type?",
+                "Model name?",
+                "Waiting for model constructors...",
+                "Model upload success!",
+                "Ready for command...",
+                # model_add
+                "Creating new model!",
+                "Model type?",
+                "Model name?",
+                "Waiting for model constructors...",
+                "Model upload success!",
+                "Ready for command...",
+                # model_list
+                set(["  SimpleClassDiagrams : SimpleClassDiagrams",
+                     "  ActionLanguage : SimpleClassDiagrams",
+                     "  CoreFormalism : SimpleClassDiagrams",
+                     "  PetriNets : SimpleClassDiagrams",
+                     "  ReachabilityGraph : SimpleClassDiagrams",
+                     "  my_pn : PetriNets",
+                     "  core : CoreFormalism"]),
+                "Ready for command...",
+                # transformation_add_AL
+                "Which metamodels do you want to use as source for the action code (empty string to finish)?",
+                "Model added as source",
+                "Which metamodels do you want to use as target for the action code (empty string to finish)?",
+                "Model added as target",
+                "Name of Action Language model?",
+                "Waiting for model constructors...",
+                "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",
+                "Ready for command...",
+                # model_list
+                set(["  SimpleClassDiagrams : SimpleClassDiagrams",
+                     "  ActionLanguage : SimpleClassDiagrams",
+                     "  CoreFormalism : SimpleClassDiagrams",
+                     "  PetriNets : SimpleClassDiagrams",
+                     "  my_pn_reachability : ReachabilityGraph",
+                     "  ReachabilityGraph : SimpleClassDiagrams",
+                     "  my_pn : PetriNets",
+                     "  core : CoreFormalism"]),
+            ]))