瀏覽代碼

Fix DEVS service to correctly include models

Yentl Van Tendeloo 7 年之前
父節點
當前提交
1c227454de
共有 4 個文件被更改,包括 17 次插入8 次删除
  1. 4 4
      bootstrap/transform.alc
  2. 3 1
      models/WSC/DEVS_simulate.alc
  3. 9 2
      services/DEVS/main.py
  4. 1 1
      wrappers/modelverse_SCCD.py

+ 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)
 	while (list_len(schedule) > 0):
 		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()
 
 		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)
 
 		mappings = new_mappings
-		log("Remaining options: " + cast_value(set_len(mappings)))
+		//log("Remaining options: " + cast_value(set_len(mappings)))
 
 		if (set_len(mappings) == 0):
 			// Stop because we have no more options remaining!
@@ -565,12 +565,12 @@ Boolean function transform_forall(host_model : Element, schedule_model : Element
 	else:
 		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):
 		mapping = set_pop(mappings)
 		RHS = set_pop(allAssociationDestinations(schedule_model, current, "RHSLink"))
 		rewrite(host_model, schedule_model, RHS, mapping)
-	log("Rewrite OK")
+	//log("Rewrite OK")
 
 	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_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")
     while (read_nr_out(all_atomics) > 0):

+ 9 - 2
services/DEVS/main.py

@@ -15,10 +15,17 @@ from infinity import INFINITY
 import threading, time
 
 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():
         print("Waiting for input...")
         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)
 
-Date:   Tue May 15 12:53:42 2018
+Date:   Tue May 15 13:44:39 2018
 
 Model author: Yentl Van Tendeloo
 Model name:   MvK Server