瀏覽代碼

Added lots of transformations, with minor patches

Yentl Van Tendeloo 7 年之前
父節點
當前提交
ea76d18d8d
共有 5 個文件被更改,包括 352 次插入53 次删除
  1. 308 1
      models/WSC/PM_to_DEVS.mvc
  2. 2 0
      models/WSC/pm.mvc
  3. 1 2
      models/WSC/pm_PM_to_DEVS.mvc
  4. 40 49
      models/WSC/pm_library.mvc
  5. 1 1
      wrappers/modelverse_SCCD.py

+ 308 - 1
models/WSC/PM_to_DEVS.mvc

@@ -4,7 +4,6 @@ include "object_oeprations.alh"
 
 Composite schedule {
     {Contains} Success success {}
-    {Contains} Failure failure {}
 
     {Contains} Atomic add_resource_handler {
         LHS {}
@@ -551,4 +550,312 @@ Composite schedule {
             }
         }
     }
+
+    {Contains} ForAll map_control {
+        LHS {
+            Pre_PM/ProcessNode pre_map_4 {
+                label = "6"
+            }
+            Pre_Trace (pre_map_4, pre_map_0) {
+                label = "7"
+            }
+            Pre_PM/ProcessNode pre_map_5 {
+                label = "8"
+            }
+            Pre_Trace (pre_map_5, pre_map_1) {
+                label = "9"
+            }
+            Pre_PM/Next (pre_map_4, pre_map_5) {
+                label = "10"
+            }
+
+            Pre_CDEVS/DEVSInstance pre_map_0 {
+                label = "0"
+            }
+            Pre_CDEVS/Port pre_map_1 {
+                label = "1"
+                constraint_name = $
+                    Boolean function constraint(model : Element, name : String):
+                        return (cast_string(read_attribute(model, name, "type")) == "control_out")!
+                    $
+            }
+            Pre_CDEVS/DEVSInstanceToPort (pre_map_0, pre_map_1) {
+                label = "2"
+            }
+
+            Pre_CDEVS/DEVSInstance pre_map_2 {
+                label = "3"
+            }
+            Pre_CDEVS/Port pre_map_3 {
+                label = "4"
+                constraint_name = $
+                    Boolean function constraint(model : Element, name : String):
+                        return (cast_string(read_attribute(model, name, "type")) == "control_in")!
+                    $
+            }
+            Pre_CDEVS/DEVSInstanceToPort (pre_map_2, pre_map_3) {
+                label = "5"
+            }
+        }
+    
+        RHS {
+            Post_CDEVS/DEVSInstance post_map_0 {
+                label = "0"
+            }
+            Post_CDEVS/Port post_map_1 {
+                label = "1"
+            }
+            Post_CDEVS/DEVSInstanceToPort (post_map_0, post_map_1) {
+                label = "2"
+            }
+
+            Post_CDEVS/DEVSInstance post_map_2 {
+                label = "3"
+            }
+            Post_CDEVS/Port post_map_3 {
+                label = "4"
+            }
+            Post_CDEVS/DEVSInstanceToPort (post_map_2, post_map_3) {
+                label = "5"
+            }
+
+            Post_PM/ProcessNode post_map_4 {
+                label = "6"
+            }
+            Post_Trace (post_map_4, post_map_0) {
+                label = "7"
+            }
+            Post_PM/ProcessNode post_map_5 {
+                label = "8"
+            }
+            Post_Trace (post_map_5, post_map_1) {
+                label = "9"
+            }
+            Post_PM/Next (post_map_4, post_map_5) {
+                label = "10"
+            }
+            Post_CDEVS/Channel (post_map_1, post_map_3) {
+                label = "11"
+            }
+        }
+    }
+
+    {Contains} ForAll map_control_decision_true {
+        LHS {
+            Pre_PM/ProcessNode pre_map_4 {
+                label = "6"
+            }
+            Pre_Trace (pre_map_4, pre_map_0) {
+                label = "7"
+            }
+            Pre_PM/ProcessNode pre_map_5 {
+                label = "8"
+            }
+            Pre_Trace (pre_map_5, pre_map_1) {
+                label = "9"
+            }
+            Pre_PM/DecisionTrue (pre_map_4, pre_map_5) {
+                label = "10"
+            }
+
+            Pre_CDEVS/DEVSInstance pre_map_0 {
+                label = "0"
+            }
+            Pre_CDEVS/Port pre_map_1 {
+                label = "1"
+                constraint_name = $
+                    Boolean function constraint(model : Element, name : String):
+                        return (cast_string(read_attribute(model, name, "type")) == "control_out1")!
+                    $
+            }
+            Pre_CDEVS/DEVSInstanceToPort (pre_map_0, pre_map_1) {
+                label = "2"
+            }
+
+            Pre_CDEVS/DEVSInstance pre_map_2 {
+                label = "3"
+            }
+            Pre_CDEVS/Port pre_map_3 {
+                label = "4"
+                constraint_name = $
+                    Boolean function constraint(model : Element, name : String):
+                        return (cast_string(read_attribute(model, name, "type")) == "control_in")!
+                    $
+            }
+            Pre_CDEVS/DEVSInstanceToPort (pre_map_2, pre_map_3) {
+                label = "5"
+            }
+        }
+    
+        RHS {
+            Post_CDEVS/DEVSInstance post_map_0 {
+                label = "0"
+            }
+            Post_CDEVS/Port post_map_1 {
+                label = "1"
+            }
+            Post_CDEVS/DEVSInstanceToPort (post_map_0, post_map_1) {
+                label = "2"
+            }
+
+            Post_CDEVS/DEVSInstance post_map_2 {
+                label = "3"
+            }
+            Post_CDEVS/Port post_map_3 {
+                label = "4"
+            }
+            Post_CDEVS/DEVSInstanceToPort (post_map_2, post_map_3) {
+                label = "5"
+            }
+
+            Post_PM/ProcessNode post_map_4 {
+                label = "6"
+            }
+            Post_Trace (post_map_4, post_map_0) {
+                label = "7"
+            }
+            Post_PM/ProcessNode post_map_5 {
+                label = "8"
+            }
+            Post_Trace (post_map_5, post_map_1) {
+                label = "9"
+            }
+            Post_PM/DecisionTrue (post_map_4, post_map_5) {
+                label = "10"
+            }
+            Post_CDEVS/Channel (post_map_1, post_map_3) {
+                label = "11"
+            }
+        }
+    }
+
+    {Contains} ForAll map_control_decision_false {
+        LHS {
+            Pre_PM/ProcessNode pre_map_4 {
+                label = "6"
+            }
+            Pre_Trace (pre_map_4, pre_map_0) {
+                label = "7"
+            }
+            Pre_PM/ProcessNode pre_map_5 {
+                label = "8"
+            }
+            Pre_Trace (pre_map_5, pre_map_1) {
+                label = "9"
+            }
+            Pre_PM/DecisionFalse (pre_map_4, pre_map_5) {
+                label = "10"
+            }
+
+            Pre_CDEVS/DEVSInstance pre_map_0 {
+                label = "0"
+            }
+            Pre_CDEVS/Port pre_map_1 {
+                label = "1"
+                constraint_name = $
+                    Boolean function constraint(model : Element, name : String):
+                        return (cast_string(read_attribute(model, name, "type")) == "control_out2")!
+                    $
+            }
+            Pre_CDEVS/DEVSInstanceToPort (pre_map_0, pre_map_1) {
+                label = "2"
+            }
+
+            Pre_CDEVS/DEVSInstance pre_map_2 {
+                label = "3"
+            }
+            Pre_CDEVS/Port pre_map_3 {
+                label = "4"
+                constraint_name = $
+                    Boolean function constraint(model : Element, name : String):
+                        return (cast_string(read_attribute(model, name, "type")) == "control_in")!
+                    $
+            }
+            Pre_CDEVS/DEVSInstanceToPort (pre_map_2, pre_map_3) {
+                label = "5"
+            }
+        }
+    
+        RHS {
+            Post_CDEVS/DEVSInstance post_map_0 {
+                label = "0"
+            }
+            Post_CDEVS/Port post_map_1 {
+                label = "1"
+            }
+            Post_CDEVS/DEVSInstanceToPort (post_map_0, post_map_1) {
+                label = "2"
+            }
+
+            Post_CDEVS/DEVSInstance post_map_2 {
+                label = "3"
+            }
+            Post_CDEVS/Port post_map_3 {
+                label = "4"
+            }
+            Post_CDEVS/DEVSInstanceToPort (post_map_2, post_map_3) {
+                label = "5"
+            }
+
+            Post_PM/ProcessNode post_map_4 {
+                label = "6"
+            }
+            Post_Trace (post_map_4, post_map_0) {
+                label = "7"
+            }
+            Post_PM/ProcessNode post_map_5 {
+                label = "8"
+            }
+            Post_Trace (post_map_5, post_map_1) {
+                label = "9"
+            }
+            Post_PM/DecisionFalse (post_map_4, post_map_5) {
+                label = "10"
+            }
+            Post_CDEVS/Channel (post_map_1, post_map_3) {
+                label = "11"
+            }
+        }
+    }
 }
+
+Initial (schedule, initial) {}
+
+OnSuccess (initial, finish) {}
+OnFailure (initial, finish) {}
+
+OnSuccess (finish, activity) {}
+OnFailure (finish, activity) {}
+
+OnSuccess (activity, parallelsplit) {}
+OnFailure (activity, parallelsplit) {}
+
+OnSuccess (parallelsplit, synchronization) {}
+OnFailure (parallelsplit, synchronization) {}
+
+OnSuccess (synchronization, xor) {}
+OnFailure (synchronization, xor) {}
+
+OnSuccess (xor, merge) {}
+OnFailure (xor, merge) {}
+
+OnSuccess (merge, multi) {}
+OnFailure (merge, multi) {}
+
+OnSuccess (multi, map_resources_to) {}
+OnFailure (multi, map_resources_to) {}
+
+OnSuccess (map_resources_to, map_resources_from) {}
+OnFailure (map_resources_to, map_resources_from) {}
+
+OnSuccess (map_resources_from, map_control) {}
+OnFailure (map_resources_from, map_control) {}
+
+OnSuccess (map_control, map_control_decision_true) {}
+OnFailure (map_control, map_control_decision_true) {}
+
+OnSuccess (map_control_decision_true, map_control_decision_false) {}
+OnFailure (map_control_decision_true, map_control_decision_false) {}
+
+OnSuccess (map_control_decision_false, success) {}
+OnFailure (map_control_decision_false, success) {}

+ 2 - 0
models/WSC/pm.mvc

@@ -28,3 +28,5 @@ Class MultiInstance : ProcessNode {
 Class SimpleMerge : ProcessNode {}
 
 Association Next (ProcessNode, ProcessNode) {}
+Association DecisionTrue (ExclusiveChoice, ProcessNode) {}
+Association DecisionFalse (ExclusiveChoice, ProcessNode) {}

+ 1 - 2
models/WSC/pm_PM_to_DEVS.mvc

@@ -14,8 +14,7 @@ Exec simulate {
 
 Finish finish {}
 
-Next (start, model) {}
-Next (model, translate) {}
+Next (start, translate) {}
 Next (translate, merge) {}
 Next (merge, simulate) {}
 Next (simulate, finish) {}

+ 40 - 49
models/WSC/pm_library.mvc

@@ -4,15 +4,6 @@ AtomicDEVSBlock ResourceHandler {
     parameters = 1
     initialState = "self.state, self.elapsed = {'resources': parameters[0], 'queue': []}, 0.0"
 
-    constructor = """
-            def __init__(self, resources):
-                AtomicDEVS.__init__(self, "__resource_handler")
-                self.state = {'resources': resources, 'queue': []}
-                self.elapsed = 0.0
-                self.resource_in = self.addInPort("resource_in")
-                self.resource_out = self.addOutPort("resource_out")
-        """
-
     timeAdvance = """
         if self.state['queue'] and self.state['resources']:
             # Can grant a resource
@@ -20,30 +11,30 @@ AtomicDEVSBlock ResourceHandler {
         else:
             # No request queued, or no available resources to handle the request
             return float('inf')
-        """
+    """
 
     outputFnc = """
         return {self.resource_out: {'id': self.state['queue'][0]}}
-        """
+    """
 
     intTransition = """
         # Processed a request that could be processed
         self.state['resources'] -= 1
         del self.state['queue'][0]
         return self.state
-        """
+    """
 
     extTransition = """
         for inp in inputs[self.resource_in]:
-            if inp['type'] == "request":
+            if inp['type'] == 'request':
                 # Queue the request
                 self.state['queue'].append(inp['id'])
-            elif inp['type'] == "release":
+            elif inp['type'] == 'release':
                 # Increment the number of available resources
                 self.state['resources'] += 1
 
         return self.state
-        """
+    """
 }
 
 InputPort rh_ri {
@@ -64,7 +55,7 @@ AtomicDEVSBlock Activity {
         class ActivityState(object):
             def __init__(self, name, distribution):
                 self.timer = float('inf')
-                self.mode = "inactive"
+                self.mode = 'inactive'
                 self.counter = 0
                 self.name = name
                 self.distribution = distribution
@@ -83,25 +74,25 @@ AtomicDEVSBlock Activity {
         """
 
     outputFnc = """
-        if self.state.mode == "active":
+        if self.state.mode == 'active':
             # Output the control token to the next model in line, and release the resources
-            return {self.control_out: {}, self.resource_out: [{'type': "release"}]}
-        elif self.state.mode == "request_resource":
+            return {self.control_out: {}, self.resource_out: [{'type': 'release'}]}
+        elif self.state.mode == 'request_resource':
             # Output a request for resources with a specified ID (used to find out whether this was our request)
-            return {self.resource_out: [{'type': "request", 'id': "%s-%s" % (self.state.name, self.state.counter)}]}
+            return {self.resource_out: [{'type': 'request', 'id': '%s-%s' % (self.state.name, self.state.counter)}]}
         else:
             return {}
         """
 
     intTransition = """
         self.state.timer -= self.timeAdvance()
-        if self.state.mode == "request_resource":
+        if self.state.mode == 'request_resource':
             # Go and request the required resource
-            self.state.mode = "wait_resource"
+            self.state.mode = 'wait_resource'
             self.state.timer = float('inf')
-        elif self.state.mode == "active":
+        elif self.state.mode == 'active':
             # Finished execution, so release resources
-            self.state.mode = "inactive"
+            self.state.mode = 'inactive'
             self.state.timer = 0.0
             self.state.timer = float('inf')
             self.state.counter += 1
@@ -110,15 +101,15 @@ AtomicDEVSBlock Activity {
 
     extTransition = """
         self.state.timer -= self.elapsed
-        if self.state.mode == "inactive" and self.control_in in inputs:
+        if self.state.mode == 'inactive' and self.control_in in inputs:
             # Got control token, so ask for the required resources
-            self.state.mode = "request_resource"
+            self.state.mode = 'request_resource'
             self.state.timer = 0.0
             # NOTE this violates DEVS, though is easy to debug
-            #print("Activate " + str(self.state.name) + " at time " + str(self.time_last[0] + self.elapsed))
-        elif self.state.mode == "wait_resource" and self.resource_in in inputs and inputs[self.resource_in]['id'] == "%s-%s" % (self.state.name, self.state.counter):
+            #print('Activate ' + str(self.state.name) + ' at time ' + str(self.time_last[0] + self.elapsed))
+        elif self.state.mode == 'wait_resource' and self.resource_in in inputs and inputs[self.resource_in]['id'] == '%s-%s' % (self.state.name, self.state.counter):
             # Got required resources, so start execution
-            self.state.mode = "active"
+            self.state.mode = 'active'
             self.state.timer = self.state.random_sample()
         return self.state
         """
@@ -208,8 +199,8 @@ OutputPort syn_co {
     name = "control_out"
 }
 
-DEVSBlockToPort (Synchronization, syn_ri) {}
-DEVSBlockToPort (Synchronization, syn_ro) {}
+DEVSBlockToPort (Synchronization, syn_ci) {}
+DEVSBlockToPort (Synchronization, syn_co) {}
 
 AtomicDEVSBlock ExclusiveChoice {
     name = "ExclusiveChoice"
@@ -321,7 +312,7 @@ AtomicDEVSBlock MultiInstance {
                 self.spawned = num
                 self.collected = 0
                 self.counter = 0
-                self.mode = "inactive"
+                self.mode = 'inactive'
                 self.running_tasks = []
                 self.requested = []
                 self.name = name
@@ -337,24 +328,24 @@ AtomicDEVSBlock MultiInstance {
         """
 
     timeAdvance = """
-        if self.state.mode == "finish":
+        if self.state.mode == 'finish':
             return 0.0
         elif self.state.running_tasks:
             return self.state.running_tasks[0][0]
-        elif self.state.mode == "request_resources":
+        elif self.state.mode == 'request_resources':
             return 0.0
         else:
             return float('inf')
         """
 
     outputFnc = """
-        if self.state.mode == "request_resources":
+        if self.state.mode == 'request_resources':
             # Request all resources in one go
             return {self.resource_out: [{'type': 'request', 'id': i} for i in self.state.requested]}
-        elif self.state.mode == "active":
+        elif self.state.mode == 'active':
             # Finished an instance, so release it
             return {self.resource_out: [{'type': 'release'}]}
-        elif self.state.mode == "finish":
+        elif self.state.mode == 'finish':
             # Finished execution of all, so pass on token
             return {self.control_out: {}}
         else:
@@ -366,17 +357,17 @@ AtomicDEVSBlock MultiInstance {
         for t in self.state.running_tasks:
             t[0] -= ta
 
-        if self.state.mode == "active":
+        if self.state.mode == 'active':
             # Finished an instance, so pop it
             del self.state.running_tasks[0]
             self.state.collected += 1
             if self.state.collected == self.state.spawned:
-                self.state.mode = "finish"
-        elif self.state.mode == "request_resources":
+                self.state.mode = 'finish'
+        elif self.state.mode == 'request_resources':
             # Requested resources, so be ready for a response
-            self.state.mode = "active"
-        elif self.state.mode == "finish":
-            self.state.mode = "inactive"
+            self.state.mode = 'active'
+        elif self.state.mode == 'finish':
+            self.state.mode = 'inactive'
             self.state.collected = 0
             self.state.counter += 1
             self.state.running_tasks = []
@@ -388,15 +379,15 @@ AtomicDEVSBlock MultiInstance {
         for t in self.state.running_tasks:
             t[0] -= self.elapsed
 
-        if self.state.mode == "inactive" and self.control_in in inputs:
-            self.state.mode = "request_resources"
-            self.state.requested = ["%s-%s-%s" % (self.state.name, self.state.counter, i) for i in range(self.state.spawned)]
+        if self.state.mode == 'inactive' and self.control_in in inputs:
+            self.state.mode = 'request_resources'
+            self.state.requested = ['%s-%s-%s' % (self.state.name, self.state.counter, i) for i in range(self.state.spawned)]
 
-        if self.state.mode in ["active", "release_resource"] and self.resource_in in inputs:
+        if self.state.mode in ['active', 'release_resource'] and self.resource_in in inputs:
             # Got a resource, so allocate it to an activity
             self.state.running_tasks.append([self.state.task_time(), self.state.requested.pop(0)])
             # NOTE this violates DEVS, though is easy to debug
-            #print("Spawn " + str(self.state.running_tasks[-1][1]) + " at time " + str(self.time_last[0] + self.elapsed))
+            #print('Spawn ' + str(self.state.running_tasks[-1][1]) + ' at time ' + str(self.time_last[0] + self.elapsed))
             self.state.running_tasks.sort()
         return self.state
         """
@@ -406,7 +397,7 @@ InputPort mi_ci {
     name = "control_in"
 }
 
-OutputPort mu_co {
+OutputPort mi_co {
     name = "control_out"
 }
 

+ 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:   Mon May 14 09:23:58 2018
+Date:   Mon May 14 16:45:16 2018
 
 Model author: Yentl Van Tendeloo
 Model name:   MvK Server