Parcourir la source

Fix DEVS service to correctly include models

Yentl Van Tendeloo il y a 7 ans
Parent
commit
1c227454de

+ 4 - 4
bootstrap/transform.alc

@@ -299,7 +299,7 @@ Element function match(host_model : Element, schedule_model : Element, LHS : Str
 	set_add_node(mappings, initial_mapping)
 	set_add_node(mappings, initial_mapping)
 	while (list_len(schedule) > 0):
 	while (list_len(schedule) > 0):
 		current_element = list_pop(schedule, list_len(schedule) - 1)
 		current_element = list_pop(schedule, list_len(schedule) - 1)
-		log("Binding element with label " + cast_value(read_attribute(schedule_model, current_element, "label")))
+		//log("Binding element with label " + cast_value(read_attribute(schedule_model, current_element, "label")))
 		new_mappings = dict_create()
 		new_mappings = dict_create()
 
 
 		while (set_len(mappings) > 0):
 		while (set_len(mappings) > 0):
@@ -313,7 +313,7 @@ Element function match(host_model : Element, schedule_model : Element, LHS : Str
 				set_add_node(new_mappings, new_map)
 				set_add_node(new_mappings, new_map)
 
 
 		mappings = new_mappings
 		mappings = new_mappings
-		log("Remaining options: " + cast_value(set_len(mappings)))
+		//log("Remaining options: " + cast_value(set_len(mappings)))
 
 
 		if (set_len(mappings) == 0):
 		if (set_len(mappings) == 0):
 			// Stop because we have no more options remaining!
 			// Stop because we have no more options remaining!
@@ -565,12 +565,12 @@ Boolean function transform_forall(host_model : Element, schedule_model : Element
 	else:
 	else:
 		result = False
 		result = False
 
 
-	log("Matches in forall: " + cast_string(set_len(mappings)))
+	//log("Matches in forall: " + cast_string(set_len(mappings)))
 	while (set_len(mappings) > 0):
 	while (set_len(mappings) > 0):
 		mapping = set_pop(mappings)
 		mapping = set_pop(mappings)
 		RHS = set_pop(allAssociationDestinations(schedule_model, current, "RHSLink"))
 		RHS = set_pop(allAssociationDestinations(schedule_model, current, "RHSLink"))
 		rewrite(host_model, schedule_model, RHS, mapping)
 		rewrite(host_model, schedule_model, RHS, mapping)
-	log("Rewrite OK")
+	//log("Rewrite OK")
 
 
 	return result!
 	return result!
 
 

+ 3 - 1
models/WSC/DEVS_simulate.alc

@@ -27,7 +27,9 @@ Boolean function main(model : Element):
     String curr_submodel_type
     String curr_submodel_type
 	String curr_submodel_parameters
 	String curr_submodel_parameters
 
 
-    model_rep = ""
+	model_rep = ""
+    model_rep = model_rep + "from DEVS import AtomicDEVS, CoupledDEVS\n"
+	model_rep = model_rep + "from infinity import INFINITY\n"
 
 
     all_atomics = allInstances(model, "DEVS/AtomicDEVSBlock")
     all_atomics = allInstances(model, "DEVS/AtomicDEVSBlock")
     while (read_nr_out(all_atomics) > 0):
     while (read_nr_out(all_atomics) > 0):

+ 9 - 2
services/DEVS/main.py

@@ -15,10 +15,17 @@ from infinity import INFINITY
 import threading, time
 import threading, time
 
 
 def pypdevs_service(port):
 def pypdevs_service(port):
-    exec(service_get(port), globals(), locals())
+    code = service_get(port)
+    model_name = str(uuid.uuid4()).replace("-", "")
 
 
-    controller = Controller(Root("Root", []))
+    with open("services/DEVS/pypdevs/models/" + model_name + ".py", 'w') as f:
+        f.write(code)
 
 
+    Root = getattr(__import__(model_name), "Root")
+    controller = Controller(Root('Root', []))
+    run_simulation(port, controller)
+
+def run_simulation(port, controller):
     def inputter():
     def inputter():
         print("Waiting for input...")
         print("Waiting for input...")
         while 1:
         while 1:

+ 1 - 1
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 May 15 12:53:42 2018
+Date:   Tue May 15 13:44:39 2018
 
 
 Model author: Yentl Van Tendeloo
 Model author: Yentl Van Tendeloo
 Model name:   MvK Server
 Model name:   MvK Server