Jelajahi Sumber

Added lots of transformations, with minor patches

Yentl Van Tendeloo 7 tahun lalu
induk
melakukan
ea76d18d8d

+ 308 - 1
models/WSC/PM_to_DEVS.mvc

@@ -4,7 +4,6 @@ include "object_oeprations.alh"
 
 
 Composite schedule {
 Composite schedule {
     {Contains} Success success {}
     {Contains} Success success {}
-    {Contains} Failure failure {}
 
 
     {Contains} Atomic add_resource_handler {
     {Contains} Atomic add_resource_handler {
         LHS {}
         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 {}
 Class SimpleMerge : ProcessNode {}
 
 
 Association Next (ProcessNode, 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 {}
 Finish finish {}
 
 
-Next (start, model) {}
-Next (model, translate) {}
+Next (start, translate) {}
 Next (translate, merge) {}
 Next (translate, merge) {}
 Next (merge, simulate) {}
 Next (merge, simulate) {}
 Next (simulate, finish) {}
 Next (simulate, finish) {}

+ 40 - 49
models/WSC/pm_library.mvc

@@ -4,15 +4,6 @@ AtomicDEVSBlock ResourceHandler {
     parameters = 1
     parameters = 1
     initialState = "self.state, self.elapsed = {'resources': parameters[0], 'queue': []}, 0.0"
     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 = """
     timeAdvance = """
         if self.state['queue'] and self.state['resources']:
         if self.state['queue'] and self.state['resources']:
             # Can grant a resource
             # Can grant a resource
@@ -20,30 +11,30 @@ AtomicDEVSBlock ResourceHandler {
         else:
         else:
             # No request queued, or no available resources to handle the request
             # No request queued, or no available resources to handle the request
             return float('inf')
             return float('inf')
-        """
+    """
 
 
     outputFnc = """
     outputFnc = """
         return {self.resource_out: {'id': self.state['queue'][0]}}
         return {self.resource_out: {'id': self.state['queue'][0]}}
-        """
+    """
 
 
     intTransition = """
     intTransition = """
         # Processed a request that could be processed
         # Processed a request that could be processed
         self.state['resources'] -= 1
         self.state['resources'] -= 1
         del self.state['queue'][0]
         del self.state['queue'][0]
         return self.state
         return self.state
-        """
+    """
 
 
     extTransition = """
     extTransition = """
         for inp in inputs[self.resource_in]:
         for inp in inputs[self.resource_in]:
-            if inp['type'] == "request":
+            if inp['type'] == 'request':
                 # Queue the request
                 # Queue the request
                 self.state['queue'].append(inp['id'])
                 self.state['queue'].append(inp['id'])
-            elif inp['type'] == "release":
+            elif inp['type'] == 'release':
                 # Increment the number of available resources
                 # Increment the number of available resources
                 self.state['resources'] += 1
                 self.state['resources'] += 1
 
 
         return self.state
         return self.state
-        """
+    """
 }
 }
 
 
 InputPort rh_ri {
 InputPort rh_ri {
@@ -64,7 +55,7 @@ AtomicDEVSBlock Activity {
         class ActivityState(object):
         class ActivityState(object):
             def __init__(self, name, distribution):
             def __init__(self, name, distribution):
                 self.timer = float('inf')
                 self.timer = float('inf')
-                self.mode = "inactive"
+                self.mode = 'inactive'
                 self.counter = 0
                 self.counter = 0
                 self.name = name
                 self.name = name
                 self.distribution = distribution
                 self.distribution = distribution
@@ -83,25 +74,25 @@ AtomicDEVSBlock Activity {
         """
         """
 
 
     outputFnc = """
     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
             # 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)
             # 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:
         else:
             return {}
             return {}
         """
         """
 
 
     intTransition = """
     intTransition = """
         self.state.timer -= self.timeAdvance()
         self.state.timer -= self.timeAdvance()
-        if self.state.mode == "request_resource":
+        if self.state.mode == 'request_resource':
             # Go and request the required resource
             # Go and request the required resource
-            self.state.mode = "wait_resource"
+            self.state.mode = 'wait_resource'
             self.state.timer = float('inf')
             self.state.timer = float('inf')
-        elif self.state.mode == "active":
+        elif self.state.mode == 'active':
             # Finished execution, so release resources
             # Finished execution, so release resources
-            self.state.mode = "inactive"
+            self.state.mode = 'inactive'
             self.state.timer = 0.0
             self.state.timer = 0.0
             self.state.timer = float('inf')
             self.state.timer = float('inf')
             self.state.counter += 1
             self.state.counter += 1
@@ -110,15 +101,15 @@ AtomicDEVSBlock Activity {
 
 
     extTransition = """
     extTransition = """
         self.state.timer -= self.elapsed
         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
             # Got control token, so ask for the required resources
-            self.state.mode = "request_resource"
+            self.state.mode = 'request_resource'
             self.state.timer = 0.0
             self.state.timer = 0.0
             # NOTE this violates DEVS, though is easy to debug
             # 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
             # Got required resources, so start execution
-            self.state.mode = "active"
+            self.state.mode = 'active'
             self.state.timer = self.state.random_sample()
             self.state.timer = self.state.random_sample()
         return self.state
         return self.state
         """
         """
@@ -208,8 +199,8 @@ OutputPort syn_co {
     name = "control_out"
     name = "control_out"
 }
 }
 
 
-DEVSBlockToPort (Synchronization, syn_ri) {}
-DEVSBlockToPort (Synchronization, syn_ro) {}
+DEVSBlockToPort (Synchronization, syn_ci) {}
+DEVSBlockToPort (Synchronization, syn_co) {}
 
 
 AtomicDEVSBlock ExclusiveChoice {
 AtomicDEVSBlock ExclusiveChoice {
     name = "ExclusiveChoice"
     name = "ExclusiveChoice"
@@ -321,7 +312,7 @@ AtomicDEVSBlock MultiInstance {
                 self.spawned = num
                 self.spawned = num
                 self.collected = 0
                 self.collected = 0
                 self.counter = 0
                 self.counter = 0
-                self.mode = "inactive"
+                self.mode = 'inactive'
                 self.running_tasks = []
                 self.running_tasks = []
                 self.requested = []
                 self.requested = []
                 self.name = name
                 self.name = name
@@ -337,24 +328,24 @@ AtomicDEVSBlock MultiInstance {
         """
         """
 
 
     timeAdvance = """
     timeAdvance = """
-        if self.state.mode == "finish":
+        if self.state.mode == 'finish':
             return 0.0
             return 0.0
         elif self.state.running_tasks:
         elif self.state.running_tasks:
             return self.state.running_tasks[0][0]
             return self.state.running_tasks[0][0]
-        elif self.state.mode == "request_resources":
+        elif self.state.mode == 'request_resources':
             return 0.0
             return 0.0
         else:
         else:
             return float('inf')
             return float('inf')
         """
         """
 
 
     outputFnc = """
     outputFnc = """
-        if self.state.mode == "request_resources":
+        if self.state.mode == 'request_resources':
             # Request all resources in one go
             # Request all resources in one go
             return {self.resource_out: [{'type': 'request', 'id': i} for i in self.state.requested]}
             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
             # Finished an instance, so release it
             return {self.resource_out: [{'type': 'release'}]}
             return {self.resource_out: [{'type': 'release'}]}
-        elif self.state.mode == "finish":
+        elif self.state.mode == 'finish':
             # Finished execution of all, so pass on token
             # Finished execution of all, so pass on token
             return {self.control_out: {}}
             return {self.control_out: {}}
         else:
         else:
@@ -366,17 +357,17 @@ AtomicDEVSBlock MultiInstance {
         for t in self.state.running_tasks:
         for t in self.state.running_tasks:
             t[0] -= ta
             t[0] -= ta
 
 
-        if self.state.mode == "active":
+        if self.state.mode == 'active':
             # Finished an instance, so pop it
             # Finished an instance, so pop it
             del self.state.running_tasks[0]
             del self.state.running_tasks[0]
             self.state.collected += 1
             self.state.collected += 1
             if self.state.collected == self.state.spawned:
             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
             # 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.collected = 0
             self.state.counter += 1
             self.state.counter += 1
             self.state.running_tasks = []
             self.state.running_tasks = []
@@ -388,15 +379,15 @@ AtomicDEVSBlock MultiInstance {
         for t in self.state.running_tasks:
         for t in self.state.running_tasks:
             t[0] -= self.elapsed
             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
             # Got a resource, so allocate it to an activity
             self.state.running_tasks.append([self.state.task_time(), self.state.requested.pop(0)])
             self.state.running_tasks.append([self.state.task_time(), self.state.requested.pop(0)])
             # NOTE this violates DEVS, though is easy to debug
             # 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()
             self.state.running_tasks.sort()
         return self.state
         return self.state
         """
         """
@@ -406,7 +397,7 @@ InputPort mi_ci {
     name = "control_in"
     name = "control_in"
 }
 }
 
 
-OutputPort mu_co {
+OutputPort mi_co {
     name = "control_out"
     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)
 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 author: Yentl Van Tendeloo
 Model name:   MvK Server
 Model name:   MvK Server