Jelajahi Sumber

First part of PM to DEVS

Yentl Van Tendeloo 7 tahun lalu
induk
melakukan
6e2acdb61f
4 mengubah file dengan 299 tambahan dan 39 penghapusan
  1. 1 0
      models/WSC/CDEVS.mvc
  2. 293 0
      models/WSC/PM_to_DEVS.mvc
  3. 0 37
      models/WSC/pm_library.mvc
  4. 5 2
      models/pm_translate.py

+ 1 - 0
models/WSC/CDEVS.mvc

@@ -8,6 +8,7 @@ Class CoupledDEVSBlock {
 Class DEVSInstance {
     name: String
     type: String
+    parameters: String
 }
 
 Association SubModel(CoupledDEVSBlock, DEVSInstance) {}

+ 293 - 0
models/WSC/PM_to_DEVS.mvc

@@ -0,0 +1,293 @@
+include "primitives.alh"
+include "modelling.alh"
+include "object_oeprations.alh"
+
+Composite schedule {
+    {Contains} Success success {}
+    {Contains} Failure failure {}
+
+    {Contains} Atomic add_resource_handler {
+        LHS {}
+        RHS {
+            Post_CDEVS/DEVSInstance post_resource_1 {
+                label = "1"
+                value_name = $
+                    String function value(model : Element, name : String, mapping : Element):
+                        return "resource_handler"!
+                    $
+                value_type = $
+                    String function value(model : Element, name : String, mapping : Element):
+                        return "ResourceHandler"!
+                    $
+            }
+            Post_CDEVS/InputPort post_resource_2 {
+                name = "resource_in"
+            }
+            Post_CDEVS/DEVSInstanceToPort (post_resource_1, post_resource_2) {}
+            Post_CDEVS/OutputPort post_resource_3 {
+                name = "resource_out"
+            }
+            Post_CDEVS/DEVSInstanceToPort (post_resource_1, post_resource_3) {}
+        }
+    }
+    
+    {Contains} ForAll initial {
+        LHS {
+            Pre_PM/Initial pre_init_0 {
+                label = "0"
+            }
+        }
+
+        RHS {
+            Post_PM/Initial post_init_0 {
+                label = "0"
+            }
+            Post_CDEVS/DEVSInstance post_init_1 {
+                label = "1"
+                value_name = $
+                    String function value(model : Element, name : String, mapping : Element):
+                        return read_attribute(model, mapping["0"], "name")!
+                    $
+                value_type = $
+                    String function value(model : Element, name : String, mapping : Element):
+                        return "Initial"!
+                    $
+            }
+            Trace (post_init_0, post_init_1) {}
+
+            Post_CDEVS/OutputPort post_init_2 {
+                name = "control_out"
+            }
+            Post_CDEVS/DEVSInstanceToPort (post_init_1, post_init_2) {}
+        }
+    }
+    
+    {Contains} ForAll finish {
+        LHS {
+            Pre_PM/Initial pre_finish_0 {
+                label = "0"
+            }
+        }
+
+        RHS {
+            Post_PM/Initial post_finish_0 {
+                label = "0"
+            }
+            Post_CDEVS/DEVSInstance post_finish_1 {
+                label = "1"
+                value_name = $
+                    String function value(model : Element, name : String, mapping : Element):
+                        return read_attribute(model, mapping["0"], "name")!
+                    $
+                value_type = $
+                    String function value(model : Element, name : String, mapping : Element):
+                        return "Finish"!
+                    $
+            }
+            Trace (post_finish_0, post_finish_1) {}
+
+            Post_CDEVS/InputPort post_finish_2 {
+                name = "control_in"
+            }
+            Post_CDEVS/DEVSInstanceToPort (post_finish_1, post_finish_2) {}
+        }
+    }
+    
+    {Contains} ForAll activity {
+        LHS {
+            Pre_PM/Initial pre_activity_0 {
+                label = "0"
+            }
+        }
+
+        RHS {
+            Post_PM/Initial post_activity_0 {
+                label = "0"
+            }
+            Post_CDEVS/DEVSInstance post_activity_1 {
+                label = "1"
+                value_name = $
+                    String function value(model : Element, name : String, mapping : Element):
+                        return read_attribute(model, mapping["0"], "name")!
+                    $
+                value_type = $
+                    String function value(model : Element, name : String, mapping : Element):
+                        return "Activity"!
+                    $
+                value_parameters = $
+                    String function value(model : Element, name : String, mapping : Element):
+                        return "[" + cast_value(read_attribute(model, mapping["0"], "name")) + ", " + cast_string(read_attribute(model, mapping["0"], "distribution")) + "]"!
+                    $
+            }
+            Trace (post_activity_0, post_activity_1) {}
+
+            Post_CDEVS/InputPort post_activity_2 {
+                name = "resource_in"
+            }
+            Post_CDEVS/DEVSInstanceToPort (post_activity_1, post_activity_2) {}
+
+            Post_CDEVS/OutputPort post_activity_3 {
+                name = "resource_out"
+            }
+            Post_CDEVS/DEVSInstanceToPort (post_activity_1, post_activity_3) {}
+
+            Post_CDEVS/InputPort post_activity_4 {
+                name = "control_in"
+            }
+            Post_CDEVS/DEVSInstanceToPort (post_activity_1, post_activity_4) {}
+
+            Post_CDEVS/OutputPort post_activity_5 {
+                name = "control_out"
+            }
+            Post_CDEVS/DEVSInstanceToPort (post_activity_1, post_activity_5) {}
+        }
+    }
+
+    {Contains} ForAll parallelsplit {
+        LHS {
+            Pre_PM/Initial pre_split_0 {
+                label = "0"
+            }
+        }
+
+        RHS {
+            Post_PM/Initial post_split_0 {
+                label = "0"
+            }
+            Post_CDEVS/DEVSInstance post_split_1 {
+                label = "1"
+                value_name = $
+                    String function value(model : Element, name : String, mapping : Element):
+                        return read_attribute(model, mapping["0"], "name")!
+                    $
+                value_type = $
+                    String function value(model : Element, name : String, mapping : Element):
+                        return "ParallelSplit"!
+                    $
+            }
+            Trace (post_split_0, post_split_1) {}
+
+            Post_CDEVS/InputPort post_split_2 {
+                name = "control_in"
+            }
+            Post_CDEVS/DEVSInstanceToPort (post_split_1, post_split_2) {}
+
+            Post_CDEVS/OutputPort post_split_3 {
+                name = "control_out"
+            }
+            Post_CDEVS/DEVSInstanceToPort (post_split_1, post_split_3) {}
+        }
+    }
+
+    {Contains} ForAll synchronization {
+        LHS {
+            Pre_PM/Initial pre_sync_0 {
+                label = "0"
+            }
+        }
+
+        RHS {
+            Post_PM/Initial post_sync_0 {
+                label = "0"
+            }
+            Post_CDEVS/DEVSInstance post_sync_1 {
+                label = "1"
+                value_name = $
+                    String function value(model : Element, name : String, mapping : Element):
+                        return read_attribute(model, mapping["0"], "name")!
+                    $
+                value_type = $
+                    String function value(model : Element, name : String, mapping : Element):
+                        return "Synchronization"!
+                    $
+            }
+            Trace (post_sync_0, post_sync_1) {}
+
+            Post_CDEVS/InputPort post_sync_2 {
+                name = "control_in"
+            }
+            Post_CDEVS/DEVSInstanceToPort (post_sync_1, post_sync_2) {}
+
+            Post_CDEVS/OutputPort post_sync_3 {
+                name = "control_out"
+            }
+            Post_CDEVS/DEVSInstanceToPort (post_sync_1, post_sync_3) {}
+        }
+    }
+
+    {Contains} ForAll xor {
+        LHS {
+            Pre_PM/Initial pre_xor_0 {
+                label = "0"
+            }
+        }
+
+        RHS {
+            Post_PM/Initial post_xor_0 {
+                label = "0"
+            }
+            Post_CDEVS/DEVSInstance post_xor_1 {
+                label = "1"
+                value_name = $
+                    String function value(model : Element, name : String, mapping : Element):
+                        return read_attribute(model, mapping["0"], "name")!
+                    $
+                value_type = $
+                    String function value(model : Element, name : String, mapping : Element):
+                        return "ExclusiveChoice"!
+                    $
+            }
+            Trace (post_xor_0, post_xor_1) {}
+
+            Post_CDEVS/InputPort post_xor_2 {
+                name = "control_in"
+            }
+            Post_CDEVS/DEVSInstanceToPort (post_xor_1, post_xor_2) {}
+
+            Post_CDEVS/OutputPort post_xor_3 {
+                name = "control_out1"
+            }
+            Post_CDEVS/DEVSInstanceToPort (post_xor_1, post_xor_3) {}
+            Post_CDEVS/OutputPort post_xor_4 {
+                name = "control_out2"
+            }
+            Post_CDEVS/DEVSInstanceToPort (post_xor_1, post_xor_4) {}
+        }
+    }
+
+    {Contains} ForAll merge {
+        LHS {
+            Pre_PM/Initial pre_merge_0 {
+                label = "0"
+            }
+        }
+
+        RHS {
+            Post_PM/Initial post_merge_0 {
+                label = "0"
+            }
+            Post_CDEVS/DEVSInstance post_merge_1 {
+                label = "1"
+                value_name = $
+                    String function value(model : Element, name : String, mapping : Element):
+                        return read_attribute(model, mapping["0"], "name")!
+                    $
+                value_type = $
+                    String function value(model : Element, name : String, mapping : Element):
+                        return "SimpleMerge"!
+                    $
+            }
+            Trace (post_merge_0, post_merge_1) {}
+
+            Post_CDEVS/InputPort post_merge_2 {
+                name = "control_in"
+            }
+            Post_CDEVS/DEVSInstanceToPort (post_merge_1, post_merge_2) {}
+
+            Post_CDEVS/OutputPort post_merge_3 {
+                name = "control_out"
+            }
+            Post_CDEVS/DEVSInstanceToPort (post_merge_1, post_merge_3) {}
+        }
+    }
+}

+ 0 - 37
models/WSC/pm_library.mvc

@@ -172,43 +172,6 @@ OutputPort split_co {
 DEVSBlockToPort (ParallelSplit, split_ci) {}
 DEVSBlockToPort (ParallelSplit, split_co) {}
 
-AtomicDEVSBlock ParallelSplit {
-    name = "ParallelSplit"
-    parameters = 0
-
-    initialState = "self.state, self.elapsed = False, 0.0"
-
-    timeAdvance = """
-        if self.state:
-            return 0.0
-        else:
-            return float('inf')
-        """
-
-    outputFnc = """
-        return {self.control_out: {}}
-        """
-
-    intTransition = """
-        return False
-        """
-
-    extTransition = """
-        return True
-        """
-}
-
-InputPort split_ci {
-    name = "control_in"
-}
-
-OutputPort split_co {
-    name = "control_out"
-}
-
-DEVSBlockToPort (ParallelSplit, split_ci) {}
-DEVSBlockToPort (ParallelSplit, split_co) {}
-
 AtomicDEVSBlock Synchronization {
     name = "Synchronization"
     parameters = 1

+ 5 - 2
models/pm_translate.py

@@ -17,11 +17,14 @@ model_add("models/PM/to_DEVS", "formalisms/ProcessModel", open("models/WSC/pm_PM
 model_add("models/DEVS/PM_library", "formalisms/DEVS/ADEVS_MM", open("models/WSC/pm_library.mvc", 'r').read())
 model_add("models/PM/example_PM", "formalisms/PM/PM_Extended_MM", open("models/WSC/pm_example.mvc", 'r').read())
 
+def traceability_pm_devs(model):
+    instantiate(model, "Association", ("PM/ProcessNode", "CDEVS/DEVSInstance"), ID="Trace")
+    
+transformation_add_MT("formalisms/PM/to_DEVS", {"PM": "formalisms/PM/PM_Extended_MM"}, {"CDEVS": "formalisms/DEVS/CDEVS_MM"}, open("models/WSC/PM_to_DEVS.mvc", 'r').read(), traceability_pm_devs)
+
 """
-transformation_add_MT("formalisms/PM/to_DEVS", {"PM": "formalisms/PM/PM_Extended_MM"}, {"ADEVS": "formalisms/DEVS/ADEVS_MM"}, open("models/WSC/PM_to_DEVS.mvc", 'r').read())
 transformation_add_AL("formalisms/DEVS/merge", {"ADEVS": "formalisms/DEVS/ADEVS_MM", "CDEVS": "formalisms/DEVS/CDEVS_MM"}, {"DEVS": "formalisms/DEVS/DEVS_MM"}, open("models/WSC/DEVS_merge.alc", 'r').read())
 transformation_add_AL("formalisms/DEVS/simulate", {"DEVS": "formalisms/DEVS/DEVS_MM"}, {"metrics": "formalisms/Metrics/Metrics_MM"}, open("models/WSC/DEVS_simulate.alc", 'r').read())
-transformation_add_AL("formalisms/Metrics/plot", {"metrics": "formalisms/Metrics/Metrics_MM"}, {"graph": "formalisms/Graph/Graph_MM"}, open("models/WSC/Metrics_plot.alc", 'r').read())
 
 pm_execute("models/PM/to_DEVS", {"PM": "models/PM/example_PM", "ADEVS library": "models/DEVS/PM_library", "Graph": "models/Graph/graph"}, {})
 """