Browse Source

Various patches

Yentl Van Tendeloo 7 years ago
parent
commit
cbee919d72

+ 0 - 1
models/WSC/DEVS_merge.alc

@@ -24,6 +24,5 @@ Boolean function main(model : Element):
 			type = list_read(split, 1)
 			// Strip of the part before the / and make it into "DEVS"
 			retype(model, key, "result/" + type)
-			log("Retype!")
 
 	return True!

+ 3 - 12
models/WSC/DEVS_simulate.alc

@@ -7,8 +7,6 @@ include "io.alh"
 include "typing.alh"
 
 Boolean function main(model : Element):
-    log("Translating DEVS to string representation!")
-
     String model_rep
     Element all_atomics
     Element curr_atomic
@@ -29,13 +27,13 @@ Boolean function main(model : Element):
     String curr_submodel_type
 	String curr_submodel_parameters
 
-    model_rep = "\nfrom DEVS import *\nfrom infinity import INFINITY\n\n"
+    model_rep = ""
 
     all_atomics = allInstances(model, "DEVS/AtomicDEVSBlock")
     while (read_nr_out(all_atomics) > 0):
         curr_atomic = set_pop(all_atomics)
         model_rep = model_rep + "class " + cast_string(read_attribute(model, curr_atomic, "name")) + "(AtomicDEVS):\n"
-        model_rep = model_rep + "\tdef __init__(self, name=" + cast_value(read_attribute(model, curr_atomic, "name")) + ", parameters):\n"
+        model_rep = model_rep + "\tdef __init__(self, name, parameters):\n"
 		model_rep = model_rep + "\t\tself.parameters = parameters\n"
         model_rep = model_rep + "\t\tAtomicDEVS.__init__(self, name)\n"
 		model_rep = model_rep + "\t\tself.initialState()\n"
@@ -62,7 +60,7 @@ Boolean function main(model : Element):
     while (read_nr_out(all_coupleds) > 0):
         curr_coupled = set_pop(all_coupleds)
         model_rep = model_rep + "class " + cast_string(read_attribute(model, curr_coupled, "name")) + "(CoupledDEVS):\n"
-        model_rep = model_rep + "\tdef __init__(self, name=" + cast_value(read_attribute(model, curr_coupled, "name")) + "):\n"
+        model_rep = model_rep + "\tdef __init__(self, name, parameters):\n"
         model_rep = model_rep + "\t\tCoupledDEVS.__init__(self, name)\n"
         model_rep = model_rep + "\t\tself.my_ports = {"
         all_ports = allAssociationDestinations(model, curr_coupled, "DEVS/DEVSBlockToPort")
@@ -70,7 +68,6 @@ Boolean function main(model : Element):
             curr_port = set_pop(all_ports)
             curr_port_name = cast_value(read_attribute(model, curr_port, "name"))
             curr_port_type = read_type(model, curr_port)
-            log(curr_port_type)
             if (curr_port_type == "DEVS/InputPort"):
                 model_rep = model_rep + curr_port_name + ": self.addInPort(" + curr_port_name + ")"
             if (curr_port_type == "DEVS/OutputPort"):
@@ -101,12 +98,10 @@ Boolean function main(model : Element):
         while (read_nr_out(all_submodels) > 0):
             curr_submodel = set_pop(all_submodels)
             curr_submodel_name = cast_value(read_attribute(model, curr_submodel, "name"))
-            log(curr_submodel_name)
             all_ports = allAssociationDestinations(model, curr_submodel, "DEVS/DEVSInstanceToPort")
             while (read_nr_out(all_ports) > 0):
                 curr_port = set_pop(all_ports)
                 out_channels = allAssociationDestinations(model, curr_port, "DEVS/Channel")
-                log(cast_value(read_nr_out(out_channels)))
                 while (read_nr_out(out_channels) > 0):
                     curr_channel = set_pop(out_channels)
                     possible_parent = allAssociationOrigins(model, curr_channel, "DEVS/DEVSInstanceToPort")
@@ -125,16 +120,12 @@ Boolean function main(model : Element):
     String devs_model
 	port = comm_connect("pypdevs_simulator")
         
-    log("(PDEVS) task name = " + get_taskname())
-    log("(PDEVS) Sending model...")
     comm_set(port, model_rep)
-    log("(PDEVS) " + port)
 
 	comm_set(port, "[\"simulate\"]")
     
     while (True):
         if (comm_hasInput(port)):
-            log(cast_value(has_input()))
             the_input = comm_get(port)
             log("(PDEVS) Got input from simulator!")
             log("(PDEVS) " + the_input)

+ 98 - 2
models/WSC/PM_to_DEVS.mvc

@@ -45,12 +45,29 @@ Composite schedule {
             }
         }
     }
+
+    {Contains} Atomic root_model {
+        LHS {}
+
+        RHS {
+            Post_DEVS/CoupledDEVSBlock post_root_0 {
+                label = "0"
+                value_name = $
+                    String function value(model : Element, name : String, mapping : Element):
+                        return "Root"!
+                    $
+            }
+        }
+    }
     
     {Contains} ForAll initial {
         LHS {
             Pre_PM/Initial pre_init_0 {
                 label = "0"
             }
+            Pre_DEVS/CoupledDEVSBlock pre_init_999 {
+                label = "root"
+            }
         }
 
         RHS {
@@ -86,6 +103,13 @@ Composite schedule {
             Post_DEVS/DEVSInstanceToPort (post_init_1, post_init_2) {
                 label = "4"
             }
+
+            Post_DEVS/CoupledDEVSBlock post_init_999 {
+                label = "root"
+            }
+            Post_DEVS/SubModel (post_init_999, post_init_1) {
+                label = "submodel"
+            }
         }
     }
     
@@ -94,6 +118,9 @@ Composite schedule {
             Pre_PM/Finish pre_finish_0 {
                 label = "0"
             }
+            Pre_DEVS/CoupledDEVSBlock pre_finish_999 {
+                label = "root"
+            }
         }
 
         RHS {
@@ -129,6 +156,13 @@ Composite schedule {
             Post_DEVS/DEVSInstanceToPort (post_finish_1, post_finish_2) {
                 label = "4"
             }
+
+            Post_DEVS/CoupledDEVSBlock post_finish_999 {
+                label = "root"
+            }
+            Post_DEVS/SubModel (post_finish_999, post_finish_1) {
+                label = "submodel"
+            }
         }
     }
     
@@ -137,6 +171,9 @@ Composite schedule {
             Pre_PM/Activity pre_activity_0 {
                 label = "0"
             }
+            Pre_DEVS/CoupledDEVSBlock pre_activity_999 {
+                label = "root"
+            }
         }
 
         RHS {
@@ -205,6 +242,13 @@ Composite schedule {
             Post_DEVS/DEVSInstanceToPort (post_activity_1, post_activity_5) {
                 label = "10"
             }
+
+            Post_DEVS/CoupledDEVSBlock post_activity_999 {
+                label = "root"
+            }
+            Post_DEVS/SubModel (post_activity_999, post_activity_1) {
+                label = "submodel"
+            }
         }
     }
 
@@ -213,6 +257,9 @@ Composite schedule {
             Pre_PM/ParallelSplit pre_split_0 {
                 label = "0"
             }
+            Pre_DEVS/CoupledDEVSBlock pre_split_999 {
+                label = "root"
+            }
         }
 
         RHS {
@@ -259,6 +306,13 @@ Composite schedule {
             Post_DEVS/DEVSInstanceToPort (post_split_1, post_split_3) {
                 label = "6"
             }
+
+            Post_DEVS/CoupledDEVSBlock post_split_999 {
+                label = "root"
+            }
+            Post_DEVS/SubModel (post_split_999, post_split_1) {
+                label = "submodel"
+            }
         }
     }
 
@@ -267,6 +321,9 @@ Composite schedule {
             Pre_PM/Synchronization pre_sync_0 {
                 label = "0"
             }
+            Pre_DEVS/CoupledDEVSBlock pre_sync_999 {
+                label = "root"
+            }
         }
 
         RHS {
@@ -313,6 +370,13 @@ Composite schedule {
             Post_DEVS/DEVSInstanceToPort (post_sync_1, post_sync_3) {
                 label = "6"
             }
+
+            Post_DEVS/CoupledDEVSBlock post_sync_999 {
+                label = "root"
+            }
+            Post_DEVS/SubModel (post_sync_999, post_sync_1) {
+                label = "submodel"
+            }
         }
     }
 
@@ -321,6 +385,9 @@ Composite schedule {
             Pre_PM/ExclusiveChoice pre_xor_0 {
                 label = "0"
             }
+            Pre_DEVS/CoupledDEVSBlock pre_xor_999 {
+                label = "root"
+            }
         }
 
         RHS {
@@ -377,6 +444,13 @@ Composite schedule {
             Post_DEVS/DEVSInstanceToPort (post_xor_1, post_xor_4) {
                 label = "8"
             }
+
+            Post_DEVS/CoupledDEVSBlock post_xor_999 {
+                label = "root"
+            }
+            Post_DEVS/SubModel (post_xor_999, post_xor_1) {
+                label = "submodel"
+            }
         }
     }
 
@@ -385,6 +459,9 @@ Composite schedule {
             Pre_PM/SimpleMerge pre_merge_0 {
                 label = "0"
             }
+            Pre_DEVS/CoupledDEVSBlock pre_merge_999 {
+                label = "root"
+            }
         }
 
         RHS {
@@ -431,6 +508,13 @@ Composite schedule {
             Post_DEVS/DEVSInstanceToPort (post_merge_1, post_merge_3) {
                 label = "6"
             }
+
+            Post_DEVS/CoupledDEVSBlock post_merge_999 {
+                label = "root"
+            }
+            Post_DEVS/SubModel (post_merge_999, post_merge_1) {
+                label = "submodel"
+            }
         }
     }
 
@@ -439,6 +523,9 @@ Composite schedule {
             Pre_PM/MultiInstance pre_multi_0 {
                 label = "0"
             }
+            Pre_DEVS/CoupledDEVSBlock pre_multi_999 {
+                label = "root"
+            }
         }
 
         RHS {
@@ -507,6 +594,13 @@ Composite schedule {
             Post_DEVS/DEVSInstanceToPort (post_multi_1, post_multi_5) {
                 label = "10"
             }
+
+            Post_DEVS/CoupledDEVSBlock post_multi_999 {
+                label = "root"
+            }
+            Post_DEVS/SubModel (post_multi_999, post_multi_1) {
+                label = "submodel"
+            }
         }
     }
 
@@ -774,7 +868,6 @@ Composite schedule {
             Pre_PM/DecisionTrue (pre_mdt_4, pre_mdt_5) {
                 label = "10"
             }
-
         }
     
         RHS {
@@ -908,7 +1001,10 @@ Composite schedule {
     }
 }
 
-Initial (schedule, initial) {}
+Initial (schedule, root_model) {}
+
+OnSuccess (root_model, initial) {}
+OnFailure (root_model, initial) {}
 
 OnSuccess (initial, add_resource_handler) {}
 OnFailure (initial, add_resource_handler) {}

+ 3 - 1
models/WSC/pm.mvc

@@ -2,7 +2,9 @@ SimpleAttribute String {}
 SimpleAttribute Natural {}
 SimpleAttribute PythonCode {}
 
-Class ProcessNode {}
+Class ProcessNode {
+    name : String
+}
 
 Class Initial : ProcessNode {}
 

+ 29 - 32
models/WSC/pm_example.mvc

@@ -1,45 +1,42 @@
-Initial init {}
+Initial init {
+    name = "initial"
+}
 Activity req {
-    distribution = """
-        def func(iteration):
-            return iteration
-        return func
-        """
+    name = "define_requirements"
+    distribution = "lambda iteration: lambda: iteration"
+}
+SimpleMerge merge {
+    name = "merge_0"
 }
-SimpleMerge merge {}
 Activity model {
-    distribution = """
-        def func(iteration):
-            return iteration
-        return func
-        """
+    name = "model_system"
+    distribution = "lambda iteration: lambda: iteration"
+}
+ParallelSplit split {
+    name = "split_0"
 }
-ParallelSplit split {}
 MultiInstance simulate {
+    name = "simulate"
     nr_instances = 10
-    distribution = """
-        def func(iteration):
-            return iteration
-        return func
-        """
+    distribution = "lambda iteration: lambda: iteration"
 }
 Activity check {
-    distribution = """
-        def func(iteration):
-            return iteration
-        return func
-        """
+    name = "check"
+    distribution = "lambda iteration: lambda: iteration"
+}
+Synchronization sync {
+    name = "sync_0"
 }
-Synchronization sync {}
 Activity evaluate {
-    distribution = """
-        def func(iteration):
-            return iteration
-        return func
-        """
-}
-ExclusiveChoice choice {}
-Finish finish {}
+    name = "evaluate"
+    distribution = "lambda iteration: lambda: iteration"
+}
+ExclusiveChoice choice {
+    name = "xor_0"
+}
+Finish finish {
+    name = "finish"
+}
 
 Next (init, req) {}
 Next (req, merge) {}

+ 63 - 0
models/WSC/pm_library.mvc

@@ -1,3 +1,66 @@
+AtomicDEVSBlock Initial {
+    name = "Initial"
+
+    initialState = """
+        self.state, self.elapsed = True, 0.0
+    """
+
+    timeAdvance = """
+        if self.state:
+            return 0.0
+        else:
+            return float('inf')
+    """
+
+    outputFnc = """
+        return {self.control_out: {}}
+    """
+
+    intTransition = """
+        return False
+    """
+
+    extTransition = """
+        return None
+    """
+
+}
+
+OutputPort init_co {
+    name = "control_out"
+}
+DEVSBlockToPort (Initial, init_co) {}
+
+AtomicDEVSBlock Finish {
+    name = "Finish"
+
+    initialState = """
+        self.state, self.elapsed = None, 0.0
+    """
+
+    timeAdvance = """
+        return float('inf')
+    """
+
+    outputFnc = """
+        return {}
+    """
+
+    intTransition = """
+        return None
+    """
+
+    extTransition = """
+        return self.elapsed
+    """
+
+}
+
+InputPort finish_ci {
+    name = "control_in"
+}
+DEVSBlockToPort (Finish, finish_ci) {}
+
 AtomicDEVSBlock ResourceHandler {
     name = "ResourceHandler"
 

+ 5 - 4
services/DEVS/main.py

@@ -6,17 +6,18 @@ from pprint import pprint
 from multiprocessing import Process, Pipe, freeze_support
 
 sys.path.append('services/DEVS/pypdevs/src')
-sys.path.append('services/DEVS/pypdevs/examples')
+sys.path.append('services/DEVS/pypdevs/models')
 
 from simulator import Controller
-from ps_model import Root
+from DEVS import AtomicDEVS, CoupledDEVS
+from infinity import INFINITY
 
 import threading, time
 
 def pypdevs_service(port):
-    exec(service_get(port), globals(), {})
+    exec(service_get(port), globals(), locals())
 
-    controller = Controller(Root())
+    controller = Controller(Root("Root", []))
 
     def inputter():
         print("Waiting for input...")

+ 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 11:14:00 2018
+Date:   Tue May 15 12:53:42 2018
 
 Model author: Yentl Van Tendeloo
 Model name:   MvK Server