Browse Source

More cleanup of code mess (+ included debug output)

Yentl Van Tendeloo 8 years ago
parent
commit
e33ebc33cd

+ 4 - 4
bootstrap/transform.alc

@@ -287,7 +287,7 @@ Element function match(host_model : Element, schedule_model : Element, LHS : Str
 	set_add(mappings, initial_mapping)
 	while (read_nr_out(schedule) > 0):
 		current_element = list_pop(schedule, read_nr_out(schedule) - 1)
-		//log("Binding element with label " + cast_v2s(read_attribute(schedule_model, current_element, "label")))
+		log("Binding element with label " + cast_v2s(read_attribute(schedule_model, current_element, "label")))
 		new_mappings = create_node()
 
 		while (read_nr_out(mappings) > 0):
@@ -301,7 +301,7 @@ Element function match(host_model : Element, schedule_model : Element, LHS : Str
 				set_add(new_mappings, new_map)
 
 		mappings = new_mappings
-		//log("Remaining options: " + cast_v2s(read_nr_out(mappings)))
+		log("Remaining options: " + cast_v2s(read_nr_out(mappings)))
 
 		if (read_nr_out(mappings) == 0):
 			// Stop because we have no more options remaining!
@@ -480,7 +480,7 @@ Boolean function transform_composite(host_model : Element, schedule_model : Elem
 
 	current = set_pop(allAssociationDestinations(schedule_model, composite, "Initial"))
 	while (is_nominal_instance(schedule_model, current, "Rule")):
-		//log("Executing " + current)
+		log("Executing " + current)
 		// Still a rule that we must execute
 		typename = read_type(schedule_model, current)
 		if (typename == "Atomic"):
@@ -533,7 +533,7 @@ Boolean function transform_forall(host_model : Element, schedule_model : Element
 	else:
 		result = False
 
-	//log("Matches in forall: " + cast_v2s(read_nr_out(mappings)))
+	log("Matches in forall: " + cast_v2s(read_nr_out(mappings)))
 	while (read_nr_out(mappings) > 0):
 		mapping = set_pop(mappings)
 		// TODO check if there are actually no deletions happening in the meantime of other matched elements...

+ 4 - 2
core/core_algorithm.alc

@@ -688,7 +688,7 @@ Void function enact_PM(pm : Element, prefix : String, user_id : String):
 
 	// Initialize Join counters
 	counters = create_node()
-	join_nodes = allInstances(pm, "ForkJoin")
+	join_nodes = allInstances(pm, "Join")
 	while (read_nr_out(join_nodes) > 0):
 		dict_add(counters, set_pop(join_nodes), 0)
 
@@ -715,7 +715,9 @@ Void function enact_PM(pm : Element, prefix : String, user_id : String):
 		elif (type == "Finish"):
 			// Should be impossible, as we would have ended...
 			result = result
-		elif (type == "ForkJoin"):
+		elif (type == "Fork"):
+			result = result
+		elif (type == "Join"):
 			// Only do this if all dependencies are fullfilled
 			// So add to the counter of this Join
 			dict_overwrite(counters, element, integer_addition(counters[element], 1))

+ 2 - 1
core/pm.mvc

@@ -22,7 +22,8 @@ SimpleClassDiagrams ProcessModel {
     Class Finish : Activity {
         lower_cardinality = 1
     }
-    Class ForkJoin : Activity {}
+    Class Fork : Activity {}
+    Class Join : Activity {}
     Class Decision : Activity {
         constraint = $
             String function constraint(model : Element, name : String):

+ 18 - 4
integration/test_powerwindow.py

@@ -234,6 +234,18 @@ class TestPowerWindow(unittest.TestCase):
                     "",
                     "reachability",
                     ] + get_constructor(open("models/reachability.alc", "r").read()) + [
+                "transformation_add_AL",
+                    "PetriNet",
+                    "",
+                    "",
+                    "pn_print",
+                    ] + get_constructor(open("models/pn_print.alc", "r").read()) + [
+                "transformation_add_AL",
+                    "Encapsulated_PetriNet",
+                    "",
+                    "",
+                    "epn_print",
+                    ] + get_constructor(open("models/epn_print.alc", "r").read()) + [
                 "transformation_add_AL",
                     "ReachabilityGraph",
                     "",
@@ -258,7 +270,7 @@ class TestPowerWindow(unittest.TestCase):
                 "exit",
                 # revise_control
                 "upload",
-                ] + get_model_constructor_2("models/control_model.mvc") + [
+                ] + get_model_constructor_2("models/control_model_wrong.mvc") + [
                 "exit",
                 # revise_query
                 "upload",
@@ -348,12 +360,12 @@ class TestPowerWindow(unittest.TestCase):
                     "Waiting for model constructors...",
                     "Ready for command...",
                     ] * 6 + [
-                # transformation_add_AL * 2
+                # transformation_add_AL * 4
                 ] + [   "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 target for the action code (empty string to finish)?",
                         "Name of Action Language model?",
                         "Waiting for model constructors...",
-                        "Ready for command...", ] * 2 + [
+                        "Ready for command...", ] * 4 + [
                 # model_list
                 model_list |
                 set([
@@ -378,7 +390,9 @@ class TestPowerWindow(unittest.TestCase):
                      "  __merged_revise_environment : SimpleClassDiagrams",
                      "  __merged_revise_query : SimpleClassDiagrams",
                      "  __merged_revise_architecture : SimpleClassDiagrams",
-                     "  matches : All_RAM",
+                     "  pn_print : ActionLanguage",
+                     "  epn_print : ActionLanguage",
+                     "  match : All_RAM",
                      "  All_RAM : SimpleClassDiagrams",
                      "  make_initial_models : All_RAM",
                      "  pm_powerwindow : ProcessModel",

+ 36 - 36
models/architecture_model.mvc

@@ -1,96 +1,96 @@
 Architecture arch{
-    Group {
+    Architecture/Group {
         name = "environment"
 
-        Port env_no_objPresent {
+        Architecture/Port env_no_objPresent {
             name = "no_objPresent"
         }
-        Port env_objPresent {
+        Architecture/Port env_objPresent {
             name = "objPresent"
         }
-        Port env_cmdDown {
+        Architecture/Port env_cmdDown {
             name = "cmdDown"
         }
-        Port env_cmdNeutral {
+        Architecture/Port env_cmdNeutral {
             name = "cmdNeutral"
         }
-        Port env_cmdUp {
+        Architecture/Port env_cmdUp {
             name = "cmdUp"
         }
     }
 
-    Group {
+    Architecture/Group {
         name = "plant"
 
-        Port plant_up {
+        Architecture/Port plant_up {
             name = "up"
         }
-        Port plant_neutral {
+        Architecture/Port plant_neutral {
             name = "neutral"
         }
-        Port plant_down {
+        Architecture/Port plant_down {
             name = "down"
         }
-        Port plant_interrupt {
+        Architecture/Port plant_interrupt {
             name = "interrupt"
         }
-        Port plant_objPresent {
+        Architecture/Port plant_objPresent {
             name = "objPresent"
         }
-        Port plant_no_objPresent {
+        Architecture/Port plant_no_objPresent {
             name = "no_objPresent"
         }
-        Port plant_objDetected {
+        Architecture/Port plant_objDetected {
             name = "objDetected"
         }
-        Port plant_no_objDetected {
+        Architecture/Port plant_no_objDetected {
             name = "no_objDetected"
         }
     }
 
-    Group {
+    Architecture/Group {
         name = "control"
 
-        Port plant_cmdDown {
+        Architecture/Port control_cmdDown {
             name = "cmdDown"
         }
-        Port plant_cmdNeutral {
+        Architecture/Port control_cmdNeutral {
             name = "cmdNeutral"
         }
-        Port plant_cmdUp {
+        Architecture/Port control_cmdUp {
             name = "cmdUp"
         }
-        Port plant_up {
+        Architecture/Port control_up {
             name = "up"
         }
-        Port plant_down {
+        Architecture/Port control_down {
             name = "down"
         }
-        Port plant_neutral {
+        Architecture/Port control_neutral {
             name = "neutral"
         }
-        Port plant_interrupt {
+        Architecture/Port control_interrupt {
             name = "interrupt"
         }
-        Port plant_objDetected {
+        Architecture/Port control_objDetected {
             name = "objDetected"
         }
-        Port plant_no_objDetected {
+        Architecture/Port control_no_objDetected {
             name = "no_objDetected"
         }
     }
 
-    Connects (env_no_objPresent, plant_no_objPresent) {}
-    Connects (env_objPresent, plant_objPresent) {}
-    Connects (env_cmdDown, control_cmdDown) {}
-    Connects (env_cmdNeutral, control_cmdNeutral) {}
-    Connects (env_cmdUp, control_cmdUp) {}
+    Architecture/Connects (env_no_objPresent, plant_no_objPresent) {}
+    Architecture/Connects (env_objPresent, plant_objPresent) {}
+    Architecture/Connects (env_cmdDown, control_cmdDown) {}
+    Architecture/Connects (env_cmdNeutral, control_cmdNeutral) {}
+    Architecture/Connects (env_cmdUp, control_cmdUp) {}
 
-    Connects (plant_objDetected, control_objDetected) {}
-    Connects (plant_no_objDetected, control_no_objDetected) {}
-    Connects (plant_interrupt, control_interrupt) {}
+    Architecture/Connects (plant_objDetected, control_objDetected) {}
+    Architecture/Connects (plant_no_objDetected, control_no_objDetected) {}
+    Architecture/Connects (plant_interrupt, control_interrupt) {}
 
-    Connects (control_up, plant_up) {}
-    Connects (controL_neutral, plant_neutral) {}
-    Connects (control_down, plant_down) {}
+    Architecture/Connects (control_up, plant_up) {}
+    Architecture/Connects (control_neutral, plant_neutral) {}
+    Architecture/Connects (control_down, plant_down) {}
 }

+ 16 - 2
models/combine_EPN.mvc

@@ -39,9 +39,23 @@ A B {
 
                 constraint = $
                     Boolean function constraint(model : Element, mapping : Element):
-                        if bool_not(value_eq(read_attribute(model, mapping["2"], "name"), string_join(string_join(read_attribute(model, mapping["0"], "name"), "/"), read_attribute(model, mapping["1"], "name")))):
+                        String name_0
+                        String name_1
+                        String name_2
+                        String name_3
+                        String name_4
+                        String name_5
+
+                        name_0 = read_attribute(model, mapping["0"], "name")
+                        name_1 = read_attribute(model, mapping["1"], "name")
+                        name_2 = read_attribute(model, mapping["2"], "name")
+                        name_3 = read_attribute(model, mapping["3"], "name")
+                        name_4 = read_attribute(model, mapping["4"], "name")
+                        name_5 = read_attribute(model, mapping["5"], "name")
+
+                        if bool_not((name_0 + "/") + name_1 == name_2):
                             return False!
-                        if bool_not(value_eq(read_attribute(model, mapping["5"], "name"), string_join(string_join(read_attribute(model, mapping["3"], "name"), "/"), read_attribute(model, mapping["4"], "name")))):
+                        if bool_not((name_3 + "/") + name_4 == name_5):
                             return False!
                         return True!
                     $

+ 29 - 11
models/control_to_EPN.mvc

@@ -6,6 +6,22 @@ All_RAM Control2EPN {
     Composite schedule {
         {Contains} Failure failure {}
         {Contains} Success success {}
+        {Contains} ForAll finish {
+            LHS {
+                Pre_Encapsulated_PetriNet/Port {
+                    label = "0"
+                }
+            }
+            RHS {
+                Post_Encapsulated_PetriNet/Port {
+                    label = "0"
+                    value_name = $
+                        String function value(model : Element, name : String, mapping : Element):
+                            return string_join("control/", read_attribute(model, name, "name"))!
+                        $
+                }
+            }
+        }
         {Contains} Atomic init_ports {
             LHS {}
             RHS {
@@ -24,7 +40,7 @@ All_RAM Control2EPN {
                     label = "10"
                     value_name = $
                         String function value(model : Element, name : String, mapping : Element):
-                            return "control/cmdDown"!
+                            return "cmdDown"!
                         $
                 }
                 Post_Encapsulated_PetriNet/PortPlace (post_ports_10, post_ports_00) {
@@ -46,7 +62,7 @@ All_RAM Control2EPN {
                     label = "11"
                     value_name = $
                         String function value(model : Element, name : String, mapping : Element):
-                            return "control/cmdNeutral"!
+                            return "cmdNeutral"!
                         $
                 }
                 Post_Encapsulated_PetriNet/PortPlace (post_ports_11, post_ports_01) {
@@ -67,7 +83,7 @@ All_RAM Control2EPN {
                     label = "12"
                     value_name = $
                         String function value(model : Element, name : String, mapping : Element):
-                            return "control/cmdUp"!
+                            return "cmdUp"!
                         $
                 }
                 Post_Encapsulated_PetriNet/PortPlace (post_ports_12, post_ports_02) {
@@ -88,7 +104,7 @@ All_RAM Control2EPN {
                     label = "13"
                     value_name = $
                         String function value(model : Element, name : String, mapping : Element):
-                            return "control/objDetected"!
+                            return "objDetected"!
                         $
                 }
                 Post_Encapsulated_PetriNet/PortPlace (post_ports_13, post_ports_03) {
@@ -109,7 +125,7 @@ All_RAM Control2EPN {
                     label = "14"
                     value_name = $
                         String function value(model : Element, name : String, mapping : Element):
-                            return "control/no_objDetected"!
+                            return "no_objDetected"!
                         $
                 }
                 Post_Encapsulated_PetriNet/PortPlace (post_ports_14, post_ports_04) {
@@ -141,7 +157,7 @@ All_RAM Control2EPN {
                     label = "15"
                     value_name = $
                         String function value(model : Element, name : String, mapping : Element):
-                            return "control/up"!
+                            return "up"!
                         $
                 }
                 Post_Encapsulated_PetriNet/PortPlace (post_ports_15, post_ports_05) {
@@ -173,7 +189,7 @@ All_RAM Control2EPN {
                     label = "16"
                     value_name = $
                         String function value(model : Element, name : String, mapping : Element):
-                            return "control/neutral"!
+                            return "neutral"!
                         $
                 }
                 Post_Encapsulated_PetriNet/PortPlace (post_ports_16, post_ports_06) {
@@ -205,7 +221,7 @@ All_RAM Control2EPN {
                     label = "17"
                     value_name = $
                         String function value(model : Element, name : String, mapping : Element):
-                            return "control/down"!
+                            return "down"!
                         $
                 }
                 Post_Encapsulated_PetriNet/PortPlace (post_ports_17, post_ports_07) {
@@ -227,7 +243,7 @@ All_RAM Control2EPN {
                     label = "18"
                     value_name = $
                         String function value(model : Element, name : String, mapping : Element):
-                            return "control/interrupt"!
+                            return "interrupt"!
                         $
                 }
                 Post_Encapsulated_PetriNet/PortPlace (post_ports_18, post_ports_08) {
@@ -801,12 +817,14 @@ All_RAM Control2EPN {
     OnSuccess (create_transitions, check_object) {}
     OnSuccess (check_object, fix_interrupt) {}
     OnSuccess (fix_interrupt, fix_interrupt_self) {}
-    OnSuccess (fix_interrupt_self, success) {}
+    OnSuccess (fix_interrupt_self, finish) {}
+    OnSuccess (finish, success) {}
 
     OnFailure (init_ports, create_states) {}
     OnFailure (create_states, create_transitions) {}
     OnFailure (create_transitions, check_object) {}
     OnFailure (check_object, fix_interrupt) {}
     OnFailure (fix_interrupt, fix_interrupt_self) {}
-    OnFailure (fix_interrupt_self, success) {}
+    OnFailure (fix_interrupt_self, finish) {}
+    OnFailure (finish, failure) {}
 }

+ 28 - 10
models/plant_to_EPN.mvc

@@ -6,6 +6,22 @@ A B {
     Composite schedule {
         {Contains} Success success {}
         {Contains} Failure failure {}
+        {Contains} ForAll finish {
+            LHS {
+                Pre_Encapsulated_PetriNet/Port {
+                    label = "0"
+                }
+            }
+            RHS {
+                Post_Encapsulated_PetriNet/Port {
+                    label = "0"
+                    value_name = $
+                        String function value(model : Element, name : String, mapping : Element):
+                            return string_join("plant/", read_attribute(model, name, "name"))!
+                        $
+                }
+            }
+        }
         {Contains} Atomic init_ports {
             LHS {}
             RHS {
@@ -24,7 +40,7 @@ A B {
                     label = "10"
                     value_name = $
                         String function value(model : Element, name : String, mapping : Element):
-                            return "plant/up"!
+                            return "up"!
                         $
                 }
                 Post_Encapsulated_PetriNet/PortPlace (post_ports_10, post_ports_00) {
@@ -46,7 +62,7 @@ A B {
                     label = "11"
                     value_name = $
                         String function value(model : Element, name : String, mapping : Element):
-                            return "plant/neutral"!
+                            return "neutral"!
                         $
                 }
                 Post_Encapsulated_PetriNet/PortPlace (post_ports_11, post_ports_01) {
@@ -68,7 +84,7 @@ A B {
                     label = "12"
                     value_name = $
                         String function value(model : Element, name : String, mapping : Element):
-                            return "plant/down"!
+                            return "down"!
                         $
                 }
                 Post_Encapsulated_PetriNet/PortPlace (post_ports_12, post_ports_02) {
@@ -90,7 +106,7 @@ A B {
                     label = "13"
                     value_name = $
                         String function value(model : Element, name : String, mapping : Element):
-                            return "plant/interrupt"!
+                            return "interrupt"!
                         $
                 }
                 Post_Encapsulated_PetriNet/PortPlace (post_ports_13, post_ports_03) {
@@ -123,7 +139,7 @@ A B {
                     label = "14"
                     value_name = $
                         String function value(model : Element, name : String, mapping : Element):
-                            return "plant/objDetected"!
+                            return "objDetected"!
                         $
                 }
                 Post_Encapsulated_PetriNet/PortPlace (post_ports_14, post_ports_04) {
@@ -156,7 +172,7 @@ A B {
                     label = "15"
                     value_name = $
                         String function value(model : Element, name : String, mapping : Element):
-                            return "plant/no_objDetected"!
+                            return "no_objDetected"!
                         $
                 }
                 Post_Encapsulated_PetriNet/PortPlace (post_ports_15, post_ports_05) {
@@ -178,7 +194,7 @@ A B {
                     label = "16"
                     value_name = $
                         String function value(model : Element, name : String, mapping : Element):
-                            return "plant/objPresent"!
+                            return "objPresent"!
                         $
                 }
                 Post_Encapsulated_PetriNet/PortPlace (post_ports_16, post_ports_06) {
@@ -200,7 +216,7 @@ A B {
                     label = "17"
                     value_name = $
                         String function value(model : Element, name : String, mapping : Element):
-                            return "plant/no_objPresent"!
+                            return "no_objPresent"!
                         $
                 }
                 Post_Encapsulated_PetriNet/PortPlace (post_ports_17, post_ports_07) {
@@ -701,12 +717,14 @@ A B {
     OnSuccess (command_transition, check_object) {}
     OnSuccess (check_object, detect) {}
     OnSuccess (detect, remove_detect) {}
-    OnSuccess (remove_detect, success) {}
+    OnSuccess (remove_detect, finish) {}
+    OnSuccess (finish, success) {}
 
     OnFailure (init_ports, create_states) {}
     OnFailure (create_states, command_transition) {}
     OnFailure (command_transition, check_object) {}
     OnFailure (check_object, detect) {}
     OnFailure (detect, remove_detect) {}
-    OnFailure (remove_detect, success) {}
+    OnFailure (remove_detect, finish) {}
+    OnFailure (finish, failure) {}
 }

+ 51 - 18
models/pm_req_analyse.mvc

@@ -9,7 +9,7 @@ ProcessModel analyse_requirements {
         name = "make_initial_models"
     }
 
-    ForkJoin forkjoin1 {}
+    Fork fork1 {}
 
     Exec revise_plant {
         name = "revise_plant"
@@ -37,12 +37,27 @@ ProcessModel analyse_requirements {
         name = "control_to_EPN"
     }
 
-    ForkJoin forkjoin2 {}
+    Exec print_plant_EPN{
+        name = "epn_print"
+    }
+    Exec print_control_EPN{
+        name = "epn_print"
+    }
+    Exec print_env_EPN{
+        name = "epn_print"
+    }
+
+    Join join2 {}
 
     Exec combine_EPN {
         name = "combine_EPN"
     }
 
+
+    Exec print_pn {
+        name = "pn_print"
+    }
+
     Exec EPN_to_PN {
         name = "EPN_to_PN"
     }
@@ -51,7 +66,7 @@ ProcessModel analyse_requirements {
         name = "reachability"
     }
 
-    ForkJoin forkjoin3 {}
+    Join join3 {}
 
     Exec match {
         name = "match"
@@ -114,24 +129,28 @@ ProcessModel analyse_requirements {
 
     Next (start, make_initial_models) {}
     Next (make_initial_models, revise_req) {}
-    Next (revise_req, forkjoin1) {}
-    Next (forkjoin1, revise_plant) {}
-    Next (forkjoin1, revise_environment) {}
-    Next (forkjoin1, revise_control) {}
-    Next (forkjoin1, revise_query) {}
-    Next (forkjoin1, revise_architecture) {}
+    Next (revise_req, fork1) {}
+    Next (fork1, revise_plant) {}
+    Next (fork1, revise_environment) {}
+    Next (fork1, revise_control) {}
+    Next (fork1, revise_query) {}
+    Next (fork1, revise_architecture) {}
     Next (revise_plant, plant_to_EPN) {}
     Next (revise_environment, environment_to_EPN) {}
     Next (revise_control, control_to_EPN) {}
-    Next (plant_to_EPN, forkjoin2) {}
-    Next (environment_to_EPN, forkjoin2) {}
-    Next (control_to_EPN, forkjoin2) {}
-    Next (revise_architecture, forkjoin2) {}
-    Next (forkjoin2, combine_EPN) {}
-    Next (combine_EPN, analyse) {}
-    Next (analyse, forkjoin3) {}
-    Next (revise_query, forkjoin3) {}
-    Next (forkjoin3, match) {}
+    Next (plant_to_EPN, print_plant_EPN) {}
+    Next (print_plant_EPN, join2) {}
+    Next (environment_to_EPN, print_env_EPN) {}
+    Next (print_env_EPN, join2) {}
+    Next (control_to_EPN, print_control_EPN) {}
+    Next (print_control_EPN, join2) {}
+    Next (revise_architecture, join2) {}
+    Next (join2, combine_EPN) {}
+    Next (combine_EPN, print_pn) {}
+    Next (print_pn, analyse) {}
+    Next (analyse, join3) {}
+    Next (revise_query, join3) {}
+    Next (join3, match) {}
     Next (match, found) {}
     Then (found, bfs) {}
     Next (bfs, revise_req) {}
@@ -247,4 +266,18 @@ ProcessModel analyse_requirements {
     Consumes (bfs, reachability_graph) {
         name = "reachability_graph"
     }
+
+    Consumes (print_pn, pn) {
+        name = "pn"
+    }
+
+    Consumes (print_plant_EPN, plant_EPN){
+        name = "epn"
+    }
+    Consumes (print_control_EPN, control_EPN){
+        name = "epn"
+    }
+    Consumes (print_env_EPN, environment_EPN){
+        name = "epn"
+    }
 }