瀏覽代碼

Added new ALC to print the intermediate EPN and PN

Yentl Van Tendeloo 8 年之前
父節點
當前提交
d45185a261
共有 5 個文件被更改,包括 131 次插入10 次删除
  1. 0 6
      core/core_algorithm.alc
  2. 24 0
      integration/test_powerwindow.py
  3. 39 0
      models/epn_print.alc
  4. 35 4
      models/pm_req_analyse.mvc
  5. 33 0
      models/pn_print.alc

+ 0 - 6
core/core_algorithm.alc

@@ -455,17 +455,12 @@ Boolean function pm_finished(worklist : Element, pm : String):
 	finished = allInstances(pm, "Finish")
 	i = 0
 	cnt = read_nr_out(finished)
-	log("Finished elements: " + set_to_string(finished))
 
-	log("Check finished")
 	while (i < cnt):
 		// Check each finished element individually
-		log("Check element " + cast_v2s(dict_read(read_edge_dst(read_out(worklist, i)), 0)))
 		if (set_in(finished, dict_read(read_edge_dst(read_out(worklist, i)), 0))):
-			log("Yes")
 			return True!
 		i = i + 1
-	log("NO")
 
 	return False!
 
@@ -764,7 +759,6 @@ Void function enact_PM(pm : Element, prefix : String, user_id : String):
 		String next
 		while (read_nr_out(all_next) > 0):
 			next = set_pop(all_next)
-			log("Adding to worklist: " + next)
 			set_add(worklist, create_tuple(next, result))
 
 	log("FINISHED")

+ 24 - 0
integration/test_powerwindow.py

@@ -207,6 +207,20 @@ class TestPowerWindow(unittest.TestCase):
                     "",
                     "matches",
                     ] + get_model_constructor_2("models/matches.mvc") + [
+                "transformation_add_AL",
+                    "PetriNet",
+                    "",
+                    "PetriNet",
+                    "",
+                    "pn_print",
+                    ] + get_constructor(open("models/pn_print.alc", "r").read()) + [
+                "transformation_add_AL",
+                    "Encapsulated_PetriNet",
+                    "",
+                    "Encapsulated_PetriNet",
+                    "",
+                    "epn_print",
+                    ] + get_constructor(open("models/epn_print.alc", "r").read()) + [
                 "model_list",
                 "process_execute",
                 "pm_powerwindow",
@@ -430,6 +444,14 @@ class TestPowerWindow(unittest.TestCase):
                 "Name of new transformation?",
                 "Waiting for model constructors...",
                 "Ready for command...",
+                # transformation_add_AL * 2
+                ] + [   "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...", ] * 2 + [
                 # model_list
                 model_list |
                 set([
@@ -446,6 +468,8 @@ class TestPowerWindow(unittest.TestCase):
                      "  refine_control : ManualOperation",
                      "  refine_environment : ManualOperation",
                      "  refine_query : ManualOperation",
+                     "  pn_print : ActionLanguage",
+                     "  epn_print : ActionLanguage",
                      "  __merged_define_req : SimpleClassDiagrams",
                      "  __merged_All_RAM : SimpleClassDiagrams",
                      "  __merged_refine_plant : SimpleClassDiagrams",

+ 39 - 0
models/epn_print.alc

@@ -0,0 +1,39 @@
+include "primitives.alh"
+include "modelling.alh"
+include "object_operations.alh"
+
+Element function pn_print(params : Element, output_mms : Element):
+	Element model
+	model = params["epn"]
+
+	Element all_places
+	String place
+	String name
+	Integer tokens
+
+	log("Places:")
+	all_places = allInstances(model, "Place")
+	while (read_nr_out(all_places) > 0):
+		place = set_pop(all_places)
+		name = read_attribute(model, place, "name")
+		tokens = read_attribute(model, place, "tokens")
+
+		log((("  " + name) + ": ") + cast_v2s(tokens))
+
+	log("Transitions:")
+	all_places = allInstances(model, "Transition")
+	while (read_nr_out(all_places) > 0):
+		place = set_pop(all_places)
+		name = read_attribute(model, place, "name")
+
+		log("  " + name)
+
+	log("Ports:")
+	all_places = allInstances(model, "Port")
+	while (read_nr_out(all_places) > 0):
+		place = set_pop(all_places)
+		name = read_attribute(model, place, "name")
+
+		log("  " + name)
+
+	return create_node()!

+ 35 - 4
models/pm_req_analyse.mvc

@@ -34,12 +34,26 @@ ProcessModel analyse_requirements {
         name = "control_to_EPN"
     }
 
+    Exec print_plant_EPN {
+        name = "epn_print"
+    }
+    Exec print_control_EPN {
+        name = "epn_print"
+    }
+    Exec print_environment_EPN {
+        name = "epn_print"
+    }
+
     ForkJoin forkjoin2 {}
 
     Exec combine_EPN {
         name = "combine_EPN"
     }
 
+    Exec print_pn {
+        name = "pn_print"
+    }
+
     Exec EPN_to_PN {
         name = "EPN_to_PN"
     }
@@ -111,11 +125,15 @@ ProcessModel analyse_requirements {
     Next (refine_plant, plant_to_EPN) {}
     Next (refine_environment, environment_to_EPN) {}
     Next (refine_control, control_to_EPN) {}
-    Next (plant_to_EPN, forkjoin2) {}
-    Next (environment_to_EPN, forkjoin2) {}
-    Next (control_to_EPN, forkjoin2) {}
+    Next (plant_to_EPN, print_plant_EPN) {}
+    Next (environment_to_EPN, print_environment_EPN) {}
+    Next (control_to_EPN, print_control_EPN) {}
+    Next (print_plant_EPN, forkjoin2) {}
+    Next (print_environment_EPN, forkjoin2) {}
+    Next (print_control_EPN, forkjoin2) {}
     Next (forkjoin2, combine_EPN) {}
-    Next (combine_EPN, analyse) {}
+    Next (combine_EPN, print_pn) {}
+    Next (print_pn, analyse) {}
     Next (analyse, forkjoin3) {}
     Next (refine_query, forkjoin3) {}
     Next (forkjoin3, matches) {}
@@ -193,4 +211,17 @@ ProcessModel analyse_requirements {
     Consumes (matches, query) {
         name = "query"
     }
+
+    Consumes (print_plant_EPN, plant_EPN) {
+        name = "epn"
+    }
+    Consumes (print_environment_EPN, environment_EPN) {
+        name = "epn"
+    }
+    Consumes (print_control_EPN, control_EPN) {
+        name = "epn"
+    }
+    Consumes (print_pn, pn) {
+        name = "pn"
+    }
 }

+ 33 - 0
models/pn_print.alc

@@ -0,0 +1,33 @@
+include "primitives.alh"
+include "modelling.alh"
+include "object_operations.alh"
+
+Element function pn_print(params : Element, output_mms : Element):
+	Element model
+	model = params["pn"]
+
+	Element all_places
+	String place
+	String name
+	Integer tokens
+
+	log(set_to_string(dict_keys(model["metamodel"]["model"])))
+
+	log("Places:")
+	all_places = allInstances(model, "Place")
+	while (read_nr_out(all_places) > 0):
+		place = set_pop(all_places)
+		name = read_attribute(model, place, "name")
+		tokens = read_attribute(model, place, "tokens")
+
+		log((("  " + name) + ": ") + cast_v2s(tokens))
+
+	log("Transitions:")
+	all_places = allInstances(model, "Transition")
+	while (read_nr_out(all_places) > 0):
+		place = set_pop(all_places)
+		name = read_attribute(model, place, "name")
+
+		log("  " + name)
+
+	return create_node()!