Explorar o código

PM execution takes a dictionary for binding

Yentl Van Tendeloo %!s(int64=7) %!d(string=hai) anos
pai
achega
e56bbdf958

+ 46 - 8
bootstrap/core_algorithm.alc

@@ -13,6 +13,7 @@ include "utils.alh"
 include "conformance_finding.alh"
 include "typing.alh"
 include "compiler.alh"
+include "random.alh"
 
 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")
 		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
 	String transformation_id
 	Element lst
@@ -796,7 +797,7 @@ Boolean function enact_action(pm : Element, element : String, prefix : String):
 	while (set_len(lst) > 0):
 		consume = set_pop(lst)
 		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
 	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")
 		elem_name = read_attribute(pm, elem, "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":
 		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]))
 		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
 	String element
 	String type
@@ -842,9 +856,28 @@ Void function enact_PM(pm : Element, prefix : String):
 	Element tuple
 	Element counters
 	Element join_nodes
+	Element keys
+	String key
 
 	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
 	counters = dict_create()
 	join_nodes = allInstances(pm, "Join")
@@ -897,7 +930,7 @@ Void function enact_PM(pm : Element, prefix : String):
 			// Execute a transformation
 			// This the difficult part!
 
-			result = enact_action(pm, element, prefix)
+			result = enact_action(pm, element, mapping)
 			output("Success")
 
 		elif (type == "Decision"):
@@ -921,6 +954,11 @@ Void function enact_PM(pm : Element, prefix : String):
 			set_add_node(worklist, create_tuple(next, result))
 
 	// 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 !
 
 String function cmd_help():
@@ -1017,7 +1055,7 @@ String function cmd_model_add(type : String, name : String, code : String):
 	else:
 		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
 	String process_id
 
@@ -1029,7 +1067,7 @@ String function cmd_process_execute(process : String, prefix : String):
 			if (element_eq(pm, read_root())):
 				return "Specified model cannot be interpreted as a ProcessModel: " + process!
 
-			enact_PM(pm, prefix)
+			enact_PM(pm, mapping)
 			return "Success"!
 		else:
 			return "Permission denied to model: " + process!
@@ -2187,7 +2225,7 @@ Void function user_function_skip_init(user_id : String):
 		elif (cmd == "model_add"):
 			output(cmd_model_add(single_input("Model type?"), single_input("Model name?"), single_input("Model textual representation?")))
 		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"):
 			output(cmd_transformation_between(dict_input("Source signature?"), dict_input("Target signature?")))
 		elif (cmd == "model_render"):

+ 11 - 0
bootstrap/random.alc

@@ -1,4 +1,5 @@
 include "primitives.alh"
+include "utils.alh"
 
 Integer seed = 1
 
@@ -30,3 +31,13 @@ Element function random_choice(list : Element):
 		return read_root()!
 	else:
 		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():
 	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 {
-    name = "test/pn"
+    name = "pn"
     type = "test/PetriNet"
 }
 Data reachability_graph {
-    name = "test/reachability"
+    name = "reachability"
     type = "test/ReachabilityGraph"
 }
 

+ 2 - 2
integration/test_powerwindow.py

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

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

@@ -1,3 +1,4 @@
 Float function random()
 Integer function random_interval(a : Integer, b : Integer)
 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)
 String function get_taskname()
 Void function sleep(seconds : Float)
+Element function alphabet()

+ 12 - 12
models/pm_req_analyse.mvc

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

+ 12 - 12
models/pm_req_analyse_debug.mvc

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

+ 0 - 5
scripts/HUTN_service.py

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

+ 0 - 1
scripts/JSON_service.py

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

+ 3 - 1
unit/test_all.py

@@ -272,17 +272,19 @@ class TestModelverse(unittest.TestCase):
         thrd.daemon = True
         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()
 
         assert set(log) == set(['"0": {"p1": 1}',
                                 '"1": {"p1": 0}',
                                 '"0" --["t1"]--> "1"'])
 
+        model_delete(".tmp")
         model_delete("RAMified")
         model_delete("merged")
         model_delete("type mappings/RAMified")
         model_delete("type mappings/merged")
+        model_delete("type mappings/.tmp")
 
     def test_render(self):
         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">
                                 <onentry>
                                     <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>
                                 </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)
 
-Date:   Tue Oct 31 13:36:27 2017
+Date:   Tue Nov  7 09:15:30 2017
 
 Model author: Yentl Van Tendeloo
 Model name:   MvK Server
@@ -2037,7 +2037,7 @@ class Modelverse(RuntimeClassBase):
         self.raiseInternalEvent(Event("result", None, [self.context]))
     
     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):
         self.raiseInternalEvent(Event("request", None, [['permission_modify', self.parameters[0], self.parameters[1]]]))