Browse Source

PM execution takes a dictionary for binding

Yentl Van Tendeloo 7 years ago
parent
commit
e56bbdf958

+ 46 - 8
bootstrap/core_algorithm.alc

@@ -13,6 +13,7 @@ include "utils.alh"
 include "conformance_finding.alh"
 include "conformance_finding.alh"
 include "typing.alh"
 include "typing.alh"
 include "compiler.alh"
 include "compiler.alh"
+include "random.alh"
 
 
 String core_model_location = "models/core"
 String core_model_location = "models/core"
 
 
@@ -763,7 +764,7 @@ Element function execute_operation(operation_id : String, input_models : Element
 		log("Negative result of execution")
 		log("Negative result of execution")
 		return read_root()!
 		return read_root()!
 
 
-Boolean function enact_action(pm : Element, element : String, prefix : String):
+Boolean function enact_action(pm : Element, element : String, mapping : Element):
 	Boolean result
 	Boolean result
 	String transformation_id
 	String transformation_id
 	Element lst
 	Element lst
@@ -796,7 +797,7 @@ Boolean function enact_action(pm : Element, element : String, prefix : String):
 	while (set_len(lst) > 0):
 	while (set_len(lst) > 0):
 		consume = set_pop(lst)
 		consume = set_pop(lst)
 		value = read_attribute(pm, readAssociationDestination(pm, consume), "name")
 		value = read_attribute(pm, readAssociationDestination(pm, consume), "name")
-		dict_add(inputs, read_attribute(pm, consume, "name"), prefix + value)
+		dict_add(inputs, read_attribute(pm, consume, "name"), mapping[value])
 
 
 	// Find all output model names and their metamodel
 	// Find all output model names and their metamodel
 	lst = allOutgoingAssociationInstances(pm, element, "Produces")
 	lst = allOutgoingAssociationInstances(pm, element, "Produces")
@@ -806,7 +807,7 @@ Boolean function enact_action(pm : Element, element : String, prefix : String):
 		type_name = read_attribute(pm, elem, "type")
 		type_name = read_attribute(pm, elem, "type")
 		elem_name = read_attribute(pm, elem, "name")
 		elem_name = read_attribute(pm, elem, "name")
 		dict_add(outputs, read_attribute(pm, produce, "name"), type_name)
 		dict_add(outputs, read_attribute(pm, produce, "name"), type_name)
-		dict_add(output_map, read_attribute(pm, produce, "name"), prefix + elem_name)
+		dict_add(output_map, read_attribute(pm, produce, "name"), mapping[elem_name])
 
 
 	if read_type(core, transformation_id) == "ActionLanguage":
 	if read_type(core, transformation_id) == "ActionLanguage":
 		log(string_join("Enacting ActionLanguage: ", read_attribute(pm, element, "name")))
 		log(string_join("Enacting ActionLanguage: ", read_attribute(pm, element, "name")))
@@ -834,7 +835,20 @@ Boolean function enact_action(pm : Element, element : String, prefix : String):
 				model_overwrite(result[key], get_entry_id(output_map[key]), get_entry_id(outputs[key]))
 				model_overwrite(result[key], get_entry_id(output_map[key]), get_entry_id(outputs[key]))
 		return True!
 		return True!
 
 
-Void function enact_PM(pm : Element, prefix : String):
+Element function PM_signature(pm : Element):
+	Element all_data
+	Element result
+	String entry
+
+	result = dict_create()
+	all_data = allInstances(pm, "Data")
+	while (set_len(all_data) > 0):
+		entry = set_pop(all_data)
+		dict_add(result, cast_string(read_attribute(pm, entry, "name")), cast_string(read_attribute(pm, entry, "type")))
+
+	return result!
+
+Void function enact_PM(pm : Element, mapping : Element):
 	Element worklist
 	Element worklist
 	String element
 	String element
 	String type
 	String type
@@ -842,9 +856,28 @@ Void function enact_PM(pm : Element, prefix : String):
 	Element tuple
 	Element tuple
 	Element counters
 	Element counters
 	Element join_nodes
 	Element join_nodes
+	Element keys
+	String key
 
 
 	output("Success")
 	output("Success")
 
 
+	// For all entries in the signature, not in the mapping, we add a mock location
+	Element signature
+	String mock_location
+	Element mock_locations
+	mock_locations = set_create()
+	signature = PM_signature(pm)
+	keys = dict_keys(signature)
+	while (set_len(keys) > 0):
+		key = set_pop(keys)
+		if (bool_not(dict_in(mapping, key))):
+			// Add mock location
+			mock_location = ""
+			while (get_entry_id(mock_location) != ""):
+				mock_location = ".tmp/" + random_string(10)
+			dict_add(mapping, key, mock_location)
+			set_add(mock_locations, mock_location)
+
 	// Initialize Join counters
 	// Initialize Join counters
 	counters = dict_create()
 	counters = dict_create()
 	join_nodes = allInstances(pm, "Join")
 	join_nodes = allInstances(pm, "Join")
@@ -897,7 +930,7 @@ Void function enact_PM(pm : Element, prefix : String):
 			// Execute a transformation
 			// Execute a transformation
 			// This the difficult part!
 			// This the difficult part!
 
 
-			result = enact_action(pm, element, prefix)
+			result = enact_action(pm, element, mapping)
 			output("Success")
 			output("Success")
 
 
 		elif (type == "Decision"):
 		elif (type == "Decision"):
@@ -921,6 +954,11 @@ Void function enact_PM(pm : Element, prefix : String):
 			set_add_node(worklist, create_tuple(next, result))
 			set_add_node(worklist, create_tuple(next, result))
 
 
 	// Reached a finish element, so stop
 	// Reached a finish element, so stop
+
+	// Remove all mock locations again
+	while (set_len(mock_locations) > 0):
+		model_delete(get_entry_id(set_pop(mock_locations)))
+
 	return !
 	return !
 
 
 String function cmd_help():
 String function cmd_help():
@@ -1017,7 +1055,7 @@ String function cmd_model_add(type : String, name : String, code : String):
 	else:
 	else:
 		return "Model not found: " + type!
 		return "Model not found: " + type!
 
 
-String function cmd_process_execute(process : String, prefix : String):
+String function cmd_process_execute(process : String, mapping : Element):
 	// Execute a process model until it reaches termination
 	// Execute a process model until it reaches termination
 	String process_id
 	String process_id
 
 
@@ -1029,7 +1067,7 @@ String function cmd_process_execute(process : String, prefix : String):
 			if (element_eq(pm, read_root())):
 			if (element_eq(pm, read_root())):
 				return "Specified model cannot be interpreted as a ProcessModel: " + process!
 				return "Specified model cannot be interpreted as a ProcessModel: " + process!
 
 
-			enact_PM(pm, prefix)
+			enact_PM(pm, mapping)
 			return "Success"!
 			return "Success"!
 		else:
 		else:
 			return "Permission denied to model: " + process!
 			return "Permission denied to model: " + process!
@@ -2187,7 +2225,7 @@ Void function user_function_skip_init(user_id : String):
 		elif (cmd == "model_add"):
 		elif (cmd == "model_add"):
 			output(cmd_model_add(single_input("Model type?"), single_input("Model name?"), single_input("Model textual representation?")))
 			output(cmd_model_add(single_input("Model type?"), single_input("Model name?"), single_input("Model textual representation?")))
 		elif (cmd == "process_execute"):
 		elif (cmd == "process_execute"):
-			output(cmd_process_execute(single_input("Process to execute?"), single_input("Model prefix to use?")))
+			output(cmd_process_execute(single_input("Process to execute?"), dict_input("Model bindings to use?")))
 		elif (cmd == "transformation_between"):
 		elif (cmd == "transformation_between"):
 			output(cmd_transformation_between(dict_input("Source signature?"), dict_input("Target signature?")))
 			output(cmd_transformation_between(dict_input("Source signature?"), dict_input("Target signature?")))
 		elif (cmd == "model_render"):
 		elif (cmd == "model_render"):

+ 11 - 0
bootstrap/random.alc

@@ -1,4 +1,5 @@
 include "primitives.alh"
 include "primitives.alh"
+include "utils.alh"
 
 
 Integer seed = 1
 Integer seed = 1
 
 
@@ -30,3 +31,13 @@ Element function random_choice(list : Element):
 		return read_root()!
 		return read_root()!
 	else:
 	else:
 		return list_read(list, random_interval(0, list_len(list) - 1))!
 		return list_read(list, random_interval(0, list_len(list) - 1))!
+
+String function random_string(length : Integer):
+	String result
+	Element chars
+
+	chars = alphabet()
+	result = ""
+	while (string_len(result) < length):
+		result = string_join(result, cast_string(random_choice(chars)))
+	return result!

+ 30 - 0
bootstrap/utils.alc

@@ -90,3 +90,33 @@ Void function list_extend(lst : Element, ext : Element):
 
 
 String function get_taskname():
 String function get_taskname():
 	return reverseKeyLookup(read_root(), read_taskroot())!
 	return reverseKeyLookup(read_root(), read_taskroot())!
+
+Element function alphabet():
+	Element chars
+	chars = list_create()
+	list_append(chars, "a")
+	list_append(chars, "b")
+	list_append(chars, "c")
+	list_append(chars, "d")
+	list_append(chars, "e")
+	list_append(chars, "f")
+	list_append(chars, "g")
+	list_append(chars, "h")
+	list_append(chars, "i")
+	list_append(chars, "j")
+	list_append(chars, "k")
+	list_append(chars, "l")
+	list_append(chars, "m")
+	list_append(chars, "n")
+	list_append(chars, "o")
+	list_append(chars, "p")
+	list_append(chars, "q")
+	list_append(chars, "s")
+	list_append(chars, "t")
+	list_append(chars, "u")
+	list_append(chars, "v")
+	list_append(chars, "w")
+	list_append(chars, "x")
+	list_append(chars, "y")
+	list_append(chars, "z")
+	return chars!

+ 2 - 2
integration/code/pm_pn_reachability.mvc

@@ -14,11 +14,11 @@ Exec reachability_print{
 }
 }
 
 
 Data pn {
 Data pn {
-    name = "test/pn"
+    name = "pn"
     type = "test/PetriNet"
     type = "test/PetriNet"
 }
 }
 Data reachability_graph {
 Data reachability_graph {
-    name = "test/reachability"
+    name = "reachability"
     type = "test/ReachabilityGraph"
     type = "test/ReachabilityGraph"
 }
 }
 
 

+ 2 - 2
integration/test_powerwindow.py

@@ -93,7 +93,7 @@ class TestPowerWindow(unittest.TestCase):
             }
             }
 
 
         try:
         try:
-            process_execute("models/pm_powerwindow", "pm_", callbacks)
+            process_execute("models/pm_powerwindow", {}, callbacks)
         except:
         except:
             import traceback
             import traceback
             print(traceback.format_exc())
             print(traceback.format_exc())
@@ -194,7 +194,7 @@ class TestPowerWindow(unittest.TestCase):
                 "models/bfs": (ctrl, "inp", "outp"),
                 "models/bfs": (ctrl, "inp", "outp"),
             }
             }
 
 
-        process_execute("models/pm_powerwindow", "pm_", callbacks)
+        process_execute("models/pm_powerwindow", {}, callbacks)
 
 
         thrd.join()
         thrd.join()
 
 

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

@@ -1,3 +1,4 @@
 Float function random()
 Float function random()
 Integer function random_interval(a : Integer, b : Integer)
 Integer function random_interval(a : Integer, b : Integer)
 Element function random_choice(list : Element)
 Element function random_choice(list : Element)
+String function random_string(length : Integer)

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

@@ -4,3 +4,4 @@ Element function list_splice(lst : Element, start : Integer, end : Integer)
 Void function list_extend(lst : Element, ext : Element)
 Void function list_extend(lst : Element, ext : Element)
 String function get_taskname()
 String function get_taskname()
 Void function sleep(seconds : Float)
 Void function sleep(seconds : Float)
+Element function alphabet()

+ 12 - 12
models/pm_req_analyse.mvc

@@ -68,51 +68,51 @@ Exec bfs {
 Decision found {}
 Decision found {}
 
 
 Data req {
 Data req {
-    name = "models/requirements"
+    name = "requirements"
     type = "formalisms/Requirements"
     type = "formalisms/Requirements"
 }
 }
 Data plant_model {
 Data plant_model {
-    name = "models/plant_model"
+    name = "plant_model"
     type = "formalisms/PW_Plant"
     type = "formalisms/PW_Plant"
 }
 }
 Data environment_model {
 Data environment_model {
-    name = "models/environment_model"
+    name = "environment_model"
     type = "formalisms/PW_Environment"
     type = "formalisms/PW_Environment"
 }
 }
 Data control_model {
 Data control_model {
-    name = "models/control_model"
+    name = "control_model"
     type = "formalisms/PW_Control"
     type = "formalisms/PW_Control"
 }
 }
 Data plant_EPN {
 Data plant_EPN {
-    name = "models/plant_EPN"
+    name = "plant_EPN"
     type = "formalisms/Encapsulated_PetriNet"
     type = "formalisms/Encapsulated_PetriNet"
 }
 }
 Data control_EPN {
 Data control_EPN {
-    name = "models/control_EPN"
+    name = "control_EPN"
     type = "formalisms/Encapsulated_PetriNet"
     type = "formalisms/Encapsulated_PetriNet"
 }
 }
 Data environment_EPN {
 Data environment_EPN {
-    name = "models/environment_EPN"
+    name = "environment_EPN"
     type = "formalisms/Encapsulated_PetriNet"
     type = "formalisms/Encapsulated_PetriNet"
 }
 }
 Data pn {
 Data pn {
-    name = "models/pn"
+    name = "pn"
     type = "formalisms/PetriNet"
     type = "formalisms/PetriNet"
 }
 }
 Data reachability_graph {
 Data reachability_graph {
-    name = "models/reachability"
+    name = "reachability"
     type = "formalisms/ReachabilityGraph"
     type = "formalisms/ReachabilityGraph"
 }
 }
 Data query {
 Data query {
-    name = "models/query"
+    name = "query"
     type = "formalisms/Query"
     type = "formalisms/Query"
 }
 }
 Data architecture {
 Data architecture {
-    name = "models/architecture"
+    name = "architecture"
     type = "formalisms/Architecture"
     type = "formalisms/Architecture"
 }
 }
 Data merged_EPN {
 Data merged_EPN {
-    name = "models/merged_EPN"
+    name = "merged_EPN"
     type = "formalisms/Encapsulated_PetriNet"
     type = "formalisms/Encapsulated_PetriNet"
 }
 }
 
 

+ 12 - 12
models/pm_req_analyse_debug.mvc

@@ -81,51 +81,51 @@ Exec bfs {
 Decision found {}
 Decision found {}
 
 
 Data req {
 Data req {
-    name = "models/requirements"
+    name = "requirements"
     type = "formalisms/Requirements"
     type = "formalisms/Requirements"
 }
 }
 Data plant_model {
 Data plant_model {
-    name = "models/plant_model"
+    name = "plant_model"
     type = "formalisms/PW_Plant"
     type = "formalisms/PW_Plant"
 }
 }
 Data environment_model {
 Data environment_model {
-    name = "models/environment_model"
+    name = "environment_model"
     type = "formalisms/PW_Environment"
     type = "formalisms/PW_Environment"
 }
 }
 Data control_model {
 Data control_model {
-    name = "models/control_model"
+    name = "control_model"
     type = "formalisms/PW_Control"
     type = "formalisms/PW_Control"
 }
 }
 Data plant_EPN {
 Data plant_EPN {
-    name = "models/plant_EPN"
+    name = "plant_EPN"
     type = "formalisms/Encapsulated_PetriNet"
     type = "formalisms/Encapsulated_PetriNet"
 }
 }
 Data control_EPN {
 Data control_EPN {
-    name = "models/control_EPN"
+    name = "control_EPN"
     type = "formalisms/Encapsulated_PetriNet"
     type = "formalisms/Encapsulated_PetriNet"
 }
 }
 Data environment_EPN {
 Data environment_EPN {
-    name = "models/environment_EPN"
+    name = "environment_EPN"
     type = "formalisms/Encapsulated_PetriNet"
     type = "formalisms/Encapsulated_PetriNet"
 }
 }
 Data pn {
 Data pn {
-    name = "models/pn"
+    name = "pn"
     type = "formalisms/PetriNet"
     type = "formalisms/PetriNet"
 }
 }
 Data reachability_graph {
 Data reachability_graph {
-    name = "models/reachability"
+    name = "reachability"
     type = "formalisms/ReachabilityGraph"
     type = "formalisms/ReachabilityGraph"
 }
 }
 Data query {
 Data query {
-    name = "models/query"
+    name = "query"
     type = "formalisms/Query"
     type = "formalisms/Query"
 }
 }
 Data architecture {
 Data architecture {
-    name = "models/architecture"
+    name = "architecture"
     type = "formalisms/Architecture"
     type = "formalisms/Architecture"
 }
 }
 Data merged_EPN {
 Data merged_EPN {
-    name = "models/merged_EPN"
+    name = "merged_EPN"
     type = "formalisms/Encapsulated_PetriNet"
     type = "formalisms/Encapsulated_PetriNet"
 }
 }
 
 

+ 0 - 5
scripts/HUTN_service.py

@@ -26,7 +26,6 @@ def clean_code(code):
     return code
     return code
 
 
 def compile_service(port):
 def compile_service(port):
-    print("Start with port " + str(port))
     start = time.time()
     start = time.time()
     temp_file = ".tmp_%s" % port
     temp_file = ".tmp_%s" % port
 
 
@@ -60,7 +59,6 @@ def compile_service(port):
 
 
     mode = service_get(port)
     mode = service_get(port)
     code = service_get(port)
     code = service_get(port)
-    print("Service set: " + str(port))
 
 
     try:
     try:
         if mode == "code":
         if mode == "code":
@@ -76,11 +74,8 @@ def compile_service(port):
     except Exception as e:
     except Exception as e:
         service_set(port, str(e))
         service_set(port, str(e))
         raise
         raise
-    print("Compile took %ss" % (time.time() - start))
 
 
-print("Start service")
 service_register("compiler", compile_service)
 service_register("compiler", compile_service)
-print("Service OK")
 
 
 try:
 try:
     while raw_input() != "STOP":
     while raw_input() != "STOP":

+ 0 - 1
scripts/JSON_service.py

@@ -74,7 +74,6 @@ def json_service(port):
     except Exception as e:
     except Exception as e:
         service_set(port, str(e))
         service_set(port, str(e))
         raise
         raise
-    print("JSON took %ss" % (time.time() - start))
 
 
 service_register("JSON", json_service)
 service_register("JSON", json_service)
 
 

+ 3 - 1
unit/test_all.py

@@ -272,17 +272,19 @@ class TestModelverse(unittest.TestCase):
         thrd.daemon = True
         thrd.daemon = True
         thrd.start()
         thrd.start()
 
 
-        process_execute("test/pn_reachability", "", {"test/refine_PN": callback_refine_PN, "test/reachability_print": (ctrl, "inp", "outp")})
+        process_execute("test/pn_reachability", {}, {"test/refine_PN": callback_refine_PN, "test/reachability_print": (ctrl, "inp", "outp")})
         thrd.join()
         thrd.join()
 
 
         assert set(log) == set(['"0": {"p1": 1}',
         assert set(log) == set(['"0": {"p1": 1}',
                                 '"1": {"p1": 0}',
                                 '"1": {"p1": 0}',
                                 '"0" --["t1"]--> "1"'])
                                 '"0" --["t1"]--> "1"'])
 
 
+        model_delete(".tmp")
         model_delete("RAMified")
         model_delete("RAMified")
         model_delete("merged")
         model_delete("merged")
         model_delete("type mappings/RAMified")
         model_delete("type mappings/RAMified")
         model_delete("type mappings/merged")
         model_delete("type mappings/merged")
+        model_delete("type mappings/.tmp")
 
 
     def test_render(self):
     def test_render(self):
         model_add("test/CausalBlockDiagrams", "formalisms/SimpleClassDiagrams", open("integration/code/cbd_design.mvc", 'r').read())
         model_add("test/CausalBlockDiagrams", "formalisms/SimpleClassDiagrams", open("integration/code/cbd_design.mvc", 'r').read())

+ 1 - 1
wrappers/classes/modelverse.xml

@@ -764,7 +764,7 @@
                             <state id="init">
                             <state id="init">
                                 <onentry>
                                 <onentry>
                                     <raise event="request">
                                     <raise event="request">
-                                        <parameter expr="['process_execute', self.parameters[0], self.parameters[1]]"/>
+                                        <parameter expr="['process_execute', self.parameters[0]] + self.dict_to_list(self.parameters[1])"/>
                                     </raise>
                                     </raise>
                                 </onentry>
                                 </onentry>
 
 

+ 2 - 2
wrappers/modelverse_SCCD.py

@@ -1,7 +1,7 @@
 """
 """
 Generated by Statechart compiler by Glenn De Jonghe, Joeri Exelmans, Simon Van Mierlo, and Yentl Van Tendeloo (for the inspiration)
 Generated by Statechart compiler by Glenn De Jonghe, Joeri Exelmans, Simon Van Mierlo, and Yentl Van Tendeloo (for the inspiration)
 
 
-Date:   Tue Oct 31 13:36:27 2017
+Date:   Tue Nov  7 09:15:30 2017
 
 
 Model author: Yentl Van Tendeloo
 Model author: Yentl Van Tendeloo
 Model name:   MvK Server
 Model name:   MvK Server
@@ -2037,7 +2037,7 @@ class Modelverse(RuntimeClassBase):
         self.raiseInternalEvent(Event("result", None, [self.context]))
         self.raiseInternalEvent(Event("result", None, [self.context]))
     
     
     def _initialized_behaviour_operations_store_on_scripted_process_execute_init_enter(self):
     def _initialized_behaviour_operations_store_on_scripted_process_execute_init_enter(self):
-        self.raiseInternalEvent(Event("request", None, [['process_execute', self.parameters[0], self.parameters[1]]]))
+        self.raiseInternalEvent(Event("request", None, [['process_execute', self.parameters[0]] + self.dict_to_list(self.parameters[1])]))
     
     
     def _initialized_behaviour_operations_permission_modify_enter(self):
     def _initialized_behaviour_operations_permission_modify_enter(self):
         self.raiseInternalEvent(Event("request", None, [['permission_modify', self.parameters[0], self.parameters[1]]]))
         self.raiseInternalEvent(Event("request", None, [['permission_modify', self.parameters[0], self.parameters[1]]]))