Procházet zdrojové kódy

fixed the Ports issue, ports where added in a global class -> not DEVS

sampieters před 1 rokem
rodič
revize
40f0ef8aa8
94 změnil soubory, kde provedl 34324 přidání a 98585 odebrání
  1. 29700 94248
      examples/BouncingBalls/PyDEVS/log.txt
  2. 40 22
      examples/BouncingBalls/PyDEVS/target.py
  3. 32 37
      examples/BouncingBalls/PyDEVS/the_target.py
  4. 1087 2830
      examples/BouncingBalls/PyDEVS/trace.txt
  5. 35 27
      examples/BouncingBallsCollision/PyDEVS/target.py
  6. 3 12
      examples/ElevatorBalls/PyDEVS/runner.py
  7. 139 111
      examples/ElevatorBalls/PyDEVS/target.py
  8. 1 0
      examples/ElevatorBalls/Python/runner.py
  9. 31 37
      examples/ElevatorBalls/Python/target.py
  10. 604 0
      examples/ElevatorBalls/idk_sccd.xml
  11. 28 32
      examples/ElevatorBalls/sccd.xml
  12. 11 8
      examples/TimerEventloop/PyDEVS/target.py
  13. 15 8
      sccd/compiler/DEVS_generator.py
  14. 940 0
      sccd/runtime/DEVS_statecharts_core old.py
  15. 61 45
      sccd/runtime/DEVS_statecharts_core.py
  16. 4 4
      tests/1.0) EventlessTransitionTest/PyDEVS/log.txt
  17. 7 5
      tests/1.0) EventlessTransitionTest/PyDEVS/target.py
  18. 6 6
      tests/1.1) AfterTransitionTest/PyDEVS/log.txt
  19. 7 5
      tests/1.1) AfterTransitionTest/PyDEVS/target.py
  20. 6 6
      tests/1.10) DeepHistoryTest/PyDEVS/log.txt
  21. 7 5
      tests/1.10) DeepHistoryTest/PyDEVS/target.py
  22. 6 6
      tests/1.11) AllStatechartTest/PyDEVS/log.txt
  23. 7 5
      tests/1.11) AllStatechartTest/PyDEVS/target.py
  24. 6 6
      tests/1.2) GuardConditionTest/PyDEVS/log.txt
  25. 7 5
      tests/1.2) GuardConditionTest/PyDEVS/target.py
  26. 6 6
      tests/1.3) TransitionToItselfTest/PyDEVS/log.txt
  27. 7 5
      tests/1.3) TransitionToItselfTest/PyDEVS/target.py
  28. 6 6
      tests/1.4) ScriptTransitionTest/PyDEVS/log.txt
  29. 7 5
      tests/1.4) ScriptTransitionTest/PyDEVS/target.py
  30. 6 6
      tests/1.5) ScriptEntryTest/PyDEVS/log.txt
  31. 7 5
      tests/1.5) ScriptEntryTest/PyDEVS/target.py
  32. 6 6
      tests/1.6) ScriptExitTest/PyDEVS/log.txt
  33. 7 5
      tests/1.6) ScriptExitTest/PyDEVS/target.py
  34. 6 6
      tests/1.7) CompositeStateTest/PyDEVS/log.txt
  35. 7 5
      tests/1.7) CompositeStateTest/PyDEVS/target.py
  36. 6 6
      tests/1.8) ParallelStateTest/PyDEVS/log.txt
  37. 7 5
      tests/1.8) ParallelStateTest/PyDEVS/target.py
  38. 6 6
      tests/1.9) ShallowHistoryTest/PyDEVS/log.txt
  39. 7 5
      tests/1.9) ShallowHistoryTest/PyDEVS/target.py
  40. 10 7
      tests/2.0) GlobalInputTest/PyDEVS/log.txt
  41. 10 6
      tests/2.0) GlobalInputTest/PyDEVS/target.py
  42. 6 6
      tests/2.1) GlobalOutputTest/PyDEVS/log.txt
  43. 7 6
      tests/2.1) GlobalOutputTest/PyDEVS/target.py
  44. 10 7
      tests/2.2) GlobalIOTest/PyDEVS/log.txt
  45. 10 7
      tests/2.2) GlobalIOTest/PyDEVS/target.py
  46. 8 6
      tests/2.3) TimedOutputTest/PyDEVS/log.txt
  47. 10 7
      tests/2.3) TimedOutputTest/PyDEVS/target.py
  48. 8 6
      tests/2.5) MultipleOutputTest/PyDEVS/log.txt
  49. 10 7
      tests/2.5) MultipleOutputTest/PyDEVS/target.py
  50. 17 13
      tests/3.0) ClassCreation/PyDEVS/log.txt
  51. 19 11
      tests/3.0) ClassCreation/PyDEVS/target.py
  52. 25 19
      tests/3.1) ClassInitialization/PyDEVS/log.txt
  53. 19 11
      tests/3.1) ClassInitialization/PyDEVS/target.py
  54. 57 44
      tests/3.10) DeleteBadFromNonParent/PyDEVS/log.txt
  55. 28 15
      tests/3.10) DeleteBadFromNonParent/PyDEVS/target.py
  56. 71 56
      tests/3.11) DeleteGoodFromNonParent/PyDEVS/log.txt
  57. 28 15
      tests/3.11) DeleteGoodFromNonParent/PyDEVS/target.py
  58. 63 49
      tests/3.16) AssociateInstance/PyDEVS/log.txt
  59. 28 15
      tests/3.16) AssociateInstance/PyDEVS/target.py
  60. 35 27
      tests/3.17) DissasociateInstance/PyDEVS/log.txt
  61. 19 11
      tests/3.17) DissasociateInstance/PyDEVS/target.py
  62. 9 9
      tests/3.17) DissasociateInstance/Python/log.txt
  63. 0 1
      tests/3.18) DissasociateMultiple/PyDEVS/faulty_log.txt
  64. 53 61
      tests/3.18) DissasociateMultiple/PyDEVS/log.txt
  65. 19 11
      tests/3.18) DissasociateMultiple/PyDEVS/target.py
  66. 9 9
      tests/3.18) DissasociateMultiple/Python/log.txt
  67. 8 6
      tests/3.19) (Diss)asociateFromParent/PyDEVS/log.txt
  68. 10 7
      tests/3.19) (Diss)asociateFromParent/PyDEVS/target.py
  69. 25 19
      tests/3.2) ClassParameterInitialization/PyDEVS/log.txt
  70. 19 11
      tests/3.2) ClassParameterInitialization/PyDEVS/target.py
  71. 8 6
      tests/3.20) (Diss)asociateFromOther/PyDEVS/log.txt
  72. 10 7
      tests/3.20) (Diss)asociateFromOther/PyDEVS/target.py
  73. 241 163
      tests/3.3) MultipleClassInstances/PyDEVS/log.txt
  74. 19 11
      tests/3.3) MultipleClassInstances/PyDEVS/target.py
  75. 43 33
      tests/3.4) MultipleClasses/PyDEVS/log.txt
  76. 28 15
      tests/3.4) MultipleClasses/PyDEVS/target.py
  77. 31 25
      tests/3.5) DeleteBeforeStarting/PyDEVS/log.txt
  78. 19 11
      tests/3.5) DeleteBeforeStarting/PyDEVS/target.py
  79. 49 39
      tests/3.6) DeleteMultipleBeforeStarting/PyDEVS/log.txt
  80. 19 11
      tests/3.6) DeleteMultipleBeforeStarting/PyDEVS/target.py
  81. 40 32
      tests/3.7) DeleteRunningInstance/PyDEVS/log.txt
  82. 19 11
      tests/3.7) DeleteRunningInstance/PyDEVS/target.py
  83. 40 32
      tests/3.8) DeleteMultipleRunning/PyDEVS/log.txt
  84. 19 11
      tests/3.8) DeleteMultipleRunning/PyDEVS/target.py
  85. 45 35
      tests/3.9) DeletedMessageTest/PyDEVS/log.txt
  86. 19 11
      tests/3.9) DeletedMessageTest/PyDEVS/target.py
  87. 8 6
      tests/4.0) NarrowCastTest/PyDEVS/log.txt
  88. 10 7
      tests/4.0) NarrowCastTest/PyDEVS/target.py
  89. 62 46
      tests/4.1) BroadcastTest/PyDEVS/log.txt
  90. 19 11
      tests/4.1) BroadcastTest/PyDEVS/target.py
  91. 8 6
      tests/5.0) Inheritance/PyDEVS/log.txt
  92. 19 11
      tests/5.0) Inheritance/PyDEVS/target.py
  93. 8 6
      tests/6.0) /PyDEVS/log.txt
  94. 10 7
      tests/6.0) /PyDEVS/target.py

Rozdílová data souboru nebyla zobrazena, protože soubor je příliš velký
+ 29700 - 94248
examples/BouncingBalls/PyDEVS/log.txt


+ 40 - 22
examples/BouncingBalls/PyDEVS/target.py

@@ -16,7 +16,7 @@ CANVAS_DIMS = (800, 550)
 # package "Bouncing_Balls_DEVS_Version"
 
 class MainAppInstance(RuntimeClassBase):
-    def __init__(self, atomdevs, id):
+    def __init__(self, atomdevs, id, start_port_id):
         RuntimeClassBase.__init__(self, atomdevs, id)
         self.associations = {}
         self.associations["fields"] = Association("Field", 0, -1)
@@ -32,8 +32,12 @@ class MainAppInstance(RuntimeClassBase):
         
         # call user defined constructor
         MainAppInstance.user_defined_constructor(self)
-        port_name = Ports.addInputPort("<narrow_cast>", self)
+        port_name = addInputPort("ui", start_port_id, True)
         atomdevs.addInPort(port_name)
+        atomdevs.state.port_mappings[port_name] = id
+        port_name = addInputPort("<narrow_cast>", start_port_id)
+        atomdevs.addInPort(port_name)
+        atomdevs.state.port_mappings[port_name] = id
     
     def user_defined_constructor(self):
         self.nr_of_fields = 0
@@ -201,16 +205,16 @@ class MainApp(ClassBase):
         self.input = self.addInPort("input")
         self.glob_outputs["ui"] = self.addOutPort("ui")
         self.outputs["fields"] = self.addOutPort("fields")
-        new_instance = self.constructObject(0, [])
+        new_instance = self.constructObject(0, 0, [])
         self.state.instances[new_instance.instance_id] = new_instance
         self.state.next_instance = self.state.next_instance + 1
     
-    def constructObject(self, id, parameters):
-        new_instance = MainAppInstance(self, id)
+    def constructObject(self, id, start_port_id, parameters):
+        new_instance = MainAppInstance(self, id, start_port_id)
         return new_instance
 
 class FieldInstance(RuntimeClassBase):
-    def __init__(self, atomdevs, id):
+    def __init__(self, atomdevs, id, start_port_id):
         RuntimeClassBase.__init__(self, atomdevs, id)
         self.associations = {}
         self.associations["balls"] = Association("Ball", 0, -1)
@@ -232,9 +236,13 @@ class FieldInstance(RuntimeClassBase):
         
         # call user defined constructor
         FieldInstance.user_defined_constructor(self)
-        port_name = Ports.addInputPort("<narrow_cast>", self)
+        port_name = addInputPort("ui", start_port_id, True)
         atomdevs.addInPort(port_name)
-        port_name = Ports.addInputPort("field_ui", self)
+        atomdevs.state.port_mappings[port_name] = id
+        port_name = addInputPort("<narrow_cast>", start_port_id)
+        atomdevs.addInPort(port_name)
+        atomdevs.state.port_mappings[port_name] = id
+        port_name = addInputPort("field_ui", start_port_id)
         atomdevs.addInPort(port_name)
         atomdevs.state.port_mappings[port_name] = id
         self.inports["field_ui"] = port_name
@@ -479,12 +487,12 @@ class Field(ClassBase):
         self.outputs["parent"] = self.addOutPort("parent")
         self.field_ui = self.addInPort("field_ui")
     
-    def constructObject(self, id, parameters):
-        new_instance = FieldInstance(self, id)
+    def constructObject(self, id, start_port_id, parameters):
+        new_instance = FieldInstance(self, id, start_port_id)
         return new_instance
 
 class ButtonInstance(RuntimeClassBase):
-    def __init__(self, atomdevs, id, window_id, event_name, button_text):
+    def __init__(self, atomdevs, id, start_port_id, window_id, event_name, button_text):
         RuntimeClassBase.__init__(self, atomdevs, id)
         self.associations = {}
         self.associations["parent"] = Association("Field", 1, 1)
@@ -505,9 +513,13 @@ class ButtonInstance(RuntimeClassBase):
         
         # call user defined constructor
         ButtonInstance.user_defined_constructor(self, window_id, event_name, button_text)
-        port_name = Ports.addInputPort("<narrow_cast>", self)
+        port_name = addInputPort("ui", start_port_id, True)
         atomdevs.addInPort(port_name)
-        port_name = Ports.addInputPort("button_ui", self)
+        atomdevs.state.port_mappings[port_name] = id
+        port_name = addInputPort("<narrow_cast>", start_port_id)
+        atomdevs.addInPort(port_name)
+        atomdevs.state.port_mappings[port_name] = id
+        port_name = addInputPort("button_ui", start_port_id)
         atomdevs.addInPort(port_name)
         atomdevs.state.port_mappings[port_name] = id
         self.inports["button_ui"] = port_name
@@ -585,12 +597,12 @@ class Button(ClassBase):
         self.outputs["parent"] = self.addOutPort("parent")
         self.button_ui = self.addInPort("button_ui")
     
-    def constructObject(self, id, parameters):
-        new_instance = ButtonInstance(self, id, parameters[1], parameters[2], parameters[3])
+    def constructObject(self, id, start_port_id, parameters):
+        new_instance = ButtonInstance(self, id, start_port_id, parameters[1], parameters[2], parameters[3])
         return new_instance
 
 class BallInstance(RuntimeClassBase):
-    def __init__(self, atomdevs, id, canvas_id, x, y):
+    def __init__(self, atomdevs, id, start_port_id, canvas_id, x, y):
         RuntimeClassBase.__init__(self, atomdevs, id)
         self.associations = {}
         self.associations["parent"] = Association("Field", 1, 1)
@@ -610,9 +622,13 @@ class BallInstance(RuntimeClassBase):
         
         # call user defined constructor
         BallInstance.user_defined_constructor(self, canvas_id, x, y)
-        port_name = Ports.addInputPort("<narrow_cast>", self)
+        port_name = addInputPort("ui", start_port_id, True)
         atomdevs.addInPort(port_name)
-        port_name = Ports.addInputPort("ball_ui", self)
+        atomdevs.state.port_mappings[port_name] = id
+        port_name = addInputPort("<narrow_cast>", start_port_id)
+        atomdevs.addInPort(port_name)
+        atomdevs.state.port_mappings[port_name] = id
+        port_name = addInputPort("ball_ui", start_port_id)
         atomdevs.addInPort(port_name)
         atomdevs.state.port_mappings[port_name] = id
         self.inports["ball_ui"] = port_name
@@ -810,8 +826,8 @@ class Ball(ClassBase):
         self.outputs["parent"] = self.addOutPort("parent")
         self.ball_ui = self.addInPort("ball_ui")
     
-    def constructObject(self, id, parameters):
-        new_instance = BallInstance(self, id, parameters[1], parameters[2], parameters[3])
+    def constructObject(self, id, start_port_id, parameters):
+        new_instance = BallInstance(self, id, start_port_id, parameters[1], parameters[2], parameters[3])
         return new_instance
 
 class Dummy(ObjectManagerState):
@@ -822,17 +838,21 @@ class Dummy(ObjectManagerState):
         instance = {}
         instance["name"] = class_name
         if class_name == "MainApp":
+            self.narrow_cast_id = self.narrow_cast_id + 0
             instance["associations"] = {}
             instance["associations"]["fields"] = Association("Field", 0, -1)
         elif class_name == "Field":
+            self.narrow_cast_id = self.narrow_cast_id + 1
             instance["associations"] = {}
             instance["associations"]["balls"] = Association("Ball", 0, -1)
             instance["associations"]["buttons"] = Association("Button", 0, -1)
             instance["associations"]["parent"] = Association("MainApp", 1, 1)
         elif class_name == "Button":
+            self.narrow_cast_id = self.narrow_cast_id + 1
             instance["associations"] = {}
             instance["associations"]["parent"] = Association("Field", 1, 1)
         elif class_name == "Ball":
+            self.narrow_cast_id = self.narrow_cast_id + 1
             instance["associations"] = {}
             instance["associations"]["parent"] = Association("Field", 1, 1)
         else:
@@ -855,9 +875,7 @@ class Controller(CoupledDEVS):
     def __init__(self, name):
         CoupledDEVS.__init__(self, name)
         self.in_ui = self.addInPort("ui")
-        Ports.addInputPort("ui")
         self.out_ui = self.addOutPort("ui")
-        Ports.addOutputPort("ui")
         self.objectmanager = self.addSubModel(ObjectManager("ObjectManager"))
         self.atomics = []
         self.atomics.append(self.addSubModel(MainApp("MainApp")))

+ 32 - 37
examples/BouncingBalls/PyDEVS/the_target.py

@@ -16,7 +16,7 @@ CANVAS_DIMS = (800, 550)
 # package "Bouncing_Balls_DEVS_Version"
 
 class MainAppInstance(RuntimeClassBase):
-    def __init__(self, atomdevs, id):
+    def __init__(self, atomdevs, id, start_port_id):
         RuntimeClassBase.__init__(self, atomdevs, id)
         self.associations = {}
         self.associations["fields"] = Association("Field", 0, -1)
@@ -32,8 +32,9 @@ class MainAppInstance(RuntimeClassBase):
         
         # call user defined constructor
         MainAppInstance.user_defined_constructor(self)
-        port_name = Ports.addInputPort("<narrow_cast>", self)
+        port_name = addInputPort("<narrow_cast>", start_port_id)
         atomdevs.addInPort(port_name)
+        atomdevs.state.port_mappings[port_name] = id
     
     def user_defined_constructor(self):
         self.nr_of_fields = 0
@@ -201,19 +202,16 @@ class MainApp(ClassBase):
         self.input = self.addInPort("input")
         self.glob_outputs["ui"] = self.addOutPort("ui")
         self.outputs["fields"] = self.addOutPort("fields")
-        #self.state.instances[self.state.next_instance] = MainAppInstance(self, 0)
-        #self.state.instances[self.state.next_instance].instance_id = 0
-        new_instance = self.constructObject(0, [])
+        new_instance = self.constructObject(0, 0, [])
         self.state.instances[new_instance.instance_id] = new_instance
-
         self.state.next_instance = self.state.next_instance + 1
     
-    def constructObject(self, id, parameters):
-        new_instance = MainAppInstance(self, id)
+    def constructObject(self, id, start_port_id, parameters):
+        new_instance = MainAppInstance(self, id, start_port_id)
         return new_instance
 
 class FieldInstance(RuntimeClassBase):
-    def __init__(self, atomdevs, id):
+    def __init__(self, atomdevs, id, start_port_id):
         RuntimeClassBase.__init__(self, atomdevs, id)
         self.associations = {}
         self.associations["balls"] = Association("Ball", 0, -1)
@@ -235,9 +233,10 @@ class FieldInstance(RuntimeClassBase):
         
         # call user defined constructor
         FieldInstance.user_defined_constructor(self)
-        port_name = Ports.addInputPort("<narrow_cast>", self)
+        port_name = addInputPort("<narrow_cast>", start_port_id)
         atomdevs.addInPort(port_name)
-        port_name = Ports.addInputPort("field_ui", self)
+        atomdevs.state.port_mappings[port_name] = id
+        port_name = addInputPort("field_ui", start_port_id)
         atomdevs.addInPort(port_name)
         atomdevs.state.port_mappings[port_name] = id
         self.inports["field_ui"] = port_name
@@ -482,12 +481,12 @@ class Field(ClassBase):
         self.outputs["parent"] = self.addOutPort("parent")
         self.field_ui = self.addInPort("field_ui")
     
-    def constructObject(self, id, parameters):
-        new_instance = FieldInstance(self, id)
+    def constructObject(self, id, start_port_id, parameters):
+        new_instance = FieldInstance(self, id, start_port_id)
         return new_instance
 
 class ButtonInstance(RuntimeClassBase):
-    def __init__(self, atomdevs, id, window_id, event_name, button_text):
+    def __init__(self, atomdevs, id, start_port_id, window_id, event_name, button_text):
         RuntimeClassBase.__init__(self, atomdevs, id)
         self.associations = {}
         self.associations["parent"] = Association("Field", 1, 1)
@@ -508,9 +507,10 @@ class ButtonInstance(RuntimeClassBase):
         
         # call user defined constructor
         ButtonInstance.user_defined_constructor(self, window_id, event_name, button_text)
-        port_name = Ports.addInputPort("<narrow_cast>", self)
+        port_name = addInputPort("<narrow_cast>", start_port_id)
         atomdevs.addInPort(port_name)
-        port_name = Ports.addInputPort("button_ui", self)
+        atomdevs.state.port_mappings[port_name] = id
+        port_name = addInputPort("button_ui", start_port_id)
         atomdevs.addInPort(port_name)
         atomdevs.state.port_mappings[port_name] = id
         self.inports["button_ui"] = port_name
@@ -588,12 +588,12 @@ class Button(ClassBase):
         self.outputs["parent"] = self.addOutPort("parent")
         self.button_ui = self.addInPort("button_ui")
     
-    def constructObject(self, id,  parameters):
-        new_instance = ButtonInstance(self, id, parameters[1], parameters[2], parameters[3])
+    def constructObject(self, id, start_port_id, parameters):
+        new_instance = ButtonInstance(self, id, start_port_id, parameters[1], parameters[2], parameters[3])
         return new_instance
 
 class BallInstance(RuntimeClassBase):
-    def __init__(self, atomdevs, id, canvas_id, x, y):
+    def __init__(self, atomdevs, id, start_port_id, canvas_id, x, y):
         RuntimeClassBase.__init__(self, atomdevs, id)
         self.associations = {}
         self.associations["parent"] = Association("Field", 1, 1)
@@ -613,9 +613,10 @@ class BallInstance(RuntimeClassBase):
         
         # call user defined constructor
         BallInstance.user_defined_constructor(self, canvas_id, x, y)
-        port_name = Ports.addInputPort("<narrow_cast>", self)
+        port_name = addInputPort("<narrow_cast>", start_port_id)
         atomdevs.addInPort(port_name)
-        port_name = Ports.addInputPort("ball_ui", self)
+        atomdevs.state.port_mappings[port_name] = id
+        port_name = addInputPort("ball_ui", start_port_id)
         atomdevs.addInPort(port_name)
         atomdevs.state.port_mappings[port_name] = id
         self.inports["ball_ui"] = port_name
@@ -813,52 +814,48 @@ class Ball(ClassBase):
         self.outputs["parent"] = self.addOutPort("parent")
         self.ball_ui = self.addInPort("ball_ui")
     
-    def constructObject(self, id, parameters):
-        new_instance = BallInstance(self, id, parameters[1], parameters[2], parameters[3])
+    def constructObject(self, id, start_port_id, parameters):
+        new_instance = BallInstance(self, id, start_port_id, parameters[1], parameters[2], parameters[3])
         return new_instance
 
 class Dummy(ObjectManagerState):
     def __init__(self):
-        super().__init__()
+        ObjectManagerState.__init__(self)
     
     def instantiate(self, class_name, construct_params):
         instance = {}
         instance["name"] = class_name
         if class_name == "MainApp":
-            #instance = MainApp(self.controller)
             instance["associations"] = {}
             instance["associations"]["fields"] = Association("Field", 0, -1)
+            self.narrow_cast_id +=  0
         elif class_name == "Field":
-            #instance = Field(self.controller)
             instance["associations"] = {}
             instance["associations"]["balls"] = Association("Ball", 0, -1)
             instance["associations"]["buttons"] = Association("Button", 0, -1)
             instance["associations"]["parent"] = Association("MainApp", 1, 1)
+            self.narrow_cast_id +=  1
         elif class_name == "Button":
-            #instance = Button(self.controller, construct_params[0], construct_params[1], construct_params[2])
             instance["associations"] = {}
             instance["associations"]["parent"] = Association("Field", 1, 1)
+            self.narrow_cast_id +=  1
         elif class_name == "Ball":
-            #instance = Ball(self.controller, construct_params[0], construct_params[1], construct_params[2])
             instance["associations"] = {}
             instance["associations"]["parent"] = Association("Field", 1, 1)
+            self.narrow_cast_id +=  1
         else:
             raise Exception("Cannot instantiate class " + class_name)
         return instance
 
-
-
 class ObjectManager(ObjectManagerBase):
     def __init__(self, name):
         ObjectManagerBase.__init__(self, name)
         self.state = Dummy()
-        
         self.input = self.addInPort("input")
         self.output["MainApp"] = self.addOutPort()
         self.output["Field"] = self.addOutPort()
         self.output["Button"] = self.addOutPort()
         self.output["Ball"] = self.addOutPort()
-
         self.state.createInstance("MainApp", [])
         self.state.to_send.append((("MainApp", 0), ("MainApp", 0), Event("start_instance", None, ["MainApp[0]"])))
 
@@ -866,9 +863,7 @@ class Controller(CoupledDEVS):
     def __init__(self, name):
         CoupledDEVS.__init__(self, name)
         self.in_ui = self.addInPort("ui")
-        Ports.addInputPort("ui")
         self.out_ui = self.addOutPort("ui")
-        Ports.addOutputPort("ui")
         self.objectmanager = self.addSubModel(ObjectManager("ObjectManager"))
         self.atomics = []
         self.atomics.append(self.addSubModel(MainApp("MainApp")))
@@ -890,10 +885,10 @@ class Controller(CoupledDEVS):
         self.connectPorts(self.objectmanager.output["Ball"], self.atomics[3].obj_manager_in)
         self.connectPorts(self.atomics[3].outputs["parent"], self.atomics[1].input)
         self.connectPorts(self.atomics[0].glob_outputs["ui"], self.out_ui)
-        self.connectPorts(self.in_ui, self.atomics[0].input)
         self.connectPorts(self.atomics[1].glob_outputs["ui"], self.out_ui)
-        self.connectPorts(self.in_ui, self.atomics[1].input)
         self.connectPorts(self.atomics[2].glob_outputs["ui"], self.out_ui)
-        self.connectPorts(self.in_ui, self.atomics[2].input)
         self.connectPorts(self.atomics[3].glob_outputs["ui"], self.out_ui)
+        self.connectPorts(self.in_ui, self.atomics[0].input)
+        self.connectPorts(self.in_ui, self.atomics[1].input)
+        self.connectPorts(self.in_ui, self.atomics[2].input)
         self.connectPorts(self.in_ui, self.atomics[3].input)

Rozdílová data souboru nebyla zobrazena, protože soubor je příliš velký
+ 1087 - 2830
examples/BouncingBalls/PyDEVS/trace.txt


+ 35 - 27
examples/BouncingBallsCollision/PyDEVS/target.py

@@ -17,7 +17,7 @@ CANVAS_DIMS = (800, 550)
 # package "Bouncing_Balls_DEVS_Version"
 
 class MainAppInstance(RuntimeClassBase):
-    def __init__(self, atomdevs, id):
+    def __init__(self, atomdevs, id, start_port_id):
         RuntimeClassBase.__init__(self, atomdevs, id)
         self.associations = {}
         self.associations["fields"] = Association("Field", 0, -1)
@@ -33,8 +33,9 @@ class MainAppInstance(RuntimeClassBase):
         
         # call user defined constructor
         MainAppInstance.user_defined_constructor(self)
-        port_name = Ports.addInputPort("<narrow_cast>", self)
+        port_name = addInputPort("<narrow_cast>", start_port_id)
         atomdevs.addInPort(port_name)
+        atomdevs.state.port_mappings[port_name] = id
     
     def user_defined_constructor(self):
         self.nr_of_fields = 0
@@ -202,16 +203,16 @@ class MainApp(ClassBase):
         self.input = self.addInPort("input")
         self.glob_outputs["ui"] = self.addOutPort("ui")
         self.outputs["fields"] = self.addOutPort("fields")
-        new_instance = self.constructObject(0, [])
+        new_instance = self.constructObject(0, 0, [])
         self.state.instances[new_instance.instance_id] = new_instance
         self.state.next_instance = self.state.next_instance + 1
     
-    def constructObject(self, id, parameters):
-        new_instance = MainAppInstance(self, id)
+    def constructObject(self, id, start_port_id, parameters):
+        new_instance = MainAppInstance(self, id, start_port_id)
         return new_instance
 
 class FieldInstance(RuntimeClassBase):
-    def __init__(self, atomdevs, id):
+    def __init__(self, atomdevs, id, start_port_id):
         RuntimeClassBase.__init__(self, atomdevs, id)
         self.associations = {}
         self.associations["balls"] = Association("Ball", 0, -1)
@@ -234,9 +235,10 @@ class FieldInstance(RuntimeClassBase):
         
         # call user defined constructor
         FieldInstance.user_defined_constructor(self)
-        port_name = Ports.addInputPort("<narrow_cast>", self)
+        port_name = addInputPort("<narrow_cast>", start_port_id)
         atomdevs.addInPort(port_name)
-        port_name = Ports.addInputPort("field_ui", self)
+        atomdevs.state.port_mappings[port_name] = id
+        port_name = addInputPort("field_ui", start_port_id)
         atomdevs.addInPort(port_name)
         atomdevs.state.port_mappings[port_name] = id
         self.inports["field_ui"] = port_name
@@ -569,12 +571,12 @@ class Field(ClassBase):
         self.outputs["parent"] = self.addOutPort("parent")
         self.field_ui = self.addInPort("field_ui")
     
-    def constructObject(self, id, parameters):
-        new_instance = FieldInstance(self, id)
+    def constructObject(self, id, start_port_id, parameters):
+        new_instance = FieldInstance(self, id, start_port_id)
         return new_instance
 
 class ButtonInstance(RuntimeClassBase):
-    def __init__(self, atomdevs, id, window_id, event_name, button_text):
+    def __init__(self, atomdevs, id, start_port_id, window_id, event_name, button_text):
         RuntimeClassBase.__init__(self, atomdevs, id)
         self.associations = {}
         self.associations["parent"] = Association("Field", 1, 1)
@@ -595,9 +597,10 @@ class ButtonInstance(RuntimeClassBase):
         
         # call user defined constructor
         ButtonInstance.user_defined_constructor(self, window_id, event_name, button_text)
-        port_name = Ports.addInputPort("<narrow_cast>", self)
+        port_name = addInputPort("<narrow_cast>", start_port_id)
         atomdevs.addInPort(port_name)
-        port_name = Ports.addInputPort("button_ui", self)
+        atomdevs.state.port_mappings[port_name] = id
+        port_name = addInputPort("button_ui", start_port_id)
         atomdevs.addInPort(port_name)
         atomdevs.state.port_mappings[port_name] = id
         self.inports["button_ui"] = port_name
@@ -675,12 +678,12 @@ class Button(ClassBase):
         self.outputs["parent"] = self.addOutPort("parent")
         self.button_ui = self.addInPort("button_ui")
     
-    def constructObject(self, id, parameters):
-        new_instance = ButtonInstance(self, id, parameters[1], parameters[2], parameters[3])
+    def constructObject(self, id, start_port_id, parameters):
+        new_instance = ButtonInstance(self, id, start_port_id, parameters[1], parameters[2], parameters[3])
         return new_instance
 
 class BallInstance(RuntimeClassBase):
-    def __init__(self, atomdevs, id, canvas_id, x, y):
+    def __init__(self, atomdevs, id, start_port_id, canvas_id, x, y):
         RuntimeClassBase.__init__(self, atomdevs, id)
         self.associations = {}
         self.associations["parent"] = Association("Field", 1, 1)
@@ -700,9 +703,10 @@ class BallInstance(RuntimeClassBase):
         
         # call user defined constructor
         BallInstance.user_defined_constructor(self, canvas_id, x, y)
-        port_name = Ports.addInputPort("<narrow_cast>", self)
+        port_name = addInputPort("<narrow_cast>", start_port_id)
         atomdevs.addInPort(port_name)
-        port_name = Ports.addInputPort("ball_ui", self)
+        atomdevs.state.port_mappings[port_name] = id
+        port_name = addInputPort("ball_ui", start_port_id)
         atomdevs.addInPort(port_name)
         atomdevs.state.port_mappings[port_name] = id
         self.inports["ball_ui"] = port_name
@@ -910,12 +914,12 @@ class Ball(ClassBase):
         self.outputs["parent"] = self.addOutPort("parent")
         self.ball_ui = self.addInPort("ball_ui")
     
-    def constructObject(self, id, parameters):
-        new_instance = BallInstance(self, id, parameters[1], parameters[2], parameters[3])
+    def constructObject(self, id, start_port_id, parameters):
+        new_instance = BallInstance(self, id, start_port_id, parameters[1], parameters[2], parameters[3])
         return new_instance
 
 class CollisionPhysicsInstance(RuntimeClassBase):
-    def __init__(self, atomdevs, id, ball1_id, ball2_id, ball1_info, ball2_info):
+    def __init__(self, atomdevs, id, start_port_id, ball1_id, ball2_id, ball1_info, ball2_info):
         RuntimeClassBase.__init__(self, atomdevs, id)
         self.associations = {}
         self.associations["parent"] = Association("Field", 1, 1)
@@ -934,9 +938,10 @@ class CollisionPhysicsInstance(RuntimeClassBase):
         
         # call user defined constructor
         CollisionPhysicsInstance.user_defined_constructor(self, ball1_id, ball2_id, ball1_info, ball2_info)
-        port_name = Ports.addInputPort("<narrow_cast>", self)
+        port_name = addInputPort("<narrow_cast>", start_port_id)
         atomdevs.addInPort(port_name)
-        port_name = Ports.addInputPort("physics_ui", self)
+        atomdevs.state.port_mappings[port_name] = id
+        port_name = addInputPort("physics_ui", start_port_id)
         atomdevs.addInPort(port_name)
         atomdevs.state.port_mappings[port_name] = id
         self.inports["physics_ui"] = port_name
@@ -1052,8 +1057,8 @@ class CollisionPhysics(ClassBase):
         self.outputs["parent"] = self.addOutPort("parent")
         self.physics_ui = self.addInPort("physics_ui")
     
-    def constructObject(self, id, parameters):
-        new_instance = CollisionPhysicsInstance(self, id, parameters[1], parameters[2], parameters[3], parameters[4])
+    def constructObject(self, id, start_port_id, parameters):
+        new_instance = CollisionPhysicsInstance(self, id, start_port_id, parameters[1], parameters[2], parameters[3], parameters[4])
         return new_instance
 
 class Dummy(ObjectManagerState):
@@ -1064,21 +1069,26 @@ class Dummy(ObjectManagerState):
         instance = {}
         instance["name"] = class_name
         if class_name == "MainApp":
+            self.narrow_cast_id = self.narrow_cast_id + 0
             instance["associations"] = {}
             instance["associations"]["fields"] = Association("Field", 0, -1)
         elif class_name == "Field":
+            self.narrow_cast_id = self.narrow_cast_id + 1
             instance["associations"] = {}
             instance["associations"]["balls"] = Association("Ball", 0, -1)
             instance["associations"]["buttons"] = Association("Button", 0, -1)
             instance["associations"]["collisions"] = Association("CollisionPhysics", 0, -1)
             instance["associations"]["parent"] = Association("MainApp", 1, 1)
         elif class_name == "Button":
+            self.narrow_cast_id = self.narrow_cast_id + 1
             instance["associations"] = {}
             instance["associations"]["parent"] = Association("Field", 1, 1)
         elif class_name == "Ball":
+            self.narrow_cast_id = self.narrow_cast_id + 1
             instance["associations"] = {}
             instance["associations"]["parent"] = Association("Field", 1, 1)
         elif class_name == "CollisionPhysics":
+            self.narrow_cast_id = self.narrow_cast_id + 1
             instance["associations"] = {}
             instance["associations"]["parent"] = Association("Field", 1, 1)
         else:
@@ -1102,9 +1112,7 @@ class Controller(CoupledDEVS):
     def __init__(self, name):
         CoupledDEVS.__init__(self, name)
         self.in_ui = self.addInPort("ui")
-        Ports.addInputPort("ui")
         self.out_ui = self.addOutPort("ui")
-        Ports.addOutputPort("ui")
         self.objectmanager = self.addSubModel(ObjectManager("ObjectManager"))
         self.atomics = []
         self.atomics.append(self.addSubModel(MainApp("MainApp")))

+ 3 - 12
examples/ElevatorBalls/PyDEVS/runner.py

@@ -1,5 +1,5 @@
 import tkinter as tk
-import examples.ElevatorBalls.PyDEVS.target as target
+import target as target
 from sccd.runtime.libs.ui_v2 import UI
 from sccd.runtime.DEVS_loop import DEVSSimulator
 
@@ -15,21 +15,12 @@ class OutputListener:
 
 if __name__ == '__main__':
 	model = target.Controller(name="controller")
-	refs = {
-		"ui": model.in_ui,  
-		"field_ui": model.atomic0.field_ui, 
-		"floor_ui": model.atomic1.floor_ui, 
-		#"control_ui": model.atomic2.control_ui,
-		"button_ui": model.atomic2.button_ui,
-		"elevator_ui": model.atomic3.elevator_ui, 
-		"ball_ui": model.atomic4.ball_ui
-		}
 
 	tkroot = tk.Tk()
 	tkroot.withdraw()
-	sim = DEVSSimulator(model, refs)
+	sim = DEVSSimulator(model)
 
-	sim.setVerbose()
+	#sim.setVerbose("./examples/BouncingBalls/PyDEVS/log.txt")
 	sim.setRealTimePlatformTk(tkroot)
 
 	ui = UI(tkroot, sim)

+ 139 - 111
examples/ElevatorBalls/PyDEVS/target.py

@@ -19,13 +19,12 @@ FLOORS = 3
 # package "Elevator Balls"
 
 class MainAppInstance(RuntimeClassBase):
-    def __init__(self, atomdevs):
-        RuntimeClassBase.__init__(self, atomdevs)
+    def __init__(self, atomdevs, id):
+        RuntimeClassBase.__init__(self, atomdevs, id)
         self.associations = {}
         self.associations["floor"] = Association("Floor", 2, -1)
         self.associations["button"] = Association("ElevatorButton", 0, -1)
         self.associations["elevator"] = Association("Elevator", 1, 1)
-        self.associations["ball"] = Association("Ball", 0, -1)
         
         self.semantics.big_step_maximality = StatechartSemantics.TakeMany
         self.semantics.internal_event_lifeline = StatechartSemantics.Queue
@@ -48,7 +47,7 @@ class MainAppInstance(RuntimeClassBase):
         atomdevs.addInPort(port_name)
         port_name = Ports.addInputPort("field_ui", self)
         atomdevs.addInPort(port_name)
-        atomdevs.port_mappings[port_name] = atomdevs.next_instance
+        atomdevs.state.port_mappings[port_name] = id
         self.inports["field_ui"] = port_name
     
     def user_defined_constructor(self):
@@ -194,24 +193,15 @@ class MainAppInstance(RuntimeClassBase):
         # transition /running
         _running_0 = Transition(self, self.states["/running"], [self.states["/running"]])
         _running_0.setAction(self._running_0_exec)
-        _running_0.setTrigger(Event("create_ball", None))
+        _running_0.setTrigger(Event("update_bounds", None))
         self.states["/running"].addTransition(_running_0)
         _running_1 = Transition(self, self.states["/running"], [self.states["/running"]])
         _running_1.setAction(self._running_1_exec)
-        _running_1.setTrigger(Event("instance_created", None))
+        _running_1.setTrigger(Event("button_pressed", None))
         self.states["/running"].addTransition(_running_1)
         _running_2 = Transition(self, self.states["/running"], [self.states["/running"]])
-        _running_2.setAction(self._running_2_exec)
-        _running_2.setTrigger(Event("update_bounds", None))
+        _running_2.setTrigger(Event("open_elevator", None))
         self.states["/running"].addTransition(_running_2)
-        _running_3 = Transition(self, self.states["/running"], [self.states["/running"]])
-        _running_3.setAction(self._running_3_exec)
-        _running_3.setTrigger(Event("button_pressed", None))
-        self.states["/running"].addTransition(_running_3)
-        _running_4 = Transition(self, self.states["/running"], [self.states["/running"]])
-        _running_4.setAction(self._running_4_exec)
-        _running_4.setTrigger(Event("open_elevator", None))
-        self.states["/running"].addTransition(_running_4)
     
     def _creating_window_enter(self):
         self.big_step.outputEvent(Event("create_window", self.getOutPortName("ui"), [CANVAS_DIMS[0], CANVAS_DIMS[1], "Bouncing Balls Elevator", self.inports['field_ui']]))
@@ -268,56 +258,43 @@ class MainAppInstance(RuntimeClassBase):
         self.big_step.outputEventOM(Event("narrow_cast", None, [self, association_name, Event("set_association_name", None, [association_name, self.canvas_id, self.window_id])]))
     
     def _running_0_exec(self, parameters):
-        floor_num = parameters[0]
-        x = parameters[1]
-        y = parameters[2]
-        self.big_step.outputEventOM(Event("create_instance", None, [self, "ball", "Ball", self.canvas_id, floor_num, x, y, self.elevator_pos, self.elevator_dim]))
-    
-    def _running_1_exec(self, parameters):
-        association_name = parameters[0]
-        self.big_step.outputEventOM(Event("start_instance", None, [self, association_name]))
-        self.big_step.outputEventOM(Event("narrow_cast", None, [self, association_name, Event("set_association_name", None, [association_name])]))
-    
-    def _running_2_exec(self, parameters):
         pos = parameters[0]
         dim = parameters[1]
         vel = parameters[2]
         self.big_step.outputEventOM(Event("broad_cast", None, [self, Event("update_elevator_bounds", None, [pos, dim, vel])]))
     
-    def _running_3_exec(self, parameters):
+    def _running_1_exec(self, parameters):
         floor_number = parameters[0]
         self.big_step.outputEventOM(Event("narrow_cast", None, [self, 'elevator', Event("move_elevator", None, [floor_number])]))
     
-    def _running_4_exec(self, parameters):
-        self.big_step.outputEventOM(Event("narrow_cast", None, [self, 'ball', Event("open_elevator", None, [])]))
-    
     def initializeStatechart(self):
         # enter default state
         self.default_targets = self.states["/creating_window"].getEffectiveTargetStates()
         RuntimeClassBase.initializeStatechart(self)
 
-class MainApp(ObjectManagerBase):
+class MainApp(ClassBase):
     def __init__(self, name):
-        ObjectManagerBase.__init__(self, name)
+        ClassBase.__init__(self, name)
         self.input = self.addInPort("input")
-        self.output = self.addOutPort("ui")
+        self.glob_outputs["ui"] = self.addOutPort("ui")
         self.outputs["floor"] = self.addOutPort("floor")
         self.outputs["button"] = self.addOutPort("button")
         self.outputs["elevator"] = self.addOutPort("elevator")
-        self.outputs["ball"] = self.addOutPort("ball")
         self.field_ui = self.addInPort("field_ui")
-        self.instances[self.next_instance] = MainAppInstance(self)
-        self.next_instance = self.next_instance + 1
+        new_instance = self.constructObject(0, [])
+        self.state.instances[new_instance.instance_id] = new_instance
+        self.state.next_instance = self.state.next_instance + 1
     
-    def constructObject(self, parameters):
-        new_instance = MainAppInstance(self)
+    def constructObject(self, id, parameters):
+        new_instance = MainAppInstance(self, id)
         return new_instance
 
 class FloorInstance(RuntimeClassBase):
-    def __init__(self, atomdevs, canvas_id, floor_num):
-        RuntimeClassBase.__init__(self, atomdevs)
+    def __init__(self, atomdevs, id, canvas_id, floor_num):
+        RuntimeClassBase.__init__(self, atomdevs, id)
         self.associations = {}
         self.associations["parent"] = Association("MainApp", 1, 1)
+        self.associations["balls"] = Association("Ball", 0, -1)
         
         self.semantics.big_step_maximality = StatechartSemantics.TakeMany
         self.semantics.internal_event_lifeline = StatechartSemantics.Queue
@@ -339,7 +316,7 @@ class FloorInstance(RuntimeClassBase):
         atomdevs.addInPort(port_name)
         port_name = Ports.addInputPort("floor_ui", self)
         atomdevs.addInPort(port_name)
-        atomdevs.port_mappings[port_name] = atomdevs.next_instance
+        atomdevs.state.port_mappings[port_name] = id
         self.inports["floor_ui"] = port_name
     
     def user_defined_constructor(self, canvas_id, floor_num):
@@ -380,10 +357,14 @@ class FloorInstance(RuntimeClassBase):
         self.states["/running/create_random_ball"].setEnter(self._running_create_random_ball_enter)
         self.states["/running/create_random_ball"].setExit(self._running_create_random_ball_exit)
         
+        # state /running/wait
+        self.states["/running/wait"] = State(4, "/running/wait", self)
+        
         # add children
         self.states[""].addChild(self.states["/creating_floor"])
         self.states[""].addChild(self.states["/running"])
         self.states["/running"].addChild(self.states["/running/create_random_ball"])
+        self.states["/running"].addChild(self.states["/running/wait"])
         self.states[""].fixTree()
         self.states[""].default_state = self.states["/creating_floor"]
         self.states["/running"].default_state = self.states["/running/create_random_ball"]
@@ -394,10 +375,16 @@ class FloorInstance(RuntimeClassBase):
         self.states["/creating_floor"].addTransition(_creating_floor_0)
         
         # transition /running/create_random_ball
-        _running_create_random_ball_0 = Transition(self, self.states["/running/create_random_ball"], [self.states["/running/create_random_ball"]])
+        _running_create_random_ball_0 = Transition(self, self.states["/running/create_random_ball"], [self.states["/running/wait"]])
         _running_create_random_ball_0.setAction(self._running_create_random_ball_0_exec)
         _running_create_random_ball_0.setTrigger(Event("_0after"))
         self.states["/running/create_random_ball"].addTransition(_running_create_random_ball_0)
+        
+        # transition /running/wait
+        _running_wait_0 = Transition(self, self.states["/running/wait"], [self.states["/running/create_random_ball"]])
+        _running_wait_0.setAction(self._running_wait_0_exec)
+        _running_wait_0.setTrigger(Event("instance_created", None))
+        self.states["/running/wait"].addTransition(_running_wait_0)
     
     def _creating_floor_enter(self):
         self.big_step.outputEvent(Event("create_rectangle", self.getOutPortName("ui"), [self.canvas_id, self.pos['x'], self.pos['y'], self.dim['x'], self.dim['y'], {'fill':'white', 'outline': 'black'}, self.inports['floor_ui']]))
@@ -409,28 +396,34 @@ class FloorInstance(RuntimeClassBase):
         self.removeTimer(0)
     
     def _running_create_random_ball_0_exec(self, parameters):
-        self.big_step.outputEventOM(Event("narrow_cast", None, [self, 'parent', Event("create_ball", None, [self.floor_num, 10, self.pos['y']])]))
+        self.big_step.outputEventOM(Event("create_instance", None, [self, "balls", "Ball", self.canvas_id, self.floor_num, 10, self.pos['y']]))
+    
+    def _running_wait_0_exec(self, parameters):
+        association_name = parameters[0]
+        self.big_step.outputEventOM(Event("start_instance", None, [self, association_name]))
+        self.big_step.outputEventOM(Event("narrow_cast", None, [self, association_name, Event("set_association_name", None, [association_name])]))
     
     def initializeStatechart(self):
         # enter default state
         self.default_targets = self.states["/creating_floor"].getEffectiveTargetStates()
         RuntimeClassBase.initializeStatechart(self)
 
-class Floor(ObjectManagerBase):
+class Floor(ClassBase):
     def __init__(self, name):
-        ObjectManagerBase.__init__(self, name)
+        ClassBase.__init__(self, name)
         self.input = self.addInPort("input")
-        self.output = self.addOutPort("ui")
+        self.glob_outputs["ui"] = self.addOutPort("ui")
         self.outputs["parent"] = self.addOutPort("parent")
+        self.outputs["balls"] = self.addOutPort("balls")
         self.floor_ui = self.addInPort("floor_ui")
     
-    def constructObject(self, parameters):
-        new_instance = FloorInstance(self, parameters[2], parameters[3])
+    def constructObject(self, id, parameters):
+        new_instance = FloorInstance(self, id, parameters[1], parameters[2])
         return new_instance
 
 class ElevatorButtonInstance(RuntimeClassBase):
-    def __init__(self, atomdevs, window_id, canvas_id, number):
-        RuntimeClassBase.__init__(self, atomdevs)
+    def __init__(self, atomdevs, id, window_id, canvas_id, number):
+        RuntimeClassBase.__init__(self, atomdevs, id)
         self.associations = {}
         self.associations["parent"] = Association("MainApp", 1, 1)
         
@@ -449,7 +442,7 @@ class ElevatorButtonInstance(RuntimeClassBase):
         atomdevs.addInPort(port_name)
         port_name = Ports.addInputPort("button_ui", self)
         atomdevs.addInPort(port_name)
-        atomdevs.port_mappings[port_name] = atomdevs.next_instance
+        atomdevs.state.port_mappings[port_name] = id
         self.inports["button_ui"] = port_name
     
     def user_defined_constructor(self, window_id, canvas_id, number):
@@ -523,21 +516,21 @@ class ElevatorButtonInstance(RuntimeClassBase):
         self.default_targets = self.states["/creating"].getEffectiveTargetStates()
         RuntimeClassBase.initializeStatechart(self)
 
-class ElevatorButton(ObjectManagerBase):
+class ElevatorButton(ClassBase):
     def __init__(self, name):
-        ObjectManagerBase.__init__(self, name)
+        ClassBase.__init__(self, name)
         self.input = self.addInPort("input")
-        self.output = self.addOutPort("ui")
+        self.glob_outputs["ui"] = self.addOutPort("ui")
         self.outputs["parent"] = self.addOutPort("parent")
         self.button_ui = self.addInPort("button_ui")
     
-    def constructObject(self, parameters):
-        new_instance = ElevatorButtonInstance(self, parameters[2], parameters[3], parameters[4])
+    def constructObject(self, id, parameters):
+        new_instance = ElevatorButtonInstance(self, id, parameters[1], parameters[2], parameters[3])
         return new_instance
 
 class ElevatorInstance(RuntimeClassBase):
-    def __init__(self, atomdevs, canvas_id):
-        RuntimeClassBase.__init__(self, atomdevs)
+    def __init__(self, atomdevs, id, canvas_id):
+        RuntimeClassBase.__init__(self, atomdevs, id)
         self.associations = {}
         self.associations["floors"] = Association("Floor", 1, 1)
         self.associations["parent"] = Association("MainApp", 1, 1)
@@ -562,7 +555,7 @@ class ElevatorInstance(RuntimeClassBase):
         atomdevs.addInPort(port_name)
         port_name = Ports.addInputPort("elevator_ui", self)
         atomdevs.addInPort(port_name)
-        atomdevs.port_mappings[port_name] = atomdevs.next_instance
+        atomdevs.state.port_mappings[port_name] = id
         self.inports["elevator_ui"] = port_name
     
     def user_defined_constructor(self, canvas_id):
@@ -710,22 +703,22 @@ class ElevatorInstance(RuntimeClassBase):
         self.default_targets = self.states["/root"].getEffectiveTargetStates()
         RuntimeClassBase.initializeStatechart(self)
 
-class Elevator(ObjectManagerBase):
+class Elevator(ClassBase):
     def __init__(self, name):
-        ObjectManagerBase.__init__(self, name)
+        ClassBase.__init__(self, name)
         self.input = self.addInPort("input")
-        self.output = self.addOutPort("ui")
+        self.glob_outputs["ui"] = self.addOutPort("ui")
         self.outputs["floors"] = self.addOutPort("floors")
         self.outputs["parent"] = self.addOutPort("parent")
         self.elevator_ui = self.addInPort("elevator_ui")
     
-    def constructObject(self, parameters):
-        new_instance = ElevatorInstance(self, parameters[2])
+    def constructObject(self, id, parameters):
+        new_instance = ElevatorInstance(self, id, parameters[1])
         return new_instance
 
 class BallInstance(RuntimeClassBase):
-    def __init__(self, atomdevs, canvas_id, floor_num, x, y, elevator_pos, elevator_dim):
-        RuntimeClassBase.__init__(self, atomdevs)
+    def __init__(self, atomdevs, id, canvas_id, floor_num, x, y):
+        RuntimeClassBase.__init__(self, atomdevs, id)
         self.associations = {}
         self.associations["parent"] = Association("MainApp", 1, 1)
         
@@ -743,15 +736,15 @@ class BallInstance(RuntimeClassBase):
         self.pos = None
         
         # call user defined constructor
-        BallInstance.user_defined_constructor(self, canvas_id, floor_num, x, y, elevator_pos, elevator_dim)
+        BallInstance.user_defined_constructor(self, canvas_id, floor_num, x, y)
         port_name = Ports.addInputPort("<narrow_cast>", self)
         atomdevs.addInPort(port_name)
         port_name = Ports.addInputPort("ball_ui", self)
         atomdevs.addInPort(port_name)
-        atomdevs.port_mappings[port_name] = atomdevs.next_instance
+        atomdevs.state.port_mappings[port_name] = id
         self.inports["ball_ui"] = port_name
     
-    def user_defined_constructor(self, canvas_id, floor_num, x, y, elevator_pos, elevator_dim):
+    def user_defined_constructor(self, canvas_id, floor_num, x, y):
         self.canvas_id = canvas_id;
         
         
@@ -759,8 +752,6 @@ class BallInstance(RuntimeClassBase):
         
         self.elevator_floor = 0;
         self.elevator_open = True;
-        self.rect_pos = elevator_pos;
-        self.rect_dim = elevator_dim;
         
         self.r = 5.0;
         self.vel = {'x': random.uniform(-5.0, 5.0), 'y': random.uniform(-5.0, 5.0)};
@@ -865,6 +856,8 @@ class BallInstance(RuntimeClassBase):
     
     def _main_behaviour_bouncing_0_exec(self, parameters):
         if self.floor_num == -1:
+            pass
+            """
             if self.pos['x'] - self.r < self.rect_pos['x'] - (self.rect_dim['x'] / 2):
                 if self.elevator_open:
                     self.floor_num = self.elevator_floor
@@ -882,6 +875,7 @@ class BallInstance(RuntimeClassBase):
             elif self.pos['y'] + self.r > self.rect_pos['y'] + (self.rect_dim['y'] / 2):
                 self.pos['y'] = self.rect_pos['y'] + (self.rect_dim['y'] / 2) - self.r
                 self.vel['y'] = -self.vel['y'] + self.rect_vel
+            """
         else:
             floor_height = ((CANVAS_DIMS[1] - 150) - ((FLOORS - 1) * FLOOR_SPACE)) / FLOORS
             floor_dim = {'x': FLOOR_LENGTH, 'y': floor_height};
@@ -932,32 +926,60 @@ class BallInstance(RuntimeClassBase):
         self.default_targets = self.states["/main_behaviour"].getEffectiveTargetStates()
         RuntimeClassBase.initializeStatechart(self)
 
-class Ball(ObjectManagerBase):
+class Ball(ClassBase):
     def __init__(self, name):
-        ObjectManagerBase.__init__(self, name)
+        ClassBase.__init__(self, name)
         self.input = self.addInPort("input")
-        self.output = self.addOutPort("ui")
+        self.glob_outputs["ui"] = self.addOutPort("ui")
         self.outputs["parent"] = self.addOutPort("parent")
         self.ball_ui = self.addInPort("ball_ui")
     
-    def constructObject(self, parameters):
-        new_instance = BallInstance(self, parameters[2], parameters[3], parameters[4], parameters[5], parameters[6], parameters[7])
+    def constructObject(self, id, parameters):
+        new_instance = BallInstance(self, id, parameters[1], parameters[2], parameters[3], parameters[4])
         return new_instance
 
-class ObjectManagerState:
+class Dummy(ObjectManagerState):
     def __init__(self):
-        self.to_send = [("MainApp", "MainApp", Event("start_instance", None, ["MainApp[0]"], 0))]
+        ObjectManagerState.__init__(self)
+    
+    def instantiate(self, class_name, construct_params):
+        instance = {}
+        instance["name"] = class_name
+        if class_name == "MainApp":
+            instance["associations"] = {}
+            instance["associations"]["floor"] = Association("Floor", 2, -1)
+            instance["associations"]["button"] = Association("ElevatorButton", 0, -1)
+            instance["associations"]["elevator"] = Association("Elevator", 1, 1)
+        elif class_name == "Floor":
+            instance["associations"] = {}
+            instance["associations"]["parent"] = Association("MainApp", 1, 1)
+            instance["associations"]["balls"] = Association("Ball", 0, -1)
+        elif class_name == "ElevatorButton":
+            instance["associations"] = {}
+            instance["associations"]["parent"] = Association("MainApp", 1, 1)
+        elif class_name == "Elevator":
+            instance["associations"] = {}
+            instance["associations"]["floors"] = Association("Floor", 1, 1)
+            instance["associations"]["parent"] = Association("MainApp", 1, 1)
+        elif class_name == "Ball":
+            instance["associations"] = {}
+            instance["associations"]["parent"] = Association("MainApp", 1, 1)
+        else:
+            raise Exception("Cannot instantiate class " + class_name)
+        return instance
 
-class ObjectManager(TheObjectManager):
+class ObjectManager(ObjectManagerBase):
     def __init__(self, name):
-        TheObjectManager.__init__(self, name)
-        self.State = ObjectManagerState()
+        ObjectManagerBase.__init__(self, name)
+        self.state = Dummy()
         self.input = self.addInPort("input")
         self.output["MainApp"] = self.addOutPort()
         self.output["Floor"] = self.addOutPort()
         self.output["ElevatorButton"] = self.addOutPort()
         self.output["Elevator"] = self.addOutPort()
         self.output["Ball"] = self.addOutPort()
+        self.state.createInstance("MainApp", [])
+        self.state.to_send.append((("MainApp", 0), ("MainApp", 0), Event("start_instance", None, ["MainApp[0]"])))
 
 class Controller(CoupledDEVS):
     def __init__(self, name):
@@ -967,32 +989,38 @@ class Controller(CoupledDEVS):
         self.out_ui = self.addOutPort("ui")
         Ports.addOutputPort("ui")
         self.objectmanager = self.addSubModel(ObjectManager("ObjectManager"))
-        self.atomic0 = self.addSubModel(MainApp("MainApp"))
-        self.atomic1 = self.addSubModel(Floor("Floor"))
-        self.atomic2 = self.addSubModel(ElevatorButton("ElevatorButton"))
-        self.atomic3 = self.addSubModel(Elevator("Elevator"))
-        self.atomic4 = self.addSubModel(Ball("Ball"))
-        self.connectPorts(self.atomic0.obj_manager_out, self.objectmanager.input)
-        self.connectPorts(self.objectmanager.output["MainApp"], self.atomic0.obj_manager_in)
-        self.connectPorts(self.atomic0.outputs["floor"], self.atomic1.input)
-        self.connectPorts(self.atomic0.outputs["button"], self.atomic2.input)
-        self.connectPorts(self.atomic0.outputs["elevator"], self.atomic3.input)
-        self.connectPorts(self.atomic0.outputs["ball"], self.atomic4.input)
-        self.connectPorts(self.atomic1.obj_manager_out, self.objectmanager.input)
-        self.connectPorts(self.objectmanager.output["Floor"], self.atomic1.obj_manager_in)
-        self.connectPorts(self.atomic1.outputs["parent"], self.atomic0.input)
-        self.connectPorts(self.atomic2.obj_manager_out, self.objectmanager.input)
-        self.connectPorts(self.objectmanager.output["ElevatorButton"], self.atomic2.obj_manager_in)
-        self.connectPorts(self.atomic2.outputs["parent"], self.atomic0.input)
-        self.connectPorts(self.atomic3.obj_manager_out, self.objectmanager.input)
-        self.connectPorts(self.objectmanager.output["Elevator"], self.atomic3.obj_manager_in)
-        self.connectPorts(self.atomic3.outputs["floors"], self.atomic1.input)
-        self.connectPorts(self.atomic3.outputs["parent"], self.atomic0.input)
-        self.connectPorts(self.atomic4.obj_manager_out, self.objectmanager.input)
-        self.connectPorts(self.objectmanager.output["Ball"], self.atomic4.obj_manager_in)
-        self.connectPorts(self.atomic4.outputs["parent"], self.atomic0.input)
-        self.connectPorts(self.atomic0.output, self.out_ui)
-        self.connectPorts(self.atomic1.output, self.out_ui)
-        self.connectPorts(self.atomic2.output, self.out_ui)
-        self.connectPorts(self.atomic3.output, self.out_ui)
-        self.connectPorts(self.atomic4.output, self.out_ui)
+        self.atomics = []
+        self.atomics.append(self.addSubModel(MainApp("MainApp")))
+        self.atomics.append(self.addSubModel(Floor("Floor")))
+        self.atomics.append(self.addSubModel(ElevatorButton("ElevatorButton")))
+        self.atomics.append(self.addSubModel(Elevator("Elevator")))
+        self.atomics.append(self.addSubModel(Ball("Ball")))
+        self.connectPorts(self.atomics[0].obj_manager_out, self.objectmanager.input)
+        self.connectPorts(self.objectmanager.output["MainApp"], self.atomics[0].obj_manager_in)
+        self.connectPorts(self.atomics[0].outputs["floor"], self.atomics[1].input)
+        self.connectPorts(self.atomics[0].outputs["button"], self.atomics[2].input)
+        self.connectPorts(self.atomics[0].outputs["elevator"], self.atomics[3].input)
+        self.connectPorts(self.atomics[1].obj_manager_out, self.objectmanager.input)
+        self.connectPorts(self.objectmanager.output["Floor"], self.atomics[1].obj_manager_in)
+        self.connectPorts(self.atomics[1].outputs["parent"], self.atomics[0].input)
+        self.connectPorts(self.atomics[1].outputs["balls"], self.atomics[4].input)
+        self.connectPorts(self.atomics[2].obj_manager_out, self.objectmanager.input)
+        self.connectPorts(self.objectmanager.output["ElevatorButton"], self.atomics[2].obj_manager_in)
+        self.connectPorts(self.atomics[2].outputs["parent"], self.atomics[0].input)
+        self.connectPorts(self.atomics[3].obj_manager_out, self.objectmanager.input)
+        self.connectPorts(self.objectmanager.output["Elevator"], self.atomics[3].obj_manager_in)
+        self.connectPorts(self.atomics[3].outputs["floors"], self.atomics[1].input)
+        self.connectPorts(self.atomics[3].outputs["parent"], self.atomics[0].input)
+        self.connectPorts(self.atomics[4].obj_manager_out, self.objectmanager.input)
+        self.connectPorts(self.objectmanager.output["Ball"], self.atomics[4].obj_manager_in)
+        self.connectPorts(self.atomics[4].outputs["parent"], self.atomics[0].input)
+        self.connectPorts(self.atomics[0].glob_outputs["ui"], self.out_ui)
+        self.connectPorts(self.in_ui, self.atomics[0].input)
+        self.connectPorts(self.atomics[1].glob_outputs["ui"], self.out_ui)
+        self.connectPorts(self.in_ui, self.atomics[1].input)
+        self.connectPorts(self.atomics[2].glob_outputs["ui"], self.out_ui)
+        self.connectPorts(self.in_ui, self.atomics[2].input)
+        self.connectPorts(self.atomics[3].glob_outputs["ui"], self.out_ui)
+        self.connectPorts(self.in_ui, self.atomics[3].input)
+        self.connectPorts(self.atomics[4].glob_outputs["ui"], self.out_ui)
+        self.connectPorts(self.in_ui, self.atomics[4].input)

+ 1 - 0
examples/ElevatorBalls/Python/runner.py

@@ -19,6 +19,7 @@ if __name__ == '__main__':
 	ui = UI(tkroot, controller)
 	controller.addMyOwnOutputListener(OutputListener(ui))
 
+	#controller.setVerbose("./examples/BouncingBalls/Python/trace.txt")
 
 	controller.start()
 	tkroot.mainloop()

+ 31 - 37
examples/ElevatorBalls/Python/target.py

@@ -185,24 +185,15 @@ class MainApp(RuntimeClassBase):
         # transition /running
         _running_0 = Transition(self, self.states["/running"], [self.states["/running"]])
         _running_0.setAction(self._running_0_exec)
-        _running_0.setTrigger(Event("create_ball", None))
+        _running_0.setTrigger(Event("update_bounds", None))
         self.states["/running"].addTransition(_running_0)
         _running_1 = Transition(self, self.states["/running"], [self.states["/running"]])
         _running_1.setAction(self._running_1_exec)
-        _running_1.setTrigger(Event("instance_created", None))
+        _running_1.setTrigger(Event("button_pressed", None))
         self.states["/running"].addTransition(_running_1)
         _running_2 = Transition(self, self.states["/running"], [self.states["/running"]])
-        _running_2.setAction(self._running_2_exec)
-        _running_2.setTrigger(Event("update_bounds", None))
+        _running_2.setTrigger(Event("open_elevator", None))
         self.states["/running"].addTransition(_running_2)
-        _running_3 = Transition(self, self.states["/running"], [self.states["/running"]])
-        _running_3.setAction(self._running_3_exec)
-        _running_3.setTrigger(Event("button_pressed", None))
-        self.states["/running"].addTransition(_running_3)
-        _running_4 = Transition(self, self.states["/running"], [self.states["/running"]])
-        _running_4.setAction(self._running_4_exec)
-        _running_4.setTrigger(Event("open_elevator", None))
-        self.states["/running"].addTransition(_running_4)
     
     def _creating_window_enter(self):
         self.big_step.outputEvent(Event("create_window", self.getOutPortName("ui"), [CANVAS_DIMS[0], CANVAS_DIMS[1], "Bouncing Balls Elevator", self.inports['field_ui']]))
@@ -257,31 +248,18 @@ class MainApp(RuntimeClassBase):
         association_name = parameters[0]
         self.big_step.outputEventOM(Event("start_instance", None, [self, association_name]))
         self.big_step.outputEventOM(Event("narrow_cast", None, [self, association_name, Event("set_association_name", None, [association_name, self.canvas_id, self.window_id])]))
+        self.big_step.outputEventOM(Event("associate_instance", None, [self, 'floor', association_name]))
     
     def _running_0_exec(self, parameters):
-        floor_num = parameters[0]
-        x = parameters[1]
-        y = parameters[2]
-        self.big_step.outputEventOM(Event("create_instance", None, [self, "ball", "Ball", self.canvas_id, floor_num, x, y, self.elevator_pos, self.elevator_dim]))
-    
-    def _running_1_exec(self, parameters):
-        association_name = parameters[0]
-        self.big_step.outputEventOM(Event("start_instance", None, [self, association_name]))
-        self.big_step.outputEventOM(Event("narrow_cast", None, [self, association_name, Event("set_association_name", None, [association_name])]))
-    
-    def _running_2_exec(self, parameters):
         pos = parameters[0]
         dim = parameters[1]
         vel = parameters[2]
         self.big_step.outputEventOM(Event("broad_cast", None, [self, Event("update_elevator_bounds", None, [pos, dim, vel])]))
     
-    def _running_3_exec(self, parameters):
+    def _running_1_exec(self, parameters):
         floor_number = parameters[0]
         self.big_step.outputEventOM(Event("narrow_cast", None, [self, 'elevator', Event("move_elevator", None, [floor_number])]))
     
-    def _running_4_exec(self, parameters):
-        self.big_step.outputEventOM(Event("narrow_cast", None, [self, 'ball', Event("open_elevator", None, [])]))
-    
     def initializeStatechart(self):
         # enter default state
         self.default_targets = self.states["/creating_window"].getEffectiveTargetStates()
@@ -348,10 +326,14 @@ class Floor(RuntimeClassBase):
         self.states["/running/create_random_ball"].setEnter(self._running_create_random_ball_enter)
         self.states["/running/create_random_ball"].setExit(self._running_create_random_ball_exit)
         
+        # state /running/wait
+        self.states["/running/wait"] = State(4, "/running/wait", self)
+        
         # add children
         self.states[""].addChild(self.states["/creating_floor"])
         self.states[""].addChild(self.states["/running"])
         self.states["/running"].addChild(self.states["/running/create_random_ball"])
+        self.states["/running"].addChild(self.states["/running/wait"])
         self.states[""].fixTree()
         self.states[""].default_state = self.states["/creating_floor"]
         self.states["/running"].default_state = self.states["/running/create_random_ball"]
@@ -362,10 +344,16 @@ class Floor(RuntimeClassBase):
         self.states["/creating_floor"].addTransition(_creating_floor_0)
         
         # transition /running/create_random_ball
-        _running_create_random_ball_0 = Transition(self, self.states["/running/create_random_ball"], [self.states["/running/create_random_ball"]])
+        _running_create_random_ball_0 = Transition(self, self.states["/running/create_random_ball"], [self.states["/running/wait"]])
         _running_create_random_ball_0.setAction(self._running_create_random_ball_0_exec)
         _running_create_random_ball_0.setTrigger(Event("_0after"))
         self.states["/running/create_random_ball"].addTransition(_running_create_random_ball_0)
+        
+        # transition /running/wait
+        _running_wait_0 = Transition(self, self.states["/running/wait"], [self.states["/running/create_random_ball"]])
+        _running_wait_0.setAction(self._running_wait_0_exec)
+        _running_wait_0.setTrigger(Event("instance_created", None))
+        self.states["/running/wait"].addTransition(_running_wait_0)
     
     def _creating_floor_enter(self):
         self.big_step.outputEvent(Event("create_rectangle", self.getOutPortName("ui"), [self.canvas_id, self.pos['x'], self.pos['y'], self.dim['x'], self.dim['y'], {'fill':'white', 'outline': 'black'}, self.inports['floor_ui']]))
@@ -377,7 +365,12 @@ class Floor(RuntimeClassBase):
         self.removeTimer(0)
     
     def _running_create_random_ball_0_exec(self, parameters):
-        self.big_step.outputEventOM(Event("narrow_cast", None, [self, 'parent', Event("create_ball", None, [self.floor_num, 10, self.pos['y']])]))
+        self.big_step.outputEventOM(Event("create_instance", None, [self, "balls", "Ball", self.canvas_id, self.floor_num, 10, self.pos['y']]))
+    
+    def _running_wait_0_exec(self, parameters):
+        association_name = parameters[0]
+        self.big_step.outputEventOM(Event("start_instance", None, [self, association_name]))
+        self.big_step.outputEventOM(Event("narrow_cast", None, [self, association_name, Event("set_association_name", None, [association_name])]))
     
     def initializeStatechart(self):
         # enter default state
@@ -642,7 +635,7 @@ class Elevator(RuntimeClassBase):
         RuntimeClassBase.initializeStatechart(self)
 
 class Ball(RuntimeClassBase):
-    def __init__(self, controller, canvas_id, floor_num, x, y, elevator_pos, elevator_dim):
+    def __init__(self, controller, canvas_id, floor_num, x, y):
         RuntimeClassBase.__init__(self, controller)
         
         self.inports["ball_ui"] = controller.addInputPort("ball_ui", self)
@@ -661,9 +654,9 @@ class Ball(RuntimeClassBase):
         self.pos = None
         
         # call user defined constructor
-        Ball.user_defined_constructor(self, canvas_id, floor_num, x, y, elevator_pos, elevator_dim)
+        Ball.user_defined_constructor(self, canvas_id, floor_num, x, y)
     
-    def user_defined_constructor(self, canvas_id, floor_num, x, y, elevator_pos, elevator_dim):
+    def user_defined_constructor(self, canvas_id, floor_num, x, y):
         self.canvas_id = canvas_id;
         
         
@@ -671,8 +664,6 @@ class Ball(RuntimeClassBase):
         
         self.elevator_floor = 0;
         self.elevator_open = True;
-        self.rect_pos = elevator_pos;
-        self.rect_dim = elevator_dim;
         
         self.r = 5.0;
         self.vel = {'x': random.uniform(-5.0, 5.0), 'y': random.uniform(-5.0, 5.0)};
@@ -777,6 +768,8 @@ class Ball(RuntimeClassBase):
     
     def _main_behaviour_bouncing_0_exec(self, parameters):
         if self.floor_num == -1:
+            pass
+            """
             if self.pos['x'] - self.r < self.rect_pos['x'] - (self.rect_dim['x'] / 2):
                 if self.elevator_open:
                     self.floor_num = self.elevator_floor
@@ -794,6 +787,7 @@ class Ball(RuntimeClassBase):
             elif self.pos['y'] + self.r > self.rect_pos['y'] + (self.rect_dim['y'] / 2):
                 self.pos['y'] = self.rect_pos['y'] + (self.rect_dim['y'] / 2) - self.r
                 self.vel['y'] = -self.vel['y'] + self.rect_vel
+            """
         else:
             floor_height = ((CANVAS_DIMS[1] - 150) - ((FLOORS - 1) * FLOOR_SPACE)) / FLOORS
             floor_dim = {'x': FLOOR_LENGTH, 'y': floor_height};
@@ -855,11 +849,11 @@ class ObjectManager(ObjectManagerBase):
             instance.associations["floor"] = Association("Floor", 2, -1)
             instance.associations["button"] = Association("ElevatorButton", 0, -1)
             instance.associations["elevator"] = Association("Elevator", 1, 1)
-            instance.associations["ball"] = Association("Ball", 0, -1)
         elif class_name == "Floor":
             instance = Floor(self.controller, construct_params[0], construct_params[1])
             instance.associations = {}
             instance.associations["parent"] = Association("MainApp", 1, 1)
+            instance.associations["balls"] = Association("Ball", 0, -1)
         elif class_name == "ElevatorButton":
             instance = ElevatorButton(self.controller, construct_params[0], construct_params[1], construct_params[2])
             instance.associations = {}
@@ -867,10 +861,10 @@ class ObjectManager(ObjectManagerBase):
         elif class_name == "Elevator":
             instance = Elevator(self.controller, construct_params[0])
             instance.associations = {}
-            instance.associations["floors"] = Association("Floor", 1, 1)
+            instance.associations["floors"] = Association("Floor", 0, -1)
             instance.associations["parent"] = Association("MainApp", 1, 1)
         elif class_name == "Ball":
-            instance = Ball(self.controller, construct_params[0], construct_params[1], construct_params[2], construct_params[3], construct_params[4], construct_params[5])
+            instance = Ball(self.controller, construct_params[0], construct_params[1], construct_params[2], construct_params[3])
             instance.associations = {}
             instance.associations["parent"] = Association("MainApp", 1, 1)
         else:

+ 604 - 0
examples/ElevatorBalls/idk_sccd.xml

@@ -0,0 +1,604 @@
+<?xml version="1.0" ?>
+<diagram author="Sam Pieters" name="Elevator Balls">
+    <top>
+        import sccd.runtime.libs.ui_v2 as ui
+        import random
+        import time
+
+        CANVAS_DIMS = (800, 550)
+        FLOOR_LENGTH = 350
+        FLOOR_SPACE = 50
+        FLOORS = 3
+    </top>
+    <inport name="ui" />
+    <outport name="ui" />
+    <class name="MainApp" default="true">
+        <relationships>
+            <association name="floor" class="Floor" min="2"/>
+            <association name="button" class="ElevatorButton" />
+            <association name="elevator" class="Elevator" min="1" max="1"/>
+            <association name="ball" class="Ball" />
+        </relationships>
+        <attribute name="window_id" />
+        <attribute name="canvas_id" />
+        <attribute name="num_floors" />
+        <attribute name="floor_dimensions" />
+        <atrribute name="floor_height" />
+        <inport name="field_ui"/>
+        <constructor>
+            <body>
+                self.num_floors = 0
+                self.button_num = FLOORS
+
+                self.elevator_pos = None
+                self.elevator_dim = None
+            </body>
+        </constructor>
+        <scxml initial="creating_window">
+            <state id="creating_window">
+                <onentry>
+                    <raise port="ui" event="create_window">
+                        <parameter expr="CANVAS_DIMS[0]"/><!-- width -->
+                        <parameter expr="CANVAS_DIMS[1]"/><!-- height -->
+                        <parameter expr='"Bouncing Balls Elevator"'/><!-- title -->
+                        <parameter expr="self.inports['field_ui']"/><!-- inport for response -->
+                    </raise>
+                </onentry>
+                <transition event="window_created" target="../creating_canvas">
+                    <parameter name="window_id" type="int" />
+                    <script>
+                        self.window_id = window_id
+                    </script>
+                    <raise port="ui" event="bind_event">
+                        <parameter expr="window_id"/><!-- widget_id -->
+                        <parameter expr="ui.EVENTS.WINDOW_CLOSE"/><!-- tk_event -->
+                        <parameter expr="'window_close'"/><!-- sccd_event_name -->
+                        <parameter expr="self.inports['field_ui']"/><!-- inport for response -->
+                    </raise>
+                    <raise port="ui" event="bind_event">
+                        <parameter expr="window_id"/><!-- widget_id -->
+                        <parameter expr="ui.EVENTS.KEY_PRESS"/><!-- tk_event -->
+                        <parameter expr="'key_press'"/><!-- sccd_event_name -->
+                        <parameter expr="self.inports['field_ui']"/><!-- inport for response -->
+                    </raise>
+                </transition>
+            </state>
+            <state id="creating_canvas">
+                <onentry>
+                    <raise port="ui" event="create_canvas">
+                        <parameter expr="self.window_id"/><!-- window_id -->
+                        <parameter expr="CANVAS_DIMS[0]"/><!-- width -->
+                        <parameter expr="CANVAS_DIMS[1] - 150"/><!-- height -->
+                        <parameter expr="{'background':'#fff'}"/><!-- style -->
+                        <parameter expr="self.inports['field_ui']"/><!-- inport for response -->
+                    </raise>
+                </onentry>
+                <transition event="canvas_created" target="../create_floors">
+                    <parameter name="canvas_id" type="int"/>
+                    <script>
+                        self.canvas_id = canvas_id
+                    </script>
+                </transition>
+            </state>
+            <state id="create_floors">
+                <transition target="../create_controls" cond="self.num_floors == FLOORS" />
+                <transition target="../wait" cond="self.num_floors != FLOORS">
+                    <raise scope="cd" event="create_instance">
+                        <parameter expr='"floor"' />
+                        <parameter expr='"Floor"' />
+                        <parameter expr="self.canvas_id" />
+                        <parameter expr="self.num_floors" />
+                    </raise>
+                    <script>
+                        self.num_floors += 1
+                    </script>
+                </transition>
+            </state>
+            <state id="wait">
+                <transition event='instance_created' target='.'>
+                    <parameter name="association_name" type="string"/>
+                    <raise scope="cd" event="start_instance">
+                        <parameter expr="association_name" />
+                    </raise>
+                </transition>
+                <transition event="instance_started" target="../create_floors" />
+            </state>
+            <state id="create_controls" initial="create_buttons">
+                <state id="create_buttons" initial="create_a_button">
+                    <state id="create_a_button">
+                        <onentry>
+                            <raise scope="cd" event="create_instance">
+                                <parameter expr='"button"' />
+                                <parameter expr='"ElevatorButton"' />
+                                <parameter expr="self.window_id" />
+                                <parameter expr="self.canvas_id" />
+                                <parameter expr="self.button_num - 1" />
+                            </raise>
+                        </onentry>
+                        <transition event='instance_created' target='../start_a_button'>
+                            <parameter name="association_name" type="string"/>
+                            <raise scope="cd" event="start_instance">
+                                <parameter expr="association_name" />
+                            </raise>
+                        </transition>
+                    </state>
+                    <state id="start_a_button">
+                        <transition event="instance_started" target="../check_next" />
+                    </state>
+                    <state id="check_next">
+                        <transition target="../create_a_button" cond="self.button_num != 1">
+                            <script>
+                                self.button_num -= 1
+                            </script>
+                        </transition>
+                        <transition target="../../../create_elevator" cond="self.button_num == 1" />
+                    </state>
+                </state>
+            </state>
+            <state id="create_elevator">
+                <transition target="../creating">
+                    <raise scope="cd" event="create_instance">
+                        <parameter expr='"elevator"' />
+                        <parameter expr='"Elevator"' />
+                        <parameter expr="self.canvas_id" />
+                    </raise>
+                </transition>
+            </state>
+            <state id="creating">
+                <transition event="instance_created" target="../running">
+                    <parameter name="association_name" type="string"/>
+                    <raise scope="cd" event="start_instance">
+                        <parameter expr="association_name" />
+                    </raise>
+                    <raise scope="narrow" event="set_association_name" target="association_name">
+                        <parameter expr="association_name" />
+                        <parameter expr="self.canvas_id" />
+                        <parameter expr="self.window_id" />
+                    </raise>
+                </transition>
+            </state>
+            <state id="running">
+                <transition event="create_ball" target=".">
+                    <parameter name="floor_num" type="int"/>
+                    <parameter name="x" type="int"/>
+                    <parameter name="y" type="int"/>
+                    <raise scope="cd" event="create_instance">
+                        <parameter expr='"ball"' />
+                        <parameter expr='"Ball"' />
+                        <parameter expr="self.canvas_id" />
+                        <parameter expr="floor_num" />
+                        <parameter expr="x" />
+                        <parameter expr="y" />
+                        <parameter expr="self.elevator_pos" />
+                        <parameter expr="self.elevator_dim" />
+                    </raise>
+                </transition>
+                <transition event='instance_created' target='.'>
+                    <parameter name="association_name" type="string"/>
+                    <raise scope="cd" event="start_instance">
+                        <parameter expr="association_name" />
+                    </raise>
+                    <raise scope="narrow" event="set_association_name" target="association_name">
+                        <parameter expr="association_name" />
+                    </raise>
+                </transition>
+                <transition event='update_bounds' target='.'>
+                    <parameter name="pos" type="dict"/>
+                    <parameter name="dim" type="dict"/>
+                    <parameter name="vel" type="int"/>
+                    <raise scope="broad" event="update_elevator_bounds">
+                        <parameter expr="pos" />
+                        <parameter expr="dim" />
+                        <parameter expr="vel" />
+                        <script>
+                            self.elevator_pos = pos
+                            self.elevator_dim = dim
+                        </script>
+                    </raise>
+                </transition>
+                <transition event='button_pressed' target='.'>
+                    <parameter name="floor_number" type="int"/>
+                    <raise scope="narrow" event="move_elevator" target="'elevator'">
+                        <parameter expr="floor_number" />
+                    </raise>
+                </transition>
+                <transition event='open_elevator' target='.'>
+                    <raise scope="narrow" event="open_elevator" target="'ball'" />
+                </transition>
+            </state>
+        </scxml>
+    </class>
+
+    <class name="Floor">
+        <attribute name="window_id" />
+        <attribute name="canvas_id" />
+        <attribute name="elevator_id" />
+        <atrribute name="pos" />
+        <inport name="floor_ui"/>
+        <relationships>
+            <association name="parent" class="MainApp" min="1" max="1" />
+        </relationships>
+        <constructor>
+            <parameter name="canvas_id" />
+            <parameter name="floor_num" />
+            <body>
+                <![CDATA[
+                self.canvas_id = canvas_id;
+                self.floor_num = floor_num;
+
+                height = CANVAS_DIMS[1] - 150
+
+                y_dim = (height - ((FLOORS - 1) * FLOOR_SPACE)) / FLOORS
+
+                self.dim = {'x': FLOOR_LENGTH, 'y': y_dim};
+
+
+                # start position from the bottom instead of from the top
+                # self.pos = {'x': FLOOR_LENGTH / 2, 'y': (y_dim /2) + (self.floor_num * (y_dim + FLOOR_SPACE))};
+
+                self.pos = {'x': FLOOR_LENGTH / 2, 'y': height - (y_dim /2) - ( self.floor_num * (y_dim + FLOOR_SPACE)  )};
+                ]]>
+            </body>
+        </constructor>
+        <scxml initial="creating_floor">
+            <state id="creating_floor">
+                <onentry>
+                    <raise port="ui" event="create_rectangle">
+                        <parameter expr="self.canvas_id" />
+                        <parameter expr="self.pos['x']"/>
+                        <parameter expr="self.pos['y']"/>
+                        <parameter expr="self.dim['x']" />
+                        <parameter expr="self.dim['y']"/>
+                        <parameter expr="{'fill':'white', 'outline': 'black'}"/><!-- style -->
+                        <parameter expr="self.inports['floor_ui']"/><!-- inport for response -->
+                    </raise>
+                </onentry>
+                <transition event="rectangle_created" target="../running">
+                </transition>
+            </state>
+            <state id="running" initial="create_random_ball">
+                <state id="create_random_ball" >
+                    <transition after="random.randint(2, 10)" target=".">
+                        <raise scope="narrow" event="create_ball" target="'parent'">
+                            <parameter expr="self.floor_num" />
+                            <parameter expr="10" />
+                            <parameter expr="self.pos['y']" />
+                        </raise>
+                    </transition>
+                </state>
+            </state>
+        </scxml>
+    </class>
+
+    <class name="ElevatorButton">
+        <inport name="button_ui"/>
+        <relationships>
+            <association name="parent" class="MainApp" min="1" max="1" />
+        </relationships>
+        <constructor>
+            <parameter name="window_id" />
+            <parameter name="canvas_id" />
+            <parameter name="number" />
+            <body>
+                self.window_id = window_id;
+                self.canvas_id = canvas_id;
+                self.button_id = None;
+                
+                self.dim = {'x': 120, 'y': (50 + (FLOORS * 30))}
+                self.pos = {'x': CANVAS_DIMS[0] - ((self.dim['x'] / 2) + 10), 'y': (self.dim['y'] / 2) + 10}
+                self.r = 10
+                self.number = number;
+            </body>
+        </constructor>
+        <scxml initial="creating">
+            <state id="creating">
+                <onentry>
+                    <raise port="ui" event="create_button">
+                        <parameter expr="self.window_id" />
+                        <parameter expr="self.number"/>
+                        <parameter expr="self.inports['button_ui']"/><!-- inport for response -->
+                    </raise>
+                </onentry>
+                <transition event="button_created" target="../running">
+                    <parameter name="button_id"/>
+                    <script>
+                        self.button_id = button_id
+                    </script>
+                    <raise port="ui" event="bind_event">
+                        <parameter expr="button_id"/><!-- widget_id -->
+                        <parameter expr="ui.EVENTS.MOUSE_CLICK"/><!-- tk_event -->
+                        <parameter expr='"mouse_click"'/><!-- sccd_event_name -->
+                        <parameter expr="self.inports['button_ui']"/><!-- inport for response -->
+                    </raise>
+                </transition>
+            </state>
+            <state id="running">
+                <transition port='button_ui' event="mouse_click" target='.' cond="button == ui.MOUSE_BUTTONS.LEFT">
+                    <parameter name="x" />
+                    <parameter name="y" />
+                    <parameter name="button" />
+                    <raise event="button_pressed" scope="narrow" target="'parent'">
+                        <parameter expr="self.number" />
+                    </raise>
+                </transition>
+            </state>
+        </scxml>
+    </class>
+
+    <class name="Elevator">
+        <attribute name="window_id" />
+        <attribute name="canvas_id" />
+        <attribute name="elevator_id" />
+        <atrribute name="pos" />
+        <inport name="elevator_ui"/>
+        <relationships>
+            <association name="floors" class="Floor" min="1" max="1" />
+            <association name="parent" class="MainApp" min="1" max="1" />
+        </relationships>
+        <constructor>
+            <parameter name="canvas_id" />
+            <body>
+                <![CDATA[
+                self.canvas_id = canvas_id;
+
+                height = CANVAS_DIMS[1] - 150
+
+                elevator_height = (height - ((FLOORS - 1) * FLOOR_SPACE)) / FLOORS
+
+                self.dim = {'x': elevator_height, 'y': elevator_height};
+                self.vel = -2;
+
+                self.current_floor = 0;
+
+                self.pos = {'x': FLOOR_LENGTH + (elevator_height / 2), 'y': (height - (elevator_height / 2))};
+                self.next_pos = {'x': FLOOR_LENGTH / 2, 'y': None};
+
+
+                self.smooth = 0.6; # value between 0 and 1
+                ]]>
+            </body>
+        </constructor>
+        <scxml initial="root">
+            <state id="root" initial="waiting">
+                <state id="waiting">
+                    <transition event="set_association_name" target="../creating_elevator">
+                        <parameter name="association_name" type="str" />
+                        <parameter name="canvas_id" type="int" />
+                        <parameter name="window_id" type="int" />
+                        <script>
+                            self.association_name = association_name
+                            self.canvas_id = canvas_id
+                            self.window_id = window_id
+                        </script>
+                    </transition>
+                </state>
+                <state id="creating_elevator">
+                    <onentry>
+                        <raise port="ui" event="create_rectangle">
+                            <parameter expr="self.canvas_id" />
+                            <parameter expr="self.pos['x']"/>
+                            <parameter expr="self.pos['y']"/>
+                            <parameter expr="self.dim['x']" />
+                            <parameter expr="self.dim['y']"/>
+                            <parameter expr="{'fill':'white', 'outline': 'black'}"/><!-- style -->
+                            <parameter expr="self.inports['elevator_ui']"/><!-- inport for response -->
+                        </raise>
+                    </onentry>
+                    <transition event="rectangle_created" target="../running">
+                        <parameter name="canvas_id" type="int" />
+                        <parameter name="rect_id" type="int" />
+                        <script>
+                            self.elevator_id = rect_id
+                        </script>
+                    </transition>
+                </state>
+                <state id="running" initial="idle">
+                    <state id="idle">
+                        <onentry>
+                            <raise scope="narrow" event="update_bounds" target="'parent'">
+                                <parameter expr="self.pos" />
+                                <parameter expr="self.dim" />
+                                <parameter expr="self.vel" />
+                            </raise>
+                        </onentry>
+                        <transition event="move_elevator" target="../move">
+                            <parameter name="floor_number" type="int"/>
+                            <script>
+                                if self.current_floor &lt; floor_number:
+                                    self.vel = -2
+                                else:
+                                    self.vel = 2
+
+                                self.current_floor = floor_number
+                                
+                                height = (CANVAS_DIMS[1] - 150)
+                                y_dim = (height - ((FLOORS - 1) * FLOOR_SPACE)) / FLOORS
+                                self.next_pos['y'] = height - (y_dim /2) - (self.current_floor * (y_dim + FLOOR_SPACE));
+                            </script>
+                        </transition>
+                    </state>
+                    <state id="move">
+                        <onentry>
+                            <raise scope="narrow" event="update_bounds" target="'parent'">
+                                <parameter expr="self.pos" />
+                                <parameter expr="self.dim" />
+                                <parameter expr="self.vel" />
+                            </raise>
+                        </onentry>
+                        <transition after="0.02" target=".">
+                            <raise port="ui" event="set_element_pos">
+                                <parameter expr="self.canvas_id"/>
+                                <parameter expr="self.elevator_id"/>
+                                <parameter expr="self.pos['x']"/>
+                                <parameter expr="self.pos['y']"/>
+                            </raise>
+                            <script>
+                                self.pos['y'] += self.vel
+                            </script>
+                        </transition>
+                        <transition target="../idle" cond="(self.vel &gt; 0 and self.pos['y'] &gt; self.next_pos['y']) or (self.vel &lt; 0 and self.pos['y'] &lt; self.next_pos['y'])">
+                            <raise scope="narrow" event="open_elevator" target="'parent'" />
+                        </transition>
+                    </state>
+                </state>
+            </state>
+        </scxml>
+    </class>
+
+    <class name="Ball">
+        <attribute name="canvas_id" />
+        <atrribute name="circle_id" />
+        <attribute name="pos" />
+        <inport name="ball_ui" />
+        <relationships>
+            <association name="parent" class="MainApp" min="1" max="1" />
+        </relationships>
+        <constructor>
+            <parameter name="canvas_id" />
+            <parameter name="floor_num" />
+            <parameter name="x" />
+            <parameter name="y" />
+            <parameter name="elevator_pos" />
+            <parameter name="elevator_dim" />
+            <body>
+                <![CDATA[
+                self.canvas_id = canvas_id;
+
+
+                self.floor_num = floor_num;
+
+                self.elevator_floor = 0;
+                self.elevator_open = True;
+                self.rect_pos = elevator_pos;
+                self.rect_dim = elevator_dim;
+
+                self.r = 5.0;
+                self.vel = {'x': random.uniform(-5.0, 5.0), 'y': random.uniform(-5.0, 5.0)};
+                self.pos = {'x': x, 'y': y};
+                self.smooth = 0.6; # value between 0 and 1
+                ]]>
+            </body>
+        </constructor>
+        <destructor>
+        </destructor>
+        <scxml initial="main_behaviour">
+            <state id="main_behaviour" initial="initializing">
+                <state id="initializing">
+                    <transition event="set_association_name" target="../creating_circle">
+                        <parameter name="association_name" type="str" />
+                        <script>
+                            self.association_name = association_name
+                        </script>
+                    </transition>
+                </state>
+                <state id="creating_circle">
+                    <onentry>
+                        <raise port="ui" event="create_circle">
+                            <parameter expr="self.canvas_id"/><!-- canvas_id -->
+                            <parameter expr="self.pos['x']"/><!-- x -->
+                            <parameter expr="self.pos['y']"/><!-- y -->
+                            <parameter expr="self.r"/><!-- r -->
+                            <parameter expr="{'fill':'#000'}"/><!-- style -->
+                            <parameter expr="self.inports['ball_ui']"/><!-- inport for response -->
+                        </raise>
+                    </onentry>
+                    <transition event="circle_created" target="../bouncing">
+                        <parameter name="canvas_id"/>
+                        <parameter name="circle_id"/>
+                        <script>
+                            self.circle_id = circle_id
+                        </script>
+                    </transition>
+                </state>
+                <state id="bouncing">
+                    <transition after="0.02" target=".">
+                        <script>
+                            <![CDATA[
+                            if self.floor_num == -1:
+                                if self.pos['x'] - self.r < self.rect_pos['x'] - (self.rect_dim['x'] / 2):
+                                    if self.elevator_open:
+                                        self.floor_num = self.elevator_floor
+                                    else:
+                                        self.pos['x'] = self.rect_pos['x'] - (self.rect_dim['x'] / 2) + self.r
+                                        self.vel['x'] = -self.vel['x']
+                                elif self.pos['x'] + self.r > self.rect_pos['x'] + (self.rect_dim['x'] / 2):
+                                    self.pos['x'] = self.rect_pos['x'] + (self.rect_dim['x'] / 2) - self.r
+                                    self.vel['x'] = -self.vel['x']
+
+                                # Check collision with the top and bottom borders
+                                if self.pos['y'] - self.r < self.rect_pos['y'] - (self.rect_dim['y'] / 2):
+                                    self.pos['y'] = self.rect_pos['y'] - (self.rect_dim['y'] / 2) + self.r
+                                    self.vel['y'] = -self.vel['y'] + self.rect_vel
+                                elif self.pos['y'] + self.r > self.rect_pos['y'] + (self.rect_dim['y'] / 2):
+                                    self.pos['y'] = self.rect_pos['y'] + (self.rect_dim['y'] / 2) - self.r
+                                    self.vel['y'] = -self.vel['y'] + self.rect_vel
+                            else:
+                                floor_height = ((CANVAS_DIMS[1] - 150) - ((FLOORS - 1) * FLOOR_SPACE)) / FLOORS
+                                floor_dim = {'x': FLOOR_LENGTH, 'y': floor_height};
+                                floor_pos = {'x': FLOOR_LENGTH / 2, 'y': (CANVAS_DIMS[1] - 150) - (floor_height /2) - ( self.floor_num * (floor_height + FLOOR_SPACE)  )};
+
+                                if self.pos['x'] - self.r < floor_pos['x'] - (floor_dim['x'] / 2):
+                                    self.pos['x'] = floor_pos['x'] - (floor_dim['x'] / 2) + self.r
+                                    self.vel['x'] = -self.vel['x']
+                                elif self.pos['x'] + self.r > floor_pos['x'] + (floor_dim['x'] / 2):
+                                    if self.elevator_open and (self.elevator_floor == self.floor_num):
+                                        self.floor_num = -1
+                                    else:
+                                        self.pos['x'] = floor_pos['x'] + (floor_dim['x'] / 2) - self.r
+                                        self.vel['x'] = -self.vel['x']
+
+                                # Check collision with the top and bottom borders
+                                if self.pos['y'] - self.r < floor_pos['y'] - (floor_dim['y'] / 2):
+                                    self.pos['y'] = floor_pos['y'] - (floor_dim['y'] / 2) + self.r
+                                    self.vel['y'] = -self.vel['y']
+                                elif self.pos['y'] + self.r > floor_pos['y'] + (floor_dim['y'] / 2):
+                                    self.pos['y'] = floor_pos['y'] + (floor_dim['y'] / 2) - self.r  # Correct position
+                                    self.vel['y'] = -self.vel['y']
+
+                            ]]>
+                        </script>
+                        <raise port="ui" event="move_element">
+                            <parameter expr="self.canvas_id"/>
+                            <parameter expr="self.circle_id"/>
+                            <parameter expr="self.vel['x']"/>
+                            <parameter expr="self.vel['y']"/>
+                        </raise>
+                        <script>
+                            self.pos['x'] += self.vel['x']
+                            self.pos['y'] += self.vel['y']
+                        </script>
+                    </transition>
+                    <transition event="open_elevator" target=".">
+                        <script>
+                            self.elevator_open = True
+                        </script>
+                    </transition>
+                    <transition target="../ball_delete" cond="self.pos['x'] - self.r &lt; 2" />
+                    <transition event="update_elevator_bounds" target=".">
+                        <parameter name="pos" type="dict" />
+                        <parameter name="dim" type="dict" />
+                        <parameter name="vel" type="int" />
+                        <script>
+                            self.rect_pos = pos
+                            self.rect_dim = dim
+                            self.rect_vel = vel
+                            self.elevator_open = False
+                        </script>
+                    </transition>
+                </state>
+                <state id="ball_delete">
+                    <transition event="delete_self" target='../../deleted'>                    
+                        <raise event="delete_ball" scope="narrow" target="'floor'">
+                            <parameter expr='self.association_name' />
+                        </raise>
+                        <raise port="ui" event="destroy_element">
+                            <parameter expr="self.canvas_id" />
+                            <parameter expr="self.circle_id" />
+                        </raise>
+                    </transition>
+                </state>
+            </state>
+            <state id='deleted' />
+        </scxml>
+    </class>
+</diagram>

+ 28 - 32
examples/ElevatorBalls/sccd.xml

@@ -17,7 +17,6 @@
             <association name="floor" class="Floor" min="2"/>
             <association name="button" class="ElevatorButton" />
             <association name="elevator" class="Elevator" min="1" max="1"/>
-            <association name="ball" class="Ball" />
         </relationships>
         <attribute name="window_id" />
         <attribute name="canvas_id" />
@@ -155,33 +154,14 @@
                         <parameter expr="self.canvas_id" />
                         <parameter expr="self.window_id" />
                     </raise>
-                </transition>
-            </state>
-            <state id="running">
-                <transition event="create_ball" target=".">
-                    <parameter name="floor_num" type="int"/>
-                    <parameter name="x" type="int"/>
-                    <parameter name="y" type="int"/>
-                    <raise scope="cd" event="create_instance">
-                        <parameter expr='"ball"' />
-                        <parameter expr='"Ball"' />
-                        <parameter expr="self.canvas_id" />
-                        <parameter expr="floor_num" />
-                        <parameter expr="x" />
-                        <parameter expr="y" />
-                        <parameter expr="self.elevator_pos" />
-                        <parameter expr="self.elevator_dim" />
-                    </raise>
-                </transition>
-                <transition event='instance_created' target='.'>
-                    <parameter name="association_name" type="string"/>
-                    <raise scope="cd" event="start_instance">
-                        <parameter expr="association_name" />
-                    </raise>
-                    <raise scope="narrow" event="set_association_name" target="association_name">
+                    <!-- associate all floors to the elevator -->
+                    <raise scope="cd" event="associate_instance">
+                        <parameter expr="'floor'" />
                         <parameter expr="association_name" />
                     </raise>
                 </transition>
+            </state>
+            <state id="running">
                 <transition event='update_bounds' target='.'>
                     <parameter name="pos" type="dict"/>
                     <parameter name="dim" type="dict"/>
@@ -203,7 +183,9 @@
                     </raise>
                 </transition>
                 <transition event='open_elevator' target='.'>
+                    <!--
                     <raise scope="narrow" event="open_elevator" target="'ball'" />
+                    -->
                 </transition>
             </state>
         </scxml>
@@ -217,6 +199,7 @@
         <inport name="floor_ui"/>
         <relationships>
             <association name="parent" class="MainApp" min="1" max="1" />
+            <association name="balls" class="Ball" />
         </relationships>
         <constructor>
             <parameter name="canvas_id" />
@@ -258,14 +241,28 @@
             </state>
             <state id="running" initial="create_random_ball">
                 <state id="create_random_ball" >
-                    <transition after="random.randint(2, 10)" target=".">
-                        <raise scope="narrow" event="create_ball" target="'parent'">
+                    <transition after="random.randint(2, 10)" target="../wait">
+                        <raise scope="cd" event="create_instance">
+                            <parameter expr='"balls"' />
+                            <parameter expr='"Ball"' />
+                            <parameter expr="self.canvas_id" />
                             <parameter expr="self.floor_num" />
                             <parameter expr="10" />
                             <parameter expr="self.pos['y']" />
                         </raise>
                     </transition>
                 </state>
+                <state id="wait">
+                    <transition event="instance_created" target="../create_random_ball">
+                        <parameter name="association_name" type="string"/>
+                        <raise scope="cd" event="start_instance">
+                            <parameter expr="association_name" />
+                        </raise>
+                        <raise scope="narrow" event="set_association_name" target="association_name">
+                            <parameter expr="association_name" />
+                        </raise>
+                    </transition>
+                </state>
             </state>
         </scxml>
     </class>
@@ -332,7 +329,7 @@
         <atrribute name="pos" />
         <inport name="elevator_ui"/>
         <relationships>
-            <association name="floors" class="Floor" min="1" max="1" />
+            <association name="floors" class="Floor" />
             <association name="parent" class="MainApp" min="1" max="1" />
         </relationships>
         <constructor>
@@ -458,8 +455,6 @@
             <parameter name="floor_num" />
             <parameter name="x" />
             <parameter name="y" />
-            <parameter name="elevator_pos" />
-            <parameter name="elevator_dim" />
             <body>
                 <![CDATA[
                 self.canvas_id = canvas_id;
@@ -469,8 +464,6 @@
 
                 self.elevator_floor = 0;
                 self.elevator_open = True;
-                self.rect_pos = elevator_pos;
-                self.rect_dim = elevator_dim;
 
                 self.r = 5.0;
                 self.vel = {'x': random.uniform(-5.0, 5.0), 'y': random.uniform(-5.0, 5.0)};
@@ -515,6 +508,8 @@
                         <script>
                             <![CDATA[
                             if self.floor_num == -1:
+                                pass
+                                """
                                 if self.pos['x'] - self.r < self.rect_pos['x'] - (self.rect_dim['x'] / 2):
                                     if self.elevator_open:
                                         self.floor_num = self.elevator_floor
@@ -532,6 +527,7 @@
                                 elif self.pos['y'] + self.r > self.rect_pos['y'] + (self.rect_dim['y'] / 2):
                                     self.pos['y'] = self.rect_pos['y'] + (self.rect_dim['y'] / 2) - self.r
                                     self.vel['y'] = -self.vel['y'] + self.rect_vel
+                                """
                             else:
                                 floor_height = ((CANVAS_DIMS[1] - 150) - ((FLOORS - 1) * FLOOR_SPACE)) / FLOORS
                                 floor_dim = {'x': FLOOR_LENGTH, 'y': floor_height};

+ 11 - 8
examples/TimerEventloop/PyDEVS/target.py

@@ -15,7 +15,7 @@ CANVAS_DIMS = (350, 300)
 # package "Timer (Eventloop Version)"
 
 class MainAppInstance(RuntimeClassBase):
-    def __init__(self, atomdevs, id):
+    def __init__(self, atomdevs, id, start_port_id):
         RuntimeClassBase.__init__(self, atomdevs, id)
         self.associations = {}
         
@@ -38,9 +38,13 @@ class MainAppInstance(RuntimeClassBase):
         
         # call user defined constructor
         MainAppInstance.user_defined_constructor(self)
-        port_name = Ports.addInputPort("<narrow_cast>", self)
+        port_name = addInputPort("ui", start_port_id, True)
         atomdevs.addInPort(port_name)
-        port_name = Ports.addInputPort("field_ui", self)
+        atomdevs.state.port_mappings[port_name] = id
+        port_name = addInputPort("<narrow_cast>", start_port_id)
+        atomdevs.addInPort(port_name)
+        atomdevs.state.port_mappings[port_name] = id
+        port_name = addInputPort("field_ui", start_port_id)
         atomdevs.addInPort(port_name)
         atomdevs.state.port_mappings[port_name] = id
         self.inports["field_ui"] = port_name
@@ -217,12 +221,12 @@ class MainApp(ClassBase):
         self.input = self.addInPort("input")
         self.glob_outputs["ui"] = self.addOutPort("ui")
         self.field_ui = self.addInPort("field_ui")
-        new_instance = self.constructObject(0, [])
+        new_instance = self.constructObject(0, 0, [])
         self.state.instances[new_instance.instance_id] = new_instance
         self.state.next_instance = self.state.next_instance + 1
     
-    def constructObject(self, id, parameters):
-        new_instance = MainAppInstance(self, id)
+    def constructObject(self, id, start_port_id, parameters):
+        new_instance = MainAppInstance(self, id, start_port_id)
         return new_instance
 
 class Dummy(ObjectManagerState):
@@ -233,6 +237,7 @@ class Dummy(ObjectManagerState):
         instance = {}
         instance["name"] = class_name
         if class_name == "MainApp":
+            self.narrow_cast_id = self.narrow_cast_id + 1
             instance["associations"] = {}
         else:
             raise Exception("Cannot instantiate class " + class_name)
@@ -251,9 +256,7 @@ class Controller(CoupledDEVS):
     def __init__(self, name):
         CoupledDEVS.__init__(self, name)
         self.in_ui = self.addInPort("ui")
-        Ports.addInputPort("ui")
         self.out_ui = self.addOutPort("ui")
-        Ports.addOutputPort("ui")
         self.objectmanager = self.addSubModel(ObjectManager("ObjectManager"))
         self.atomics = []
         self.atomics.append(self.addSubModel(MainApp("MainApp")))

+ 15 - 8
sccd/compiler/DEVS_generator.py

@@ -89,6 +89,7 @@ class DEVSGenerator(Visitor):
                 # cannot instantiate abstract class
                 self.writer.add(GLC.ThrowExceptionStatement(GLC.String("Cannot instantiate abstract class \"" + c.name + "\" with unimplemented methods \"" + "\", \"".join(c.abstract_method_names) + "\".")))
             else:
+                self.writer.addAssignment("self.narrow_cast_id", f"self.narrow_cast_id + {len(c.inports)}")
                 self.writer.addAssignment(
                     "instance[\"associations\"]", GLC.MapExpression())
                 for a in c.associations:
@@ -153,10 +154,8 @@ class DEVSGenerator(Visitor):
 
         for i in class_diagram.inports:
             self.writer.addAssignment(GLC.SelfProperty("in_" + i), GLC.FunctionCall(GLC.SelfProperty("addInPort"), [GLC.String(i)]))
-            self.writer.add(GLC.FunctionCall("Ports.addInputPort", [GLC.String(i)]))
         for o in class_diagram.outports:
             self.writer.addAssignment(GLC.SelfProperty("out_" + o), GLC.FunctionCall(GLC.SelfProperty("addOutPort"), [GLC.String(o)]))
-            self.writer.add(GLC.FunctionCall("Ports.addOutputPort", [GLC.String(o)]))
 
         # Add AtomicDEVS models
         self.writer.addAssignment(GLC.SelfProperty("objectmanager"), (GLC.FunctionCall(GLC.SelfProperty("addSubModel"),
@@ -245,6 +244,7 @@ class DEVSGenerator(Visitor):
         self.writer.beginConstructor()
         self.writer.addFormalParameter("atomdevs")
         self.writer.addFormalParameter("id")
+        self.writer.addFormalParameter("start_port_id")
 
         for p in class_node.constructors[0].getParams():
             self.writer.addFormalParameter(p.getIdent(), p.getDefault())
@@ -318,14 +318,20 @@ class DEVSGenerator(Visitor):
             self.writer.addActualParameter(p.getIdent())
         self.writer.endSuperClassMethodCall()
 
-        # TODO
-        #if constructor.parent_class.name != constructor.parent_class.class_diagram.default_class.name:
-        self.writer.addAssignment("port_name", GLC.FunctionCall("Ports.addInputPort", [GLC.String("<narrow_cast>"), "self"]))
+        for inp in class_node.class_diagram.inports:
+            self.writer.addAssignment("port_name", GLC.FunctionCall("addInputPort", [GLC.String(inp), "start_port_id", "True"]))
+            self.writer.add(GLC.FunctionCall("atomdevs.addInPort", ["port_name"]))
+            self.writer.addAssignment("atomdevs.state.port_mappings[port_name]", "id")
+
+
+
+        self.writer.addAssignment("port_name", GLC.FunctionCall("addInputPort", [GLC.String("<narrow_cast>"), "start_port_id"]))
         self.writer.add(GLC.FunctionCall("atomdevs.addInPort", ["port_name"]))
+        self.writer.addAssignment("atomdevs.state.port_mappings[port_name]", "id")
 
         for inp in class_node.inports:
             #self.writer.addAssignment(GLC.SelfProperty(f"inports[\"{inp}\"]"), f"(\'{inp}\', atomdevs.next_instance)")
-            self.writer.addAssignment("port_name", GLC.FunctionCall("Ports.addInputPort", [GLC.String(inp), "self"]))
+            self.writer.addAssignment("port_name", GLC.FunctionCall("addInputPort", [GLC.String(inp), "start_port_id"]))
             self.writer.add(GLC.FunctionCall("atomdevs.addInPort", ["port_name"]))
             self.writer.addAssignment("atomdevs.state.port_mappings[port_name]", "id")
             self.writer.addAssignment(f"self.inports[\"{inp}\"]", "port_name")
@@ -409,11 +415,12 @@ class DEVSGenerator(Visitor):
 
         self.writer.beginMethod("constructObject")
 
-        parameters = [GLC.SelfExpression(), "id"]
+        parameters = [GLC.SelfExpression(), "id", "start_port_id"]
         for i, _ in enumerate(constructor.parameters):
             parameters.append(f"parameters[{i+1}]")
 
         self.writer.addFormalParameter("id")
+        self.writer.addFormalParameter("start_port_id")
         self.writer.addFormalParameter("parameters")
         self.writer.beginMethodBody()
         self.writer.addAssignment("new_instance", GLC.FunctionCall(f"{class_node.name}Instance", parameters))
@@ -464,7 +471,7 @@ class DEVSGenerator(Visitor):
                 GLC.FunctionCall(GLC.Property("controller", "addOutputPort"), [GLC.String(p), GLC.SelfExpression()]))
 
         if constructor.parent_class.name == constructor.parent_class.class_diagram.default_class.name:
-            self.writer.addAssignment("new_instance", "self.constructObject(0, [])")
+            self.writer.addAssignment("new_instance", "self.constructObject(0, 0, [])")
             self.writer.addAssignment("self.state.instances[new_instance.instance_id]", "new_instance")
             #self.writer.addAssignment("self.state.instances[self.state.next_instance]", f"{constructor.parent_class.name}Instance(self)")
             self.writer.addAssignment("self.state.next_instance", "self.state.next_instance + 1")

+ 940 - 0
sccd/runtime/DEVS_statecharts_core old.py

@@ -0,0 +1,940 @@
+# TODO: The associations are sometimes getting pushed differently, fix this
+
+import sys
+import re
+from sccd.runtime.event_queue import EventQueue
+from pypdevs.infinity import INFINITY
+from pypdevs.DEVS import *
+
+from sccd.runtime.statecharts_core import StatechartSemantics, BigStepState, ComboStepState, SmallStepState
+from sccd.runtime.statecharts_core import State, HistoryState, ShallowHistoryState, DeepHistoryState, ParallelState
+from sccd.runtime.statecharts_core import RuntimeException, AssociationException,AssociationReferenceException, ParameterException, InputException
+from sccd.runtime.statecharts_core import ELSE_GUARD, Association, Event
+
+
+from heapq import heappush, heappop, heapify
+import threading
+
+def get_private_port(text):
+    match = re.search(r'private_\d+_(\w+)', text)
+
+    if match:
+        result = match.group(1)
+        return result
+    
+class Transition:
+    def __init__(self, obj, source, targets):
+        self.guard = None
+        self.action = None
+        self.trigger = None
+        self.source = source
+        self.targets = targets
+        self.obj = obj
+        self.enabled_event = None  # the event that enabled this transition
+        self.optimize()
+
+    def isEnabled(self, events, enabled_transitions):
+        if self.trigger is None:
+            self.enabled_event = None
+            return (self.guard is None) or (self.guard == ELSE_GUARD and not enabled_transitions) or self.guard([])
+        else:
+            for event in events:
+                if (self.trigger.name == event.name and (
+                        not self.trigger.port or self.trigger.port == event.port)) and (
+                        (self.guard is None) or (self.guard == ELSE_GUARD and not enabled_transitions) or self.guard(
+                        event.parameters)):
+                    self.enabled_event = event
+                    return True
+
+    # @profile
+    def fire(self, statechart):
+        # exit states...
+        exit_set = self.__exitSet()
+        for s in exit_set:
+            # remember which state(s) we were in if a history state is present
+            for h in s.history:
+                f = lambda s0: s0.ancestors and s0.parent == s
+                if isinstance(h, DeepHistoryState):
+                    f = lambda s0: not s0.descendants and s0 in s.descendants
+                self.obj.history_values[h.state_id] = list(filter(f, self.obj.configuration))
+        for s in exit_set:
+            #########################################
+            # TODO, here trace for exit state
+            statechart.text += "\n"
+            statechart.text += "\t\t\tEXIT STATE in model <%s>\n" % statechart.name
+            statechart.text += f"\t\t\tState: {str(s)} (name: {s.name})\n"
+            #########################################
+
+            self.obj.eventless_states -= s.has_eventless_transitions
+            # execute exit action(s)
+            if s.exit:
+                s.exit()
+            self.obj.configuration_bitmap &= ~2 ** s.state_id
+
+        # combo state changed area
+        self.obj.combo_step.changed_bitmap |= 2 ** self.lca.state_id
+        self.obj.combo_step.changed_bitmap |= self.lca.descendant_bitmap
+
+        #########################################
+         # TODO, here trace for fired transition
+        statechart.text += "\n"
+        statechart.text += "\t\t\tTRANSITION FIRED in model <%s>\n" % statechart.name
+        statechart.text += "\t\t\t%s\n" % str(self)
+        #########################################
+        # execute transition action(s)
+        if self.action:
+            self.action(self.enabled_event.parameters if self.enabled_event else [])
+
+        # enter states...
+        targets = self.__getEffectiveTargetStates()
+        enter_set = self.__enterSet(targets)
+        for s in enter_set:
+            #########################################
+            # TODO, here trace for enter state
+            statechart.text += "\n"
+            statechart.text += "\t\t\tENTER STATE in model <%s>\n" % statechart.name
+            statechart.text += f"\t\t\tState: {str(s)} (name: {s.name})\n"
+            #########################################
+
+            self.obj.eventless_states += s.has_eventless_transitions
+            self.obj.configuration_bitmap |= 2 ** s.state_id
+            # execute enter action(s)
+            if s.enter:
+                s.enter()
+
+        if self.obj.eventless_states:
+            self.obj.controller.state.eventless.add(self.obj)
+        else:
+            self.obj.controller.state.eventless.discard(self.obj)
+
+        try:
+            self.obj.configuration = self.obj.config_mem[self.obj.configuration_bitmap]
+        except:
+            self.obj.configuration = self.obj.config_mem[self.obj.configuration_bitmap] = sorted(
+                [s for s in list(self.obj.states.values()) if 2 ** s.state_id & self.obj.configuration_bitmap],
+                key=lambda s: s.state_id)
+        self.enabled_event = None
+
+    def __getEffectiveTargetStates(self):
+        targets = []
+        for target in self.targets:
+            for e_t in target.getEffectiveTargetStates():
+                if not e_t in targets:
+                    targets.append(e_t)
+        return targets
+
+    def __exitSet(self):
+        return [s for s in reversed(self.lca.descendants) if (s in self.obj.configuration)]
+
+    def __enterSet(self, targets):
+        target = targets[0]
+        for a in reversed(target.ancestors):
+            if a in self.source.ancestors:
+                continue
+            else:
+                yield a
+        for target in targets:
+            yield target
+
+    def setGuard(self, guard):
+        self.guard = guard
+
+    def setAction(self, action):
+        self.action = action
+
+    def setTrigger(self, trigger):
+        self.trigger = trigger
+        if self.trigger is None:
+            self.source.has_eventless_transitions = True
+
+    def optimize(self):
+        # the least-common ancestor can be computed statically
+        if self.source in self.targets[0].ancestors:
+            self.lca = self.source
+        else:
+            self.lca = self.source.parent
+            target = self.targets[0]
+            if self.source.parent != target.parent:  # external
+                for a in self.source.ancestors:
+                    if a in target.ancestors:
+                        self.lca = a
+                        break
+
+    def __repr__(self):
+        return "Transition(%s -> %s)" % (self.source.name, self.targets[0].name)
+
+
+class RuntimeClassBase(object):
+    def __init__(self, controller, id):
+        self.events = EventQueue()
+
+        self.active = False
+
+        # Instead of controller, do the class for which the instanced 
+        self.controller = controller
+        self.instance_id = id
+
+        self.__set_stable(True)
+        self.inports = {}
+        self.outports = {}
+        self.timers = {}
+        self.states = {}
+        self.eventless_states = 0
+        self.configuration_bitmap = 0
+        self.transition_mem = {}
+        self.config_mem = {}
+
+        self.semantics = StatechartSemantics()
+
+    # to break ties in the heap, compare by number of events in the list
+    def __lt__(self, other):
+        return len(self.events.event_list) < len(other.events.event_list)
+
+    def getChildren(self, link_name):
+        pass
+
+    def getSingleChild(self, link_name):
+        return self.getChildren(link_name)[0]  # assume this will return a single child...
+
+    def getOutPortName(self, port_name):
+        return self.outports[port_name] if port_name in self.outports else port_name
+
+    def getInPortName(self, port_name):
+        return self.inports[port_name] if port_name in self.inports else port_name
+
+    def start(self):
+        self.configuration = []
+
+        self.active = True
+
+        self.current_state = {}
+        self.history_values = {}
+        self.timers = {}
+        self.timers_to_add = {}
+
+        self.big_step = BigStepState()
+        self.combo_step = ComboStepState()
+        self.small_step = SmallStepState()
+
+        self.__set_stable(False)
+
+        self.initializeStatechart()
+        self.processBigStepOutput()
+
+    def stop(self):
+        self.active = False
+        self.__set_stable(True)
+
+    def updateConfiguration(self, states):
+        self.configuration.extend(states)
+        self.configuration_bitmap = sum([2 ** s.state_id for s in states])
+
+    def getSimulatedTime(self):
+        return self.controller.state.simulated_time * 1000
+
+    def addTimer(self, index, timeout):
+        self.timers_to_add[index] = (self.controller.state.simulated_time + timeout, Event("_%iafter" % index))
+
+    def removeTimer(self, index):
+        if index in self.timers_to_add:
+            del self.timers_to_add[index]
+        if index in self.timers:
+            self.events.remove(self.timers[index])
+            del self.timers[index]
+        self.earliest_event_time = self.events.getEarliestTime()
+
+    def addEvent(self, event_list, time_offset=0):
+        event_time = self.controller.state.simulated_time + time_offset
+        if not (event_time, self) in self.controller.state.instance_times:
+            heappush(self.controller.state.instance_times, (event_time, self))
+        if event_time < self.earliest_event_time:
+            self.earliest_event_time = event_time
+        if not isinstance(event_list, list):
+            event_list = [event_list]
+        for e in event_list:
+            self.events.add(event_time, e)
+
+    def processBigStepOutput(self):
+        for e in self.big_step.output_events_port:
+            self.controller.state.outputEvent(e)
+        for e in self.big_step.output_events_om:
+            self.controller.state.addEvent(e)
+    def __set_stable(self, is_stable):
+        self.is_stable = is_stable
+        # self.earliest_event_time keeps track of the earliest time this instance will execute a transition
+        if not is_stable:
+            self.earliest_event_time = self.controller.state.simulated_time
+        
+        elif not self.active:
+            self.earliest_event_time = INFINITY
+        else:
+            self.earliest_event_time = self.events.getEarliestTime()
+        if self.earliest_event_time != INFINITY:
+            if not (self.earliest_event_time, self) in self.controller.state.instance_times:
+                heappush(self.controller.state.instance_times, (self.earliest_event_time, self))
+
+    def step(self):
+        is_stable = False
+        while not is_stable:
+            due = []
+            if self.events.getEarliestTime() <= self.controller.state.simulated_time:
+                due = [self.events.pop()]
+            is_stable = not self.bigStep(due)
+            self.processBigStepOutput()
+        for index, entry in list(self.timers_to_add.items()):
+            self.timers[index] = self.events.add(*entry)
+        self.timers_to_add = {}
+        self.__set_stable(True)
+
+    def inState(self, state_strings):
+        state_ids = [self.states[state_string].state_id for state_string in state_strings]
+        for state_id in state_ids:
+            for s in self.configuration:
+                if s.state_id == state_id:
+                    break
+            else:
+                return False
+        return True
+
+    def bigStep(self, input_events):
+        self.big_step.next(input_events)
+        self.small_step.reset()
+        self.combo_step.reset()
+        while self.comboStep():
+            self.big_step.has_stepped = True
+            if self.semantics.big_step_maximality == StatechartSemantics.TakeOne:
+                break  # Take One -> only one combo step allowed
+        return self.big_step.has_stepped
+
+    def comboStep(self):
+        self.combo_step.next()
+        while self.smallStep():
+            self.combo_step.has_stepped = True
+        return self.combo_step.has_stepped
+
+    # generate transition candidates for current small step
+    # @profile
+    def generateCandidates(self):
+        changed_bitmap = self.combo_step.changed_bitmap
+        key = (self.configuration_bitmap, changed_bitmap)
+        try:
+            transitions = self.transition_mem[key]
+        except:
+            self.transition_mem[key] = transitions = [t for s in self.configuration if
+                                                      not (2 ** s.state_id & changed_bitmap) for t in s.transitions]
+
+        enabledEvents = self.getEnabledEvents()
+        enabledTransitions = []
+        for t in transitions:
+            if t.isEnabled(enabledEvents, enabledTransitions):
+                enabledTransitions.append(t)
+        return enabledTransitions
+
+    # @profile
+    def smallStep(self):
+        def __younger_than(x, y):
+            if x.source in y.source.ancestors:
+                return 1
+            elif y.source in x.source.ancestors:
+                return -1
+            else:
+                return 0
+
+        if self.small_step.has_stepped:
+            self.small_step.next()
+        candidates = self.generateCandidates()
+        if candidates:
+            to_skip = set()
+            conflicting = []
+            for c1 in candidates:
+                if c1 not in to_skip:
+                    conflict = [c1]
+                    for c2 in candidates[candidates.index(c1):]:
+                        if c2.source in c1.source.ancestors or c1.source in c2.source.ancestors:
+                            conflict.append(c2)
+                            to_skip.add(c2)
+
+                    if sys.version_info[0] < 3:
+                        conflicting.append(sorted(conflict, cmp=__younger_than))
+                    else:
+                        import functools
+                        conflicting.append(sorted(conflict, key=functools.cmp_to_key(__younger_than)))
+
+            if self.semantics.concurrency == StatechartSemantics.Single:
+                candidate = conflicting[0]
+                if self.semantics.priority == StatechartSemantics.SourceParent:
+                    candidate[-1].fire(self.controller.state)
+                else:
+                    candidate[0].fire(self.controller.state)
+            elif self.semantics.concurrency == StatechartSemantics.Many:
+                pass  # TODO: implement
+            self.small_step.has_stepped = True
+        return self.small_step.has_stepped
+
+    # @profile
+    def getEnabledEvents(self):
+        result = self.small_step.current_events + self.combo_step.current_events
+        if self.semantics.input_event_lifeline == StatechartSemantics.Whole or (
+                not self.big_step.has_stepped and
+                (self.semantics.input_event_lifeline == StatechartSemantics.FirstComboStep or (
+                        not self.combo_step.has_stepped and
+                        self.semantics.input_event_lifeline == StatechartSemantics.FirstSmallStep))):
+            result += self.big_step.input_events
+        return result
+
+    def raiseInternalEvent(self, event):
+        if self.semantics.internal_event_lifeline == StatechartSemantics.NextSmallStep:
+            self.small_step.addNextEvent(event)
+        elif self.semantics.internal_event_lifeline == StatechartSemantics.NextComboStep:
+            self.combo_step.addNextEvent(event)
+        elif self.semantics.internal_event_lifeline == StatechartSemantics.Queue:
+            self.addEvent(event)
+
+    def initializeStatechart(self):
+        self.updateConfiguration(self.default_targets)
+        for state in self.default_targets:
+            self.eventless_states += state.has_eventless_transitions
+            if state.enter:
+                state.enter()
+        if self.eventless_states:
+            pass
+            # TODO: Check (untill now no problems)
+            #self.controller.object_manager.eventless.add(self)
+    
+class ClassState():
+    def __init__(self, name) -> None:
+        self.name = name
+        self.next_time = INFINITY
+        
+        self.port_mappings = {}
+        
+        self.input_queue = EventQueue()
+        self.simulated_time = 0
+        self.to_send = []
+
+        self.events = EventQueue()
+        self.instances = {}
+        self.next_instance = 0
+        self.instance_times = []
+        self.eventless = set()
+
+        #self.lock = threading.Condition()
+
+        self.text = ""
+
+    def __str__(self) -> str:
+        return self.text
+
+    def getEarliestEventTime(self):
+        #with self.lock:
+        while self.instance_times and self.instance_times[0][0] < self.instance_times[0][1].earliest_event_time:
+            heappop(self.instance_times)
+        return min(INFINITY if not self.instance_times else self.instance_times[0][0], self.events.getEarliestTime())
+        
+    def addEvent(self, event, time_offset = 0):
+        self.events.add(self.simulated_time + time_offset, event)
+        
+    # broadcast an event to all instances
+    def broadcast(self, source, new_event, time_offset = 0):
+        for i in self.instances:
+            if self.instances[i] != source:
+                self.instances[i].addEvent(new_event, time_offset)
+        
+    def stepAll(self):
+        self.step()
+        self.to_step = set()
+        if len(self.instance_times) > (4 * len(self.instances)):
+            new_instance_times = []
+            for it in self.instances:
+                if it.earliest_event_time != INFINITY:
+                    new_instance_times.append((it.earliest_event_time, it))
+            self.instance_times = new_instance_times
+            heapify(self.instance_times)
+        while self.instance_times and self.instance_times[0][0] <= self.simulated_time:
+            self.to_step.add(heappop(self.instance_times)[1])
+        for i in self.to_step | self.eventless:
+            if i.active and (i.earliest_event_time <= self.simulated_time or i.eventless_states):
+                i.step()
+
+    def step(self):
+        while self.events.getEarliestTime() <= self.simulated_time:
+            if self.events:
+                self.handleEvent(self.events.pop())
+               
+    def start(self):
+        for i in self.instances:
+            i.start()
+
+    def handleInput(self):
+        while not self.input_queue.isEmpty():
+            event_time = self.input_queue.getEarliestTime()
+            e = self.input_queue.pop()
+
+            target_instance = None
+            if e.getPort():
+                target_instance = self.port_mappings[e.getPort()]
+                if target_instance is not None:
+                    target_instance = self.instances[target_instance] 
+                    e.port = get_private_port(e.port)
+            if target_instance == None:
+                self.broadcast(None,e, event_time - self.simulated_time)
+            else:
+                target_instance.addEvent(e, event_time - self.simulated_time)
+        
+
+    def addInput(self, input_event_list, time_offset = 0):
+        if not isinstance(input_event_list, list):
+            input_event_list = [input_event_list]
+
+        for e in input_event_list:
+            if e.getName() == "":
+                raise InputException("Input event can't have an empty name.")
+            
+            #if e.getPort() not in self.IPorts:
+            #    raise InputException("Input port mismatch, no such port: " + e.getPort() + ".")
+                
+            self.input_queue.add((0 if self.simulated_time is None else 0) + time_offset, e)
+
+
+    def handleEvent(self, e):
+        parameters = e.parameters
+        source = parameters[0]
+        parameters[0] = source.instance_id
+        self.to_send.append(((self.name, source.instance_id), None, e))
+
+
+    def outputEvent(self, event):
+        self.to_send.append(event)
+
+
+class ClassBase(AtomicDEVS):    
+    def __init__(self, name):
+        AtomicDEVS.__init__(self, name)
+        self.glob_outputs = {}
+        self.outputs = {}
+        self.state = ClassState(name)
+        self.obj_manager_in = self.addInPort("obj_manager_in")
+        self.obj_manager_out = self.addOutPort("obj_manager_out")
+
+    def constructObject(self, id, parameters):
+        raise "Something went wrong "
+
+    def extTransition(self, inputs):
+        # Update simulated time
+        self.state.simulated_time += self.elapsed
+        self.state.next_time = 0
+        self.state.text = ""
+
+        # Collect all inputs
+        all_inputs = [input for input_list in inputs.values() for input in input_list]
+        for input in all_inputs:
+            if isinstance(input, str):
+                tem = eval(input)
+                instance = self.state.port_mappings.setdefault(tem.port, None)
+                self.state.addInput(tem)
+            elif input[2].name == "create_instance":
+                new_instance = self.constructObject(input[1][1], input[2].parameters[2:])
+                self.state.instances[new_instance.instance_id] = new_instance
+                ev = Event("instance_created", None, [input[2].parameters[1]])
+                self.state.to_send.append((input[1], input[0], ev))
+                self.state.next_instance += 1
+            elif input[2].name == "broad_cast":
+                # Handle when in the instance atomicDEVS
+                if input[0][0] == self.name:
+                    source = self.state.instances[input[0][1]]
+                    self.state.broadcast(source, input[2].parameters[1])
+                self.state.broadcast(None, input[2].parameters[1])
+            elif input[2].name == "start_instance":
+                instance = self.state.instances[input[1][1]]
+                instance.start()
+                ev = Event("instance_started", None, [input[2].parameters[0]])
+                self.state.to_send.append((input[1], input[0], ev))
+            elif input[2].name == "delete_instance":   
+                instance_ids =  input[2].parameters[0]
+                for id in instance_ids:
+                    instance = self.state.instances[id]  
+                    self.state.port_mappings = {k: v for k, v in self.state.port_mappings.items() if v != id}
+                    del self.state.instances[instance.instance_id]
+                    self.state.eventless.discard(instance.instance_id)
+                    instance.user_defined_destructor()
+                    instance.stop()
+                    del instance
+                ev = Event("instance_deleted", None, [input[2].parameters[1]])
+                self.state.to_send.append((input[1], input[0], ev))
+            elif input[2].name == "associate_instance":
+                ev = Event("instance_associated", None, input[2].parameters)
+                self.state.to_send.append((input[1], input[0], ev))
+            elif input[2].name == "disassociate_instance":
+                ev = Event("instance_disassociated", None, input[2].parameters)
+                self.state.to_send.append((input[1], input[0], ev))
+            elif input[2].name == "instance_created":
+                instance = self.state.instances[input[1][1]]
+                instance.addEvent(input[2])
+            elif input[2].name == "instance_started":
+                instance = self.state.instances[input[1][1]]
+                instance.addEvent(input[2])
+            elif input[2].name == "instance_deleted":
+                instance = self.state.instances[input[1][1]]
+                instance.addEvent(input[2])
+            elif input[2].name == "instance_associated":
+                instance = self.state.instances[input[1][1]]
+                instance.addEvent(input[2])
+            elif input[2].name == "instance_disassociated":
+                instance = self.state.instances[input[1][1]]
+                instance.addEvent(input[2])
+            else:
+                ev = input[2]
+
+                new_port = None
+                for key, value in self.state.port_mappings.items():
+                    if value == ev.port[1]:
+                        new_port = key
+                        break
+                
+                if new_port is None:
+                    new_port = 0
+                ev.port = new_port
+                self.state.addInput(ev)
+        return self.state
+    
+    def intTransition(self):
+        self.state.to_send = self.state.to_send[1:]
+        self.state.text = ""
+
+        if len(self.state.to_send) == 0:
+            # Update simulated time and clear previous messages 
+            self.state.simulated_time += self.state.next_time
+            # Calculate the next event time, clamp to ensure non-negative result
+            self.state.next_time = min(self.state.getEarliestEventTime(), self.state.simulated_time + self.state.input_queue.getEarliestTime())
+            self.state.next_time -= self.state.simulated_time
+            self.state.next_time = max(self.state.next_time, 0.0)
+            # Handle incoming inputs and do a step in all statecharts
+            self.state.handleInput()
+            self.state.stepAll()
+        else:
+            self.state.next_time = 0
+        return self.state
+
+    def outputFnc(self):
+        to_dict = {}
+        if not len(self.state.to_send) == 0:
+            sending = self.state.to_send[0]
+            if isinstance(sending, tuple) and sending[2].port == None:
+                to_dict[self.obj_manager_out] = sending
+            else:
+                the_port = next((port for port in self.OPorts if port.name == sending.port), None)
+                to_dict[the_port] = sending
+        return to_dict
+    
+    def timeAdvance(self):
+        return self.state.next_time
+
+class ObjectManagerState():
+    def __init__(self):
+        self.to_send = []
+        self.instances = []
+
+        self.regex_pattern = re.compile("^([a-zA-Z_]\w*)(?:\[(\d+)\])?$")
+        self.handlers = {
+                    "broad_cast": self.handleBroadCastEvent,
+                    "narrow_cast": self.handleNarrowCastEvent,
+                    "create_instance": self.handleCreateEvent,
+                    "associate_instance": self.handleAssociateEvent,
+                    "start_instance": self.handleStartEvent,
+                    "delete_instance": self.handleDeleteEvent,
+                    "disassociate_instance": self.handleDisassociateEvent,
+                    }
+
+    def handleEvent(self, e):
+        self.handlers[e[2].getName()](e)
+    
+    def processAssociationReference(self, input_string):
+        if len(input_string) == 0:
+            raise AssociationReferenceException("Empty association reference.")
+        path_string =  input_string.split("/")
+        result = []
+        for piece in path_string:
+            match = self.regex_pattern.match(piece)
+            if match:
+                name = match.group(1)
+                index = match.group(2)
+                if index is None:
+                    index = -1
+                result.append((name,int(index)))
+            else:
+                raise AssociationReferenceException("Invalid entry in association reference. Input string: " + input_string)
+        return result
+
+    def getInstances(self, source, traversal_list):
+        currents = [{
+            "instance": source,
+            "ref": None,
+            "assoc_name": None,
+            "assoc_index": None,
+            "path": ""
+        }]
+        # currents = [source]
+        for (name, index) in traversal_list:
+            nexts = []
+            for current in currents:
+                instance = current["instance"][1]
+
+                association = self.instances[instance]["associations"][name]
+                if (index >= 0 ):
+                    try:
+                        nexts.append({
+                            "class": association.to_class,
+                            "instance": (association.to_class, association.instances[index]),
+                            "ref": current["instance"],
+                            "assoc_name": name,
+                            "assoc_index": index,
+                            "path": current["path"] + ("" if current["path"] == "" else "/") + name + "[" + str(index) + "]"
+                        })
+                    except KeyError:
+                        # Entry was removed, so ignore this request
+                        pass
+                elif (index == -1):
+                    for i in association.instances:
+                        nexts.append({
+                            "class": association.to_class,
+                            "instance": (association.to_class, association.instances[i]),
+                            "ref": current["instance"],
+                            "assoc_name": name,
+                            "assoc_index": index,
+                            "path": current["path"] + ("" if current["path"] == "" else "/") + name + "[" + str(index) + "]"
+                        })
+                else:
+                    raise AssociationReferenceException("Incorrect index in association reference.")
+            currents = nexts
+        return currents
+
+    def handleNarrowCastEvent(self, parameters):
+        if len(parameters[2].parameters) != 3:
+            raise ParameterException("The narrow_cast event needs 3 parameters.")
+        else:
+            source = parameters[0]
+            
+            parameters = parameters[2].parameters
+            if not isinstance(parameters[1], list):
+                targets = [parameters[1]]
+            else:
+                targets = parameters[1]
+
+            for target in targets:
+                traversal_list = self.processAssociationReference(target)
+                cast_event = parameters[2]
+                for i in self.getInstances(source, traversal_list):
+                    to_send_event = Event(cast_event.name, i["instance"], cast_event.parameters)
+                    self.to_send.append((source,  i["instance"], to_send_event))
+
+    def handleBroadCastEvent(self, parameters):
+        if len(parameters[2].parameters) != 2:
+            raise ParameterException("The broadcast event needs 2 parameters (source of event and event name).")
+        
+        ev = Event('broad_cast', None, parameters[2].parameters)
+        # Extract unique names
+        unique_classes = {entry["name"] for entry in self.instances}
+        for aclass in unique_classes:
+            # The index of target does not matter as it gets broadcasted to every instance
+            self.to_send.append((parameters[0], (aclass, 0), ev))
+
+    def handleCreateEvent(self, parameters):
+        if len(parameters[2].parameters) < 2:
+            raise ParameterException("The create event needs at least 2 parameters.")
+        else:
+            source = parameters[0]
+
+            association_name = parameters[2].parameters[1]
+            
+            traversal_list = self.processAssociationReference(association_name)
+            instances = self.getInstances(source, traversal_list)
+            
+            association = self.instances[source[1]]["associations"][association_name]
+
+            if association.allowedToAdd():
+                ''' allow subclasses to be instantiated '''
+                class_name = association.to_class if len(parameters[2].parameters) == 2 else parameters[2].parameters[2]
+                new_instance = self.createInstance(class_name, parameters[2].parameters[3:])
+
+                #  Work on index instead of the instance
+                new_instance_index = len(self.instances) - 1
+
+                if not new_instance:
+                    raise ParameterException("Creating instance: no such class: " + class_name)
+                try:
+                    index = association.addInstance(new_instance_index)
+                except AssociationException as exception:
+                    raise RuntimeException("Error adding instance to association '" + association_name + "': " + str(exception))
+                p = new_instance["associations"].get("parent")
+                if p:
+                    p.addInstance(source[1])
+                
+                parameters[2].parameters[1] = f"{association_name}[{index}]"
+                ev = Event('create_instance', None, parameters[2].parameters)
+                self.to_send.append((parameters[0], (class_name, new_instance_index), ev))
+                return [source, association_name+"["+str(index)+"]"]
+            else:
+                #source.addEvent(Event("instance_creation_error", None, [association_name]))
+                return []
+    
+    def handleStartEvent(self, parameters):
+        if len(parameters[2].parameters) != 2:
+            raise ParameterException("The start instance event needs 2 parameters.")  
+        else:
+            source = parameters[0]
+            traversal_list = self.processAssociationReference(parameters[2].parameters[1])
+
+            # TODO: it is possible that we need to get the right index here because not needed now
+            to_class = None
+            for i in self.getInstances(source, traversal_list):
+                to_class = i["instance"]
+            self.to_send.append((source, to_class, Event('start_instance', None, parameters[2].parameters[1:])))
+        
+    def createInstance(self, to_class, construct_params = []):
+        instance = self.instantiate(to_class, construct_params)
+        self.instances.append(instance)
+        return instance
+    
+    def handleAssociateEvent(self, parameters):
+        if len(parameters[2].parameters) != 3:
+            raise ParameterException("The associate_instance event needs 3 parameters.")
+        else:
+            source = parameters[0]
+            to_copy_list = self.getInstances(source, self.processAssociationReference(parameters[2].parameters[1]))
+            if len(to_copy_list) != 1:
+                raise AssociationReferenceException("Invalid source association reference.")
+            wrapped_to_copy_instance = to_copy_list[0]["instance"][1]
+            dest_list = self.processAssociationReference(parameters[2].parameters[2])
+            if len(dest_list) == 0:
+                raise AssociationReferenceException("Invalid destination association reference.")
+            last = dest_list.pop()
+            if last[1] != -1:
+                raise AssociationReferenceException("Last association name in association reference should not be accompanied by an index.")
+                
+            added_links = []
+            to_class = None
+            for i in self.getInstances(source, dest_list):
+                to_class = i["instance"]
+                association = self.instances[i["instance"][1]]["associations"][last[0]]
+                if association.allowedToAdd():
+                    index = association.addInstance(wrapped_to_copy_instance)
+                    added_links.append(i["path"] + ("" if i["path"] == "" else "/") + last[0] + "[" + str(index) + "]")
+
+            self.to_send.append((source, to_class, Event('associate_instance', None, [added_links])))  
+
+    def handleDisassociateEvent(self, parameters):
+        if len(parameters[2].parameters) < 2:
+            raise ParameterException("The disassociate_instance event needs at least 2 parameters.")
+        else:
+            source = parameters[0]
+            association_name = parameters[2].parameters[1]
+            if not isinstance(association_name, list):
+                association_name = [association_name]
+            deleted_links = []
+            
+            to_class = None
+            for a_n in association_name:
+                traversal_list = self.processAssociationReference(a_n)
+                instances = self.getInstances(source, traversal_list)
+                
+                for i in instances:
+                    try:
+                        to_class = i["instance"]
+                        instance = self.instances[i['ref'][1]]
+                        association = instance['associations'][i['assoc_name']]
+
+                        index = association.removeInstance(i["instance"][1])
+                        #index = i['ref'].associations[i['assoc_name']].removeInstance(i["instance"])
+                        deleted_links.append(a_n +  "[" + str(index) + "]")
+                    except AssociationException as exception:
+                        raise RuntimeException("Error disassociating '" + a_n + "': " + str(exception))
+                
+            self.to_send.append((None, source, Event('instance_disassociated', None, [deleted_links])))  
+
+    def handleDeleteEvent(self, parameters):
+        if len(parameters) < 2:
+            raise ParameterException("The delete event needs at least 2 parameters.")
+        else:
+            source = parameters[0]
+            association_name = parameters[2].parameters[1]
+            
+            traversal_list = self.processAssociationReference(association_name)
+            instances = self.getInstances(source, traversal_list)
+
+            association = self.instances[source[1]]["associations"][traversal_list[0][0]]
+            
+            # TODO: THis to class only for when there are no instance
+            to_class = (association.to_class, 0)
+            to_remove = []
+            for i in instances:
+                to_class = i["instance"]
+                to_remove.append(i["instance"][1])
+                try:
+                    for assoc_name in self.instances[i["instance"][1]]["associations"]:
+                        if assoc_name != 'parent':
+                            traversal_list = self.processAssociationReference(assoc_name)
+                            instances = self.getInstances(to_class, traversal_list)
+                            if len(instances) > 0:
+                                raise RuntimeException("Error removing instance from association %s, still %i children left connected with association %s" % (association_name, len(instances), assoc_name))
+                    association.removeInstance(i["instance"][1])
+                except AssociationException as exception:
+                    raise RuntimeException("Error removing instance from association '" + association_name + "': " + str(exception))
+            parameters[2].parameters[0] = to_remove
+            self.to_send.append((source, to_class, Event('delete_instance', None, parameters[2].parameters)))
+            #source.addEvent(Event("delete_instance", parameters = [parameters[1]]))
+
+class ObjectManagerBase(AtomicDEVS):
+    def __init__(self, name):
+        AtomicDEVS.__init__(self, name)
+        self.output = {}
+
+        self.to_propagate = ["instance_created", "instance_started", "instance_associated", "instance_disassociated", "instance_deleted"]
+
+    def extTransition(self, inputs):
+        all_inputs = inputs[self.input]
+        if all_inputs[2].name in self.to_propagate:
+            self.state.to_send.append(all_inputs)
+        else:
+            self.state.handleEvent(all_inputs)
+        
+        return self.state
+    
+    def intTransition(self):
+        self.state.to_send.clear()
+        return self.state
+    
+    def outputFnc(self):
+        out_dict = {}
+        for source, target, message in self.state.to_send:
+            out_dict.setdefault(self.output.get(target[0]), []).append((source, target, message))
+        return out_dict
+    
+    def timeAdvance(self):
+        return 0 if self.state.to_send else INFINITY
+    
+# TODO: port class as wrapper to define the in and out ports the same as in SCCD
+class Ports:
+    private_port_counter = 0
+
+    inports = {}
+    outports = {}
+
+    @classmethod
+    def addOutputPort(self, virtual_name, instance=None):
+        if instance == None:
+            port_name = virtual_name
+        else:
+            port_name = "private_" + str(self.private_port_counter) + "_" + virtual_name
+            self.outports[port_name] = instance
+            self.private_port_counter += 1
+        return port_name
+
+    @classmethod
+    def addInputPort(self, virtual_name, instance=None):
+        if instance == None:
+            port_name = virtual_name
+        else:
+            port_name = "private_" + str(self.private_port_counter) + "_" + virtual_name
+            self.inports[port_name] = instance
+            self.private_port_counter += 1
+        return port_name

+ 61 - 45
sccd/runtime/DEVS_statecharts_core.py

@@ -490,8 +490,9 @@ class ClassState():
             if e.getName() == "":
                 raise InputException("Input event can't have an empty name.")
             
+            if e.getPort() not in self.port_mappings:
             #if e.getPort() not in self.IPorts:
-            #    raise InputException("Input port mismatch, no such port: " + e.getPort() + ".")
+                raise InputException("Input port mismatch, no such port: " + e.getPort() + ".")
                 
             self.input_queue.add((0 if self.simulated_time is None else 0) + time_offset, e)
 
@@ -502,6 +503,7 @@ class ClassState():
         parameters[0] = source.instance_id
         self.to_send.append(((self.name, source.instance_id), None, e))
 
+
     def outputEvent(self, event):
         self.to_send.append(event)
 
@@ -527,14 +529,14 @@ class ClassBase(AtomicDEVS):
         # Collect all inputs
         all_inputs = [input for input_list in inputs.values() for input in input_list]
         for input in all_inputs:
+            # TODO, this should be translated somewhere else
             if isinstance(input, str):
-                tem = eval(input)
-                instance = self.state.port_mappings.setdefault(tem.port, None)
-                self.state.addInput(tem)
-            elif input[2].name == "create_instance":
-                new_instance = self.constructObject(input[1][1], input[2].parameters[2:])
+                input = (None, None, eval(input))
+            if input[2].name == "create_instance":
+                new_instance = self.constructObject(input[1][1], input[2].parameters[1], input[2].parameters[3:])
+                # new_instance = self.constructObject(input[1][1], input[2].parameters[2:])
                 self.state.instances[new_instance.instance_id] = new_instance
-                ev = Event("instance_created", None, [input[2].parameters[1]])
+                ev = Event("instance_created", None, [input[2].parameters[2]])
                 self.state.to_send.append((input[1], input[0], ev))
                 self.state.next_instance += 1
             elif input[2].name == "broad_cast":
@@ -583,16 +585,6 @@ class ClassBase(AtomicDEVS):
                 instance.addEvent(input[2])
             else:
                 ev = input[2]
-
-                new_port = None
-                for key, value in self.state.port_mappings.items():
-                    if value == ev.port[1]:
-                        new_port = key
-                        break
-                
-                if new_port is None:
-                    new_port = 0
-                ev.port = new_port
                 self.state.addInput(ev)
         return self.state
     
@@ -633,6 +625,9 @@ class ObjectManagerState():
         self.to_send = []
         self.instances = []
 
+        self.narrow_cast_id = 0
+        self.narrow_cast_ports = {}
+
         self.regex_pattern = re.compile("^([a-zA-Z_]\w*)(?:\[(\d+)\])?$")
         self.handlers = {
                     "broad_cast": self.handleBroadCastEvent,
@@ -723,7 +718,8 @@ class ObjectManagerState():
                 traversal_list = self.processAssociationReference(target)
                 cast_event = parameters[2]
                 for i in self.getInstances(source, traversal_list):
-                    to_send_event = Event(cast_event.name, i["instance"], cast_event.parameters)
+                    to_send_event = Event(cast_event.name, self.narrow_cast_ports[i["instance"][1]], cast_event.parameters)
+                    # to_send_event = Event(cast_event.name, i["instance"], cast_event.parameters)
                     self.to_send.append((source,  i["instance"], to_send_event))
 
     def handleBroadCastEvent(self, parameters):
@@ -751,6 +747,9 @@ class ObjectManagerState():
             association = self.instances[source[1]]["associations"][association_name]
 
             if association.allowedToAdd():
+                # TODO: Needed here to know the id for the first port
+                starting_port_id = self.narrow_cast_id
+
                 ''' allow subclasses to be instantiated '''
                 class_name = association.to_class if len(parameters[2].parameters) == 2 else parameters[2].parameters[2]
                 new_instance = self.createInstance(class_name, parameters[2].parameters[3:])
@@ -768,8 +767,18 @@ class ObjectManagerState():
                 if p:
                     p.addInstance(source[1])
                 
+
                 parameters[2].parameters[1] = f"{association_name}[{index}]"
-                ev = Event('create_instance', None, parameters[2].parameters)
+
+                old_params = [parameters[2].parameters[0]]
+                old_params.append(starting_port_id)
+                old_params.extend(parameters[2].parameters[1:])
+
+
+                
+
+                ev = Event('create_instance', None, old_params)
+                #ev = Event('create_instance', None, parameters[2].parameters)
                 self.to_send.append((parameters[0], (class_name, new_instance_index), ev))
                 return [source, association_name+"["+str(index)+"]"]
             else:
@@ -788,9 +797,22 @@ class ObjectManagerState():
             for i in self.getInstances(source, traversal_list):
                 to_class = i["instance"]
             self.to_send.append((source, to_class, Event('start_instance', None, parameters[2].parameters[1:])))
+    
+    def addtestInputPort(self, virtual_name, instance = None):
+        if instance == None:
+            port_name = virtual_name
+        else:
+            port_name = "private_" + str(self.narrow_cast_id) + "_" + virtual_name
+            self.narrow_cast_id += 1
+        #self.input_ports[port_name] = InputPortEntry(virtual_name, instance)
+        return port_name
         
     def createInstance(self, to_class, construct_params = []):
+        test = self.addtestInputPort("<narrow_cast>", 0)
         instance = self.instantiate(to_class, construct_params)
+        
+        self.narrow_cast_ports[len(self.instances)] = test
+
         self.instances.append(instance)
         return instance
     
@@ -874,7 +896,11 @@ class ObjectManagerState():
                             traversal_list = self.processAssociationReference(assoc_name)
                             instances = self.getInstances(to_class, traversal_list)
                             if len(instances) > 0:
-                                raise RuntimeException("Error removing instance from association %s, still %i children left connected with association %s" % (association_name, len(instances), assoc_name))
+                                pass
+                                #raise RuntimeException("Error removing instance from association %s, still %i children left connected with association %s" % (association_name, len(instances), assoc_name))
+                    
+                    del self.narrow_cast_ports[i["instance"][1]]
+
                     association.removeInstance(i["instance"][1])
                 except AssociationException as exception:
                     raise RuntimeException("Error removing instance from association '" + association_name + "': " + str(exception))
@@ -910,30 +936,20 @@ class ObjectManagerBase(AtomicDEVS):
     
     def timeAdvance(self):
         return 0 if self.state.to_send else INFINITY
-    
-# TODO: port class as wrapper to define the in and out ports the same as in SCCD
-class Ports:
-    private_port_counter = 0
 
-    inports = {}
-    outports = {}
-
-    @classmethod
-    def addOutputPort(self, virtual_name, instance=None):
-        if instance == None:
-            port_name = virtual_name
-        else:
-            port_name = "private_" + str(self.private_port_counter) + "_" + virtual_name
-            self.outports[port_name] = instance
-            self.private_port_counter += 1
-        return port_name
-
-    @classmethod
-    def addInputPort(self, virtual_name, instance=None):
-        if instance == None:
-            port_name = virtual_name
-        else:
-            port_name = "private_" + str(self.private_port_counter) + "_" + virtual_name
-            self.inports[port_name] = instance
-            self.private_port_counter += 1
+"""  
+def addInputPort(virtual_name, private_port_id):
+        port_name = "private_" + str(private_port_id) + "_" + virtual_name
         return port_name
+"""
+
+def addInputPort(virtual_name, private_port_id, is_global = False):
+    if is_global:
+        port_name = virtual_name
+    else:
+        port_name = "private_" + str(private_port_id) + "_" + virtual_name
+    return port_name
+
+def addOutputPort(virtual_name, private_port_id):
+    port_name = "private_" + str(private_port_id) + "_" + virtual_name
+    return port_name

+ 4 - 4
tests/1.0) EventlessTransitionTest/PyDEVS/log.txt

@@ -8,7 +8,7 @@ __  Current Time:   0.000000 __________________________________________
 
 
 	INITIAL CONDITIONS in model <Controller.ObjectManager>
-		Initial State: <target.Dummy object at 0x1064727b0>
+		Initial State: <target.Dummy object at 0x1049b2810>
 		Next scheduled internal transition at time 0.000000
 
 
@@ -31,7 +31,7 @@ __  Current Time:   0.000000 __________________________________________
 
 
 	INTERNAL TRANSITION in model <Controller.ObjectManager>
-		New State: <target.Dummy object at 0x1064727b0>
+		New State: <target.Dummy object at 0x1049b2810>
 		Output Port Configuration:
 			port <port1>:
 				[(('MainApp', 0), ('MainApp', 0), (event name: start_instance; port: None; parameters: ['MainApp[0]']))]
@@ -45,7 +45,7 @@ __  Current Time:   0.000000 __________________________________________
 		Input Port Configuration:
 			port <input>:
 				(('MainApp', 0), ('MainApp', 0), (event name: instance_started; port: None; parameters: ['MainApp[0]']))
-		New State: <target.Dummy object at 0x1064727b0>
+		New State: <target.Dummy object at 0x1049b2810>
 		Next scheduled internal transition at time 0.000000
 
 
@@ -90,7 +90,7 @@ __  Current Time:   0.000000 __________________________________________
 
 
 	INTERNAL TRANSITION in model <Controller.ObjectManager>
-		New State: <target.Dummy object at 0x1064727b0>
+		New State: <target.Dummy object at 0x1049b2810>
 		Output Port Configuration:
 			port <port1>:
 				[(('MainApp', 0), ('MainApp', 0), (event name: instance_started; port: None; parameters: ['MainApp[0]']))]

+ 7 - 5
tests/1.0) EventlessTransitionTest/PyDEVS/target.py

@@ -12,7 +12,7 @@ from sccd.runtime.DEVS_statecharts_core import *
 # package "EventlessTransitionTest"
 
 class MainAppInstance(RuntimeClassBase):
-    def __init__(self, atomdevs, id):
+    def __init__(self, atomdevs, id, start_port_id):
         RuntimeClassBase.__init__(self, atomdevs, id)
         self.associations = {}
         
@@ -27,8 +27,9 @@ class MainAppInstance(RuntimeClassBase):
         
         # call user defined constructor
         MainAppInstance.user_defined_constructor(self)
-        port_name = Ports.addInputPort("<narrow_cast>", self)
+        port_name = addInputPort("<narrow_cast>", start_port_id)
         atomdevs.addInPort(port_name)
+        atomdevs.state.port_mappings[port_name] = id
     
     def user_defined_constructor(self):
         pass
@@ -73,12 +74,12 @@ class MainApp(ClassBase):
     def __init__(self, name):
         ClassBase.__init__(self, name)
         self.input = self.addInPort("input")
-        new_instance = self.constructObject(0, [])
+        new_instance = self.constructObject(0, 0, [])
         self.state.instances[new_instance.instance_id] = new_instance
         self.state.next_instance = self.state.next_instance + 1
     
-    def constructObject(self, id, parameters):
-        new_instance = MainAppInstance(self, id)
+    def constructObject(self, id, start_port_id, parameters):
+        new_instance = MainAppInstance(self, id, start_port_id)
         return new_instance
 
 class Dummy(ObjectManagerState):
@@ -89,6 +90,7 @@ class Dummy(ObjectManagerState):
         instance = {}
         instance["name"] = class_name
         if class_name == "MainApp":
+            self.narrow_cast_id = self.narrow_cast_id + 0
             instance["associations"] = {}
         else:
             raise Exception("Cannot instantiate class " + class_name)

+ 6 - 6
tests/1.1) AfterTransitionTest/PyDEVS/log.txt

@@ -8,7 +8,7 @@ __  Current Time:   0.000000 __________________________________________
 
 
 	INITIAL CONDITIONS in model <Controller.ObjectManager>
-		Initial State: <target.Dummy object at 0x104bfafc0>
+		Initial State: <target.Dummy object at 0x104a7cef0>
 		Next scheduled internal transition at time 0.000000
 
 
@@ -25,13 +25,13 @@ __  Current Time:   0.000000 __________________________________________
 			port <obj_manager_in>:
 				[(('MainApp', 0), ('MainApp', 0), (event name: start_instance; port: None; parameters: ['MainApp[0]']))]
 			port <input>:
-			port <private_1_<narrow_cast>>:
+			port <private_0_<narrow_cast>>:
 		New State: 
 		Next scheduled internal transition at time 0.000000
 
 
 	INTERNAL TRANSITION in model <Controller.ObjectManager>
-		New State: <target.Dummy object at 0x104bfafc0>
+		New State: <target.Dummy object at 0x104a7cef0>
 		Output Port Configuration:
 			port <port1>:
 				[(('MainApp', 0), ('MainApp', 0), (event name: start_instance; port: None; parameters: ['MainApp[0]']))]
@@ -45,7 +45,7 @@ __  Current Time:   0.000000 __________________________________________
 		Input Port Configuration:
 			port <input>:
 				(('MainApp', 0), ('MainApp', 0), (event name: instance_started; port: None; parameters: ['MainApp[0]']))
-		New State: <target.Dummy object at 0x104bfafc0>
+		New State: <target.Dummy object at 0x104a7cef0>
 		Next scheduled internal transition at time 0.000000
 
 
@@ -75,13 +75,13 @@ __  Current Time:   0.000000 __________________________________________
 			port <obj_manager_in>:
 				[(('MainApp', 0), ('MainApp', 0), (event name: instance_started; port: None; parameters: ['MainApp[0]']))]
 			port <input>:
-			port <private_1_<narrow_cast>>:
+			port <private_0_<narrow_cast>>:
 		New State: 
 		Next scheduled internal transition at time 0.000000
 
 
 	INTERNAL TRANSITION in model <Controller.ObjectManager>
-		New State: <target.Dummy object at 0x104bfafc0>
+		New State: <target.Dummy object at 0x104a7cef0>
 		Output Port Configuration:
 			port <port1>:
 				[(('MainApp', 0), ('MainApp', 0), (event name: instance_started; port: None; parameters: ['MainApp[0]']))]

+ 7 - 5
tests/1.1) AfterTransitionTest/PyDEVS/target.py

@@ -12,7 +12,7 @@ from sccd.runtime.DEVS_statecharts_core import *
 # package "AfterTransitionTest"
 
 class MainAppInstance(RuntimeClassBase):
-    def __init__(self, atomdevs, id):
+    def __init__(self, atomdevs, id, start_port_id):
         RuntimeClassBase.__init__(self, atomdevs, id)
         self.associations = {}
         
@@ -27,8 +27,9 @@ class MainAppInstance(RuntimeClassBase):
         
         # call user defined constructor
         MainAppInstance.user_defined_constructor(self)
-        port_name = Ports.addInputPort("<narrow_cast>", self)
+        port_name = addInputPort("<narrow_cast>", start_port_id)
         atomdevs.addInPort(port_name)
+        atomdevs.state.port_mappings[port_name] = id
     
     def user_defined_constructor(self):
         pass
@@ -81,12 +82,12 @@ class MainApp(ClassBase):
     def __init__(self, name):
         ClassBase.__init__(self, name)
         self.input = self.addInPort("input")
-        new_instance = self.constructObject(0, [])
+        new_instance = self.constructObject(0, 0, [])
         self.state.instances[new_instance.instance_id] = new_instance
         self.state.next_instance = self.state.next_instance + 1
     
-    def constructObject(self, id, parameters):
-        new_instance = MainAppInstance(self, id)
+    def constructObject(self, id, start_port_id, parameters):
+        new_instance = MainAppInstance(self, id, start_port_id)
         return new_instance
 
 class Dummy(ObjectManagerState):
@@ -97,6 +98,7 @@ class Dummy(ObjectManagerState):
         instance = {}
         instance["name"] = class_name
         if class_name == "MainApp":
+            self.narrow_cast_id = self.narrow_cast_id + 0
             instance["associations"] = {}
         else:
             raise Exception("Cannot instantiate class " + class_name)

+ 6 - 6
tests/1.10) DeepHistoryTest/PyDEVS/log.txt

@@ -8,7 +8,7 @@ __  Current Time:   0.000000 __________________________________________
 
 
 	INITIAL CONDITIONS in model <Controller.ObjectManager>
-		Initial State: <target.Dummy object at 0x106375370>
+		Initial State: <target.Dummy object at 0x1049eb830>
 		Next scheduled internal transition at time 0.000000
 
 
@@ -25,13 +25,13 @@ __  Current Time:   0.000000 __________________________________________
 			port <obj_manager_in>:
 				[(('MainApp', 0), ('MainApp', 0), (event name: start_instance; port: None; parameters: ['MainApp[0]']))]
 			port <input>:
-			port <private_10_<narrow_cast>>:
+			port <private_0_<narrow_cast>>:
 		New State: 
 		Next scheduled internal transition at time 0.000000
 
 
 	INTERNAL TRANSITION in model <Controller.ObjectManager>
-		New State: <target.Dummy object at 0x106375370>
+		New State: <target.Dummy object at 0x1049eb830>
 		Output Port Configuration:
 			port <port1>:
 				[(('MainApp', 0), ('MainApp', 0), (event name: start_instance; port: None; parameters: ['MainApp[0]']))]
@@ -45,7 +45,7 @@ __  Current Time:   0.000000 __________________________________________
 		Input Port Configuration:
 			port <input>:
 				(('MainApp', 0), ('MainApp', 0), (event name: instance_started; port: None; parameters: ['MainApp[0]']))
-		New State: <target.Dummy object at 0x106375370>
+		New State: <target.Dummy object at 0x1049eb830>
 		Next scheduled internal transition at time 0.000000
 
 
@@ -75,13 +75,13 @@ __  Current Time:   0.000000 __________________________________________
 			port <obj_manager_in>:
 				[(('MainApp', 0), ('MainApp', 0), (event name: instance_started; port: None; parameters: ['MainApp[0]']))]
 			port <input>:
-			port <private_10_<narrow_cast>>:
+			port <private_0_<narrow_cast>>:
 		New State: 
 		Next scheduled internal transition at time 0.000000
 
 
 	INTERNAL TRANSITION in model <Controller.ObjectManager>
-		New State: <target.Dummy object at 0x106375370>
+		New State: <target.Dummy object at 0x1049eb830>
 		Output Port Configuration:
 			port <port1>:
 				[(('MainApp', 0), ('MainApp', 0), (event name: instance_started; port: None; parameters: ['MainApp[0]']))]

+ 7 - 5
tests/1.10) DeepHistoryTest/PyDEVS/target.py

@@ -12,7 +12,7 @@ from sccd.runtime.DEVS_statecharts_core import *
 # package "AfterTransitionTest"
 
 class MainAppInstance(RuntimeClassBase):
-    def __init__(self, atomdevs, id):
+    def __init__(self, atomdevs, id, start_port_id):
         RuntimeClassBase.__init__(self, atomdevs, id)
         self.associations = {}
         
@@ -27,8 +27,9 @@ class MainAppInstance(RuntimeClassBase):
         
         # call user defined constructor
         MainAppInstance.user_defined_constructor(self)
-        port_name = Ports.addInputPort("<narrow_cast>", self)
+        port_name = addInputPort("<narrow_cast>", start_port_id)
         atomdevs.addInPort(port_name)
+        atomdevs.state.port_mappings[port_name] = id
     
     def user_defined_constructor(self):
         pass
@@ -60,12 +61,12 @@ class MainApp(ClassBase):
     def __init__(self, name):
         ClassBase.__init__(self, name)
         self.input = self.addInPort("input")
-        new_instance = self.constructObject(0, [])
+        new_instance = self.constructObject(0, 0, [])
         self.state.instances[new_instance.instance_id] = new_instance
         self.state.next_instance = self.state.next_instance + 1
     
-    def constructObject(self, id, parameters):
-        new_instance = MainAppInstance(self, id)
+    def constructObject(self, id, start_port_id, parameters):
+        new_instance = MainAppInstance(self, id, start_port_id)
         return new_instance
 
 class Dummy(ObjectManagerState):
@@ -76,6 +77,7 @@ class Dummy(ObjectManagerState):
         instance = {}
         instance["name"] = class_name
         if class_name == "MainApp":
+            self.narrow_cast_id = self.narrow_cast_id + 0
             instance["associations"] = {}
         else:
             raise Exception("Cannot instantiate class " + class_name)

+ 6 - 6
tests/1.11) AllStatechartTest/PyDEVS/log.txt

@@ -8,7 +8,7 @@ __  Current Time:   0.000000 __________________________________________
 
 
 	INITIAL CONDITIONS in model <Controller.ObjectManager>
-		Initial State: <target.Dummy object at 0x106472900>
+		Initial State: <target.Dummy object at 0x1049e9a60>
 		Next scheduled internal transition at time 0.000000
 
 
@@ -25,13 +25,13 @@ __  Current Time:   0.000000 __________________________________________
 			port <obj_manager_in>:
 				[(('MainApp', 0), ('MainApp', 0), (event name: start_instance; port: None; parameters: ['MainApp[0]']))]
 			port <input>:
-			port <private_11_<narrow_cast>>:
+			port <private_0_<narrow_cast>>:
 		New State: 
 		Next scheduled internal transition at time 0.000000
 
 
 	INTERNAL TRANSITION in model <Controller.ObjectManager>
-		New State: <target.Dummy object at 0x106472900>
+		New State: <target.Dummy object at 0x1049e9a60>
 		Output Port Configuration:
 			port <port1>:
 				[(('MainApp', 0), ('MainApp', 0), (event name: start_instance; port: None; parameters: ['MainApp[0]']))]
@@ -45,7 +45,7 @@ __  Current Time:   0.000000 __________________________________________
 		Input Port Configuration:
 			port <input>:
 				(('MainApp', 0), ('MainApp', 0), (event name: instance_started; port: None; parameters: ['MainApp[0]']))
-		New State: <target.Dummy object at 0x106472900>
+		New State: <target.Dummy object at 0x1049e9a60>
 		Next scheduled internal transition at time 0.000000
 
 
@@ -75,13 +75,13 @@ __  Current Time:   0.000000 __________________________________________
 			port <obj_manager_in>:
 				[(('MainApp', 0), ('MainApp', 0), (event name: instance_started; port: None; parameters: ['MainApp[0]']))]
 			port <input>:
-			port <private_11_<narrow_cast>>:
+			port <private_0_<narrow_cast>>:
 		New State: 
 		Next scheduled internal transition at time 0.000000
 
 
 	INTERNAL TRANSITION in model <Controller.ObjectManager>
-		New State: <target.Dummy object at 0x106472900>
+		New State: <target.Dummy object at 0x1049e9a60>
 		Output Port Configuration:
 			port <port1>:
 				[(('MainApp', 0), ('MainApp', 0), (event name: instance_started; port: None; parameters: ['MainApp[0]']))]

+ 7 - 5
tests/1.11) AllStatechartTest/PyDEVS/target.py

@@ -12,7 +12,7 @@ from sccd.runtime.DEVS_statecharts_core import *
 # package "AfterTransitionTest"
 
 class MainAppInstance(RuntimeClassBase):
-    def __init__(self, atomdevs, id):
+    def __init__(self, atomdevs, id, start_port_id):
         RuntimeClassBase.__init__(self, atomdevs, id)
         self.associations = {}
         
@@ -27,8 +27,9 @@ class MainAppInstance(RuntimeClassBase):
         
         # call user defined constructor
         MainAppInstance.user_defined_constructor(self)
-        port_name = Ports.addInputPort("<narrow_cast>", self)
+        port_name = addInputPort("<narrow_cast>", start_port_id)
         atomdevs.addInPort(port_name)
+        atomdevs.state.port_mappings[port_name] = id
     
     def user_defined_constructor(self):
         pass
@@ -60,12 +61,12 @@ class MainApp(ClassBase):
     def __init__(self, name):
         ClassBase.__init__(self, name)
         self.input = self.addInPort("input")
-        new_instance = self.constructObject(0, [])
+        new_instance = self.constructObject(0, 0, [])
         self.state.instances[new_instance.instance_id] = new_instance
         self.state.next_instance = self.state.next_instance + 1
     
-    def constructObject(self, id, parameters):
-        new_instance = MainAppInstance(self, id)
+    def constructObject(self, id, start_port_id, parameters):
+        new_instance = MainAppInstance(self, id, start_port_id)
         return new_instance
 
 class Dummy(ObjectManagerState):
@@ -76,6 +77,7 @@ class Dummy(ObjectManagerState):
         instance = {}
         instance["name"] = class_name
         if class_name == "MainApp":
+            self.narrow_cast_id = self.narrow_cast_id + 0
             instance["associations"] = {}
         else:
             raise Exception("Cannot instantiate class " + class_name)

+ 6 - 6
tests/1.2) GuardConditionTest/PyDEVS/log.txt

@@ -8,7 +8,7 @@ __  Current Time:   0.000000 __________________________________________
 
 
 	INITIAL CONDITIONS in model <Controller.ObjectManager>
-		Initial State: <target.Dummy object at 0x1064de450>
+		Initial State: <target.Dummy object at 0x104a7d880>
 		Next scheduled internal transition at time 0.000000
 
 
@@ -25,13 +25,13 @@ __  Current Time:   0.000000 __________________________________________
 			port <obj_manager_in>:
 				[(('MainApp', 0), ('MainApp', 0), (event name: start_instance; port: None; parameters: ['MainApp[0]']))]
 			port <input>:
-			port <private_2_<narrow_cast>>:
+			port <private_0_<narrow_cast>>:
 		New State: 
 		Next scheduled internal transition at time 0.000000
 
 
 	INTERNAL TRANSITION in model <Controller.ObjectManager>
-		New State: <target.Dummy object at 0x1064de450>
+		New State: <target.Dummy object at 0x104a7d880>
 		Output Port Configuration:
 			port <port1>:
 				[(('MainApp', 0), ('MainApp', 0), (event name: start_instance; port: None; parameters: ['MainApp[0]']))]
@@ -45,7 +45,7 @@ __  Current Time:   0.000000 __________________________________________
 		Input Port Configuration:
 			port <input>:
 				(('MainApp', 0), ('MainApp', 0), (event name: instance_started; port: None; parameters: ['MainApp[0]']))
-		New State: <target.Dummy object at 0x1064de450>
+		New State: <target.Dummy object at 0x104a7d880>
 		Next scheduled internal transition at time 0.000000
 
 
@@ -84,13 +84,13 @@ __  Current Time:   0.000000 __________________________________________
 			port <obj_manager_in>:
 				[(('MainApp', 0), ('MainApp', 0), (event name: instance_started; port: None; parameters: ['MainApp[0]']))]
 			port <input>:
-			port <private_2_<narrow_cast>>:
+			port <private_0_<narrow_cast>>:
 		New State: 
 		Next scheduled internal transition at time 0.000000
 
 
 	INTERNAL TRANSITION in model <Controller.ObjectManager>
-		New State: <target.Dummy object at 0x1064de450>
+		New State: <target.Dummy object at 0x104a7d880>
 		Output Port Configuration:
 			port <port1>:
 				[(('MainApp', 0), ('MainApp', 0), (event name: instance_started; port: None; parameters: ['MainApp[0]']))]

+ 7 - 5
tests/1.2) GuardConditionTest/PyDEVS/target.py

@@ -13,7 +13,7 @@ VALUE = 5
 # package "GuardConditionTest"
 
 class MainAppInstance(RuntimeClassBase):
-    def __init__(self, atomdevs, id):
+    def __init__(self, atomdevs, id, start_port_id):
         RuntimeClassBase.__init__(self, atomdevs, id)
         self.associations = {}
         
@@ -28,8 +28,9 @@ class MainAppInstance(RuntimeClassBase):
         
         # call user defined constructor
         MainAppInstance.user_defined_constructor(self)
-        port_name = Ports.addInputPort("<narrow_cast>", self)
+        port_name = addInputPort("<narrow_cast>", start_port_id)
         atomdevs.addInPort(port_name)
+        atomdevs.state.port_mappings[port_name] = id
     
     def user_defined_constructor(self):
         pass
@@ -85,12 +86,12 @@ class MainApp(ClassBase):
     def __init__(self, name):
         ClassBase.__init__(self, name)
         self.input = self.addInPort("input")
-        new_instance = self.constructObject(0, [])
+        new_instance = self.constructObject(0, 0, [])
         self.state.instances[new_instance.instance_id] = new_instance
         self.state.next_instance = self.state.next_instance + 1
     
-    def constructObject(self, id, parameters):
-        new_instance = MainAppInstance(self, id)
+    def constructObject(self, id, start_port_id, parameters):
+        new_instance = MainAppInstance(self, id, start_port_id)
         return new_instance
 
 class Dummy(ObjectManagerState):
@@ -101,6 +102,7 @@ class Dummy(ObjectManagerState):
         instance = {}
         instance["name"] = class_name
         if class_name == "MainApp":
+            self.narrow_cast_id = self.narrow_cast_id + 0
             instance["associations"] = {}
         else:
             raise Exception("Cannot instantiate class " + class_name)

+ 6 - 6
tests/1.3) TransitionToItselfTest/PyDEVS/log.txt

@@ -8,7 +8,7 @@ __  Current Time:   0.000000 __________________________________________
 
 
 	INITIAL CONDITIONS in model <Controller.ObjectManager>
-		Initial State: <target.Dummy object at 0x1063db2f0>
+		Initial State: <target.Dummy object at 0x1047f5910>
 		Next scheduled internal transition at time 0.000000
 
 
@@ -25,13 +25,13 @@ __  Current Time:   0.000000 __________________________________________
 			port <obj_manager_in>:
 				[(('MainApp', 0), ('MainApp', 0), (event name: start_instance; port: None; parameters: ['MainApp[0]']))]
 			port <input>:
-			port <private_3_<narrow_cast>>:
+			port <private_0_<narrow_cast>>:
 		New State: 
 		Next scheduled internal transition at time 0.000000
 
 
 	INTERNAL TRANSITION in model <Controller.ObjectManager>
-		New State: <target.Dummy object at 0x1063db2f0>
+		New State: <target.Dummy object at 0x1047f5910>
 		Output Port Configuration:
 			port <port1>:
 				[(('MainApp', 0), ('MainApp', 0), (event name: start_instance; port: None; parameters: ['MainApp[0]']))]
@@ -45,7 +45,7 @@ __  Current Time:   0.000000 __________________________________________
 		Input Port Configuration:
 			port <input>:
 				(('MainApp', 0), ('MainApp', 0), (event name: instance_started; port: None; parameters: ['MainApp[0]']))
-		New State: <target.Dummy object at 0x1063db2f0>
+		New State: <target.Dummy object at 0x1047f5910>
 		Next scheduled internal transition at time 0.000000
 
 
@@ -93,13 +93,13 @@ __  Current Time:   0.000000 __________________________________________
 			port <obj_manager_in>:
 				[(('MainApp', 0), ('MainApp', 0), (event name: instance_started; port: None; parameters: ['MainApp[0]']))]
 			port <input>:
-			port <private_3_<narrow_cast>>:
+			port <private_0_<narrow_cast>>:
 		New State: 
 		Next scheduled internal transition at time 0.000000
 
 
 	INTERNAL TRANSITION in model <Controller.ObjectManager>
-		New State: <target.Dummy object at 0x1063db2f0>
+		New State: <target.Dummy object at 0x1047f5910>
 		Output Port Configuration:
 			port <port1>:
 				[(('MainApp', 0), ('MainApp', 0), (event name: instance_started; port: None; parameters: ['MainApp[0]']))]

+ 7 - 5
tests/1.3) TransitionToItselfTest/PyDEVS/target.py

@@ -12,7 +12,7 @@ from sccd.runtime.DEVS_statecharts_core import *
 # package "AfterTransitionTest"
 
 class MainAppInstance(RuntimeClassBase):
-    def __init__(self, atomdevs, id):
+    def __init__(self, atomdevs, id, start_port_id):
         RuntimeClassBase.__init__(self, atomdevs, id)
         self.associations = {}
         
@@ -27,8 +27,9 @@ class MainAppInstance(RuntimeClassBase):
         
         # call user defined constructor
         MainAppInstance.user_defined_constructor(self)
-        port_name = Ports.addInputPort("<narrow_cast>", self)
+        port_name = addInputPort("<narrow_cast>", start_port_id)
         atomdevs.addInPort(port_name)
+        atomdevs.state.port_mappings[port_name] = id
     
     def user_defined_constructor(self):
         self.value = 0
@@ -84,12 +85,12 @@ class MainApp(ClassBase):
     def __init__(self, name):
         ClassBase.__init__(self, name)
         self.input = self.addInPort("input")
-        new_instance = self.constructObject(0, [])
+        new_instance = self.constructObject(0, 0, [])
         self.state.instances[new_instance.instance_id] = new_instance
         self.state.next_instance = self.state.next_instance + 1
     
-    def constructObject(self, id, parameters):
-        new_instance = MainAppInstance(self, id)
+    def constructObject(self, id, start_port_id, parameters):
+        new_instance = MainAppInstance(self, id, start_port_id)
         return new_instance
 
 class Dummy(ObjectManagerState):
@@ -100,6 +101,7 @@ class Dummy(ObjectManagerState):
         instance = {}
         instance["name"] = class_name
         if class_name == "MainApp":
+            self.narrow_cast_id = self.narrow_cast_id + 0
             instance["associations"] = {}
         else:
             raise Exception("Cannot instantiate class " + class_name)

+ 6 - 6
tests/1.4) ScriptTransitionTest/PyDEVS/log.txt

@@ -8,7 +8,7 @@ __  Current Time:   0.000000 __________________________________________
 
 
 	INITIAL CONDITIONS in model <Controller.ObjectManager>
-		Initial State: <target.Dummy object at 0x1063dbb30>
+		Initial State: <target.Dummy object at 0x104a7ccb0>
 		Next scheduled internal transition at time 0.000000
 
 
@@ -25,13 +25,13 @@ __  Current Time:   0.000000 __________________________________________
 			port <obj_manager_in>:
 				[(('MainApp', 0), ('MainApp', 0), (event name: start_instance; port: None; parameters: ['MainApp[0]']))]
 			port <input>:
-			port <private_4_<narrow_cast>>:
+			port <private_0_<narrow_cast>>:
 		New State: 
 		Next scheduled internal transition at time 0.000000
 
 
 	INTERNAL TRANSITION in model <Controller.ObjectManager>
-		New State: <target.Dummy object at 0x1063dbb30>
+		New State: <target.Dummy object at 0x104a7ccb0>
 		Output Port Configuration:
 			port <port1>:
 				[(('MainApp', 0), ('MainApp', 0), (event name: start_instance; port: None; parameters: ['MainApp[0]']))]
@@ -45,7 +45,7 @@ __  Current Time:   0.000000 __________________________________________
 		Input Port Configuration:
 			port <input>:
 				(('MainApp', 0), ('MainApp', 0), (event name: instance_started; port: None; parameters: ['MainApp[0]']))
-		New State: <target.Dummy object at 0x1063dbb30>
+		New State: <target.Dummy object at 0x104a7ccb0>
 		Next scheduled internal transition at time 0.000000
 
 
@@ -75,13 +75,13 @@ __  Current Time:   0.000000 __________________________________________
 			port <obj_manager_in>:
 				[(('MainApp', 0), ('MainApp', 0), (event name: instance_started; port: None; parameters: ['MainApp[0]']))]
 			port <input>:
-			port <private_4_<narrow_cast>>:
+			port <private_0_<narrow_cast>>:
 		New State: 
 		Next scheduled internal transition at time 0.000000
 
 
 	INTERNAL TRANSITION in model <Controller.ObjectManager>
-		New State: <target.Dummy object at 0x1063dbb30>
+		New State: <target.Dummy object at 0x104a7ccb0>
 		Output Port Configuration:
 			port <port1>:
 				[(('MainApp', 0), ('MainApp', 0), (event name: instance_started; port: None; parameters: ['MainApp[0]']))]

+ 7 - 5
tests/1.4) ScriptTransitionTest/PyDEVS/target.py

@@ -12,7 +12,7 @@ from sccd.runtime.DEVS_statecharts_core import *
 # package "AfterTransitionTest"
 
 class MainAppInstance(RuntimeClassBase):
-    def __init__(self, atomdevs, id):
+    def __init__(self, atomdevs, id, start_port_id):
         RuntimeClassBase.__init__(self, atomdevs, id)
         self.associations = {}
         
@@ -27,8 +27,9 @@ class MainAppInstance(RuntimeClassBase):
         
         # call user defined constructor
         MainAppInstance.user_defined_constructor(self)
-        port_name = Ports.addInputPort("<narrow_cast>", self)
+        port_name = addInputPort("<narrow_cast>", start_port_id)
         atomdevs.addInPort(port_name)
+        atomdevs.state.port_mappings[port_name] = id
     
     def user_defined_constructor(self):
         self.value = 0
@@ -88,12 +89,12 @@ class MainApp(ClassBase):
     def __init__(self, name):
         ClassBase.__init__(self, name)
         self.input = self.addInPort("input")
-        new_instance = self.constructObject(0, [])
+        new_instance = self.constructObject(0, 0, [])
         self.state.instances[new_instance.instance_id] = new_instance
         self.state.next_instance = self.state.next_instance + 1
     
-    def constructObject(self, id, parameters):
-        new_instance = MainAppInstance(self, id)
+    def constructObject(self, id, start_port_id, parameters):
+        new_instance = MainAppInstance(self, id, start_port_id)
         return new_instance
 
 class Dummy(ObjectManagerState):
@@ -104,6 +105,7 @@ class Dummy(ObjectManagerState):
         instance = {}
         instance["name"] = class_name
         if class_name == "MainApp":
+            self.narrow_cast_id = self.narrow_cast_id + 0
             instance["associations"] = {}
         else:
             raise Exception("Cannot instantiate class " + class_name)

+ 6 - 6
tests/1.5) ScriptEntryTest/PyDEVS/log.txt

@@ -8,7 +8,7 @@ __  Current Time:   0.000000 __________________________________________
 
 
 	INITIAL CONDITIONS in model <Controller.ObjectManager>
-		Initial State: <target.Dummy object at 0x106324a40>
+		Initial State: <target.Dummy object at 0x104a7e450>
 		Next scheduled internal transition at time 0.000000
 
 
@@ -25,13 +25,13 @@ __  Current Time:   0.000000 __________________________________________
 			port <obj_manager_in>:
 				[(('MainApp', 0), ('MainApp', 0), (event name: start_instance; port: None; parameters: ['MainApp[0]']))]
 			port <input>:
-			port <private_5_<narrow_cast>>:
+			port <private_0_<narrow_cast>>:
 		New State: 
 		Next scheduled internal transition at time 0.000000
 
 
 	INTERNAL TRANSITION in model <Controller.ObjectManager>
-		New State: <target.Dummy object at 0x106324a40>
+		New State: <target.Dummy object at 0x104a7e450>
 		Output Port Configuration:
 			port <port1>:
 				[(('MainApp', 0), ('MainApp', 0), (event name: start_instance; port: None; parameters: ['MainApp[0]']))]
@@ -45,7 +45,7 @@ __  Current Time:   0.000000 __________________________________________
 		Input Port Configuration:
 			port <input>:
 				(('MainApp', 0), ('MainApp', 0), (event name: instance_started; port: None; parameters: ['MainApp[0]']))
-		New State: <target.Dummy object at 0x106324a40>
+		New State: <target.Dummy object at 0x104a7e450>
 		Next scheduled internal transition at time 0.000000
 
 
@@ -93,13 +93,13 @@ __  Current Time:   0.000000 __________________________________________
 			port <obj_manager_in>:
 				[(('MainApp', 0), ('MainApp', 0), (event name: instance_started; port: None; parameters: ['MainApp[0]']))]
 			port <input>:
-			port <private_5_<narrow_cast>>:
+			port <private_0_<narrow_cast>>:
 		New State: 
 		Next scheduled internal transition at time 0.000000
 
 
 	INTERNAL TRANSITION in model <Controller.ObjectManager>
-		New State: <target.Dummy object at 0x106324a40>
+		New State: <target.Dummy object at 0x104a7e450>
 		Output Port Configuration:
 			port <port1>:
 				[(('MainApp', 0), ('MainApp', 0), (event name: instance_started; port: None; parameters: ['MainApp[0]']))]

+ 7 - 5
tests/1.5) ScriptEntryTest/PyDEVS/target.py

@@ -12,7 +12,7 @@ from sccd.runtime.DEVS_statecharts_core import *
 # package "AfterTransitionTest"
 
 class MainAppInstance(RuntimeClassBase):
-    def __init__(self, atomdevs, id):
+    def __init__(self, atomdevs, id, start_port_id):
         RuntimeClassBase.__init__(self, atomdevs, id)
         self.associations = {}
         
@@ -27,8 +27,9 @@ class MainAppInstance(RuntimeClassBase):
         
         # call user defined constructor
         MainAppInstance.user_defined_constructor(self)
-        port_name = Ports.addInputPort("<narrow_cast>", self)
+        port_name = addInputPort("<narrow_cast>", start_port_id)
         atomdevs.addInPort(port_name)
+        atomdevs.state.port_mappings[port_name] = id
     
     def user_defined_constructor(self):
         self.value = 0
@@ -84,12 +85,12 @@ class MainApp(ClassBase):
     def __init__(self, name):
         ClassBase.__init__(self, name)
         self.input = self.addInPort("input")
-        new_instance = self.constructObject(0, [])
+        new_instance = self.constructObject(0, 0, [])
         self.state.instances[new_instance.instance_id] = new_instance
         self.state.next_instance = self.state.next_instance + 1
     
-    def constructObject(self, id, parameters):
-        new_instance = MainAppInstance(self, id)
+    def constructObject(self, id, start_port_id, parameters):
+        new_instance = MainAppInstance(self, id, start_port_id)
         return new_instance
 
 class Dummy(ObjectManagerState):
@@ -100,6 +101,7 @@ class Dummy(ObjectManagerState):
         instance = {}
         instance["name"] = class_name
         if class_name == "MainApp":
+            self.narrow_cast_id = self.narrow_cast_id + 0
             instance["associations"] = {}
         else:
             raise Exception("Cannot instantiate class " + class_name)

+ 6 - 6
tests/1.6) ScriptExitTest/PyDEVS/log.txt

@@ -8,7 +8,7 @@ __  Current Time:   0.000000 __________________________________________
 
 
 	INITIAL CONDITIONS in model <Controller.ObjectManager>
-		Initial State: <target.Dummy object at 0x10571a4b0>
+		Initial State: <target.Dummy object at 0x104a7cb90>
 		Next scheduled internal transition at time 0.000000
 
 
@@ -25,13 +25,13 @@ __  Current Time:   0.000000 __________________________________________
 			port <obj_manager_in>:
 				[(('MainApp', 0), ('MainApp', 0), (event name: start_instance; port: None; parameters: ['MainApp[0]']))]
 			port <input>:
-			port <private_6_<narrow_cast>>:
+			port <private_0_<narrow_cast>>:
 		New State: 
 		Next scheduled internal transition at time 0.000000
 
 
 	INTERNAL TRANSITION in model <Controller.ObjectManager>
-		New State: <target.Dummy object at 0x10571a4b0>
+		New State: <target.Dummy object at 0x104a7cb90>
 		Output Port Configuration:
 			port <port1>:
 				[(('MainApp', 0), ('MainApp', 0), (event name: start_instance; port: None; parameters: ['MainApp[0]']))]
@@ -45,7 +45,7 @@ __  Current Time:   0.000000 __________________________________________
 		Input Port Configuration:
 			port <input>:
 				(('MainApp', 0), ('MainApp', 0), (event name: instance_started; port: None; parameters: ['MainApp[0]']))
-		New State: <target.Dummy object at 0x10571a4b0>
+		New State: <target.Dummy object at 0x104a7cb90>
 		Next scheduled internal transition at time 0.000000
 
 
@@ -129,13 +129,13 @@ __  Current Time:   0.000000 __________________________________________
 			port <obj_manager_in>:
 				[(('MainApp', 0), ('MainApp', 0), (event name: instance_started; port: None; parameters: ['MainApp[0]']))]
 			port <input>:
-			port <private_6_<narrow_cast>>:
+			port <private_0_<narrow_cast>>:
 		New State: 
 		Next scheduled internal transition at time 0.000000
 
 
 	INTERNAL TRANSITION in model <Controller.ObjectManager>
-		New State: <target.Dummy object at 0x10571a4b0>
+		New State: <target.Dummy object at 0x104a7cb90>
 		Output Port Configuration:
 			port <port1>:
 				[(('MainApp', 0), ('MainApp', 0), (event name: instance_started; port: None; parameters: ['MainApp[0]']))]

+ 7 - 5
tests/1.6) ScriptExitTest/PyDEVS/target.py

@@ -12,7 +12,7 @@ from sccd.runtime.DEVS_statecharts_core import *
 # package "AfterTransitionTest"
 
 class MainAppInstance(RuntimeClassBase):
-    def __init__(self, atomdevs, id):
+    def __init__(self, atomdevs, id, start_port_id):
         RuntimeClassBase.__init__(self, atomdevs, id)
         self.associations = {}
         
@@ -27,8 +27,9 @@ class MainAppInstance(RuntimeClassBase):
         
         # call user defined constructor
         MainAppInstance.user_defined_constructor(self)
-        port_name = Ports.addInputPort("<narrow_cast>", self)
+        port_name = addInputPort("<narrow_cast>", start_port_id)
         atomdevs.addInPort(port_name)
+        atomdevs.state.port_mappings[port_name] = id
     
     def user_defined_constructor(self):
         self.value = 0
@@ -84,12 +85,12 @@ class MainApp(ClassBase):
     def __init__(self, name):
         ClassBase.__init__(self, name)
         self.input = self.addInPort("input")
-        new_instance = self.constructObject(0, [])
+        new_instance = self.constructObject(0, 0, [])
         self.state.instances[new_instance.instance_id] = new_instance
         self.state.next_instance = self.state.next_instance + 1
     
-    def constructObject(self, id, parameters):
-        new_instance = MainAppInstance(self, id)
+    def constructObject(self, id, start_port_id, parameters):
+        new_instance = MainAppInstance(self, id, start_port_id)
         return new_instance
 
 class Dummy(ObjectManagerState):
@@ -100,6 +101,7 @@ class Dummy(ObjectManagerState):
         instance = {}
         instance["name"] = class_name
         if class_name == "MainApp":
+            self.narrow_cast_id = self.narrow_cast_id + 0
             instance["associations"] = {}
         else:
             raise Exception("Cannot instantiate class " + class_name)

+ 6 - 6
tests/1.7) CompositeStateTest/PyDEVS/log.txt

@@ -8,7 +8,7 @@ __  Current Time:   0.000000 __________________________________________
 
 
 	INITIAL CONDITIONS in model <Controller.ObjectManager>
-		Initial State: <target.Dummy object at 0x106326c60>
+		Initial State: <target.Dummy object at 0x104a7f080>
 		Next scheduled internal transition at time 0.000000
 
 
@@ -25,13 +25,13 @@ __  Current Time:   0.000000 __________________________________________
 			port <obj_manager_in>:
 				[(('MainApp', 0), ('MainApp', 0), (event name: start_instance; port: None; parameters: ['MainApp[0]']))]
 			port <input>:
-			port <private_7_<narrow_cast>>:
+			port <private_0_<narrow_cast>>:
 		New State: 
 		Next scheduled internal transition at time 0.000000
 
 
 	INTERNAL TRANSITION in model <Controller.ObjectManager>
-		New State: <target.Dummy object at 0x106326c60>
+		New State: <target.Dummy object at 0x104a7f080>
 		Output Port Configuration:
 			port <port1>:
 				[(('MainApp', 0), ('MainApp', 0), (event name: start_instance; port: None; parameters: ['MainApp[0]']))]
@@ -45,7 +45,7 @@ __  Current Time:   0.000000 __________________________________________
 		Input Port Configuration:
 			port <input>:
 				(('MainApp', 0), ('MainApp', 0), (event name: instance_started; port: None; parameters: ['MainApp[0]']))
-		New State: <target.Dummy object at 0x106326c60>
+		New State: <target.Dummy object at 0x104a7f080>
 		Next scheduled internal transition at time 0.000000
 
 
@@ -96,13 +96,13 @@ __  Current Time:   0.000000 __________________________________________
 			port <obj_manager_in>:
 				[(('MainApp', 0), ('MainApp', 0), (event name: instance_started; port: None; parameters: ['MainApp[0]']))]
 			port <input>:
-			port <private_7_<narrow_cast>>:
+			port <private_0_<narrow_cast>>:
 		New State: 
 		Next scheduled internal transition at time 0.000000
 
 
 	INTERNAL TRANSITION in model <Controller.ObjectManager>
-		New State: <target.Dummy object at 0x106326c60>
+		New State: <target.Dummy object at 0x104a7f080>
 		Output Port Configuration:
 			port <port1>:
 				[(('MainApp', 0), ('MainApp', 0), (event name: instance_started; port: None; parameters: ['MainApp[0]']))]

+ 7 - 5
tests/1.7) CompositeStateTest/PyDEVS/target.py

@@ -12,7 +12,7 @@ from sccd.runtime.DEVS_statecharts_core import *
 # package "AfterTransitionTest"
 
 class MainAppInstance(RuntimeClassBase):
-    def __init__(self, atomdevs, id):
+    def __init__(self, atomdevs, id, start_port_id):
         RuntimeClassBase.__init__(self, atomdevs, id)
         self.associations = {}
         
@@ -27,8 +27,9 @@ class MainAppInstance(RuntimeClassBase):
         
         # call user defined constructor
         MainAppInstance.user_defined_constructor(self)
-        port_name = Ports.addInputPort("<narrow_cast>", self)
+        port_name = addInputPort("<narrow_cast>", start_port_id)
         atomdevs.addInPort(port_name)
+        atomdevs.state.port_mappings[port_name] = id
     
     def user_defined_constructor(self):
         pass
@@ -92,12 +93,12 @@ class MainApp(ClassBase):
     def __init__(self, name):
         ClassBase.__init__(self, name)
         self.input = self.addInPort("input")
-        new_instance = self.constructObject(0, [])
+        new_instance = self.constructObject(0, 0, [])
         self.state.instances[new_instance.instance_id] = new_instance
         self.state.next_instance = self.state.next_instance + 1
     
-    def constructObject(self, id, parameters):
-        new_instance = MainAppInstance(self, id)
+    def constructObject(self, id, start_port_id, parameters):
+        new_instance = MainAppInstance(self, id, start_port_id)
         return new_instance
 
 class Dummy(ObjectManagerState):
@@ -108,6 +109,7 @@ class Dummy(ObjectManagerState):
         instance = {}
         instance["name"] = class_name
         if class_name == "MainApp":
+            self.narrow_cast_id = self.narrow_cast_id + 0
             instance["associations"] = {}
         else:
             raise Exception("Cannot instantiate class " + class_name)

+ 6 - 6
tests/1.8) ParallelStateTest/PyDEVS/log.txt

@@ -8,7 +8,7 @@ __  Current Time:   0.000000 __________________________________________
 
 
 	INITIAL CONDITIONS in model <Controller.ObjectManager>
-		Initial State: <target.Dummy object at 0x1063764e0>
+		Initial State: <target.Dummy object at 0x1049e9940>
 		Next scheduled internal transition at time 0.000000
 
 
@@ -25,13 +25,13 @@ __  Current Time:   0.000000 __________________________________________
 			port <obj_manager_in>:
 				[(('MainApp', 0), ('MainApp', 0), (event name: start_instance; port: None; parameters: ['MainApp[0]']))]
 			port <input>:
-			port <private_8_<narrow_cast>>:
+			port <private_0_<narrow_cast>>:
 		New State: 
 		Next scheduled internal transition at time 0.000000
 
 
 	INTERNAL TRANSITION in model <Controller.ObjectManager>
-		New State: <target.Dummy object at 0x1063764e0>
+		New State: <target.Dummy object at 0x1049e9940>
 		Output Port Configuration:
 			port <port1>:
 				[(('MainApp', 0), ('MainApp', 0), (event name: start_instance; port: None; parameters: ['MainApp[0]']))]
@@ -45,7 +45,7 @@ __  Current Time:   0.000000 __________________________________________
 		Input Port Configuration:
 			port <input>:
 				(('MainApp', 0), ('MainApp', 0), (event name: instance_started; port: None; parameters: ['MainApp[0]']))
-		New State: <target.Dummy object at 0x1063764e0>
+		New State: <target.Dummy object at 0x1049e9940>
 		Next scheduled internal transition at time 0.000000
 
 
@@ -75,13 +75,13 @@ __  Current Time:   0.000000 __________________________________________
 			port <obj_manager_in>:
 				[(('MainApp', 0), ('MainApp', 0), (event name: instance_started; port: None; parameters: ['MainApp[0]']))]
 			port <input>:
-			port <private_8_<narrow_cast>>:
+			port <private_0_<narrow_cast>>:
 		New State: 
 		Next scheduled internal transition at time 0.000000
 
 
 	INTERNAL TRANSITION in model <Controller.ObjectManager>
-		New State: <target.Dummy object at 0x1063764e0>
+		New State: <target.Dummy object at 0x1049e9940>
 		Output Port Configuration:
 			port <port1>:
 				[(('MainApp', 0), ('MainApp', 0), (event name: instance_started; port: None; parameters: ['MainApp[0]']))]

+ 7 - 5
tests/1.8) ParallelStateTest/PyDEVS/target.py

@@ -12,7 +12,7 @@ from sccd.runtime.DEVS_statecharts_core import *
 # package "AfterTransitionTest"
 
 class MainAppInstance(RuntimeClassBase):
-    def __init__(self, atomdevs, id):
+    def __init__(self, atomdevs, id, start_port_id):
         RuntimeClassBase.__init__(self, atomdevs, id)
         self.associations = {}
         
@@ -27,8 +27,9 @@ class MainAppInstance(RuntimeClassBase):
         
         # call user defined constructor
         MainAppInstance.user_defined_constructor(self)
-        port_name = Ports.addInputPort("<narrow_cast>", self)
+        port_name = addInputPort("<narrow_cast>", start_port_id)
         atomdevs.addInPort(port_name)
+        atomdevs.state.port_mappings[port_name] = id
     
     def user_defined_constructor(self):
         pass
@@ -78,12 +79,12 @@ class MainApp(ClassBase):
     def __init__(self, name):
         ClassBase.__init__(self, name)
         self.input = self.addInPort("input")
-        new_instance = self.constructObject(0, [])
+        new_instance = self.constructObject(0, 0, [])
         self.state.instances[new_instance.instance_id] = new_instance
         self.state.next_instance = self.state.next_instance + 1
     
-    def constructObject(self, id, parameters):
-        new_instance = MainAppInstance(self, id)
+    def constructObject(self, id, start_port_id, parameters):
+        new_instance = MainAppInstance(self, id, start_port_id)
         return new_instance
 
 class Dummy(ObjectManagerState):
@@ -94,6 +95,7 @@ class Dummy(ObjectManagerState):
         instance = {}
         instance["name"] = class_name
         if class_name == "MainApp":
+            self.narrow_cast_id = self.narrow_cast_id + 0
             instance["associations"] = {}
         else:
             raise Exception("Cannot instantiate class " + class_name)

+ 6 - 6
tests/1.9) ShallowHistoryTest/PyDEVS/log.txt

@@ -8,7 +8,7 @@ __  Current Time:   0.000000 __________________________________________
 
 
 	INITIAL CONDITIONS in model <Controller.ObjectManager>
-		Initial State: <target.Dummy object at 0x10611aa50>
+		Initial State: <target.Dummy object at 0x1049eaf00>
 		Next scheduled internal transition at time 0.000000
 
 
@@ -25,13 +25,13 @@ __  Current Time:   0.000000 __________________________________________
 			port <obj_manager_in>:
 				[(('MainApp', 0), ('MainApp', 0), (event name: start_instance; port: None; parameters: ['MainApp[0]']))]
 			port <input>:
-			port <private_9_<narrow_cast>>:
+			port <private_0_<narrow_cast>>:
 		New State: 
 		Next scheduled internal transition at time 0.000000
 
 
 	INTERNAL TRANSITION in model <Controller.ObjectManager>
-		New State: <target.Dummy object at 0x10611aa50>
+		New State: <target.Dummy object at 0x1049eaf00>
 		Output Port Configuration:
 			port <port1>:
 				[(('MainApp', 0), ('MainApp', 0), (event name: start_instance; port: None; parameters: ['MainApp[0]']))]
@@ -45,7 +45,7 @@ __  Current Time:   0.000000 __________________________________________
 		Input Port Configuration:
 			port <input>:
 				(('MainApp', 0), ('MainApp', 0), (event name: instance_started; port: None; parameters: ['MainApp[0]']))
-		New State: <target.Dummy object at 0x10611aa50>
+		New State: <target.Dummy object at 0x1049eaf00>
 		Next scheduled internal transition at time 0.000000
 
 
@@ -75,13 +75,13 @@ __  Current Time:   0.000000 __________________________________________
 			port <obj_manager_in>:
 				[(('MainApp', 0), ('MainApp', 0), (event name: instance_started; port: None; parameters: ['MainApp[0]']))]
 			port <input>:
-			port <private_9_<narrow_cast>>:
+			port <private_0_<narrow_cast>>:
 		New State: 
 		Next scheduled internal transition at time 0.000000
 
 
 	INTERNAL TRANSITION in model <Controller.ObjectManager>
-		New State: <target.Dummy object at 0x10611aa50>
+		New State: <target.Dummy object at 0x1049eaf00>
 		Output Port Configuration:
 			port <port1>:
 				[(('MainApp', 0), ('MainApp', 0), (event name: instance_started; port: None; parameters: ['MainApp[0]']))]

+ 7 - 5
tests/1.9) ShallowHistoryTest/PyDEVS/target.py

@@ -12,7 +12,7 @@ from sccd.runtime.DEVS_statecharts_core import *
 # package "AfterTransitionTest"
 
 class MainAppInstance(RuntimeClassBase):
-    def __init__(self, atomdevs, id):
+    def __init__(self, atomdevs, id, start_port_id):
         RuntimeClassBase.__init__(self, atomdevs, id)
         self.associations = {}
         
@@ -27,8 +27,9 @@ class MainAppInstance(RuntimeClassBase):
         
         # call user defined constructor
         MainAppInstance.user_defined_constructor(self)
-        port_name = Ports.addInputPort("<narrow_cast>", self)
+        port_name = addInputPort("<narrow_cast>", start_port_id)
         atomdevs.addInPort(port_name)
+        atomdevs.state.port_mappings[port_name] = id
     
     def user_defined_constructor(self):
         pass
@@ -60,12 +61,12 @@ class MainApp(ClassBase):
     def __init__(self, name):
         ClassBase.__init__(self, name)
         self.input = self.addInPort("input")
-        new_instance = self.constructObject(0, [])
+        new_instance = self.constructObject(0, 0, [])
         self.state.instances[new_instance.instance_id] = new_instance
         self.state.next_instance = self.state.next_instance + 1
     
-    def constructObject(self, id, parameters):
-        new_instance = MainAppInstance(self, id)
+    def constructObject(self, id, start_port_id, parameters):
+        new_instance = MainAppInstance(self, id, start_port_id)
         return new_instance
 
 class Dummy(ObjectManagerState):
@@ -76,6 +77,7 @@ class Dummy(ObjectManagerState):
         instance = {}
         instance["name"] = class_name
         if class_name == "MainApp":
+            self.narrow_cast_id = self.narrow_cast_id + 0
             instance["associations"] = {}
         else:
             raise Exception("Cannot instantiate class " + class_name)

+ 10 - 7
tests/2.0) GlobalInputTest/PyDEVS/log.txt

@@ -8,7 +8,7 @@ __  Current Time:   0.000000 __________________________________________
 
 
 	INITIAL CONDITIONS in model <Controller.ObjectManager>
-		Initial State: <target.Dummy object at 0x1058aa000>
+		Initial State: <target.Dummy object at 0x1049e9940>
 		Next scheduled internal transition at time 0.000000
 
 
@@ -25,13 +25,14 @@ __  Current Time:   0.000000 __________________________________________
 			port <obj_manager_in>:
 				[(('MainApp', 0), ('MainApp', 0), (event name: start_instance; port: None; parameters: ['MainApp[0]']))]
 			port <input>:
-			port <private_12_<narrow_cast>>:
+			port <ui>:
+			port <private_0_<narrow_cast>>:
 		New State: 
 		Next scheduled internal transition at time 0.000000
 
 
 	INTERNAL TRANSITION in model <Controller.ObjectManager>
-		New State: <target.Dummy object at 0x1058aa000>
+		New State: <target.Dummy object at 0x1049e9940>
 		Output Port Configuration:
 			port <port1>:
 				[(('MainApp', 0), ('MainApp', 0), (event name: start_instance; port: None; parameters: ['MainApp[0]']))]
@@ -45,7 +46,7 @@ __  Current Time:   0.000000 __________________________________________
 		Input Port Configuration:
 			port <input>:
 				(('MainApp', 0), ('MainApp', 0), (event name: instance_started; port: None; parameters: ['MainApp[0]']))
-		New State: <target.Dummy object at 0x1058aa000>
+		New State: <target.Dummy object at 0x1049e9940>
 		Next scheduled internal transition at time 0.000000
 
 
@@ -75,13 +76,14 @@ __  Current Time:   0.000000 __________________________________________
 			port <obj_manager_in>:
 				[(('MainApp', 0), ('MainApp', 0), (event name: instance_started; port: None; parameters: ['MainApp[0]']))]
 			port <input>:
-			port <private_12_<narrow_cast>>:
+			port <ui>:
+			port <private_0_<narrow_cast>>:
 		New State: 
 		Next scheduled internal transition at time 0.000000
 
 
 	INTERNAL TRANSITION in model <Controller.ObjectManager>
-		New State: <target.Dummy object at 0x1058aa000>
+		New State: <target.Dummy object at 0x1049e9940>
 		Output Port Configuration:
 			port <port1>:
 				[(('MainApp', 0), ('MainApp', 0), (event name: instance_started; port: None; parameters: ['MainApp[0]']))]
@@ -126,7 +128,8 @@ __  Current Time:   0.000000 __________________________________________
 			port <obj_manager_in>:
 			port <input>:
 				['Event("input_event","ui",[\'0.00\'])']
-			port <private_12_<narrow_cast>>:
+			port <ui>:
+			port <private_0_<narrow_cast>>:
 		New State: 
 		Next scheduled internal transition at time 0.000000
 

+ 10 - 6
tests/2.0) GlobalInputTest/PyDEVS/target.py

@@ -12,7 +12,7 @@ from sccd.runtime.DEVS_statecharts_core import *
 # package "Global Input Test"
 
 class MainAppInstance(RuntimeClassBase):
-    def __init__(self, atomdevs, id):
+    def __init__(self, atomdevs, id, start_port_id):
         RuntimeClassBase.__init__(self, atomdevs, id)
         self.associations = {}
         
@@ -27,8 +27,12 @@ class MainAppInstance(RuntimeClassBase):
         
         # call user defined constructor
         MainAppInstance.user_defined_constructor(self)
-        port_name = Ports.addInputPort("<narrow_cast>", self)
+        port_name = addInputPort("ui", start_port_id, True)
         atomdevs.addInPort(port_name)
+        atomdevs.state.port_mappings[port_name] = id
+        port_name = addInputPort("<narrow_cast>", start_port_id)
+        atomdevs.addInPort(port_name)
+        atomdevs.state.port_mappings[port_name] = id
     
     def user_defined_constructor(self):
         pass
@@ -69,12 +73,12 @@ class MainApp(ClassBase):
     def __init__(self, name):
         ClassBase.__init__(self, name)
         self.input = self.addInPort("input")
-        new_instance = self.constructObject(0, [])
+        new_instance = self.constructObject(0, 0, [])
         self.state.instances[new_instance.instance_id] = new_instance
         self.state.next_instance = self.state.next_instance + 1
     
-    def constructObject(self, id, parameters):
-        new_instance = MainAppInstance(self, id)
+    def constructObject(self, id, start_port_id, parameters):
+        new_instance = MainAppInstance(self, id, start_port_id)
         return new_instance
 
 class Dummy(ObjectManagerState):
@@ -85,6 +89,7 @@ class Dummy(ObjectManagerState):
         instance = {}
         instance["name"] = class_name
         if class_name == "MainApp":
+            self.narrow_cast_id = self.narrow_cast_id + 0
             instance["associations"] = {}
         else:
             raise Exception("Cannot instantiate class " + class_name)
@@ -103,7 +108,6 @@ class Controller(CoupledDEVS):
     def __init__(self, name):
         CoupledDEVS.__init__(self, name)
         self.in_ui = self.addInPort("ui")
-        Ports.addInputPort("ui")
         self.objectmanager = self.addSubModel(ObjectManager("ObjectManager"))
         self.atomics = []
         self.atomics.append(self.addSubModel(MainApp("MainApp")))

+ 6 - 6
tests/2.1) GlobalOutputTest/PyDEVS/log.txt

@@ -8,7 +8,7 @@ __  Current Time:   0.000000 __________________________________________
 
 
 	INITIAL CONDITIONS in model <Controller.ObjectManager>
-		Initial State: <target.Dummy object at 0x10634a150>
+		Initial State: <target.Dummy object at 0x104a4f260>
 		Next scheduled internal transition at time 0.000000
 
 
@@ -25,13 +25,13 @@ __  Current Time:   0.000000 __________________________________________
 			port <obj_manager_in>:
 				[(('MainApp', 0), ('MainApp', 0), (event name: start_instance; port: None; parameters: ['MainApp[0]']))]
 			port <input>:
-			port <private_13_<narrow_cast>>:
+			port <private_0_<narrow_cast>>:
 		New State: 
 		Next scheduled internal transition at time 0.000000
 
 
 	INTERNAL TRANSITION in model <Controller.ObjectManager>
-		New State: <target.Dummy object at 0x10634a150>
+		New State: <target.Dummy object at 0x104a4f260>
 		Output Port Configuration:
 			port <port1>:
 				[(('MainApp', 0), ('MainApp', 0), (event name: start_instance; port: None; parameters: ['MainApp[0]']))]
@@ -57,7 +57,7 @@ __  Current Time:   0.000000 __________________________________________
 		Input Port Configuration:
 			port <input>:
 				(('MainApp', 0), ('MainApp', 0), (event name: instance_started; port: None; parameters: ['MainApp[0]']))
-		New State: <target.Dummy object at 0x10634a150>
+		New State: <target.Dummy object at 0x104a4f260>
 		Next scheduled internal transition at time 0.000000
 
 
@@ -89,13 +89,13 @@ __  Current Time:   0.000000 __________________________________________
 			port <obj_manager_in>:
 				[(('MainApp', 0), ('MainApp', 0), (event name: instance_started; port: None; parameters: ['MainApp[0]']))]
 			port <input>:
-			port <private_13_<narrow_cast>>:
+			port <private_0_<narrow_cast>>:
 		New State: 
 		Next scheduled internal transition at time 0.000000
 
 
 	INTERNAL TRANSITION in model <Controller.ObjectManager>
-		New State: <target.Dummy object at 0x10634a150>
+		New State: <target.Dummy object at 0x104a4f260>
 		Output Port Configuration:
 			port <port1>:
 				[(('MainApp', 0), ('MainApp', 0), (event name: instance_started; port: None; parameters: ['MainApp[0]']))]

+ 7 - 6
tests/2.1) GlobalOutputTest/PyDEVS/target.py

@@ -12,7 +12,7 @@ from sccd.runtime.DEVS_statecharts_core import *
 # package "Global Output Test"
 
 class MainAppInstance(RuntimeClassBase):
-    def __init__(self, atomdevs, id):
+    def __init__(self, atomdevs, id, start_port_id):
         RuntimeClassBase.__init__(self, atomdevs, id)
         self.associations = {}
         
@@ -27,8 +27,9 @@ class MainAppInstance(RuntimeClassBase):
         
         # call user defined constructor
         MainAppInstance.user_defined_constructor(self)
-        port_name = Ports.addInputPort("<narrow_cast>", self)
+        port_name = addInputPort("<narrow_cast>", start_port_id)
         atomdevs.addInPort(port_name)
+        atomdevs.state.port_mappings[port_name] = id
     
     def user_defined_constructor(self):
         pass
@@ -65,12 +66,12 @@ class MainApp(ClassBase):
         ClassBase.__init__(self, name)
         self.input = self.addInPort("input")
         self.glob_outputs["Outport"] = self.addOutPort("Outport")
-        new_instance = self.constructObject(0, [])
+        new_instance = self.constructObject(0, 0, [])
         self.state.instances[new_instance.instance_id] = new_instance
         self.state.next_instance = self.state.next_instance + 1
     
-    def constructObject(self, id, parameters):
-        new_instance = MainAppInstance(self, id)
+    def constructObject(self, id, start_port_id, parameters):
+        new_instance = MainAppInstance(self, id, start_port_id)
         return new_instance
 
 class Dummy(ObjectManagerState):
@@ -81,6 +82,7 @@ class Dummy(ObjectManagerState):
         instance = {}
         instance["name"] = class_name
         if class_name == "MainApp":
+            self.narrow_cast_id = self.narrow_cast_id + 0
             instance["associations"] = {}
         else:
             raise Exception("Cannot instantiate class " + class_name)
@@ -99,7 +101,6 @@ class Controller(CoupledDEVS):
     def __init__(self, name):
         CoupledDEVS.__init__(self, name)
         self.out_Outport = self.addOutPort("Outport")
-        Ports.addOutputPort("Outport")
         self.objectmanager = self.addSubModel(ObjectManager("ObjectManager"))
         self.atomics = []
         self.atomics.append(self.addSubModel(MainApp("MainApp")))

+ 10 - 7
tests/2.2) GlobalIOTest/PyDEVS/log.txt

@@ -8,7 +8,7 @@ __  Current Time:   0.000000 __________________________________________
 
 
 	INITIAL CONDITIONS in model <Controller.ObjectManager>
-		Initial State: <target.Dummy object at 0x1065051c0>
+		Initial State: <target.Dummy object at 0x104a9caa0>
 		Next scheduled internal transition at time 0.000000
 
 
@@ -25,13 +25,14 @@ __  Current Time:   0.000000 __________________________________________
 			port <obj_manager_in>:
 				[(('MainApp', 0), ('MainApp', 0), (event name: start_instance; port: None; parameters: ['MainApp[0]']))]
 			port <input>:
-			port <private_14_<narrow_cast>>:
+			port <Inport>:
+			port <private_0_<narrow_cast>>:
 		New State: 
 		Next scheduled internal transition at time 0.000000
 
 
 	INTERNAL TRANSITION in model <Controller.ObjectManager>
-		New State: <target.Dummy object at 0x1065051c0>
+		New State: <target.Dummy object at 0x104a9caa0>
 		Output Port Configuration:
 			port <port1>:
 				[(('MainApp', 0), ('MainApp', 0), (event name: start_instance; port: None; parameters: ['MainApp[0]']))]
@@ -45,7 +46,7 @@ __  Current Time:   0.000000 __________________________________________
 		Input Port Configuration:
 			port <input>:
 				(('MainApp', 0), ('MainApp', 0), (event name: instance_started; port: None; parameters: ['MainApp[0]']))
-		New State: <target.Dummy object at 0x1065051c0>
+		New State: <target.Dummy object at 0x104a9caa0>
 		Next scheduled internal transition at time 0.000000
 
 
@@ -77,13 +78,14 @@ __  Current Time:   0.000000 __________________________________________
 			port <obj_manager_in>:
 				[(('MainApp', 0), ('MainApp', 0), (event name: instance_started; port: None; parameters: ['MainApp[0]']))]
 			port <input>:
-			port <private_14_<narrow_cast>>:
+			port <Inport>:
+			port <private_0_<narrow_cast>>:
 		New State: 
 		Next scheduled internal transition at time 0.000000
 
 
 	INTERNAL TRANSITION in model <Controller.ObjectManager>
-		New State: <target.Dummy object at 0x1065051c0>
+		New State: <target.Dummy object at 0x104a9caa0>
 		Output Port Configuration:
 			port <port1>:
 				[(('MainApp', 0), ('MainApp', 0), (event name: instance_started; port: None; parameters: ['MainApp[0]']))]
@@ -130,7 +132,8 @@ __  Current Time:   0.000000 __________________________________________
 			port <obj_manager_in>:
 			port <input>:
 				['Event("input_event","Inport",[])']
-			port <private_14_<narrow_cast>>:
+			port <Inport>:
+			port <private_0_<narrow_cast>>:
 		New State: 
 		Next scheduled internal transition at time 0.000000
 

+ 10 - 7
tests/2.2) GlobalIOTest/PyDEVS/target.py

@@ -12,7 +12,7 @@ from sccd.runtime.DEVS_statecharts_core import *
 # package "Global IO Test"
 
 class MainAppInstance(RuntimeClassBase):
-    def __init__(self, atomdevs, id):
+    def __init__(self, atomdevs, id, start_port_id):
         RuntimeClassBase.__init__(self, atomdevs, id)
         self.associations = {}
         
@@ -27,8 +27,12 @@ class MainAppInstance(RuntimeClassBase):
         
         # call user defined constructor
         MainAppInstance.user_defined_constructor(self)
-        port_name = Ports.addInputPort("<narrow_cast>", self)
+        port_name = addInputPort("Inport", start_port_id, True)
         atomdevs.addInPort(port_name)
+        atomdevs.state.port_mappings[port_name] = id
+        port_name = addInputPort("<narrow_cast>", start_port_id)
+        atomdevs.addInPort(port_name)
+        atomdevs.state.port_mappings[port_name] = id
     
     def user_defined_constructor(self):
         pass
@@ -74,12 +78,12 @@ class MainApp(ClassBase):
         ClassBase.__init__(self, name)
         self.input = self.addInPort("input")
         self.glob_outputs["Outport"] = self.addOutPort("Outport")
-        new_instance = self.constructObject(0, [])
+        new_instance = self.constructObject(0, 0, [])
         self.state.instances[new_instance.instance_id] = new_instance
         self.state.next_instance = self.state.next_instance + 1
     
-    def constructObject(self, id, parameters):
-        new_instance = MainAppInstance(self, id)
+    def constructObject(self, id, start_port_id, parameters):
+        new_instance = MainAppInstance(self, id, start_port_id)
         return new_instance
 
 class Dummy(ObjectManagerState):
@@ -90,6 +94,7 @@ class Dummy(ObjectManagerState):
         instance = {}
         instance["name"] = class_name
         if class_name == "MainApp":
+            self.narrow_cast_id = self.narrow_cast_id + 0
             instance["associations"] = {}
         else:
             raise Exception("Cannot instantiate class " + class_name)
@@ -108,9 +113,7 @@ class Controller(CoupledDEVS):
     def __init__(self, name):
         CoupledDEVS.__init__(self, name)
         self.in_Inport = self.addInPort("Inport")
-        Ports.addInputPort("Inport")
         self.out_Outport = self.addOutPort("Outport")
-        Ports.addOutputPort("Outport")
         self.objectmanager = self.addSubModel(ObjectManager("ObjectManager"))
         self.atomics = []
         self.atomics.append(self.addSubModel(MainApp("MainApp")))

+ 8 - 6
tests/2.3) TimedOutputTest/PyDEVS/log.txt

@@ -8,7 +8,7 @@ __  Current Time:   0.000000 __________________________________________
 
 
 	INITIAL CONDITIONS in model <Controller.ObjectManager>
-		Initial State: <target.Dummy object at 0x106506b70>
+		Initial State: <target.Dummy object at 0x104a9e870>
 		Next scheduled internal transition at time 0.000000
 
 
@@ -25,13 +25,14 @@ __  Current Time:   0.000000 __________________________________________
 			port <obj_manager_in>:
 				[(('MainApp', 0), ('MainApp', 0), (event name: start_instance; port: None; parameters: ['MainApp[0]']))]
 			port <input>:
-			port <private_15_<narrow_cast>>:
+			port <ui>:
+			port <private_0_<narrow_cast>>:
 		New State: 
 		Next scheduled internal transition at time 0.000000
 
 
 	INTERNAL TRANSITION in model <Controller.ObjectManager>
-		New State: <target.Dummy object at 0x106506b70>
+		New State: <target.Dummy object at 0x104a9e870>
 		Output Port Configuration:
 			port <port1>:
 				[(('MainApp', 0), ('MainApp', 0), (event name: start_instance; port: None; parameters: ['MainApp[0]']))]
@@ -45,7 +46,7 @@ __  Current Time:   0.000000 __________________________________________
 		Input Port Configuration:
 			port <input>:
 				(('MainApp', 0), ('MainApp', 0), (event name: instance_started; port: None; parameters: ['MainApp[0]']))
-		New State: <target.Dummy object at 0x106506b70>
+		New State: <target.Dummy object at 0x104a9e870>
 		Next scheduled internal transition at time 0.000000
 
 
@@ -77,13 +78,14 @@ __  Current Time:   0.000000 __________________________________________
 			port <obj_manager_in>:
 				[(('MainApp', 0), ('MainApp', 0), (event name: instance_started; port: None; parameters: ['MainApp[0]']))]
 			port <input>:
-			port <private_15_<narrow_cast>>:
+			port <ui>:
+			port <private_0_<narrow_cast>>:
 		New State: 
 		Next scheduled internal transition at time 0.000000
 
 
 	INTERNAL TRANSITION in model <Controller.ObjectManager>
-		New State: <target.Dummy object at 0x106506b70>
+		New State: <target.Dummy object at 0x104a9e870>
 		Output Port Configuration:
 			port <port1>:
 				[(('MainApp', 0), ('MainApp', 0), (event name: instance_started; port: None; parameters: ['MainApp[0]']))]

+ 10 - 7
tests/2.3) TimedOutputTest/PyDEVS/target.py

@@ -12,7 +12,7 @@ from sccd.runtime.DEVS_statecharts_core import *
 # package "Output Test"
 
 class MainAppInstance(RuntimeClassBase):
-    def __init__(self, atomdevs, id):
+    def __init__(self, atomdevs, id, start_port_id):
         RuntimeClassBase.__init__(self, atomdevs, id)
         self.associations = {}
         
@@ -27,8 +27,12 @@ class MainAppInstance(RuntimeClassBase):
         
         # call user defined constructor
         MainAppInstance.user_defined_constructor(self)
-        port_name = Ports.addInputPort("<narrow_cast>", self)
+        port_name = addInputPort("ui", start_port_id, True)
         atomdevs.addInPort(port_name)
+        atomdevs.state.port_mappings[port_name] = id
+        port_name = addInputPort("<narrow_cast>", start_port_id)
+        atomdevs.addInPort(port_name)
+        atomdevs.state.port_mappings[port_name] = id
     
     def user_defined_constructor(self):
         pass
@@ -82,12 +86,12 @@ class MainApp(ClassBase):
         ClassBase.__init__(self, name)
         self.input = self.addInPort("input")
         self.glob_outputs["ui"] = self.addOutPort("ui")
-        new_instance = self.constructObject(0, [])
+        new_instance = self.constructObject(0, 0, [])
         self.state.instances[new_instance.instance_id] = new_instance
         self.state.next_instance = self.state.next_instance + 1
     
-    def constructObject(self, id, parameters):
-        new_instance = MainAppInstance(self, id)
+    def constructObject(self, id, start_port_id, parameters):
+        new_instance = MainAppInstance(self, id, start_port_id)
         return new_instance
 
 class Dummy(ObjectManagerState):
@@ -98,6 +102,7 @@ class Dummy(ObjectManagerState):
         instance = {}
         instance["name"] = class_name
         if class_name == "MainApp":
+            self.narrow_cast_id = self.narrow_cast_id + 0
             instance["associations"] = {}
         else:
             raise Exception("Cannot instantiate class " + class_name)
@@ -116,9 +121,7 @@ class Controller(CoupledDEVS):
     def __init__(self, name):
         CoupledDEVS.__init__(self, name)
         self.in_ui = self.addInPort("ui")
-        Ports.addInputPort("ui")
         self.out_ui = self.addOutPort("ui")
-        Ports.addOutputPort("ui")
         self.objectmanager = self.addSubModel(ObjectManager("ObjectManager"))
         self.atomics = []
         self.atomics.append(self.addSubModel(MainApp("MainApp")))

+ 8 - 6
tests/2.5) MultipleOutputTest/PyDEVS/log.txt

@@ -8,7 +8,7 @@ __  Current Time:   0.000000 __________________________________________
 
 
 	INITIAL CONDITIONS in model <Controller.ObjectManager>
-		Initial State: <target.Dummy object at 0x1064de5d0>
+		Initial State: <target.Dummy object at 0x104aa0a10>
 		Next scheduled internal transition at time 0.000000
 
 
@@ -25,13 +25,14 @@ __  Current Time:   0.000000 __________________________________________
 			port <obj_manager_in>:
 				[(('MainApp', 0), ('MainApp', 0), (event name: start_instance; port: None; parameters: ['MainApp[0]']))]
 			port <input>:
-			port <private_16_<narrow_cast>>:
+			port <ui>:
+			port <private_0_<narrow_cast>>:
 		New State: 
 		Next scheduled internal transition at time 0.000000
 
 
 	INTERNAL TRANSITION in model <Controller.ObjectManager>
-		New State: <target.Dummy object at 0x1064de5d0>
+		New State: <target.Dummy object at 0x104aa0a10>
 		Output Port Configuration:
 			port <port1>:
 				[(('MainApp', 0), ('MainApp', 0), (event name: start_instance; port: None; parameters: ['MainApp[0]']))]
@@ -45,7 +46,7 @@ __  Current Time:   0.000000 __________________________________________
 		Input Port Configuration:
 			port <input>:
 				(('MainApp', 0), ('MainApp', 0), (event name: instance_started; port: None; parameters: ['MainApp[0]']))
-		New State: <target.Dummy object at 0x1064de5d0>
+		New State: <target.Dummy object at 0x104aa0a10>
 		Next scheduled internal transition at time 0.000000
 
 
@@ -77,13 +78,14 @@ __  Current Time:   0.000000 __________________________________________
 			port <obj_manager_in>:
 				[(('MainApp', 0), ('MainApp', 0), (event name: instance_started; port: None; parameters: ['MainApp[0]']))]
 			port <input>:
-			port <private_16_<narrow_cast>>:
+			port <ui>:
+			port <private_0_<narrow_cast>>:
 		New State: 
 		Next scheduled internal transition at time 0.000000
 
 
 	INTERNAL TRANSITION in model <Controller.ObjectManager>
-		New State: <target.Dummy object at 0x1064de5d0>
+		New State: <target.Dummy object at 0x104aa0a10>
 		Output Port Configuration:
 			port <port1>:
 				[(('MainApp', 0), ('MainApp', 0), (event name: instance_started; port: None; parameters: ['MainApp[0]']))]

+ 10 - 7
tests/2.5) MultipleOutputTest/PyDEVS/target.py

@@ -12,7 +12,7 @@ from sccd.runtime.DEVS_statecharts_core import *
 # package "Multiple Output Test"
 
 class MainAppInstance(RuntimeClassBase):
-    def __init__(self, atomdevs, id):
+    def __init__(self, atomdevs, id, start_port_id):
         RuntimeClassBase.__init__(self, atomdevs, id)
         self.associations = {}
         
@@ -27,8 +27,12 @@ class MainAppInstance(RuntimeClassBase):
         
         # call user defined constructor
         MainAppInstance.user_defined_constructor(self)
-        port_name = Ports.addInputPort("<narrow_cast>", self)
+        port_name = addInputPort("ui", start_port_id, True)
         atomdevs.addInPort(port_name)
+        atomdevs.state.port_mappings[port_name] = id
+        port_name = addInputPort("<narrow_cast>", start_port_id)
+        atomdevs.addInPort(port_name)
+        atomdevs.state.port_mappings[port_name] = id
     
     def user_defined_constructor(self):
         self.amount = 1
@@ -106,12 +110,12 @@ class MainApp(ClassBase):
         ClassBase.__init__(self, name)
         self.input = self.addInPort("input")
         self.glob_outputs["ui"] = self.addOutPort("ui")
-        new_instance = self.constructObject(0, [])
+        new_instance = self.constructObject(0, 0, [])
         self.state.instances[new_instance.instance_id] = new_instance
         self.state.next_instance = self.state.next_instance + 1
     
-    def constructObject(self, id, parameters):
-        new_instance = MainAppInstance(self, id)
+    def constructObject(self, id, start_port_id, parameters):
+        new_instance = MainAppInstance(self, id, start_port_id)
         return new_instance
 
 class Dummy(ObjectManagerState):
@@ -122,6 +126,7 @@ class Dummy(ObjectManagerState):
         instance = {}
         instance["name"] = class_name
         if class_name == "MainApp":
+            self.narrow_cast_id = self.narrow_cast_id + 0
             instance["associations"] = {}
         else:
             raise Exception("Cannot instantiate class " + class_name)
@@ -140,9 +145,7 @@ class Controller(CoupledDEVS):
     def __init__(self, name):
         CoupledDEVS.__init__(self, name)
         self.in_ui = self.addInPort("ui")
-        Ports.addInputPort("ui")
         self.out_ui = self.addOutPort("ui")
-        Ports.addOutputPort("ui")
         self.objectmanager = self.addSubModel(ObjectManager("ObjectManager"))
         self.atomics = []
         self.atomics.append(self.addSubModel(MainApp("MainApp")))

+ 17 - 13
tests/3.0) ClassCreation/PyDEVS/log.txt

@@ -13,7 +13,7 @@ __  Current Time:   0.000000 __________________________________________
 
 
 	INITIAL CONDITIONS in model <Controller.ObjectManager>
-		Initial State: <target.Dummy object at 0x106324f20>
+		Initial State: <target.Dummy object at 0x104a9c8c0>
 		Next scheduled internal transition at time 0.000000
 
 
@@ -30,13 +30,14 @@ __  Current Time:   0.000000 __________________________________________
 			port <obj_manager_in>:
 				[(('MainApp', 0), ('MainApp', 0), (event name: start_instance; port: None; parameters: ['MainApp[0]']))]
 			port <input>:
-			port <private_17_<narrow_cast>>:
+			port <ui>:
+			port <private_0_<narrow_cast>>:
 		New State: 
 		Next scheduled internal transition at time 0.000000
 
 
 	INTERNAL TRANSITION in model <Controller.ObjectManager>
-		New State: <target.Dummy object at 0x106324f20>
+		New State: <target.Dummy object at 0x104a9c8c0>
 		Output Port Configuration:
 			port <port1>:
 				[(('MainApp', 0), ('MainApp', 0), (event name: start_instance; port: None; parameters: ['MainApp[0]']))]
@@ -51,7 +52,7 @@ __  Current Time:   0.000000 __________________________________________
 		Input Port Configuration:
 			port <input>:
 				(('MainApp', 0), ('MainApp', 0), (event name: instance_started; port: None; parameters: ['MainApp[0]']))
-		New State: <target.Dummy object at 0x106324f20>
+		New State: <target.Dummy object at 0x104a9c8c0>
 		Next scheduled internal transition at time 0.000000
 
 
@@ -72,7 +73,7 @@ __  Current Time:   0.000000 __________________________________________
 		Input Port Configuration:
 			port <input>:
 				(('MainApp', 0), None, (event name: create_instance; port: None; parameters: [0, 'linkA[0]', 'A']))
-		New State: <target.Dummy object at 0x106324f20>
+		New State: <target.Dummy object at 0x104a9c8c0>
 		Next scheduled internal transition at time 0.000000
 
 
@@ -92,9 +93,10 @@ __  Current Time:   0.000000 __________________________________________
 	EXTERNAL TRANSITION in model <Controller.A>
 		Input Port Configuration:
 			port <obj_manager_in>:
-				[(('MainApp', 0), ('A', 1), (event name: create_instance; port: None; parameters: [0, 'linkA[0]', 'A']))]
+				[(('MainApp', 0), ('A', 1), (event name: create_instance; port: None; parameters: [0, 1, 'linkA[0]', 'A']))]
 			port <input>:
-			port <private_18_<narrow_cast>>:
+			port <ui>:
+			port <private_1_<narrow_cast>>:
 		New State: 
 		Next scheduled internal transition at time 0.000000
 
@@ -104,18 +106,19 @@ __  Current Time:   0.000000 __________________________________________
 			port <obj_manager_in>:
 				[(('MainApp', 0), ('MainApp', 0), (event name: instance_started; port: None; parameters: ['MainApp[0]']))]
 			port <input>:
-			port <private_17_<narrow_cast>>:
+			port <ui>:
+			port <private_0_<narrow_cast>>:
 		New State: 
 		Next scheduled internal transition at time 0.000000
 
 
 	INTERNAL TRANSITION in model <Controller.ObjectManager>
-		New State: <target.Dummy object at 0x106324f20>
+		New State: <target.Dummy object at 0x104a9c8c0>
 		Output Port Configuration:
 			port <port1>:
 				[(('MainApp', 0), ('MainApp', 0), (event name: instance_started; port: None; parameters: ['MainApp[0]']))]
 			port <port2>:
-				[(('MainApp', 0), ('A', 1), (event name: create_instance; port: None; parameters: [0, 'linkA[0]', 'A']))]
+				[(('MainApp', 0), ('A', 1), (event name: create_instance; port: None; parameters: [0, 1, 'linkA[0]', 'A']))]
 		Next scheduled internal transition at time inf
 
 
@@ -126,7 +129,7 @@ __  Current Time:   0.000000 __________________________________________
 		Input Port Configuration:
 			port <input>:
 				(('A', 1), ('MainApp', 0), (event name: instance_created; port: None; parameters: ['linkA[0]']))
-		New State: <target.Dummy object at 0x106324f20>
+		New State: <target.Dummy object at 0x104a9c8c0>
 		Next scheduled internal transition at time 0.000000
 
 
@@ -171,13 +174,14 @@ __  Current Time:   0.000000 __________________________________________
 			port <obj_manager_in>:
 				[(('A', 1), ('MainApp', 0), (event name: instance_created; port: None; parameters: ['linkA[0]']))]
 			port <input>:
-			port <private_17_<narrow_cast>>:
+			port <ui>:
+			port <private_0_<narrow_cast>>:
 		New State: 
 		Next scheduled internal transition at time 0.000000
 
 
 	INTERNAL TRANSITION in model <Controller.ObjectManager>
-		New State: <target.Dummy object at 0x106324f20>
+		New State: <target.Dummy object at 0x104a9c8c0>
 		Output Port Configuration:
 			port <port1>:
 				[(('A', 1), ('MainApp', 0), (event name: instance_created; port: None; parameters: ['linkA[0]']))]

+ 19 - 11
tests/3.0) ClassCreation/PyDEVS/target.py

@@ -12,7 +12,7 @@ from sccd.runtime.DEVS_statecharts_core import *
 # package "Create Instance"
 
 class MainAppInstance(RuntimeClassBase):
-    def __init__(self, atomdevs, id):
+    def __init__(self, atomdevs, id, start_port_id):
         RuntimeClassBase.__init__(self, atomdevs, id)
         self.associations = {}
         self.associations["linkA"] = Association("A", 0, -1)
@@ -28,8 +28,12 @@ class MainAppInstance(RuntimeClassBase):
         
         # call user defined constructor
         MainAppInstance.user_defined_constructor(self)
-        port_name = Ports.addInputPort("<narrow_cast>", self)
+        port_name = addInputPort("ui", start_port_id, True)
         atomdevs.addInPort(port_name)
+        atomdevs.state.port_mappings[port_name] = id
+        port_name = addInputPort("<narrow_cast>", start_port_id)
+        atomdevs.addInPort(port_name)
+        atomdevs.state.port_mappings[port_name] = id
     
     def user_defined_constructor(self):
         pass
@@ -81,16 +85,16 @@ class MainApp(ClassBase):
         self.input = self.addInPort("input")
         self.glob_outputs["ui"] = self.addOutPort("ui")
         self.outputs["linkA"] = self.addOutPort("linkA")
-        new_instance = self.constructObject(0, [])
+        new_instance = self.constructObject(0, 0, [])
         self.state.instances[new_instance.instance_id] = new_instance
         self.state.next_instance = self.state.next_instance + 1
     
-    def constructObject(self, id, parameters):
-        new_instance = MainAppInstance(self, id)
+    def constructObject(self, id, start_port_id, parameters):
+        new_instance = MainAppInstance(self, id, start_port_id)
         return new_instance
 
 class AInstance(RuntimeClassBase):
-    def __init__(self, atomdevs, id):
+    def __init__(self, atomdevs, id, start_port_id):
         RuntimeClassBase.__init__(self, atomdevs, id)
         self.associations = {}
         
@@ -105,8 +109,12 @@ class AInstance(RuntimeClassBase):
         
         # call user defined constructor
         AInstance.user_defined_constructor(self)
-        port_name = Ports.addInputPort("<narrow_cast>", self)
+        port_name = addInputPort("ui", start_port_id, True)
+        atomdevs.addInPort(port_name)
+        atomdevs.state.port_mappings[port_name] = id
+        port_name = addInputPort("<narrow_cast>", start_port_id)
         atomdevs.addInPort(port_name)
+        atomdevs.state.port_mappings[port_name] = id
     
     def user_defined_constructor(self):
         pass
@@ -144,8 +152,8 @@ class A(ClassBase):
         self.input = self.addInPort("input")
         self.glob_outputs["ui"] = self.addOutPort("ui")
     
-    def constructObject(self, id, parameters):
-        new_instance = AInstance(self, id)
+    def constructObject(self, id, start_port_id, parameters):
+        new_instance = AInstance(self, id, start_port_id)
         return new_instance
 
 class Dummy(ObjectManagerState):
@@ -156,9 +164,11 @@ class Dummy(ObjectManagerState):
         instance = {}
         instance["name"] = class_name
         if class_name == "MainApp":
+            self.narrow_cast_id = self.narrow_cast_id + 0
             instance["associations"] = {}
             instance["associations"]["linkA"] = Association("A", 0, -1)
         elif class_name == "A":
+            self.narrow_cast_id = self.narrow_cast_id + 0
             instance["associations"] = {}
         else:
             raise Exception("Cannot instantiate class " + class_name)
@@ -178,9 +188,7 @@ class Controller(CoupledDEVS):
     def __init__(self, name):
         CoupledDEVS.__init__(self, name)
         self.in_ui = self.addInPort("ui")
-        Ports.addInputPort("ui")
         self.out_ui = self.addOutPort("ui")
-        Ports.addOutputPort("ui")
         self.objectmanager = self.addSubModel(ObjectManager("ObjectManager"))
         self.atomics = []
         self.atomics.append(self.addSubModel(MainApp("MainApp")))

+ 25 - 19
tests/3.1) ClassInitialization/PyDEVS/log.txt

@@ -13,7 +13,7 @@ __  Current Time:   0.000000 __________________________________________
 
 
 	INITIAL CONDITIONS in model <Controller.ObjectManager>
-		Initial State: <target.Dummy object at 0x10652c080>
+		Initial State: <target.Dummy object at 0x104a4e390>
 		Next scheduled internal transition at time 0.000000
 
 
@@ -30,13 +30,14 @@ __  Current Time:   0.000000 __________________________________________
 			port <obj_manager_in>:
 				[(('MainApp', 0), ('MainApp', 0), (event name: start_instance; port: None; parameters: ['MainApp[0]']))]
 			port <input>:
-			port <private_19_<narrow_cast>>:
+			port <ui>:
+			port <private_0_<narrow_cast>>:
 		New State: 
 		Next scheduled internal transition at time 0.000000
 
 
 	INTERNAL TRANSITION in model <Controller.ObjectManager>
-		New State: <target.Dummy object at 0x10652c080>
+		New State: <target.Dummy object at 0x104a4e390>
 		Output Port Configuration:
 			port <port1>:
 				[(('MainApp', 0), ('MainApp', 0), (event name: start_instance; port: None; parameters: ['MainApp[0]']))]
@@ -51,7 +52,7 @@ __  Current Time:   0.000000 __________________________________________
 		Input Port Configuration:
 			port <input>:
 				(('MainApp', 0), ('MainApp', 0), (event name: instance_started; port: None; parameters: ['MainApp[0]']))
-		New State: <target.Dummy object at 0x10652c080>
+		New State: <target.Dummy object at 0x104a4e390>
 		Next scheduled internal transition at time 0.000000
 
 
@@ -72,7 +73,7 @@ __  Current Time:   0.000000 __________________________________________
 		Input Port Configuration:
 			port <input>:
 				(('MainApp', 0), None, (event name: create_instance; port: None; parameters: [0, 'linkA[0]', 'A']))
-		New State: <target.Dummy object at 0x10652c080>
+		New State: <target.Dummy object at 0x104a4e390>
 		Next scheduled internal transition at time 0.000000
 
 
@@ -92,9 +93,10 @@ __  Current Time:   0.000000 __________________________________________
 	EXTERNAL TRANSITION in model <Controller.A>
 		Input Port Configuration:
 			port <obj_manager_in>:
-				[(('MainApp', 0), ('A', 1), (event name: create_instance; port: None; parameters: [0, 'linkA[0]', 'A']))]
+				[(('MainApp', 0), ('A', 1), (event name: create_instance; port: None; parameters: [0, 1, 'linkA[0]', 'A']))]
 			port <input>:
-			port <private_20_<narrow_cast>>:
+			port <ui>:
+			port <private_1_<narrow_cast>>:
 		New State: 
 		Next scheduled internal transition at time 0.000000
 
@@ -104,18 +106,19 @@ __  Current Time:   0.000000 __________________________________________
 			port <obj_manager_in>:
 				[(('MainApp', 0), ('MainApp', 0), (event name: instance_started; port: None; parameters: ['MainApp[0]']))]
 			port <input>:
-			port <private_19_<narrow_cast>>:
+			port <ui>:
+			port <private_0_<narrow_cast>>:
 		New State: 
 		Next scheduled internal transition at time 0.000000
 
 
 	INTERNAL TRANSITION in model <Controller.ObjectManager>
-		New State: <target.Dummy object at 0x10652c080>
+		New State: <target.Dummy object at 0x104a4e390>
 		Output Port Configuration:
 			port <port1>:
 				[(('MainApp', 0), ('MainApp', 0), (event name: instance_started; port: None; parameters: ['MainApp[0]']))]
 			port <port2>:
-				[(('MainApp', 0), ('A', 1), (event name: create_instance; port: None; parameters: [0, 'linkA[0]', 'A']))]
+				[(('MainApp', 0), ('A', 1), (event name: create_instance; port: None; parameters: [0, 1, 'linkA[0]', 'A']))]
 		Next scheduled internal transition at time inf
 
 
@@ -126,7 +129,7 @@ __  Current Time:   0.000000 __________________________________________
 		Input Port Configuration:
 			port <input>:
 				(('A', 1), ('MainApp', 0), (event name: instance_created; port: None; parameters: ['linkA[0]']))
-		New State: <target.Dummy object at 0x10652c080>
+		New State: <target.Dummy object at 0x104a4e390>
 		Next scheduled internal transition at time 0.000000
 
 
@@ -171,13 +174,14 @@ __  Current Time:   0.000000 __________________________________________
 			port <obj_manager_in>:
 				[(('A', 1), ('MainApp', 0), (event name: instance_created; port: None; parameters: ['linkA[0]']))]
 			port <input>:
-			port <private_19_<narrow_cast>>:
+			port <ui>:
+			port <private_0_<narrow_cast>>:
 		New State: 
 		Next scheduled internal transition at time 0.000000
 
 
 	INTERNAL TRANSITION in model <Controller.ObjectManager>
-		New State: <target.Dummy object at 0x10652c080>
+		New State: <target.Dummy object at 0x104a4e390>
 		Output Port Configuration:
 			port <port1>:
 				[(('A', 1), ('MainApp', 0), (event name: instance_created; port: None; parameters: ['linkA[0]']))]
@@ -226,7 +230,7 @@ __  Current Time:   0.000000 __________________________________________
 		Input Port Configuration:
 			port <input>:
 				(('MainApp', 0), None, (event name: start_instance; port: None; parameters: [0, 'linkA[0]']))
-		New State: <target.Dummy object at 0x10652c080>
+		New State: <target.Dummy object at 0x104a4e390>
 		Next scheduled internal transition at time 0.000000
 
 
@@ -248,13 +252,14 @@ __  Current Time:   0.000000 __________________________________________
 			port <obj_manager_in>:
 				[(('MainApp', 0), ('A', 1), (event name: start_instance; port: None; parameters: ['linkA[0]']))]
 			port <input>:
-			port <private_20_<narrow_cast>>:
+			port <ui>:
+			port <private_1_<narrow_cast>>:
 		New State: 
 		Next scheduled internal transition at time 0.000000
 
 
 	INTERNAL TRANSITION in model <Controller.ObjectManager>
-		New State: <target.Dummy object at 0x10652c080>
+		New State: <target.Dummy object at 0x104a4e390>
 		Output Port Configuration:
 			port <port1>:
 			port <port2>:
@@ -281,7 +286,7 @@ __  Current Time:   0.000000 __________________________________________
 		Input Port Configuration:
 			port <input>:
 				(('A', 1), ('MainApp', 0), (event name: instance_started; port: None; parameters: ['linkA[0]']))
-		New State: <target.Dummy object at 0x10652c080>
+		New State: <target.Dummy object at 0x104a4e390>
 		Next scheduled internal transition at time 0.000000
 
 
@@ -313,13 +318,14 @@ __  Current Time:   0.000000 __________________________________________
 			port <obj_manager_in>:
 				[(('A', 1), ('MainApp', 0), (event name: instance_started; port: None; parameters: ['linkA[0]']))]
 			port <input>:
-			port <private_19_<narrow_cast>>:
+			port <ui>:
+			port <private_0_<narrow_cast>>:
 		New State: 
 		Next scheduled internal transition at time 0.000000
 
 
 	INTERNAL TRANSITION in model <Controller.ObjectManager>
-		New State: <target.Dummy object at 0x10652c080>
+		New State: <target.Dummy object at 0x104a4e390>
 		Output Port Configuration:
 			port <port1>:
 				[(('A', 1), ('MainApp', 0), (event name: instance_started; port: None; parameters: ['linkA[0]']))]

+ 19 - 11
tests/3.1) ClassInitialization/PyDEVS/target.py

@@ -12,7 +12,7 @@ from sccd.runtime.DEVS_statecharts_core import *
 # package "Create and Start Instance"
 
 class MainAppInstance(RuntimeClassBase):
-    def __init__(self, atomdevs, id):
+    def __init__(self, atomdevs, id, start_port_id):
         RuntimeClassBase.__init__(self, atomdevs, id)
         self.associations = {}
         self.associations["linkA"] = Association("A", 0, -1)
@@ -28,8 +28,12 @@ class MainAppInstance(RuntimeClassBase):
         
         # call user defined constructor
         MainAppInstance.user_defined_constructor(self)
-        port_name = Ports.addInputPort("<narrow_cast>", self)
+        port_name = addInputPort("ui", start_port_id, True)
         atomdevs.addInPort(port_name)
+        atomdevs.state.port_mappings[port_name] = id
+        port_name = addInputPort("<narrow_cast>", start_port_id)
+        atomdevs.addInPort(port_name)
+        atomdevs.state.port_mappings[port_name] = id
     
     def user_defined_constructor(self):
         pass
@@ -92,16 +96,16 @@ class MainApp(ClassBase):
         self.input = self.addInPort("input")
         self.glob_outputs["ui"] = self.addOutPort("ui")
         self.outputs["linkA"] = self.addOutPort("linkA")
-        new_instance = self.constructObject(0, [])
+        new_instance = self.constructObject(0, 0, [])
         self.state.instances[new_instance.instance_id] = new_instance
         self.state.next_instance = self.state.next_instance + 1
     
-    def constructObject(self, id, parameters):
-        new_instance = MainAppInstance(self, id)
+    def constructObject(self, id, start_port_id, parameters):
+        new_instance = MainAppInstance(self, id, start_port_id)
         return new_instance
 
 class AInstance(RuntimeClassBase):
-    def __init__(self, atomdevs, id):
+    def __init__(self, atomdevs, id, start_port_id):
         RuntimeClassBase.__init__(self, atomdevs, id)
         self.associations = {}
         
@@ -116,8 +120,12 @@ class AInstance(RuntimeClassBase):
         
         # call user defined constructor
         AInstance.user_defined_constructor(self)
-        port_name = Ports.addInputPort("<narrow_cast>", self)
+        port_name = addInputPort("ui", start_port_id, True)
+        atomdevs.addInPort(port_name)
+        atomdevs.state.port_mappings[port_name] = id
+        port_name = addInputPort("<narrow_cast>", start_port_id)
         atomdevs.addInPort(port_name)
+        atomdevs.state.port_mappings[port_name] = id
     
     def user_defined_constructor(self):
         pass
@@ -155,8 +163,8 @@ class A(ClassBase):
         self.input = self.addInPort("input")
         self.glob_outputs["ui"] = self.addOutPort("ui")
     
-    def constructObject(self, id, parameters):
-        new_instance = AInstance(self, id)
+    def constructObject(self, id, start_port_id, parameters):
+        new_instance = AInstance(self, id, start_port_id)
         return new_instance
 
 class Dummy(ObjectManagerState):
@@ -167,9 +175,11 @@ class Dummy(ObjectManagerState):
         instance = {}
         instance["name"] = class_name
         if class_name == "MainApp":
+            self.narrow_cast_id = self.narrow_cast_id + 0
             instance["associations"] = {}
             instance["associations"]["linkA"] = Association("A", 0, -1)
         elif class_name == "A":
+            self.narrow_cast_id = self.narrow_cast_id + 0
             instance["associations"] = {}
         else:
             raise Exception("Cannot instantiate class " + class_name)
@@ -189,9 +199,7 @@ class Controller(CoupledDEVS):
     def __init__(self, name):
         CoupledDEVS.__init__(self, name)
         self.in_ui = self.addInPort("ui")
-        Ports.addInputPort("ui")
         self.out_ui = self.addOutPort("ui")
-        Ports.addOutputPort("ui")
         self.objectmanager = self.addSubModel(ObjectManager("ObjectManager"))
         self.atomics = []
         self.atomics.append(self.addSubModel(MainApp("MainApp")))

+ 57 - 44
tests/3.10) DeleteBadFromNonParent/PyDEVS/log.txt

@@ -18,7 +18,7 @@ __  Current Time:   0.000000 __________________________________________
 
 
 	INITIAL CONDITIONS in model <Controller.ObjectManager>
-		Initial State: <target.Dummy object at 0x1076baf00>
+		Initial State: <target.Dummy object at 0x1049c2b70>
 		Next scheduled internal transition at time 0.000000
 
 
@@ -35,13 +35,14 @@ __  Current Time:   0.000000 __________________________________________
 			port <obj_manager_in>:
 				[(('MainApp', 0), ('MainApp', 0), (event name: start_instance; port: None; parameters: ['MainApp[0]']))]
 			port <input>:
-			port <private_49_<narrow_cast>>:
+			port <ui>:
+			port <private_0_<narrow_cast>>:
 		New State: 
 		Next scheduled internal transition at time 0.000000
 
 
 	INTERNAL TRANSITION in model <Controller.ObjectManager>
-		New State: <target.Dummy object at 0x1076baf00>
+		New State: <target.Dummy object at 0x1049c2b70>
 		Output Port Configuration:
 			port <port1>:
 				[(('MainApp', 0), ('MainApp', 0), (event name: start_instance; port: None; parameters: ['MainApp[0]']))]
@@ -57,7 +58,7 @@ __  Current Time:   0.000000 __________________________________________
 		Input Port Configuration:
 			port <input>:
 				(('MainApp', 0), ('MainApp', 0), (event name: instance_started; port: None; parameters: ['MainApp[0]']))
-		New State: <target.Dummy object at 0x1076baf00>
+		New State: <target.Dummy object at 0x1049c2b70>
 		Next scheduled internal transition at time 0.000000
 
 
@@ -79,7 +80,7 @@ __  Current Time:   0.000000 __________________________________________
 		Input Port Configuration:
 			port <input>:
 				(('MainApp', 0), None, (event name: create_instance; port: None; parameters: [0, 'linkA[0]', 'A']))
-		New State: <target.Dummy object at 0x1076baf00>
+		New State: <target.Dummy object at 0x1049c2b70>
 		Next scheduled internal transition at time 0.000000
 
 
@@ -100,9 +101,10 @@ __  Current Time:   0.000000 __________________________________________
 	EXTERNAL TRANSITION in model <Controller.A>
 		Input Port Configuration:
 			port <obj_manager_in>:
-				[(('MainApp', 0), ('A', 1), (event name: create_instance; port: None; parameters: [0, 'linkA[0]', 'A']))]
+				[(('MainApp', 0), ('A', 1), (event name: create_instance; port: None; parameters: [0, 1, 'linkA[0]', 'A']))]
 			port <input>:
-			port <private_50_<narrow_cast>>:
+			port <ui>:
+			port <private_1_<narrow_cast>>:
 		New State: 
 		Next scheduled internal transition at time 0.000000
 
@@ -112,18 +114,19 @@ __  Current Time:   0.000000 __________________________________________
 			port <obj_manager_in>:
 				[(('MainApp', 0), ('MainApp', 0), (event name: instance_started; port: None; parameters: ['MainApp[0]']))]
 			port <input>:
-			port <private_49_<narrow_cast>>:
+			port <ui>:
+			port <private_0_<narrow_cast>>:
 		New State: 
 		Next scheduled internal transition at time 0.000000
 
 
 	INTERNAL TRANSITION in model <Controller.ObjectManager>
-		New State: <target.Dummy object at 0x1076baf00>
+		New State: <target.Dummy object at 0x1049c2b70>
 		Output Port Configuration:
 			port <port1>:
 				[(('MainApp', 0), ('MainApp', 0), (event name: instance_started; port: None; parameters: ['MainApp[0]']))]
 			port <port2>:
-				[(('MainApp', 0), ('A', 1), (event name: create_instance; port: None; parameters: [0, 'linkA[0]', 'A']))]
+				[(('MainApp', 0), ('A', 1), (event name: create_instance; port: None; parameters: [0, 1, 'linkA[0]', 'A']))]
 			port <port3>:
 		Next scheduled internal transition at time inf
 
@@ -135,7 +138,7 @@ __  Current Time:   0.000000 __________________________________________
 		Input Port Configuration:
 			port <input>:
 				(('A', 1), ('MainApp', 0), (event name: instance_created; port: None; parameters: ['linkA[0]']))
-		New State: <target.Dummy object at 0x1076baf00>
+		New State: <target.Dummy object at 0x1049c2b70>
 		Next scheduled internal transition at time 0.000000
 
 
@@ -183,13 +186,14 @@ __  Current Time:   0.000000 __________________________________________
 			port <obj_manager_in>:
 				[(('A', 1), ('MainApp', 0), (event name: instance_created; port: None; parameters: ['linkA[0]']))]
 			port <input>:
-			port <private_49_<narrow_cast>>:
+			port <ui>:
+			port <private_0_<narrow_cast>>:
 		New State: 
 		Next scheduled internal transition at time 0.000000
 
 
 	INTERNAL TRANSITION in model <Controller.ObjectManager>
-		New State: <target.Dummy object at 0x1076baf00>
+		New State: <target.Dummy object at 0x1049c2b70>
 		Output Port Configuration:
 			port <port1>:
 				[(('A', 1), ('MainApp', 0), (event name: instance_created; port: None; parameters: ['linkA[0]']))]
@@ -241,7 +245,7 @@ __  Current Time:   0.000000 __________________________________________
 		Input Port Configuration:
 			port <input>:
 				(('MainApp', 0), None, (event name: start_instance; port: None; parameters: [0, 'linkA[0]']))
-		New State: <target.Dummy object at 0x1076baf00>
+		New State: <target.Dummy object at 0x1049c2b70>
 		Next scheduled internal transition at time 0.000000
 
 
@@ -264,13 +268,14 @@ __  Current Time:   0.000000 __________________________________________
 			port <obj_manager_in>:
 				[(('MainApp', 0), ('A', 1), (event name: start_instance; port: None; parameters: ['linkA[0]']))]
 			port <input>:
-			port <private_50_<narrow_cast>>:
+			port <ui>:
+			port <private_1_<narrow_cast>>:
 		New State: 
 		Next scheduled internal transition at time 0.000000
 
 
 	INTERNAL TRANSITION in model <Controller.ObjectManager>
-		New State: <target.Dummy object at 0x1076baf00>
+		New State: <target.Dummy object at 0x1049c2b70>
 		Output Port Configuration:
 			port <port1>:
 			port <port2>:
@@ -299,7 +304,7 @@ __  Current Time:   0.000000 __________________________________________
 		Input Port Configuration:
 			port <input>:
 				(('A', 1), ('MainApp', 0), (event name: instance_started; port: None; parameters: ['linkA[0]']))
-		New State: <target.Dummy object at 0x1076baf00>
+		New State: <target.Dummy object at 0x1049c2b70>
 		Next scheduled internal transition at time 0.000000
 
 
@@ -333,13 +338,14 @@ __  Current Time:   0.000000 __________________________________________
 			port <obj_manager_in>:
 				[(('A', 1), ('MainApp', 0), (event name: instance_started; port: None; parameters: ['linkA[0]']))]
 			port <input>:
-			port <private_49_<narrow_cast>>:
+			port <ui>:
+			port <private_0_<narrow_cast>>:
 		New State: 
 		Next scheduled internal transition at time 0.000000
 
 
 	INTERNAL TRANSITION in model <Controller.ObjectManager>
-		New State: <target.Dummy object at 0x1076baf00>
+		New State: <target.Dummy object at 0x1049c2b70>
 		Output Port Configuration:
 			port <port1>:
 				[(('A', 1), ('MainApp', 0), (event name: instance_started; port: None; parameters: ['linkA[0]']))]
@@ -391,7 +397,7 @@ __  Current Time:   0.000000 __________________________________________
 		Input Port Configuration:
 			port <input>:
 				(('MainApp', 0), None, (event name: create_instance; port: None; parameters: [0, 'linkB[0]', 'B']))
-		New State: <target.Dummy object at 0x1076baf00>
+		New State: <target.Dummy object at 0x1049c2b70>
 		Next scheduled internal transition at time 0.000000
 
 
@@ -412,20 +418,21 @@ __  Current Time:   0.000000 __________________________________________
 	EXTERNAL TRANSITION in model <Controller.B>
 		Input Port Configuration:
 			port <obj_manager_in>:
-				[(('MainApp', 0), ('B', 2), (event name: create_instance; port: None; parameters: [0, 'linkB[0]', 'B']))]
+				[(('MainApp', 0), ('B', 2), (event name: create_instance; port: None; parameters: [0, 2, 'linkB[0]', 'B']))]
 			port <input>:
-			port <private_51_<narrow_cast>>:
+			port <ui>:
+			port <private_2_<narrow_cast>>:
 		New State: 
 		Next scheduled internal transition at time 0.000000
 
 
 	INTERNAL TRANSITION in model <Controller.ObjectManager>
-		New State: <target.Dummy object at 0x1076baf00>
+		New State: <target.Dummy object at 0x1049c2b70>
 		Output Port Configuration:
 			port <port1>:
 			port <port2>:
 			port <port3>:
-				[(('MainApp', 0), ('B', 2), (event name: create_instance; port: None; parameters: [0, 'linkB[0]', 'B']))]
+				[(('MainApp', 0), ('B', 2), (event name: create_instance; port: None; parameters: [0, 2, 'linkB[0]', 'B']))]
 		Next scheduled internal transition at time inf
 
 
@@ -436,7 +443,7 @@ __  Current Time:   0.000000 __________________________________________
 		Input Port Configuration:
 			port <input>:
 				(('B', 2), ('MainApp', 0), (event name: instance_created; port: None; parameters: ['linkB[0]']))
-		New State: <target.Dummy object at 0x1076baf00>
+		New State: <target.Dummy object at 0x1049c2b70>
 		Next scheduled internal transition at time 0.000000
 
 
@@ -457,13 +464,14 @@ __  Current Time:   0.000000 __________________________________________
 			port <obj_manager_in>:
 				[(('B', 2), ('MainApp', 0), (event name: instance_created; port: None; parameters: ['linkB[0]']))]
 			port <input>:
-			port <private_49_<narrow_cast>>:
+			port <ui>:
+			port <private_0_<narrow_cast>>:
 		New State: 
 		Next scheduled internal transition at time 0.000000
 
 
 	INTERNAL TRANSITION in model <Controller.ObjectManager>
-		New State: <target.Dummy object at 0x1076baf00>
+		New State: <target.Dummy object at 0x1049c2b70>
 		Output Port Configuration:
 			port <port1>:
 				[(('B', 2), ('MainApp', 0), (event name: instance_created; port: None; parameters: ['linkB[0]']))]
@@ -515,7 +523,7 @@ __  Current Time:   0.000000 __________________________________________
 		Input Port Configuration:
 			port <input>:
 				(('MainApp', 0), None, (event name: start_instance; port: None; parameters: [0, 'linkB[0]']))
-		New State: <target.Dummy object at 0x1076baf00>
+		New State: <target.Dummy object at 0x1049c2b70>
 		Next scheduled internal transition at time 0.000000
 
 
@@ -538,13 +546,14 @@ __  Current Time:   0.000000 __________________________________________
 			port <obj_manager_in>:
 				[(('MainApp', 0), ('B', 2), (event name: start_instance; port: None; parameters: ['linkB[0]']))]
 			port <input>:
-			port <private_51_<narrow_cast>>:
+			port <ui>:
+			port <private_2_<narrow_cast>>:
 		New State: 
 		Next scheduled internal transition at time 0.000000
 
 
 	INTERNAL TRANSITION in model <Controller.ObjectManager>
-		New State: <target.Dummy object at 0x1076baf00>
+		New State: <target.Dummy object at 0x1049c2b70>
 		Output Port Configuration:
 			port <port1>:
 			port <port2>:
@@ -572,7 +581,7 @@ __  Current Time:   0.000000 __________________________________________
 		Input Port Configuration:
 			port <input>:
 				(('B', 2), ('MainApp', 0), (event name: instance_started; port: None; parameters: ['linkB[0]']))
-		New State: <target.Dummy object at 0x1076baf00>
+		New State: <target.Dummy object at 0x1049c2b70>
 		Next scheduled internal transition at time 0.000000
 
 
@@ -604,13 +613,14 @@ __  Current Time:   0.000000 __________________________________________
 			port <obj_manager_in>:
 				[(('B', 2), ('MainApp', 0), (event name: instance_started; port: None; parameters: ['linkB[0]']))]
 			port <input>:
-			port <private_49_<narrow_cast>>:
+			port <ui>:
+			port <private_0_<narrow_cast>>:
 		New State: 
 		Next scheduled internal transition at time 0.000000
 
 
 	INTERNAL TRANSITION in model <Controller.ObjectManager>
-		New State: <target.Dummy object at 0x1076baf00>
+		New State: <target.Dummy object at 0x1049c2b70>
 		Output Port Configuration:
 			port <port1>:
 				[(('B', 2), ('MainApp', 0), (event name: instance_started; port: None; parameters: ['linkB[0]']))]
@@ -662,7 +672,7 @@ __  Current Time:   0.000000 __________________________________________
 		Input Port Configuration:
 			port <input>:
 				(('MainApp', 0), None, (event name: narrow_cast; port: None; parameters: [0, 'linkA[0]', (event name: remove; port: None)]))
-		New State: <target.Dummy object at 0x1076baf00>
+		New State: <target.Dummy object at 0x1049c2b70>
 		Next scheduled internal transition at time 0.000000
 
 
@@ -683,19 +693,20 @@ __  Current Time:   0.000000 __________________________________________
 	EXTERNAL TRANSITION in model <Controller.A>
 		Input Port Configuration:
 			port <obj_manager_in>:
-				[(('MainApp', 0), ('A', 1), (event name: remove; port: 0))]
+				[(('MainApp', 0), ('A', 1), (event name: remove; port: private_1_<narrow_cast>))]
 			port <input>:
-			port <private_50_<narrow_cast>>:
+			port <ui>:
+			port <private_1_<narrow_cast>>:
 		New State: 
 		Next scheduled internal transition at time 0.000000
 
 
 	INTERNAL TRANSITION in model <Controller.ObjectManager>
-		New State: <target.Dummy object at 0x1076baf00>
+		New State: <target.Dummy object at 0x1049c2b70>
 		Output Port Configuration:
 			port <port1>:
 			port <port2>:
-				[(('MainApp', 0), ('A', 1), (event name: remove; port: ('A', 1)))]
+				[(('MainApp', 0), ('A', 1), (event name: remove; port: private_1_<narrow_cast>))]
 			port <port3>:
 		Next scheduled internal transition at time inf
 
@@ -740,7 +751,7 @@ __  Current Time:   0.000000 __________________________________________
 		Input Port Configuration:
 			port <input>:
 				(('A', 1), None, (event name: delete_instance; port: None; parameters: [[], 'linkB[0]']))
-		New State: <target.Dummy object at 0x1076baf00>
+		New State: <target.Dummy object at 0x1049c2b70>
 		Next scheduled internal transition at time 0.000000
 
 
@@ -762,13 +773,14 @@ __  Current Time:   0.000000 __________________________________________
 			port <obj_manager_in>:
 				[(('A', 1), ('B', 0), (event name: delete_instance; port: None; parameters: [[], 'linkB[0]']))]
 			port <input>:
-			port <private_51_<narrow_cast>>:
+			port <ui>:
+			port <private_2_<narrow_cast>>:
 		New State: 
 		Next scheduled internal transition at time 0.000000
 
 
 	INTERNAL TRANSITION in model <Controller.ObjectManager>
-		New State: <target.Dummy object at 0x1076baf00>
+		New State: <target.Dummy object at 0x1049c2b70>
 		Output Port Configuration:
 			port <port1>:
 			port <port2>:
@@ -784,7 +796,7 @@ __  Current Time:   0.000000 __________________________________________
 		Input Port Configuration:
 			port <input>:
 				(('B', 0), ('A', 1), (event name: instance_deleted; port: None; parameters: ['linkB[0]']))
-		New State: <target.Dummy object at 0x1076baf00>
+		New State: <target.Dummy object at 0x1049c2b70>
 		Next scheduled internal transition at time 0.000000
 
 
@@ -805,13 +817,14 @@ __  Current Time:   0.000000 __________________________________________
 			port <obj_manager_in>:
 				[(('B', 0), ('A', 1), (event name: instance_deleted; port: None; parameters: ['linkB[0]']))]
 			port <input>:
-			port <private_50_<narrow_cast>>:
+			port <ui>:
+			port <private_1_<narrow_cast>>:
 		New State: 
 		Next scheduled internal transition at time 0.000000
 
 
 	INTERNAL TRANSITION in model <Controller.ObjectManager>
-		New State: <target.Dummy object at 0x1076baf00>
+		New State: <target.Dummy object at 0x1049c2b70>
 		Output Port Configuration:
 			port <port1>:
 			port <port2>:

+ 28 - 15
tests/3.10) DeleteBadFromNonParent/PyDEVS/target.py

@@ -13,7 +13,7 @@ from sccd.runtime.DEVS_statecharts_core import *
 # package "Delete from Non Parent"
 
 class MainAppInstance(RuntimeClassBase):
-    def __init__(self, atomdevs, id):
+    def __init__(self, atomdevs, id, start_port_id):
         RuntimeClassBase.__init__(self, atomdevs, id)
         self.associations = {}
         self.associations["linkA"] = Association("A", 0, -1)
@@ -30,8 +30,12 @@ class MainAppInstance(RuntimeClassBase):
         
         # call user defined constructor
         MainAppInstance.user_defined_constructor(self)
-        port_name = Ports.addInputPort("<narrow_cast>", self)
+        port_name = addInputPort("ui", start_port_id, True)
         atomdevs.addInPort(port_name)
+        atomdevs.state.port_mappings[port_name] = id
+        port_name = addInputPort("<narrow_cast>", start_port_id)
+        atomdevs.addInPort(port_name)
+        atomdevs.state.port_mappings[port_name] = id
     
     def user_defined_constructor(self):
         self.assoc_name = None
@@ -134,16 +138,16 @@ class MainApp(ClassBase):
         self.glob_outputs["ui"] = self.addOutPort("ui")
         self.outputs["linkA"] = self.addOutPort("linkA")
         self.outputs["linkB"] = self.addOutPort("linkB")
-        new_instance = self.constructObject(0, [])
+        new_instance = self.constructObject(0, 0, [])
         self.state.instances[new_instance.instance_id] = new_instance
         self.state.next_instance = self.state.next_instance + 1
     
-    def constructObject(self, id, parameters):
-        new_instance = MainAppInstance(self, id)
+    def constructObject(self, id, start_port_id, parameters):
+        new_instance = MainAppInstance(self, id, start_port_id)
         return new_instance
 
 class AInstance(RuntimeClassBase):
-    def __init__(self, atomdevs, id):
+    def __init__(self, atomdevs, id, start_port_id):
         RuntimeClassBase.__init__(self, atomdevs, id)
         self.associations = {}
         self.associations["linkB"] = Association("B", 0, -1)
@@ -159,8 +163,12 @@ class AInstance(RuntimeClassBase):
         
         # call user defined constructor
         AInstance.user_defined_constructor(self)
-        port_name = Ports.addInputPort("<narrow_cast>", self)
+        port_name = addInputPort("ui", start_port_id, True)
+        atomdevs.addInPort(port_name)
+        atomdevs.state.port_mappings[port_name] = id
+        port_name = addInputPort("<narrow_cast>", start_port_id)
         atomdevs.addInPort(port_name)
+        atomdevs.state.port_mappings[port_name] = id
     
     def user_defined_constructor(self):
         pass
@@ -212,12 +220,12 @@ class A(ClassBase):
         self.glob_outputs["ui"] = self.addOutPort("ui")
         self.outputs["linkB"] = self.addOutPort("linkB")
     
-    def constructObject(self, id, parameters):
-        new_instance = AInstance(self, id)
+    def constructObject(self, id, start_port_id, parameters):
+        new_instance = AInstance(self, id, start_port_id)
         return new_instance
 
 class BInstance(RuntimeClassBase):
-    def __init__(self, atomdevs, id):
+    def __init__(self, atomdevs, id, start_port_id):
         RuntimeClassBase.__init__(self, atomdevs, id)
         self.associations = {}
         
@@ -232,8 +240,12 @@ class BInstance(RuntimeClassBase):
         
         # call user defined constructor
         BInstance.user_defined_constructor(self)
-        port_name = Ports.addInputPort("<narrow_cast>", self)
+        port_name = addInputPort("ui", start_port_id, True)
+        atomdevs.addInPort(port_name)
+        atomdevs.state.port_mappings[port_name] = id
+        port_name = addInputPort("<narrow_cast>", start_port_id)
         atomdevs.addInPort(port_name)
+        atomdevs.state.port_mappings[port_name] = id
     
     def user_defined_constructor(self):
         pass
@@ -271,8 +283,8 @@ class B(ClassBase):
         self.input = self.addInPort("input")
         self.glob_outputs["ui"] = self.addOutPort("ui")
     
-    def constructObject(self, id, parameters):
-        new_instance = BInstance(self, id)
+    def constructObject(self, id, start_port_id, parameters):
+        new_instance = BInstance(self, id, start_port_id)
         return new_instance
 
 class Dummy(ObjectManagerState):
@@ -283,13 +295,16 @@ class Dummy(ObjectManagerState):
         instance = {}
         instance["name"] = class_name
         if class_name == "MainApp":
+            self.narrow_cast_id = self.narrow_cast_id + 0
             instance["associations"] = {}
             instance["associations"]["linkA"] = Association("A", 0, -1)
             instance["associations"]["linkB"] = Association("B", 0, -1)
         elif class_name == "A":
+            self.narrow_cast_id = self.narrow_cast_id + 0
             instance["associations"] = {}
             instance["associations"]["linkB"] = Association("B", 0, -1)
         elif class_name == "B":
+            self.narrow_cast_id = self.narrow_cast_id + 0
             instance["associations"] = {}
         else:
             raise Exception("Cannot instantiate class " + class_name)
@@ -310,9 +325,7 @@ class Controller(CoupledDEVS):
     def __init__(self, name):
         CoupledDEVS.__init__(self, name)
         self.in_ui = self.addInPort("ui")
-        Ports.addInputPort("ui")
         self.out_ui = self.addOutPort("ui")
-        Ports.addOutputPort("ui")
         self.objectmanager = self.addSubModel(ObjectManager("ObjectManager"))
         self.atomics = []
         self.atomics.append(self.addSubModel(MainApp("MainApp")))

+ 71 - 56
tests/3.11) DeleteGoodFromNonParent/PyDEVS/log.txt

@@ -18,7 +18,7 @@ __  Current Time:   0.000000 __________________________________________
 
 
 	INITIAL CONDITIONS in model <Controller.ObjectManager>
-		Initial State: <target.Dummy object at 0x1076e9a30>
+		Initial State: <target.Dummy object at 0x104a9e2d0>
 		Next scheduled internal transition at time 0.000000
 
 
@@ -35,13 +35,14 @@ __  Current Time:   0.000000 __________________________________________
 			port <obj_manager_in>:
 				[(('MainApp', 0), ('MainApp', 0), (event name: start_instance; port: None; parameters: ['MainApp[0]']))]
 			port <input>:
-			port <private_52_<narrow_cast>>:
+			port <ui>:
+			port <private_0_<narrow_cast>>:
 		New State: 
 		Next scheduled internal transition at time 0.000000
 
 
 	INTERNAL TRANSITION in model <Controller.ObjectManager>
-		New State: <target.Dummy object at 0x1076e9a30>
+		New State: <target.Dummy object at 0x104a9e2d0>
 		Output Port Configuration:
 			port <port1>:
 				[(('MainApp', 0), ('MainApp', 0), (event name: start_instance; port: None; parameters: ['MainApp[0]']))]
@@ -57,7 +58,7 @@ __  Current Time:   0.000000 __________________________________________
 		Input Port Configuration:
 			port <input>:
 				(('MainApp', 0), ('MainApp', 0), (event name: instance_started; port: None; parameters: ['MainApp[0]']))
-		New State: <target.Dummy object at 0x1076e9a30>
+		New State: <target.Dummy object at 0x104a9e2d0>
 		Next scheduled internal transition at time 0.000000
 
 
@@ -79,7 +80,7 @@ __  Current Time:   0.000000 __________________________________________
 		Input Port Configuration:
 			port <input>:
 				(('MainApp', 0), None, (event name: create_instance; port: None; parameters: [0, 'linkA[0]', 'A']))
-		New State: <target.Dummy object at 0x1076e9a30>
+		New State: <target.Dummy object at 0x104a9e2d0>
 		Next scheduled internal transition at time 0.000000
 
 
@@ -100,9 +101,10 @@ __  Current Time:   0.000000 __________________________________________
 	EXTERNAL TRANSITION in model <Controller.A>
 		Input Port Configuration:
 			port <obj_manager_in>:
-				[(('MainApp', 0), ('A', 1), (event name: create_instance; port: None; parameters: [0, 'linkA[0]', 'A']))]
+				[(('MainApp', 0), ('A', 1), (event name: create_instance; port: None; parameters: [0, 1, 'linkA[0]', 'A']))]
 			port <input>:
-			port <private_53_<narrow_cast>>:
+			port <ui>:
+			port <private_1_<narrow_cast>>:
 		New State: 
 		Next scheduled internal transition at time 0.000000
 
@@ -112,18 +114,19 @@ __  Current Time:   0.000000 __________________________________________
 			port <obj_manager_in>:
 				[(('MainApp', 0), ('MainApp', 0), (event name: instance_started; port: None; parameters: ['MainApp[0]']))]
 			port <input>:
-			port <private_52_<narrow_cast>>:
+			port <ui>:
+			port <private_0_<narrow_cast>>:
 		New State: 
 		Next scheduled internal transition at time 0.000000
 
 
 	INTERNAL TRANSITION in model <Controller.ObjectManager>
-		New State: <target.Dummy object at 0x1076e9a30>
+		New State: <target.Dummy object at 0x104a9e2d0>
 		Output Port Configuration:
 			port <port1>:
 				[(('MainApp', 0), ('MainApp', 0), (event name: instance_started; port: None; parameters: ['MainApp[0]']))]
 			port <port2>:
-				[(('MainApp', 0), ('A', 1), (event name: create_instance; port: None; parameters: [0, 'linkA[0]', 'A']))]
+				[(('MainApp', 0), ('A', 1), (event name: create_instance; port: None; parameters: [0, 1, 'linkA[0]', 'A']))]
 			port <port3>:
 		Next scheduled internal transition at time inf
 
@@ -135,7 +138,7 @@ __  Current Time:   0.000000 __________________________________________
 		Input Port Configuration:
 			port <input>:
 				(('A', 1), ('MainApp', 0), (event name: instance_created; port: None; parameters: ['linkA[0]']))
-		New State: <target.Dummy object at 0x1076e9a30>
+		New State: <target.Dummy object at 0x104a9e2d0>
 		Next scheduled internal transition at time 0.000000
 
 
@@ -183,13 +186,14 @@ __  Current Time:   0.000000 __________________________________________
 			port <obj_manager_in>:
 				[(('A', 1), ('MainApp', 0), (event name: instance_created; port: None; parameters: ['linkA[0]']))]
 			port <input>:
-			port <private_52_<narrow_cast>>:
+			port <ui>:
+			port <private_0_<narrow_cast>>:
 		New State: 
 		Next scheduled internal transition at time 0.000000
 
 
 	INTERNAL TRANSITION in model <Controller.ObjectManager>
-		New State: <target.Dummy object at 0x1076e9a30>
+		New State: <target.Dummy object at 0x104a9e2d0>
 		Output Port Configuration:
 			port <port1>:
 				[(('A', 1), ('MainApp', 0), (event name: instance_created; port: None; parameters: ['linkA[0]']))]
@@ -241,7 +245,7 @@ __  Current Time:   0.000000 __________________________________________
 		Input Port Configuration:
 			port <input>:
 				(('MainApp', 0), None, (event name: start_instance; port: None; parameters: [0, 'linkA[0]']))
-		New State: <target.Dummy object at 0x1076e9a30>
+		New State: <target.Dummy object at 0x104a9e2d0>
 		Next scheduled internal transition at time 0.000000
 
 
@@ -264,13 +268,14 @@ __  Current Time:   0.000000 __________________________________________
 			port <obj_manager_in>:
 				[(('MainApp', 0), ('A', 1), (event name: start_instance; port: None; parameters: ['linkA[0]']))]
 			port <input>:
-			port <private_53_<narrow_cast>>:
+			port <ui>:
+			port <private_1_<narrow_cast>>:
 		New State: 
 		Next scheduled internal transition at time 0.000000
 
 
 	INTERNAL TRANSITION in model <Controller.ObjectManager>
-		New State: <target.Dummy object at 0x1076e9a30>
+		New State: <target.Dummy object at 0x104a9e2d0>
 		Output Port Configuration:
 			port <port1>:
 			port <port2>:
@@ -299,7 +304,7 @@ __  Current Time:   0.000000 __________________________________________
 		Input Port Configuration:
 			port <input>:
 				(('A', 1), ('MainApp', 0), (event name: instance_started; port: None; parameters: ['linkA[0]']))
-		New State: <target.Dummy object at 0x1076e9a30>
+		New State: <target.Dummy object at 0x104a9e2d0>
 		Next scheduled internal transition at time 0.000000
 
 
@@ -333,13 +338,14 @@ __  Current Time:   0.000000 __________________________________________
 			port <obj_manager_in>:
 				[(('A', 1), ('MainApp', 0), (event name: instance_started; port: None; parameters: ['linkA[0]']))]
 			port <input>:
-			port <private_52_<narrow_cast>>:
+			port <ui>:
+			port <private_0_<narrow_cast>>:
 		New State: 
 		Next scheduled internal transition at time 0.000000
 
 
 	INTERNAL TRANSITION in model <Controller.ObjectManager>
-		New State: <target.Dummy object at 0x1076e9a30>
+		New State: <target.Dummy object at 0x104a9e2d0>
 		Output Port Configuration:
 			port <port1>:
 				[(('A', 1), ('MainApp', 0), (event name: instance_started; port: None; parameters: ['linkA[0]']))]
@@ -391,7 +397,7 @@ __  Current Time:   0.000000 __________________________________________
 		Input Port Configuration:
 			port <input>:
 				(('MainApp', 0), None, (event name: create_instance; port: None; parameters: [0, 'linkB[0]', 'B']))
-		New State: <target.Dummy object at 0x1076e9a30>
+		New State: <target.Dummy object at 0x104a9e2d0>
 		Next scheduled internal transition at time 0.000000
 
 
@@ -412,20 +418,21 @@ __  Current Time:   0.000000 __________________________________________
 	EXTERNAL TRANSITION in model <Controller.B>
 		Input Port Configuration:
 			port <obj_manager_in>:
-				[(('MainApp', 0), ('B', 2), (event name: create_instance; port: None; parameters: [0, 'linkB[0]', 'B']))]
+				[(('MainApp', 0), ('B', 2), (event name: create_instance; port: None; parameters: [0, 2, 'linkB[0]', 'B']))]
 			port <input>:
-			port <private_54_<narrow_cast>>:
+			port <ui>:
+			port <private_2_<narrow_cast>>:
 		New State: 
 		Next scheduled internal transition at time 0.000000
 
 
 	INTERNAL TRANSITION in model <Controller.ObjectManager>
-		New State: <target.Dummy object at 0x1076e9a30>
+		New State: <target.Dummy object at 0x104a9e2d0>
 		Output Port Configuration:
 			port <port1>:
 			port <port2>:
 			port <port3>:
-				[(('MainApp', 0), ('B', 2), (event name: create_instance; port: None; parameters: [0, 'linkB[0]', 'B']))]
+				[(('MainApp', 0), ('B', 2), (event name: create_instance; port: None; parameters: [0, 2, 'linkB[0]', 'B']))]
 		Next scheduled internal transition at time inf
 
 
@@ -436,7 +443,7 @@ __  Current Time:   0.000000 __________________________________________
 		Input Port Configuration:
 			port <input>:
 				(('B', 2), ('MainApp', 0), (event name: instance_created; port: None; parameters: ['linkB[0]']))
-		New State: <target.Dummy object at 0x1076e9a30>
+		New State: <target.Dummy object at 0x104a9e2d0>
 		Next scheduled internal transition at time 0.000000
 
 
@@ -457,13 +464,14 @@ __  Current Time:   0.000000 __________________________________________
 			port <obj_manager_in>:
 				[(('B', 2), ('MainApp', 0), (event name: instance_created; port: None; parameters: ['linkB[0]']))]
 			port <input>:
-			port <private_52_<narrow_cast>>:
+			port <ui>:
+			port <private_0_<narrow_cast>>:
 		New State: 
 		Next scheduled internal transition at time 0.000000
 
 
 	INTERNAL TRANSITION in model <Controller.ObjectManager>
-		New State: <target.Dummy object at 0x1076e9a30>
+		New State: <target.Dummy object at 0x104a9e2d0>
 		Output Port Configuration:
 			port <port1>:
 				[(('B', 2), ('MainApp', 0), (event name: instance_created; port: None; parameters: ['linkB[0]']))]
@@ -515,7 +523,7 @@ __  Current Time:   0.000000 __________________________________________
 		Input Port Configuration:
 			port <input>:
 				(('MainApp', 0), None, (event name: start_instance; port: None; parameters: [0, 'linkB[0]']))
-		New State: <target.Dummy object at 0x1076e9a30>
+		New State: <target.Dummy object at 0x104a9e2d0>
 		Next scheduled internal transition at time 0.000000
 
 
@@ -538,13 +546,14 @@ __  Current Time:   0.000000 __________________________________________
 			port <obj_manager_in>:
 				[(('MainApp', 0), ('B', 2), (event name: start_instance; port: None; parameters: ['linkB[0]']))]
 			port <input>:
-			port <private_54_<narrow_cast>>:
+			port <ui>:
+			port <private_2_<narrow_cast>>:
 		New State: 
 		Next scheduled internal transition at time 0.000000
 
 
 	INTERNAL TRANSITION in model <Controller.ObjectManager>
-		New State: <target.Dummy object at 0x1076e9a30>
+		New State: <target.Dummy object at 0x104a9e2d0>
 		Output Port Configuration:
 			port <port1>:
 			port <port2>:
@@ -572,7 +581,7 @@ __  Current Time:   0.000000 __________________________________________
 		Input Port Configuration:
 			port <input>:
 				(('B', 2), ('MainApp', 0), (event name: instance_started; port: None; parameters: ['linkB[0]']))
-		New State: <target.Dummy object at 0x1076e9a30>
+		New State: <target.Dummy object at 0x104a9e2d0>
 		Next scheduled internal transition at time 0.000000
 
 
@@ -604,13 +613,14 @@ __  Current Time:   0.000000 __________________________________________
 			port <obj_manager_in>:
 				[(('B', 2), ('MainApp', 0), (event name: instance_started; port: None; parameters: ['linkB[0]']))]
 			port <input>:
-			port <private_52_<narrow_cast>>:
+			port <ui>:
+			port <private_0_<narrow_cast>>:
 		New State: 
 		Next scheduled internal transition at time 0.000000
 
 
 	INTERNAL TRANSITION in model <Controller.ObjectManager>
-		New State: <target.Dummy object at 0x1076e9a30>
+		New State: <target.Dummy object at 0x104a9e2d0>
 		Output Port Configuration:
 			port <port1>:
 				[(('B', 2), ('MainApp', 0), (event name: instance_started; port: None; parameters: ['linkB[0]']))]
@@ -662,7 +672,7 @@ __  Current Time:   0.000000 __________________________________________
 		Input Port Configuration:
 			port <input>:
 				(('MainApp', 0), None, (event name: associate_instance; port: None; parameters: [0, 'linkB[0]', 'linkA/linkB']))
-		New State: <target.Dummy object at 0x1076e9a30>
+		New State: <target.Dummy object at 0x104a9e2d0>
 		Next scheduled internal transition at time 0.000000
 
 
@@ -685,13 +695,14 @@ __  Current Time:   0.000000 __________________________________________
 			port <obj_manager_in>:
 				[(('MainApp', 0), ('A', 1), (event name: associate_instance; port: None; parameters: [['linkA[-1]/linkB[0]']]))]
 			port <input>:
-			port <private_53_<narrow_cast>>:
+			port <ui>:
+			port <private_1_<narrow_cast>>:
 		New State: 
 		Next scheduled internal transition at time 0.000000
 
 
 	INTERNAL TRANSITION in model <Controller.ObjectManager>
-		New State: <target.Dummy object at 0x1076e9a30>
+		New State: <target.Dummy object at 0x104a9e2d0>
 		Output Port Configuration:
 			port <port1>:
 			port <port2>:
@@ -707,7 +718,7 @@ __  Current Time:   0.000000 __________________________________________
 		Input Port Configuration:
 			port <input>:
 				(('A', 1), ('MainApp', 0), (event name: instance_associated; port: None; parameters: [['linkA[-1]/linkB[0]']]))
-		New State: <target.Dummy object at 0x1076e9a30>
+		New State: <target.Dummy object at 0x104a9e2d0>
 		Next scheduled internal transition at time 0.000000
 
 
@@ -729,13 +740,14 @@ __  Current Time:   0.000000 __________________________________________
 			port <obj_manager_in>:
 				[(('A', 1), ('MainApp', 0), (event name: instance_associated; port: None; parameters: [['linkA[-1]/linkB[0]']]))]
 			port <input>:
-			port <private_52_<narrow_cast>>:
+			port <ui>:
+			port <private_0_<narrow_cast>>:
 		New State: 
 		Next scheduled internal transition at time 0.000000
 
 
 	INTERNAL TRANSITION in model <Controller.ObjectManager>
-		New State: <target.Dummy object at 0x1076e9a30>
+		New State: <target.Dummy object at 0x104a9e2d0>
 		Output Port Configuration:
 			port <port1>:
 				[(('A', 1), ('MainApp', 0), (event name: instance_associated; port: None; parameters: [['linkA[-1]/linkB[0]']]))]
@@ -786,7 +798,7 @@ __  Current Time:   0.000000 __________________________________________
 		Input Port Configuration:
 			port <input>:
 				(('MainApp', 0), None, (event name: narrow_cast; port: None; parameters: [0, 'linkA[0]', (event name: remove; port: None)]))
-		New State: <target.Dummy object at 0x1076e9a30>
+		New State: <target.Dummy object at 0x104a9e2d0>
 		Next scheduled internal transition at time 0.000000
 
 
@@ -807,19 +819,20 @@ __  Current Time:   0.000000 __________________________________________
 	EXTERNAL TRANSITION in model <Controller.A>
 		Input Port Configuration:
 			port <obj_manager_in>:
-				[(('MainApp', 0), ('A', 1), (event name: remove; port: 0))]
+				[(('MainApp', 0), ('A', 1), (event name: remove; port: private_1_<narrow_cast>))]
 			port <input>:
-			port <private_53_<narrow_cast>>:
+			port <ui>:
+			port <private_1_<narrow_cast>>:
 		New State: 
 		Next scheduled internal transition at time 0.000000
 
 
 	INTERNAL TRANSITION in model <Controller.ObjectManager>
-		New State: <target.Dummy object at 0x1076e9a30>
+		New State: <target.Dummy object at 0x104a9e2d0>
 		Output Port Configuration:
 			port <port1>:
 			port <port2>:
-				[(('MainApp', 0), ('A', 1), (event name: remove; port: ('A', 1)))]
+				[(('MainApp', 0), ('A', 1), (event name: remove; port: private_1_<narrow_cast>))]
 			port <port3>:
 		Next scheduled internal transition at time inf
 
@@ -864,7 +877,7 @@ __  Current Time:   0.000000 __________________________________________
 		Input Port Configuration:
 			port <input>:
 				(('A', 1), None, (event name: delete_instance; port: None; parameters: [[2], 'linkB[0]']))
-		New State: <target.Dummy object at 0x1076e9a30>
+		New State: <target.Dummy object at 0x104a9e2d0>
 		Next scheduled internal transition at time 0.000000
 
 
@@ -884,20 +897,21 @@ __  Current Time:   0.000000 __________________________________________
 	EXTERNAL TRANSITION in model <Controller.B>
 		Input Port Configuration:
 			port <obj_manager_in>:
-				[(('A', 1), ('B', 0), (event name: delete_instance; port: None; parameters: [[2], 'linkB[0]']))]
+				[(('A', 1), ('B', 2), (event name: delete_instance; port: None; parameters: [[2], 'linkB[0]']))]
 			port <input>:
-			port <private_54_<narrow_cast>>:
+			port <ui>:
+			port <private_2_<narrow_cast>>:
 		New State: 
 		Next scheduled internal transition at time 0.000000
 
 
 	INTERNAL TRANSITION in model <Controller.ObjectManager>
-		New State: <target.Dummy object at 0x1076e9a30>
+		New State: <target.Dummy object at 0x104a9e2d0>
 		Output Port Configuration:
 			port <port1>:
 			port <port2>:
 			port <port3>:
-				[(('A', 1), ('B', 0), (event name: delete_instance; port: None; parameters: [[2], 'linkB[0]']))]
+				[(('A', 1), ('B', 2), (event name: delete_instance; port: None; parameters: [[2], 'linkB[0]']))]
 		Next scheduled internal transition at time inf
 
 
@@ -907,8 +921,8 @@ __  Current Time:   0.000000 __________________________________________
 	EXTERNAL TRANSITION in model <Controller.ObjectManager>
 		Input Port Configuration:
 			port <input>:
-				(('B', 0), ('A', 1), (event name: instance_deleted; port: None; parameters: ['linkB[0]']))
-		New State: <target.Dummy object at 0x1076e9a30>
+				(('B', 2), ('A', 1), (event name: instance_deleted; port: None; parameters: ['linkB[0]']))
+		New State: <target.Dummy object at 0x104a9e2d0>
 		Next scheduled internal transition at time 0.000000
 
 
@@ -916,7 +930,7 @@ __  Current Time:   0.000000 __________________________________________
 		New State: 
 		Output Port Configuration:
 			port <obj_manager_out>:
-				(('B', 0), ('A', 1), (event name: instance_deleted; port: None; parameters: ['linkB[0]']))
+				(('B', 2), ('A', 1), (event name: instance_deleted; port: None; parameters: ['linkB[0]']))
 			port <ui>:
 		Next scheduled internal transition at time inf
 
@@ -927,19 +941,20 @@ __  Current Time:   0.000000 __________________________________________
 	EXTERNAL TRANSITION in model <Controller.A>
 		Input Port Configuration:
 			port <obj_manager_in>:
-				[(('B', 0), ('A', 1), (event name: instance_deleted; port: None; parameters: ['linkB[0]']))]
+				[(('B', 2), ('A', 1), (event name: instance_deleted; port: None; parameters: ['linkB[0]']))]
 			port <input>:
-			port <private_53_<narrow_cast>>:
+			port <ui>:
+			port <private_1_<narrow_cast>>:
 		New State: 
 		Next scheduled internal transition at time 0.000000
 
 
 	INTERNAL TRANSITION in model <Controller.ObjectManager>
-		New State: <target.Dummy object at 0x1076e9a30>
+		New State: <target.Dummy object at 0x104a9e2d0>
 		Output Port Configuration:
 			port <port1>:
 			port <port2>:
-				[(('B', 0), ('A', 1), (event name: instance_deleted; port: None; parameters: ['linkB[0]']))]
+				[(('B', 2), ('A', 1), (event name: instance_deleted; port: None; parameters: ['linkB[0]']))]
 			port <port3>:
 		Next scheduled internal transition at time inf
 

+ 28 - 15
tests/3.11) DeleteGoodFromNonParent/PyDEVS/target.py

@@ -13,7 +13,7 @@ from sccd.runtime.DEVS_statecharts_core import *
 # package "Delete from Non Parent"
 
 class MainAppInstance(RuntimeClassBase):
-    def __init__(self, atomdevs, id):
+    def __init__(self, atomdevs, id, start_port_id):
         RuntimeClassBase.__init__(self, atomdevs, id)
         self.associations = {}
         self.associations["linkA"] = Association("A", 0, -1)
@@ -30,8 +30,12 @@ class MainAppInstance(RuntimeClassBase):
         
         # call user defined constructor
         MainAppInstance.user_defined_constructor(self)
-        port_name = Ports.addInputPort("<narrow_cast>", self)
+        port_name = addInputPort("ui", start_port_id, True)
         atomdevs.addInPort(port_name)
+        atomdevs.state.port_mappings[port_name] = id
+        port_name = addInputPort("<narrow_cast>", start_port_id)
+        atomdevs.addInPort(port_name)
+        atomdevs.state.port_mappings[port_name] = id
     
     def user_defined_constructor(self):
         self.assoc_name = None
@@ -147,16 +151,16 @@ class MainApp(ClassBase):
         self.glob_outputs["ui"] = self.addOutPort("ui")
         self.outputs["linkA"] = self.addOutPort("linkA")
         self.outputs["linkB"] = self.addOutPort("linkB")
-        new_instance = self.constructObject(0, [])
+        new_instance = self.constructObject(0, 0, [])
         self.state.instances[new_instance.instance_id] = new_instance
         self.state.next_instance = self.state.next_instance + 1
     
-    def constructObject(self, id, parameters):
-        new_instance = MainAppInstance(self, id)
+    def constructObject(self, id, start_port_id, parameters):
+        new_instance = MainAppInstance(self, id, start_port_id)
         return new_instance
 
 class AInstance(RuntimeClassBase):
-    def __init__(self, atomdevs, id):
+    def __init__(self, atomdevs, id, start_port_id):
         RuntimeClassBase.__init__(self, atomdevs, id)
         self.associations = {}
         self.associations["linkB"] = Association("B", 0, -1)
@@ -172,8 +176,12 @@ class AInstance(RuntimeClassBase):
         
         # call user defined constructor
         AInstance.user_defined_constructor(self)
-        port_name = Ports.addInputPort("<narrow_cast>", self)
+        port_name = addInputPort("ui", start_port_id, True)
+        atomdevs.addInPort(port_name)
+        atomdevs.state.port_mappings[port_name] = id
+        port_name = addInputPort("<narrow_cast>", start_port_id)
         atomdevs.addInPort(port_name)
+        atomdevs.state.port_mappings[port_name] = id
     
     def user_defined_constructor(self):
         pass
@@ -235,12 +243,12 @@ class A(ClassBase):
         self.glob_outputs["ui"] = self.addOutPort("ui")
         self.outputs["linkB"] = self.addOutPort("linkB")
     
-    def constructObject(self, id, parameters):
-        new_instance = AInstance(self, id)
+    def constructObject(self, id, start_port_id, parameters):
+        new_instance = AInstance(self, id, start_port_id)
         return new_instance
 
 class BInstance(RuntimeClassBase):
-    def __init__(self, atomdevs, id):
+    def __init__(self, atomdevs, id, start_port_id):
         RuntimeClassBase.__init__(self, atomdevs, id)
         self.associations = {}
         
@@ -255,8 +263,12 @@ class BInstance(RuntimeClassBase):
         
         # call user defined constructor
         BInstance.user_defined_constructor(self)
-        port_name = Ports.addInputPort("<narrow_cast>", self)
+        port_name = addInputPort("ui", start_port_id, True)
+        atomdevs.addInPort(port_name)
+        atomdevs.state.port_mappings[port_name] = id
+        port_name = addInputPort("<narrow_cast>", start_port_id)
         atomdevs.addInPort(port_name)
+        atomdevs.state.port_mappings[port_name] = id
     
     def user_defined_constructor(self):
         pass
@@ -294,8 +306,8 @@ class B(ClassBase):
         self.input = self.addInPort("input")
         self.glob_outputs["ui"] = self.addOutPort("ui")
     
-    def constructObject(self, id, parameters):
-        new_instance = BInstance(self, id)
+    def constructObject(self, id, start_port_id, parameters):
+        new_instance = BInstance(self, id, start_port_id)
         return new_instance
 
 class Dummy(ObjectManagerState):
@@ -306,13 +318,16 @@ class Dummy(ObjectManagerState):
         instance = {}
         instance["name"] = class_name
         if class_name == "MainApp":
+            self.narrow_cast_id = self.narrow_cast_id + 0
             instance["associations"] = {}
             instance["associations"]["linkA"] = Association("A", 0, -1)
             instance["associations"]["linkB"] = Association("B", 0, -1)
         elif class_name == "A":
+            self.narrow_cast_id = self.narrow_cast_id + 0
             instance["associations"] = {}
             instance["associations"]["linkB"] = Association("B", 0, -1)
         elif class_name == "B":
+            self.narrow_cast_id = self.narrow_cast_id + 0
             instance["associations"] = {}
         else:
             raise Exception("Cannot instantiate class " + class_name)
@@ -333,9 +348,7 @@ class Controller(CoupledDEVS):
     def __init__(self, name):
         CoupledDEVS.__init__(self, name)
         self.in_ui = self.addInPort("ui")
-        Ports.addInputPort("ui")
         self.out_ui = self.addOutPort("ui")
-        Ports.addOutputPort("ui")
         self.objectmanager = self.addSubModel(ObjectManager("ObjectManager"))
         self.atomics = []
         self.atomics.append(self.addSubModel(MainApp("MainApp")))

+ 63 - 49
tests/3.16) AssociateInstance/PyDEVS/log.txt

@@ -18,7 +18,7 @@ __  Current Time:   0.000000 __________________________________________
 
 
 	INITIAL CONDITIONS in model <Controller.ObjectManager>
-		Initial State: <target.Dummy object at 0x107639820>
+		Initial State: <target.Dummy object at 0x104c98170>
 		Next scheduled internal transition at time 0.000000
 
 
@@ -35,13 +35,14 @@ __  Current Time:   0.000000 __________________________________________
 			port <obj_manager_in>:
 				[(('MainApp', 0), ('MainApp', 0), (event name: start_instance; port: None; parameters: ['MainApp[0]']))]
 			port <input>:
-			port <private_55_<narrow_cast>>:
+			port <ui>:
+			port <private_0_<narrow_cast>>:
 		New State: 
 		Next scheduled internal transition at time 0.000000
 
 
 	INTERNAL TRANSITION in model <Controller.ObjectManager>
-		New State: <target.Dummy object at 0x107639820>
+		New State: <target.Dummy object at 0x104c98170>
 		Output Port Configuration:
 			port <port1>:
 				[(('MainApp', 0), ('MainApp', 0), (event name: start_instance; port: None; parameters: ['MainApp[0]']))]
@@ -57,7 +58,7 @@ __  Current Time:   0.000000 __________________________________________
 		Input Port Configuration:
 			port <input>:
 				(('MainApp', 0), ('MainApp', 0), (event name: instance_started; port: None; parameters: ['MainApp[0]']))
-		New State: <target.Dummy object at 0x107639820>
+		New State: <target.Dummy object at 0x104c98170>
 		Next scheduled internal transition at time 0.000000
 
 
@@ -79,7 +80,7 @@ __  Current Time:   0.000000 __________________________________________
 		Input Port Configuration:
 			port <input>:
 				(('MainApp', 0), None, (event name: create_instance; port: None; parameters: [0, 'linkA[0]', 'A']))
-		New State: <target.Dummy object at 0x107639820>
+		New State: <target.Dummy object at 0x104c98170>
 		Next scheduled internal transition at time 0.000000
 
 
@@ -100,9 +101,10 @@ __  Current Time:   0.000000 __________________________________________
 	EXTERNAL TRANSITION in model <Controller.A>
 		Input Port Configuration:
 			port <obj_manager_in>:
-				[(('MainApp', 0), ('A', 1), (event name: create_instance; port: None; parameters: [0, 'linkA[0]', 'A']))]
+				[(('MainApp', 0), ('A', 1), (event name: create_instance; port: None; parameters: [0, 1, 'linkA[0]', 'A']))]
 			port <input>:
-			port <private_56_<narrow_cast>>:
+			port <ui>:
+			port <private_1_<narrow_cast>>:
 		New State: 
 		Next scheduled internal transition at time 0.000000
 
@@ -112,18 +114,19 @@ __  Current Time:   0.000000 __________________________________________
 			port <obj_manager_in>:
 				[(('MainApp', 0), ('MainApp', 0), (event name: instance_started; port: None; parameters: ['MainApp[0]']))]
 			port <input>:
-			port <private_55_<narrow_cast>>:
+			port <ui>:
+			port <private_0_<narrow_cast>>:
 		New State: 
 		Next scheduled internal transition at time 0.000000
 
 
 	INTERNAL TRANSITION in model <Controller.ObjectManager>
-		New State: <target.Dummy object at 0x107639820>
+		New State: <target.Dummy object at 0x104c98170>
 		Output Port Configuration:
 			port <port1>:
 				[(('MainApp', 0), ('MainApp', 0), (event name: instance_started; port: None; parameters: ['MainApp[0]']))]
 			port <port2>:
-				[(('MainApp', 0), ('A', 1), (event name: create_instance; port: None; parameters: [0, 'linkA[0]', 'A']))]
+				[(('MainApp', 0), ('A', 1), (event name: create_instance; port: None; parameters: [0, 1, 'linkA[0]', 'A']))]
 			port <port3>:
 		Next scheduled internal transition at time inf
 
@@ -135,7 +138,7 @@ __  Current Time:   0.000000 __________________________________________
 		Input Port Configuration:
 			port <input>:
 				(('A', 1), ('MainApp', 0), (event name: instance_created; port: None; parameters: ['linkA[0]']))
-		New State: <target.Dummy object at 0x107639820>
+		New State: <target.Dummy object at 0x104c98170>
 		Next scheduled internal transition at time 0.000000
 
 
@@ -183,13 +186,14 @@ __  Current Time:   0.000000 __________________________________________
 			port <obj_manager_in>:
 				[(('A', 1), ('MainApp', 0), (event name: instance_created; port: None; parameters: ['linkA[0]']))]
 			port <input>:
-			port <private_55_<narrow_cast>>:
+			port <ui>:
+			port <private_0_<narrow_cast>>:
 		New State: 
 		Next scheduled internal transition at time 0.000000
 
 
 	INTERNAL TRANSITION in model <Controller.ObjectManager>
-		New State: <target.Dummy object at 0x107639820>
+		New State: <target.Dummy object at 0x104c98170>
 		Output Port Configuration:
 			port <port1>:
 				[(('A', 1), ('MainApp', 0), (event name: instance_created; port: None; parameters: ['linkA[0]']))]
@@ -241,7 +245,7 @@ __  Current Time:   0.000000 __________________________________________
 		Input Port Configuration:
 			port <input>:
 				(('MainApp', 0), None, (event name: start_instance; port: None; parameters: [0, 'linkA[0]']))
-		New State: <target.Dummy object at 0x107639820>
+		New State: <target.Dummy object at 0x104c98170>
 		Next scheduled internal transition at time 0.000000
 
 
@@ -264,13 +268,14 @@ __  Current Time:   0.000000 __________________________________________
 			port <obj_manager_in>:
 				[(('MainApp', 0), ('A', 1), (event name: start_instance; port: None; parameters: ['linkA[0]']))]
 			port <input>:
-			port <private_56_<narrow_cast>>:
+			port <ui>:
+			port <private_1_<narrow_cast>>:
 		New State: 
 		Next scheduled internal transition at time 0.000000
 
 
 	INTERNAL TRANSITION in model <Controller.ObjectManager>
-		New State: <target.Dummy object at 0x107639820>
+		New State: <target.Dummy object at 0x104c98170>
 		Output Port Configuration:
 			port <port1>:
 			port <port2>:
@@ -299,7 +304,7 @@ __  Current Time:   0.000000 __________________________________________
 		Input Port Configuration:
 			port <input>:
 				(('A', 1), ('MainApp', 0), (event name: instance_started; port: None; parameters: ['linkA[0]']))
-		New State: <target.Dummy object at 0x107639820>
+		New State: <target.Dummy object at 0x104c98170>
 		Next scheduled internal transition at time 0.000000
 
 
@@ -333,13 +338,14 @@ __  Current Time:   0.000000 __________________________________________
 			port <obj_manager_in>:
 				[(('A', 1), ('MainApp', 0), (event name: instance_started; port: None; parameters: ['linkA[0]']))]
 			port <input>:
-			port <private_55_<narrow_cast>>:
+			port <ui>:
+			port <private_0_<narrow_cast>>:
 		New State: 
 		Next scheduled internal transition at time 0.000000
 
 
 	INTERNAL TRANSITION in model <Controller.ObjectManager>
-		New State: <target.Dummy object at 0x107639820>
+		New State: <target.Dummy object at 0x104c98170>
 		Output Port Configuration:
 			port <port1>:
 				[(('A', 1), ('MainApp', 0), (event name: instance_started; port: None; parameters: ['linkA[0]']))]
@@ -391,7 +397,7 @@ __  Current Time:   0.000000 __________________________________________
 		Input Port Configuration:
 			port <input>:
 				(('MainApp', 0), None, (event name: create_instance; port: None; parameters: [0, 'linkB[0]', 'B']))
-		New State: <target.Dummy object at 0x107639820>
+		New State: <target.Dummy object at 0x104c98170>
 		Next scheduled internal transition at time 0.000000
 
 
@@ -412,20 +418,21 @@ __  Current Time:   0.000000 __________________________________________
 	EXTERNAL TRANSITION in model <Controller.B>
 		Input Port Configuration:
 			port <obj_manager_in>:
-				[(('MainApp', 0), ('B', 2), (event name: create_instance; port: None; parameters: [0, 'linkB[0]', 'B']))]
+				[(('MainApp', 0), ('B', 2), (event name: create_instance; port: None; parameters: [0, 2, 'linkB[0]', 'B']))]
 			port <input>:
-			port <private_57_<narrow_cast>>:
+			port <ui>:
+			port <private_2_<narrow_cast>>:
 		New State: 
 		Next scheduled internal transition at time 0.000000
 
 
 	INTERNAL TRANSITION in model <Controller.ObjectManager>
-		New State: <target.Dummy object at 0x107639820>
+		New State: <target.Dummy object at 0x104c98170>
 		Output Port Configuration:
 			port <port1>:
 			port <port2>:
 			port <port3>:
-				[(('MainApp', 0), ('B', 2), (event name: create_instance; port: None; parameters: [0, 'linkB[0]', 'B']))]
+				[(('MainApp', 0), ('B', 2), (event name: create_instance; port: None; parameters: [0, 2, 'linkB[0]', 'B']))]
 		Next scheduled internal transition at time inf
 
 
@@ -436,7 +443,7 @@ __  Current Time:   0.000000 __________________________________________
 		Input Port Configuration:
 			port <input>:
 				(('B', 2), ('MainApp', 0), (event name: instance_created; port: None; parameters: ['linkB[0]']))
-		New State: <target.Dummy object at 0x107639820>
+		New State: <target.Dummy object at 0x104c98170>
 		Next scheduled internal transition at time 0.000000
 
 
@@ -457,13 +464,14 @@ __  Current Time:   0.000000 __________________________________________
 			port <obj_manager_in>:
 				[(('B', 2), ('MainApp', 0), (event name: instance_created; port: None; parameters: ['linkB[0]']))]
 			port <input>:
-			port <private_55_<narrow_cast>>:
+			port <ui>:
+			port <private_0_<narrow_cast>>:
 		New State: 
 		Next scheduled internal transition at time 0.000000
 
 
 	INTERNAL TRANSITION in model <Controller.ObjectManager>
-		New State: <target.Dummy object at 0x107639820>
+		New State: <target.Dummy object at 0x104c98170>
 		Output Port Configuration:
 			port <port1>:
 				[(('B', 2), ('MainApp', 0), (event name: instance_created; port: None; parameters: ['linkB[0]']))]
@@ -515,7 +523,7 @@ __  Current Time:   0.000000 __________________________________________
 		Input Port Configuration:
 			port <input>:
 				(('MainApp', 0), None, (event name: start_instance; port: None; parameters: [0, 'linkB[0]']))
-		New State: <target.Dummy object at 0x107639820>
+		New State: <target.Dummy object at 0x104c98170>
 		Next scheduled internal transition at time 0.000000
 
 
@@ -538,13 +546,14 @@ __  Current Time:   0.000000 __________________________________________
 			port <obj_manager_in>:
 				[(('MainApp', 0), ('B', 2), (event name: start_instance; port: None; parameters: ['linkB[0]']))]
 			port <input>:
-			port <private_57_<narrow_cast>>:
+			port <ui>:
+			port <private_2_<narrow_cast>>:
 		New State: 
 		Next scheduled internal transition at time 0.000000
 
 
 	INTERNAL TRANSITION in model <Controller.ObjectManager>
-		New State: <target.Dummy object at 0x107639820>
+		New State: <target.Dummy object at 0x104c98170>
 		Output Port Configuration:
 			port <port1>:
 			port <port2>:
@@ -572,7 +581,7 @@ __  Current Time:   0.000000 __________________________________________
 		Input Port Configuration:
 			port <input>:
 				(('B', 2), ('MainApp', 0), (event name: instance_started; port: None; parameters: ['linkB[0]']))
-		New State: <target.Dummy object at 0x107639820>
+		New State: <target.Dummy object at 0x104c98170>
 		Next scheduled internal transition at time 0.000000
 
 
@@ -604,13 +613,14 @@ __  Current Time:   0.000000 __________________________________________
 			port <obj_manager_in>:
 				[(('B', 2), ('MainApp', 0), (event name: instance_started; port: None; parameters: ['linkB[0]']))]
 			port <input>:
-			port <private_55_<narrow_cast>>:
+			port <ui>:
+			port <private_0_<narrow_cast>>:
 		New State: 
 		Next scheduled internal transition at time 0.000000
 
 
 	INTERNAL TRANSITION in model <Controller.ObjectManager>
-		New State: <target.Dummy object at 0x107639820>
+		New State: <target.Dummy object at 0x104c98170>
 		Output Port Configuration:
 			port <port1>:
 				[(('B', 2), ('MainApp', 0), (event name: instance_started; port: None; parameters: ['linkB[0]']))]
@@ -662,7 +672,7 @@ __  Current Time:   0.000000 __________________________________________
 		Input Port Configuration:
 			port <input>:
 				(('MainApp', 0), None, (event name: associate_instance; port: None; parameters: [0, 'linkB[0]', 'linkA/linkB']))
-		New State: <target.Dummy object at 0x107639820>
+		New State: <target.Dummy object at 0x104c98170>
 		Next scheduled internal transition at time 0.000000
 
 
@@ -685,13 +695,14 @@ __  Current Time:   0.000000 __________________________________________
 			port <obj_manager_in>:
 				[(('MainApp', 0), ('A', 1), (event name: associate_instance; port: None; parameters: [['linkA[-1]/linkB[0]']]))]
 			port <input>:
-			port <private_56_<narrow_cast>>:
+			port <ui>:
+			port <private_1_<narrow_cast>>:
 		New State: 
 		Next scheduled internal transition at time 0.000000
 
 
 	INTERNAL TRANSITION in model <Controller.ObjectManager>
-		New State: <target.Dummy object at 0x107639820>
+		New State: <target.Dummy object at 0x104c98170>
 		Output Port Configuration:
 			port <port1>:
 			port <port2>:
@@ -707,7 +718,7 @@ __  Current Time:   0.000000 __________________________________________
 		Input Port Configuration:
 			port <input>:
 				(('A', 1), ('MainApp', 0), (event name: instance_associated; port: None; parameters: [['linkA[-1]/linkB[0]']]))
-		New State: <target.Dummy object at 0x107639820>
+		New State: <target.Dummy object at 0x104c98170>
 		Next scheduled internal transition at time 0.000000
 
 
@@ -729,13 +740,14 @@ __  Current Time:   0.000000 __________________________________________
 			port <obj_manager_in>:
 				[(('A', 1), ('MainApp', 0), (event name: instance_associated; port: None; parameters: [['linkA[-1]/linkB[0]']]))]
 			port <input>:
-			port <private_55_<narrow_cast>>:
+			port <ui>:
+			port <private_0_<narrow_cast>>:
 		New State: 
 		Next scheduled internal transition at time 0.000000
 
 
 	INTERNAL TRANSITION in model <Controller.ObjectManager>
-		New State: <target.Dummy object at 0x107639820>
+		New State: <target.Dummy object at 0x104c98170>
 		Output Port Configuration:
 			port <port1>:
 				[(('A', 1), ('MainApp', 0), (event name: instance_associated; port: None; parameters: [['linkA[-1]/linkB[0]']]))]
@@ -786,7 +798,7 @@ __  Current Time:   0.000000 __________________________________________
 		Input Port Configuration:
 			port <input>:
 				(('MainApp', 0), None, (event name: narrow_cast; port: None; parameters: [0, 'linkA[0]', (event name: test_link; port: None)]))
-		New State: <target.Dummy object at 0x107639820>
+		New State: <target.Dummy object at 0x104c98170>
 		Next scheduled internal transition at time 0.000000
 
 
@@ -807,19 +819,20 @@ __  Current Time:   0.000000 __________________________________________
 	EXTERNAL TRANSITION in model <Controller.A>
 		Input Port Configuration:
 			port <obj_manager_in>:
-				[(('MainApp', 0), ('A', 1), (event name: test_link; port: 0))]
+				[(('MainApp', 0), ('A', 1), (event name: test_link; port: private_1_<narrow_cast>))]
 			port <input>:
-			port <private_56_<narrow_cast>>:
+			port <ui>:
+			port <private_1_<narrow_cast>>:
 		New State: 
 		Next scheduled internal transition at time 0.000000
 
 
 	INTERNAL TRANSITION in model <Controller.ObjectManager>
-		New State: <target.Dummy object at 0x107639820>
+		New State: <target.Dummy object at 0x104c98170>
 		Output Port Configuration:
 			port <port1>:
 			port <port2>:
-				[(('MainApp', 0), ('A', 1), (event name: test_link; port: ('A', 1)))]
+				[(('MainApp', 0), ('A', 1), (event name: test_link; port: private_1_<narrow_cast>))]
 			port <port3>:
 		Next scheduled internal transition at time inf
 
@@ -864,7 +877,7 @@ __  Current Time:   0.000000 __________________________________________
 		Input Port Configuration:
 			port <input>:
 				(('A', 1), None, (event name: narrow_cast; port: None; parameters: [1, 'linkB[0]', (event name: test_new_link; port: None)]))
-		New State: <target.Dummy object at 0x107639820>
+		New State: <target.Dummy object at 0x104c98170>
 		Next scheduled internal transition at time 0.000000
 
 
@@ -884,20 +897,21 @@ __  Current Time:   0.000000 __________________________________________
 	EXTERNAL TRANSITION in model <Controller.B>
 		Input Port Configuration:
 			port <obj_manager_in>:
-				[(('A', 1), ('B', 2), (event name: test_new_link; port: 0))]
+				[(('A', 1), ('B', 2), (event name: test_new_link; port: private_2_<narrow_cast>))]
 			port <input>:
-			port <private_57_<narrow_cast>>:
+			port <ui>:
+			port <private_2_<narrow_cast>>:
 		New State: 
 		Next scheduled internal transition at time 0.000000
 
 
 	INTERNAL TRANSITION in model <Controller.ObjectManager>
-		New State: <target.Dummy object at 0x107639820>
+		New State: <target.Dummy object at 0x104c98170>
 		Output Port Configuration:
 			port <port1>:
 			port <port2>:
 			port <port3>:
-				[(('A', 1), ('B', 2), (event name: test_new_link; port: ('B', 2)))]
+				[(('A', 1), ('B', 2), (event name: test_new_link; port: private_2_<narrow_cast>))]
 		Next scheduled internal transition at time inf
 
 

+ 28 - 15
tests/3.16) AssociateInstance/PyDEVS/target.py

@@ -13,7 +13,7 @@ from sccd.runtime.DEVS_statecharts_core import *
 # package "Delete from Non Parent"
 
 class MainAppInstance(RuntimeClassBase):
-    def __init__(self, atomdevs, id):
+    def __init__(self, atomdevs, id, start_port_id):
         RuntimeClassBase.__init__(self, atomdevs, id)
         self.associations = {}
         self.associations["linkA"] = Association("A", 0, -1)
@@ -30,8 +30,12 @@ class MainAppInstance(RuntimeClassBase):
         
         # call user defined constructor
         MainAppInstance.user_defined_constructor(self)
-        port_name = Ports.addInputPort("<narrow_cast>", self)
+        port_name = addInputPort("ui", start_port_id, True)
         atomdevs.addInPort(port_name)
+        atomdevs.state.port_mappings[port_name] = id
+        port_name = addInputPort("<narrow_cast>", start_port_id)
+        atomdevs.addInPort(port_name)
+        atomdevs.state.port_mappings[port_name] = id
     
     def user_defined_constructor(self):
         self.assoc_name = None
@@ -148,16 +152,16 @@ class MainApp(ClassBase):
         self.glob_outputs["ui"] = self.addOutPort("ui")
         self.outputs["linkA"] = self.addOutPort("linkA")
         self.outputs["linkB"] = self.addOutPort("linkB")
-        new_instance = self.constructObject(0, [])
+        new_instance = self.constructObject(0, 0, [])
         self.state.instances[new_instance.instance_id] = new_instance
         self.state.next_instance = self.state.next_instance + 1
     
-    def constructObject(self, id, parameters):
-        new_instance = MainAppInstance(self, id)
+    def constructObject(self, id, start_port_id, parameters):
+        new_instance = MainAppInstance(self, id, start_port_id)
         return new_instance
 
 class AInstance(RuntimeClassBase):
-    def __init__(self, atomdevs, id):
+    def __init__(self, atomdevs, id, start_port_id):
         RuntimeClassBase.__init__(self, atomdevs, id)
         self.associations = {}
         self.associations["linkB"] = Association("B", 0, -1)
@@ -173,8 +177,12 @@ class AInstance(RuntimeClassBase):
         
         # call user defined constructor
         AInstance.user_defined_constructor(self)
-        port_name = Ports.addInputPort("<narrow_cast>", self)
+        port_name = addInputPort("ui", start_port_id, True)
+        atomdevs.addInPort(port_name)
+        atomdevs.state.port_mappings[port_name] = id
+        port_name = addInputPort("<narrow_cast>", start_port_id)
         atomdevs.addInPort(port_name)
+        atomdevs.state.port_mappings[port_name] = id
     
     def user_defined_constructor(self):
         pass
@@ -226,12 +234,12 @@ class A(ClassBase):
         self.glob_outputs["ui"] = self.addOutPort("ui")
         self.outputs["linkB"] = self.addOutPort("linkB")
     
-    def constructObject(self, id, parameters):
-        new_instance = AInstance(self, id)
+    def constructObject(self, id, start_port_id, parameters):
+        new_instance = AInstance(self, id, start_port_id)
         return new_instance
 
 class BInstance(RuntimeClassBase):
-    def __init__(self, atomdevs, id):
+    def __init__(self, atomdevs, id, start_port_id):
         RuntimeClassBase.__init__(self, atomdevs, id)
         self.associations = {}
         
@@ -246,8 +254,12 @@ class BInstance(RuntimeClassBase):
         
         # call user defined constructor
         BInstance.user_defined_constructor(self)
-        port_name = Ports.addInputPort("<narrow_cast>", self)
+        port_name = addInputPort("ui", start_port_id, True)
+        atomdevs.addInPort(port_name)
+        atomdevs.state.port_mappings[port_name] = id
+        port_name = addInputPort("<narrow_cast>", start_port_id)
         atomdevs.addInPort(port_name)
+        atomdevs.state.port_mappings[port_name] = id
     
     def user_defined_constructor(self):
         pass
@@ -298,8 +310,8 @@ class B(ClassBase):
         self.input = self.addInPort("input")
         self.glob_outputs["ui"] = self.addOutPort("ui")
     
-    def constructObject(self, id, parameters):
-        new_instance = BInstance(self, id)
+    def constructObject(self, id, start_port_id, parameters):
+        new_instance = BInstance(self, id, start_port_id)
         return new_instance
 
 class Dummy(ObjectManagerState):
@@ -310,13 +322,16 @@ class Dummy(ObjectManagerState):
         instance = {}
         instance["name"] = class_name
         if class_name == "MainApp":
+            self.narrow_cast_id = self.narrow_cast_id + 0
             instance["associations"] = {}
             instance["associations"]["linkA"] = Association("A", 0, -1)
             instance["associations"]["linkB"] = Association("B", 0, -1)
         elif class_name == "A":
+            self.narrow_cast_id = self.narrow_cast_id + 0
             instance["associations"] = {}
             instance["associations"]["linkB"] = Association("B", 0, -1)
         elif class_name == "B":
+            self.narrow_cast_id = self.narrow_cast_id + 0
             instance["associations"] = {}
         else:
             raise Exception("Cannot instantiate class " + class_name)
@@ -337,9 +352,7 @@ class Controller(CoupledDEVS):
     def __init__(self, name):
         CoupledDEVS.__init__(self, name)
         self.in_ui = self.addInPort("ui")
-        Ports.addInputPort("ui")
         self.out_ui = self.addOutPort("ui")
-        Ports.addOutputPort("ui")
         self.objectmanager = self.addSubModel(ObjectManager("ObjectManager"))
         self.atomics = []
         self.atomics.append(self.addSubModel(MainApp("MainApp")))

+ 35 - 27
tests/3.17) DissasociateInstance/PyDEVS/log.txt

@@ -13,7 +13,7 @@ __  Current Time:   0.000000 __________________________________________
 
 
 	INITIAL CONDITIONS in model <Controller.ObjectManager>
-		Initial State: <target.Dummy object at 0x107609280>
+		Initial State: <target.Dummy object at 0x104c4bec0>
 		Next scheduled internal transition at time 0.000000
 
 
@@ -30,13 +30,14 @@ __  Current Time:   0.000000 __________________________________________
 			port <obj_manager_in>:
 				[(('MainApp', 0), ('MainApp', 0), (event name: start_instance; port: None; parameters: ['MainApp[0]']))]
 			port <input>:
-			port <private_58_<narrow_cast>>:
+			port <ui>:
+			port <private_0_<narrow_cast>>:
 		New State: 
 		Next scheduled internal transition at time 0.000000
 
 
 	INTERNAL TRANSITION in model <Controller.ObjectManager>
-		New State: <target.Dummy object at 0x107609280>
+		New State: <target.Dummy object at 0x104c4bec0>
 		Output Port Configuration:
 			port <port1>:
 				[(('MainApp', 0), ('MainApp', 0), (event name: start_instance; port: None; parameters: ['MainApp[0]']))]
@@ -51,7 +52,7 @@ __  Current Time:   0.000000 __________________________________________
 		Input Port Configuration:
 			port <input>:
 				(('MainApp', 0), ('MainApp', 0), (event name: instance_started; port: None; parameters: ['MainApp[0]']))
-		New State: <target.Dummy object at 0x107609280>
+		New State: <target.Dummy object at 0x104c4bec0>
 		Next scheduled internal transition at time 0.000000
 
 
@@ -72,7 +73,7 @@ __  Current Time:   0.000000 __________________________________________
 		Input Port Configuration:
 			port <input>:
 				(('MainApp', 0), None, (event name: create_instance; port: None; parameters: [0, 'linkA[0]', 'A']))
-		New State: <target.Dummy object at 0x107609280>
+		New State: <target.Dummy object at 0x104c4bec0>
 		Next scheduled internal transition at time 0.000000
 
 
@@ -92,9 +93,10 @@ __  Current Time:   0.000000 __________________________________________
 	EXTERNAL TRANSITION in model <Controller.A>
 		Input Port Configuration:
 			port <obj_manager_in>:
-				[(('MainApp', 0), ('A', 1), (event name: create_instance; port: None; parameters: [0, 'linkA[0]', 'A']))]
+				[(('MainApp', 0), ('A', 1), (event name: create_instance; port: None; parameters: [0, 1, 'linkA[0]', 'A']))]
 			port <input>:
-			port <private_59_<narrow_cast>>:
+			port <ui>:
+			port <private_1_<narrow_cast>>:
 		New State: 
 		Next scheduled internal transition at time 0.000000
 
@@ -104,18 +106,19 @@ __  Current Time:   0.000000 __________________________________________
 			port <obj_manager_in>:
 				[(('MainApp', 0), ('MainApp', 0), (event name: instance_started; port: None; parameters: ['MainApp[0]']))]
 			port <input>:
-			port <private_58_<narrow_cast>>:
+			port <ui>:
+			port <private_0_<narrow_cast>>:
 		New State: 
 		Next scheduled internal transition at time 0.000000
 
 
 	INTERNAL TRANSITION in model <Controller.ObjectManager>
-		New State: <target.Dummy object at 0x107609280>
+		New State: <target.Dummy object at 0x104c4bec0>
 		Output Port Configuration:
 			port <port1>:
 				[(('MainApp', 0), ('MainApp', 0), (event name: instance_started; port: None; parameters: ['MainApp[0]']))]
 			port <port2>:
-				[(('MainApp', 0), ('A', 1), (event name: create_instance; port: None; parameters: [0, 'linkA[0]', 'A']))]
+				[(('MainApp', 0), ('A', 1), (event name: create_instance; port: None; parameters: [0, 1, 'linkA[0]', 'A']))]
 		Next scheduled internal transition at time inf
 
 
@@ -126,7 +129,7 @@ __  Current Time:   0.000000 __________________________________________
 		Input Port Configuration:
 			port <input>:
 				(('A', 1), ('MainApp', 0), (event name: instance_created; port: None; parameters: ['linkA[0]']))
-		New State: <target.Dummy object at 0x107609280>
+		New State: <target.Dummy object at 0x104c4bec0>
 		Next scheduled internal transition at time 0.000000
 
 
@@ -171,13 +174,14 @@ __  Current Time:   0.000000 __________________________________________
 			port <obj_manager_in>:
 				[(('A', 1), ('MainApp', 0), (event name: instance_created; port: None; parameters: ['linkA[0]']))]
 			port <input>:
-			port <private_58_<narrow_cast>>:
+			port <ui>:
+			port <private_0_<narrow_cast>>:
 		New State: 
 		Next scheduled internal transition at time 0.000000
 
 
 	INTERNAL TRANSITION in model <Controller.ObjectManager>
-		New State: <target.Dummy object at 0x107609280>
+		New State: <target.Dummy object at 0x104c4bec0>
 		Output Port Configuration:
 			port <port1>:
 				[(('A', 1), ('MainApp', 0), (event name: instance_created; port: None; parameters: ['linkA[0]']))]
@@ -226,7 +230,7 @@ __  Current Time:   0.000000 __________________________________________
 		Input Port Configuration:
 			port <input>:
 				(('MainApp', 0), None, (event name: start_instance; port: None; parameters: [0, 'linkA[0]']))
-		New State: <target.Dummy object at 0x107609280>
+		New State: <target.Dummy object at 0x104c4bec0>
 		Next scheduled internal transition at time 0.000000
 
 
@@ -248,13 +252,14 @@ __  Current Time:   0.000000 __________________________________________
 			port <obj_manager_in>:
 				[(('MainApp', 0), ('A', 1), (event name: start_instance; port: None; parameters: ['linkA[0]']))]
 			port <input>:
-			port <private_59_<narrow_cast>>:
+			port <ui>:
+			port <private_1_<narrow_cast>>:
 		New State: 
 		Next scheduled internal transition at time 0.000000
 
 
 	INTERNAL TRANSITION in model <Controller.ObjectManager>
-		New State: <target.Dummy object at 0x107609280>
+		New State: <target.Dummy object at 0x104c4bec0>
 		Output Port Configuration:
 			port <port1>:
 			port <port2>:
@@ -281,7 +286,7 @@ __  Current Time:   0.000000 __________________________________________
 		Input Port Configuration:
 			port <input>:
 				(('A', 1), ('MainApp', 0), (event name: instance_started; port: None; parameters: ['linkA[0]']))
-		New State: <target.Dummy object at 0x107609280>
+		New State: <target.Dummy object at 0x104c4bec0>
 		Next scheduled internal transition at time 0.000000
 
 
@@ -322,13 +327,14 @@ __  Current Time:   0.000000 __________________________________________
 			port <obj_manager_in>:
 				[(('A', 1), ('MainApp', 0), (event name: instance_started; port: None; parameters: ['linkA[0]']))]
 			port <input>:
-			port <private_58_<narrow_cast>>:
+			port <ui>:
+			port <private_0_<narrow_cast>>:
 		New State: 
 		Next scheduled internal transition at time 0.000000
 
 
 	INTERNAL TRANSITION in model <Controller.ObjectManager>
-		New State: <target.Dummy object at 0x107609280>
+		New State: <target.Dummy object at 0x104c4bec0>
 		Output Port Configuration:
 			port <port1>:
 				[(('A', 1), ('MainApp', 0), (event name: instance_started; port: None; parameters: ['linkA[0]']))]
@@ -377,7 +383,7 @@ __  Current Time:   0.000000 __________________________________________
 		Input Port Configuration:
 			port <input>:
 				(('MainApp', 0), None, (event name: narrow_cast; port: None; parameters: [0, 'linkA[0]', (event name: link_check; port: None; parameters: ['linkA[0]'])]))
-		New State: <target.Dummy object at 0x107609280>
+		New State: <target.Dummy object at 0x104c4bec0>
 		Next scheduled internal transition at time 0.000000
 
 
@@ -398,7 +404,7 @@ __  Current Time:   0.000000 __________________________________________
 		Input Port Configuration:
 			port <input>:
 				(('MainApp', 0), None, (event name: disassociate_instance; port: None; parameters: [0, 'linkA']))
-		New State: <target.Dummy object at 0x107609280>
+		New State: <target.Dummy object at 0x104c4bec0>
 		Next scheduled internal transition at time 0.000000
 
 
@@ -418,9 +424,10 @@ __  Current Time:   0.000000 __________________________________________
 	EXTERNAL TRANSITION in model <Controller.A>
 		Input Port Configuration:
 			port <obj_manager_in>:
-				[(('MainApp', 0), ('A', 1), (event name: link_check; port: 0; parameters: ['linkA[0]']))]
+				[(('MainApp', 0), ('A', 1), (event name: link_check; port: private_1_<narrow_cast>; parameters: ['linkA[0]']))]
 			port <input>:
-			port <private_59_<narrow_cast>>:
+			port <ui>:
+			port <private_1_<narrow_cast>>:
 		New State: 
 		Next scheduled internal transition at time 0.000000
 
@@ -430,18 +437,19 @@ __  Current Time:   0.000000 __________________________________________
 			port <obj_manager_in>:
 				[(None, ('MainApp', 0), (event name: instance_disassociated; port: None; parameters: [['linkA[0]']]))]
 			port <input>:
-			port <private_58_<narrow_cast>>:
+			port <ui>:
+			port <private_0_<narrow_cast>>:
 		New State: 
 		Next scheduled internal transition at time 0.000000
 
 
 	INTERNAL TRANSITION in model <Controller.ObjectManager>
-		New State: <target.Dummy object at 0x107609280>
+		New State: <target.Dummy object at 0x104c4bec0>
 		Output Port Configuration:
 			port <port1>:
 				[(None, ('MainApp', 0), (event name: instance_disassociated; port: None; parameters: [['linkA[0]']]))]
 			port <port2>:
-				[(('MainApp', 0), ('A', 1), (event name: link_check; port: ('A', 1); parameters: ['linkA[0]']))]
+				[(('MainApp', 0), ('A', 1), (event name: link_check; port: private_1_<narrow_cast>; parameters: ['linkA[0]']))]
 		Next scheduled internal transition at time inf
 
 
@@ -518,7 +526,7 @@ __  Current Time:   0.000000 __________________________________________
 		Input Port Configuration:
 			port <input>:
 				(('MainApp', 0), None, (event name: narrow_cast; port: None; parameters: [0, 'linkA[0]', (event name: sanity_check; port: None)]))
-		New State: <target.Dummy object at 0x107609280>
+		New State: <target.Dummy object at 0x104c4bec0>
 		Next scheduled internal transition at time inf
 
 

+ 19 - 11
tests/3.17) DissasociateInstance/PyDEVS/target.py

@@ -12,7 +12,7 @@ from sccd.runtime.DEVS_statecharts_core import *
 # package "Dissasociate an instance"
 
 class MainAppInstance(RuntimeClassBase):
-    def __init__(self, atomdevs, id):
+    def __init__(self, atomdevs, id, start_port_id):
         RuntimeClassBase.__init__(self, atomdevs, id)
         self.associations = {}
         self.associations["linkA"] = Association("A", 0, -1)
@@ -28,8 +28,12 @@ class MainAppInstance(RuntimeClassBase):
         
         # call user defined constructor
         MainAppInstance.user_defined_constructor(self)
-        port_name = Ports.addInputPort("<narrow_cast>", self)
+        port_name = addInputPort("ui", start_port_id, True)
         atomdevs.addInPort(port_name)
+        atomdevs.state.port_mappings[port_name] = id
+        port_name = addInputPort("<narrow_cast>", start_port_id)
+        atomdevs.addInPort(port_name)
+        atomdevs.state.port_mappings[port_name] = id
     
     def user_defined_constructor(self):
         self.association_name = None
@@ -120,16 +124,16 @@ class MainApp(ClassBase):
         self.input = self.addInPort("input")
         self.glob_outputs["ui"] = self.addOutPort("ui")
         self.outputs["linkA"] = self.addOutPort("linkA")
-        new_instance = self.constructObject(0, [])
+        new_instance = self.constructObject(0, 0, [])
         self.state.instances[new_instance.instance_id] = new_instance
         self.state.next_instance = self.state.next_instance + 1
     
-    def constructObject(self, id, parameters):
-        new_instance = MainAppInstance(self, id)
+    def constructObject(self, id, start_port_id, parameters):
+        new_instance = MainAppInstance(self, id, start_port_id)
         return new_instance
 
 class AInstance(RuntimeClassBase):
-    def __init__(self, atomdevs, id):
+    def __init__(self, atomdevs, id, start_port_id):
         RuntimeClassBase.__init__(self, atomdevs, id)
         self.associations = {}
         
@@ -144,8 +148,12 @@ class AInstance(RuntimeClassBase):
         
         # call user defined constructor
         AInstance.user_defined_constructor(self)
-        port_name = Ports.addInputPort("<narrow_cast>", self)
+        port_name = addInputPort("ui", start_port_id, True)
+        atomdevs.addInPort(port_name)
+        atomdevs.state.port_mappings[port_name] = id
+        port_name = addInputPort("<narrow_cast>", start_port_id)
         atomdevs.addInPort(port_name)
+        atomdevs.state.port_mappings[port_name] = id
     
     def user_defined_constructor(self):
         pass
@@ -209,8 +217,8 @@ class A(ClassBase):
         self.input = self.addInPort("input")
         self.glob_outputs["ui"] = self.addOutPort("ui")
     
-    def constructObject(self, id, parameters):
-        new_instance = AInstance(self, id)
+    def constructObject(self, id, start_port_id, parameters):
+        new_instance = AInstance(self, id, start_port_id)
         return new_instance
 
 class Dummy(ObjectManagerState):
@@ -221,9 +229,11 @@ class Dummy(ObjectManagerState):
         instance = {}
         instance["name"] = class_name
         if class_name == "MainApp":
+            self.narrow_cast_id = self.narrow_cast_id + 0
             instance["associations"] = {}
             instance["associations"]["linkA"] = Association("A", 0, -1)
         elif class_name == "A":
+            self.narrow_cast_id = self.narrow_cast_id + 0
             instance["associations"] = {}
         else:
             raise Exception("Cannot instantiate class " + class_name)
@@ -243,9 +253,7 @@ class Controller(CoupledDEVS):
     def __init__(self, name):
         CoupledDEVS.__init__(self, name)
         self.in_ui = self.addInPort("ui")
-        Ports.addInputPort("ui")
         self.out_ui = self.addOutPort("ui")
-        Ports.addOutputPort("ui")
         self.objectmanager = self.addSubModel(ObjectManager("ObjectManager"))
         self.atomics = []
         self.atomics.append(self.addSubModel(MainApp("MainApp")))

+ 9 - 9
tests/3.17) DissasociateInstance/Python/log.txt

@@ -16,15 +16,6 @@ OUTPUT EVENT to port <ui>
 OUTPUT EVENT to port <ui>
 	\Event: (event name: statechart_started_succesfully; port: ui; parameters: ['0.00'])
 
-EXIT STATE in model <A>
-		State: /state1
-
-TRANSITION FIRED in model <A>
-		Transition(/state1 -> /state2)
-
-ENTER STATE in model <A>
-		State: /state2
-
 EXIT STATE in model <MainApp>
 		State: /state2
 
@@ -37,6 +28,15 @@ ENTER STATE in model <MainApp>
 OUTPUT EVENT to port <ui>
 	\Event: (event name: instance_started_succesfully; port: ui; parameters: ['0.00', 'linkA[0]'])
 
+EXIT STATE in model <A>
+		State: /state1
+
+TRANSITION FIRED in model <A>
+		Transition(/state1 -> /state2)
+
+ENTER STATE in model <A>
+		State: /state2
+
 
 EXIT STATE in model <MainApp>
 		State: /state3

+ 0 - 1
tests/3.18) DissasociateMultiple/PyDEVS/faulty_log.txt

@@ -4,5 +4,4 @@
 0.00 (event name: statechart_started_succesfully; port: ui; parameters: ['0.00'])
 0.00 (event name: instance_started_succesfully; port: ui; parameters: ['0.00', 'linkA[1]'])
 0.00 (event name: instance_linked_succesfully; port: ui; parameters: ['0.00', 'linkA[1]'])
-0.00 (event name: instance_linked_succesfully; port: ui; parameters: ['0.00', 'linkA[1]'])
 0.00 (event name: instance_disassociated_succesfully; port: ui; parameters: ['0.00', ['linkA[0]', 'linkA[1]']])

+ 53 - 61
tests/3.18) DissasociateMultiple/PyDEVS/log.txt

@@ -13,7 +13,7 @@ __  Current Time:   0.000000 __________________________________________
 
 
 	INITIAL CONDITIONS in model <Controller.ObjectManager>
-		Initial State: <target.Dummy object at 0x10652eba0>
+		Initial State: <target.Dummy object at 0x104a9cbf0>
 		Next scheduled internal transition at time 0.000000
 
 
@@ -30,13 +30,14 @@ __  Current Time:   0.000000 __________________________________________
 			port <obj_manager_in>:
 				[(('MainApp', 0), ('MainApp', 0), (event name: start_instance; port: None; parameters: ['MainApp[0]']))]
 			port <input>:
-			port <private_60_<narrow_cast>>:
+			port <ui>:
+			port <private_0_<narrow_cast>>:
 		New State: 
 		Next scheduled internal transition at time 0.000000
 
 
 	INTERNAL TRANSITION in model <Controller.ObjectManager>
-		New State: <target.Dummy object at 0x10652eba0>
+		New State: <target.Dummy object at 0x104a9cbf0>
 		Output Port Configuration:
 			port <port1>:
 				[(('MainApp', 0), ('MainApp', 0), (event name: start_instance; port: None; parameters: ['MainApp[0]']))]
@@ -51,7 +52,7 @@ __  Current Time:   0.000000 __________________________________________
 		Input Port Configuration:
 			port <input>:
 				(('MainApp', 0), ('MainApp', 0), (event name: instance_started; port: None; parameters: ['MainApp[0]']))
-		New State: <target.Dummy object at 0x10652eba0>
+		New State: <target.Dummy object at 0x104a9cbf0>
 		Next scheduled internal transition at time 0.000000
 
 
@@ -72,7 +73,7 @@ __  Current Time:   0.000000 __________________________________________
 		Input Port Configuration:
 			port <input>:
 				(('MainApp', 0), None, (event name: create_instance; port: None; parameters: [0, 'linkA[0]', 'A']))
-		New State: <target.Dummy object at 0x10652eba0>
+		New State: <target.Dummy object at 0x104a9cbf0>
 		Next scheduled internal transition at time 0.000000
 
 
@@ -92,9 +93,10 @@ __  Current Time:   0.000000 __________________________________________
 	EXTERNAL TRANSITION in model <Controller.A>
 		Input Port Configuration:
 			port <obj_manager_in>:
-				[(('MainApp', 0), ('A', 1), (event name: create_instance; port: None; parameters: [0, 'linkA[0]', 'A']))]
+				[(('MainApp', 0), ('A', 1), (event name: create_instance; port: None; parameters: [0, 1, 'linkA[0]', 'A']))]
 			port <input>:
-			port <private_61_<narrow_cast>>:
+			port <ui>:
+			port <private_1_<narrow_cast>>:
 		New State: 
 		Next scheduled internal transition at time 0.000000
 
@@ -104,18 +106,19 @@ __  Current Time:   0.000000 __________________________________________
 			port <obj_manager_in>:
 				[(('MainApp', 0), ('MainApp', 0), (event name: instance_started; port: None; parameters: ['MainApp[0]']))]
 			port <input>:
-			port <private_60_<narrow_cast>>:
+			port <ui>:
+			port <private_0_<narrow_cast>>:
 		New State: 
 		Next scheduled internal transition at time 0.000000
 
 
 	INTERNAL TRANSITION in model <Controller.ObjectManager>
-		New State: <target.Dummy object at 0x10652eba0>
+		New State: <target.Dummy object at 0x104a9cbf0>
 		Output Port Configuration:
 			port <port1>:
 				[(('MainApp', 0), ('MainApp', 0), (event name: instance_started; port: None; parameters: ['MainApp[0]']))]
 			port <port2>:
-				[(('MainApp', 0), ('A', 1), (event name: create_instance; port: None; parameters: [0, 'linkA[0]', 'A']))]
+				[(('MainApp', 0), ('A', 1), (event name: create_instance; port: None; parameters: [0, 1, 'linkA[0]', 'A']))]
 		Next scheduled internal transition at time inf
 
 
@@ -126,7 +129,7 @@ __  Current Time:   0.000000 __________________________________________
 		Input Port Configuration:
 			port <input>:
 				(('A', 1), ('MainApp', 0), (event name: instance_created; port: None; parameters: ['linkA[0]']))
-		New State: <target.Dummy object at 0x10652eba0>
+		New State: <target.Dummy object at 0x104a9cbf0>
 		Next scheduled internal transition at time 0.000000
 
 
@@ -171,13 +174,14 @@ __  Current Time:   0.000000 __________________________________________
 			port <obj_manager_in>:
 				[(('A', 1), ('MainApp', 0), (event name: instance_created; port: None; parameters: ['linkA[0]']))]
 			port <input>:
-			port <private_60_<narrow_cast>>:
+			port <ui>:
+			port <private_0_<narrow_cast>>:
 		New State: 
 		Next scheduled internal transition at time 0.000000
 
 
 	INTERNAL TRANSITION in model <Controller.ObjectManager>
-		New State: <target.Dummy object at 0x10652eba0>
+		New State: <target.Dummy object at 0x104a9cbf0>
 		Output Port Configuration:
 			port <port1>:
 				[(('A', 1), ('MainApp', 0), (event name: instance_created; port: None; parameters: ['linkA[0]']))]
@@ -226,7 +230,7 @@ __  Current Time:   0.000000 __________________________________________
 		Input Port Configuration:
 			port <input>:
 				(('MainApp', 0), None, (event name: start_instance; port: None; parameters: [0, 'linkA[0]']))
-		New State: <target.Dummy object at 0x10652eba0>
+		New State: <target.Dummy object at 0x104a9cbf0>
 		Next scheduled internal transition at time 0.000000
 
 
@@ -247,7 +251,7 @@ __  Current Time:   0.000000 __________________________________________
 		Input Port Configuration:
 			port <input>:
 				(('MainApp', 0), None, (event name: create_instance; port: None; parameters: [0, 'linkA[1]', 'A']))
-		New State: <target.Dummy object at 0x10652eba0>
+		New State: <target.Dummy object at 0x104a9cbf0>
 		Next scheduled internal transition at time 0.000000
 
 
@@ -267,20 +271,22 @@ __  Current Time:   0.000000 __________________________________________
 	EXTERNAL TRANSITION in model <Controller.A>
 		Input Port Configuration:
 			port <obj_manager_in>:
-				[(('MainApp', 0), ('A', 1), (event name: start_instance; port: None; parameters: ['linkA[0]'])), (('MainApp', 0), ('A', 2), (event name: create_instance; port: None; parameters: [0, 'linkA[1]', 'A']))]
+				[(('MainApp', 0), ('A', 1), (event name: start_instance; port: None; parameters: ['linkA[0]'])), (('MainApp', 0), ('A', 2), (event name: create_instance; port: None; parameters: [0, 2, 'linkA[1]', 'A']))]
 			port <input>:
-			port <private_61_<narrow_cast>>:
-			port <private_62_<narrow_cast>>:
+			port <ui>:
+			port <private_1_<narrow_cast>>:
+			port <ui>:
+			port <private_2_<narrow_cast>>:
 		New State: 
 		Next scheduled internal transition at time 0.000000
 
 
 	INTERNAL TRANSITION in model <Controller.ObjectManager>
-		New State: <target.Dummy object at 0x10652eba0>
+		New State: <target.Dummy object at 0x104a9cbf0>
 		Output Port Configuration:
 			port <port1>:
 			port <port2>:
-				[(('MainApp', 0), ('A', 1), (event name: start_instance; port: None; parameters: ['linkA[0]'])), (('MainApp', 0), ('A', 2), (event name: create_instance; port: None; parameters: [0, 'linkA[1]', 'A']))]
+				[(('MainApp', 0), ('A', 1), (event name: start_instance; port: None; parameters: ['linkA[0]'])), (('MainApp', 0), ('A', 2), (event name: create_instance; port: None; parameters: [0, 2, 'linkA[1]', 'A']))]
 		Next scheduled internal transition at time inf
 
 
@@ -303,7 +309,7 @@ __  Current Time:   0.000000 __________________________________________
 		Input Port Configuration:
 			port <input>:
 				(('A', 1), ('MainApp', 0), (event name: instance_started; port: None; parameters: ['linkA[0]']))
-		New State: <target.Dummy object at 0x10652eba0>
+		New State: <target.Dummy object at 0x104a9cbf0>
 		Next scheduled internal transition at time 0.000000
 
 
@@ -323,7 +329,7 @@ __  Current Time:   0.000000 __________________________________________
 		Input Port Configuration:
 			port <input>:
 				(('A', 2), ('MainApp', 0), (event name: instance_created; port: None; parameters: ['linkA[1]']))
-		New State: <target.Dummy object at 0x10652eba0>
+		New State: <target.Dummy object at 0x104a9cbf0>
 		Next scheduled internal transition at time 0.000000
 
 
@@ -364,13 +370,14 @@ __  Current Time:   0.000000 __________________________________________
 			port <obj_manager_in>:
 				[(('A', 1), ('MainApp', 0), (event name: instance_started; port: None; parameters: ['linkA[0]'])), (('A', 2), ('MainApp', 0), (event name: instance_created; port: None; parameters: ['linkA[1]']))]
 			port <input>:
-			port <private_60_<narrow_cast>>:
+			port <ui>:
+			port <private_0_<narrow_cast>>:
 		New State: 
 		Next scheduled internal transition at time 0.000000
 
 
 	INTERNAL TRANSITION in model <Controller.ObjectManager>
-		New State: <target.Dummy object at 0x10652eba0>
+		New State: <target.Dummy object at 0x104a9cbf0>
 		Output Port Configuration:
 			port <port1>:
 				[(('A', 1), ('MainApp', 0), (event name: instance_started; port: None; parameters: ['linkA[0]'])), (('A', 2), ('MainApp', 0), (event name: instance_created; port: None; parameters: ['linkA[1]']))]
@@ -431,7 +438,7 @@ __  Current Time:   0.000000 __________________________________________
 		Input Port Configuration:
 			port <input>:
 				(('MainApp', 0), None, (event name: start_instance; port: None; parameters: [0, 'linkA[1]']))
-		New State: <target.Dummy object at 0x10652eba0>
+		New State: <target.Dummy object at 0x104a9cbf0>
 		Next scheduled internal transition at time 0.000000
 
 
@@ -453,14 +460,16 @@ __  Current Time:   0.000000 __________________________________________
 			port <obj_manager_in>:
 				[(('MainApp', 0), ('A', 2), (event name: start_instance; port: None; parameters: ['linkA[1]']))]
 			port <input>:
-			port <private_61_<narrow_cast>>:
-			port <private_62_<narrow_cast>>:
+			port <ui>:
+			port <private_1_<narrow_cast>>:
+			port <ui>:
+			port <private_2_<narrow_cast>>:
 		New State: 
 		Next scheduled internal transition at time 0.000000
 
 
 	INTERNAL TRANSITION in model <Controller.ObjectManager>
-		New State: <target.Dummy object at 0x10652eba0>
+		New State: <target.Dummy object at 0x104a9cbf0>
 		Output Port Configuration:
 			port <port1>:
 			port <port2>:
@@ -487,7 +496,7 @@ __  Current Time:   0.000000 __________________________________________
 		Input Port Configuration:
 			port <input>:
 				(('A', 2), ('MainApp', 0), (event name: instance_started; port: None; parameters: ['linkA[1]']))
-		New State: <target.Dummy object at 0x10652eba0>
+		New State: <target.Dummy object at 0x104a9cbf0>
 		Next scheduled internal transition at time 0.000000
 
 
@@ -528,13 +537,14 @@ __  Current Time:   0.000000 __________________________________________
 			port <obj_manager_in>:
 				[(('A', 2), ('MainApp', 0), (event name: instance_started; port: None; parameters: ['linkA[1]']))]
 			port <input>:
-			port <private_60_<narrow_cast>>:
+			port <ui>:
+			port <private_0_<narrow_cast>>:
 		New State: 
 		Next scheduled internal transition at time 0.000000
 
 
 	INTERNAL TRANSITION in model <Controller.ObjectManager>
-		New State: <target.Dummy object at 0x10652eba0>
+		New State: <target.Dummy object at 0x104a9cbf0>
 		Output Port Configuration:
 			port <port1>:
 				[(('A', 2), ('MainApp', 0), (event name: instance_started; port: None; parameters: ['linkA[1]']))]
@@ -583,7 +593,7 @@ __  Current Time:   0.000000 __________________________________________
 		Input Port Configuration:
 			port <input>:
 				(('MainApp', 0), None, (event name: narrow_cast; port: None; parameters: [0, 'linkA[1]', (event name: link_check; port: None; parameters: ['linkA[1]'])]))
-		New State: <target.Dummy object at 0x10652eba0>
+		New State: <target.Dummy object at 0x104a9cbf0>
 		Next scheduled internal transition at time 0.000000
 
 
@@ -604,7 +614,7 @@ __  Current Time:   0.000000 __________________________________________
 		Input Port Configuration:
 			port <input>:
 				(('MainApp', 0), None, (event name: disassociate_instance; port: None; parameters: [0, 'linkA']))
-		New State: <target.Dummy object at 0x10652eba0>
+		New State: <target.Dummy object at 0x104a9cbf0>
 		Next scheduled internal transition at time 0.000000
 
 
@@ -624,10 +634,12 @@ __  Current Time:   0.000000 __________________________________________
 	EXTERNAL TRANSITION in model <Controller.A>
 		Input Port Configuration:
 			port <obj_manager_in>:
-				[(('MainApp', 0), ('A', 2), (event name: link_check; port: 0; parameters: ['linkA[1]']))]
+				[(('MainApp', 0), ('A', 2), (event name: link_check; port: private_2_<narrow_cast>; parameters: ['linkA[1]']))]
 			port <input>:
-			port <private_61_<narrow_cast>>:
-			port <private_62_<narrow_cast>>:
+			port <ui>:
+			port <private_1_<narrow_cast>>:
+			port <ui>:
+			port <private_2_<narrow_cast>>:
 		New State: 
 		Next scheduled internal transition at time 0.000000
 
@@ -637,18 +649,19 @@ __  Current Time:   0.000000 __________________________________________
 			port <obj_manager_in>:
 				[(None, ('MainApp', 0), (event name: instance_disassociated; port: None; parameters: [['linkA[0]', 'linkA[1]']]))]
 			port <input>:
-			port <private_60_<narrow_cast>>:
+			port <ui>:
+			port <private_0_<narrow_cast>>:
 		New State: 
 		Next scheduled internal transition at time 0.000000
 
 
 	INTERNAL TRANSITION in model <Controller.ObjectManager>
-		New State: <target.Dummy object at 0x10652eba0>
+		New State: <target.Dummy object at 0x104a9cbf0>
 		Output Port Configuration:
 			port <port1>:
 				[(None, ('MainApp', 0), (event name: instance_disassociated; port: None; parameters: [['linkA[0]', 'linkA[1]']]))]
 			port <port2>:
-				[(('MainApp', 0), ('A', 2), (event name: link_check; port: ('A', 2); parameters: ['linkA[1]']))]
+				[(('MainApp', 0), ('A', 2), (event name: link_check; port: private_2_<narrow_cast>; parameters: ['linkA[1]']))]
 		Next scheduled internal transition at time inf
 
 
@@ -666,33 +679,12 @@ __  Current Time:   0.000000 __________________________________________
 			ENTER STATE in model <A>
 			State: State(2) (name: /state2)
 
-			EXIT STATE in model <A>
-			State: State(2) (name: /state2)
-
-			TRANSITION FIRED in model <A>
-			Transition(/state2 -> /state2)
-
-			ENTER STATE in model <A>
-			State: State(2) (name: /state2)
-
 		Output Port Configuration:
 			port <obj_manager_out>:
 			port <ui>:
 		Next scheduled internal transition at time 0.000000
 
 
-__  Current Time:   0.000000 __________________________________________ 
-
-
-	INTERNAL TRANSITION in model <Controller.A>
-		New State: 
-		Output Port Configuration:
-			port <obj_manager_out>:
-			port <ui>:
-				(event name: instance_linked_succesfully; port: ui; parameters: ['0.00', 'linkA[1]'])
-		Next scheduled internal transition at time 0.000000
-
-
 __  Current Time:   0.000000 __________________________________________ 
 
 
@@ -746,7 +738,7 @@ __  Current Time:   0.000000 __________________________________________
 		Input Port Configuration:
 			port <input>:
 				(('MainApp', 0), None, (event name: narrow_cast; port: None; parameters: [0, 'linkA[1]', (event name: sanity_check; port: None)]))
-		New State: <target.Dummy object at 0x10652eba0>
+		New State: <target.Dummy object at 0x104a9cbf0>
 		Next scheduled internal transition at time inf
 
 

+ 19 - 11
tests/3.18) DissasociateMultiple/PyDEVS/target.py

@@ -12,7 +12,7 @@ from sccd.runtime.DEVS_statecharts_core import *
 # package "Dissasociate multiple instances"
 
 class MainAppInstance(RuntimeClassBase):
-    def __init__(self, atomdevs, id):
+    def __init__(self, atomdevs, id, start_port_id):
         RuntimeClassBase.__init__(self, atomdevs, id)
         self.associations = {}
         self.associations["linkA"] = Association("A", 0, -1)
@@ -28,8 +28,12 @@ class MainAppInstance(RuntimeClassBase):
         
         # call user defined constructor
         MainAppInstance.user_defined_constructor(self)
-        port_name = Ports.addInputPort("<narrow_cast>", self)
+        port_name = addInputPort("ui", start_port_id, True)
         atomdevs.addInPort(port_name)
+        atomdevs.state.port_mappings[port_name] = id
+        port_name = addInputPort("<narrow_cast>", start_port_id)
+        atomdevs.addInPort(port_name)
+        atomdevs.state.port_mappings[port_name] = id
     
     def user_defined_constructor(self):
         self.association_name = None
@@ -140,16 +144,16 @@ class MainApp(ClassBase):
         self.input = self.addInPort("input")
         self.glob_outputs["ui"] = self.addOutPort("ui")
         self.outputs["linkA"] = self.addOutPort("linkA")
-        new_instance = self.constructObject(0, [])
+        new_instance = self.constructObject(0, 0, [])
         self.state.instances[new_instance.instance_id] = new_instance
         self.state.next_instance = self.state.next_instance + 1
     
-    def constructObject(self, id, parameters):
-        new_instance = MainAppInstance(self, id)
+    def constructObject(self, id, start_port_id, parameters):
+        new_instance = MainAppInstance(self, id, start_port_id)
         return new_instance
 
 class AInstance(RuntimeClassBase):
-    def __init__(self, atomdevs, id):
+    def __init__(self, atomdevs, id, start_port_id):
         RuntimeClassBase.__init__(self, atomdevs, id)
         self.associations = {}
         
@@ -164,8 +168,12 @@ class AInstance(RuntimeClassBase):
         
         # call user defined constructor
         AInstance.user_defined_constructor(self)
-        port_name = Ports.addInputPort("<narrow_cast>", self)
+        port_name = addInputPort("ui", start_port_id, True)
+        atomdevs.addInPort(port_name)
+        atomdevs.state.port_mappings[port_name] = id
+        port_name = addInputPort("<narrow_cast>", start_port_id)
         atomdevs.addInPort(port_name)
+        atomdevs.state.port_mappings[port_name] = id
     
     def user_defined_constructor(self):
         pass
@@ -229,8 +237,8 @@ class A(ClassBase):
         self.input = self.addInPort("input")
         self.glob_outputs["ui"] = self.addOutPort("ui")
     
-    def constructObject(self, id, parameters):
-        new_instance = AInstance(self, id)
+    def constructObject(self, id, start_port_id, parameters):
+        new_instance = AInstance(self, id, start_port_id)
         return new_instance
 
 class Dummy(ObjectManagerState):
@@ -241,9 +249,11 @@ class Dummy(ObjectManagerState):
         instance = {}
         instance["name"] = class_name
         if class_name == "MainApp":
+            self.narrow_cast_id = self.narrow_cast_id + 0
             instance["associations"] = {}
             instance["associations"]["linkA"] = Association("A", 0, -1)
         elif class_name == "A":
+            self.narrow_cast_id = self.narrow_cast_id + 0
             instance["associations"] = {}
         else:
             raise Exception("Cannot instantiate class " + class_name)
@@ -263,9 +273,7 @@ class Controller(CoupledDEVS):
     def __init__(self, name):
         CoupledDEVS.__init__(self, name)
         self.in_ui = self.addInPort("ui")
-        Ports.addInputPort("ui")
         self.out_ui = self.addOutPort("ui")
-        Ports.addOutputPort("ui")
         self.objectmanager = self.addSubModel(ObjectManager("ObjectManager"))
         self.atomics = []
         self.atomics.append(self.addSubModel(MainApp("MainApp")))

+ 9 - 9
tests/3.18) DissasociateMultiple/Python/log.txt

@@ -42,6 +42,15 @@ OUTPUT EVENT to port <ui>
 OUTPUT EVENT to port <ui>
 	\Event: (event name: statechart_started_succesfully; port: ui; parameters: ['0.00'])
 
+EXIT STATE in model <A>
+		State: /state1
+
+TRANSITION FIRED in model <A>
+		Transition(/state1 -> /state2)
+
+ENTER STATE in model <A>
+		State: /state2
+
 EXIT STATE in model <MainApp>
 		State: /state3
 
@@ -54,15 +63,6 @@ ENTER STATE in model <MainApp>
 OUTPUT EVENT to port <ui>
 	\Event: (event name: instance_started_succesfully; port: ui; parameters: ['0.00', 'linkA[1]'])
 
-EXIT STATE in model <A>
-		State: /state1
-
-TRANSITION FIRED in model <A>
-		Transition(/state1 -> /state2)
-
-ENTER STATE in model <A>
-		State: /state2
-
 
 EXIT STATE in model <MainApp>
 		State: /state4

+ 8 - 6
tests/3.19) (Diss)asociateFromParent/PyDEVS/log.txt

@@ -8,7 +8,7 @@ __  Current Time:   0.000000 __________________________________________
 
 
 	INITIAL CONDITIONS in model <Controller.ObjectManager>
-		Initial State: <target.Dummy object at 0x107638080>
+		Initial State: <target.Dummy object at 0x104aa1f40>
 		Next scheduled internal transition at time 0.000000
 
 
@@ -25,13 +25,14 @@ __  Current Time:   0.000000 __________________________________________
 			port <obj_manager_in>:
 				[(('MainApp', 0), ('MainApp', 0), (event name: start_instance; port: None; parameters: ['MainApp[0]']))]
 			port <input>:
-			port <private_63_<narrow_cast>>:
+			port <ui>:
+			port <private_0_<narrow_cast>>:
 		New State: 
 		Next scheduled internal transition at time 0.000000
 
 
 	INTERNAL TRANSITION in model <Controller.ObjectManager>
-		New State: <target.Dummy object at 0x107638080>
+		New State: <target.Dummy object at 0x104aa1f40>
 		Output Port Configuration:
 			port <port1>:
 				[(('MainApp', 0), ('MainApp', 0), (event name: start_instance; port: None; parameters: ['MainApp[0]']))]
@@ -45,7 +46,7 @@ __  Current Time:   0.000000 __________________________________________
 		Input Port Configuration:
 			port <input>:
 				(('MainApp', 0), ('MainApp', 0), (event name: instance_started; port: None; parameters: ['MainApp[0]']))
-		New State: <target.Dummy object at 0x107638080>
+		New State: <target.Dummy object at 0x104aa1f40>
 		Next scheduled internal transition at time 0.000000
 
 
@@ -77,13 +78,14 @@ __  Current Time:   0.000000 __________________________________________
 			port <obj_manager_in>:
 				[(('MainApp', 0), ('MainApp', 0), (event name: instance_started; port: None; parameters: ['MainApp[0]']))]
 			port <input>:
-			port <private_63_<narrow_cast>>:
+			port <ui>:
+			port <private_0_<narrow_cast>>:
 		New State: 
 		Next scheduled internal transition at time 0.000000
 
 
 	INTERNAL TRANSITION in model <Controller.ObjectManager>
-		New State: <target.Dummy object at 0x107638080>
+		New State: <target.Dummy object at 0x104aa1f40>
 		Output Port Configuration:
 			port <port1>:
 				[(('MainApp', 0), ('MainApp', 0), (event name: instance_started; port: None; parameters: ['MainApp[0]']))]

+ 10 - 7
tests/3.19) (Diss)asociateFromParent/PyDEVS/target.py

@@ -13,7 +13,7 @@ from sccd.runtime.DEVS_statecharts_core import *
 # package "Dissasociate and associate an instance"
 
 class MainAppInstance(RuntimeClassBase):
-    def __init__(self, atomdevs, id):
+    def __init__(self, atomdevs, id, start_port_id):
         RuntimeClassBase.__init__(self, atomdevs, id)
         self.associations = {}
         
@@ -28,8 +28,12 @@ class MainAppInstance(RuntimeClassBase):
         
         # call user defined constructor
         MainAppInstance.user_defined_constructor(self)
-        port_name = Ports.addInputPort("<narrow_cast>", self)
+        port_name = addInputPort("ui", start_port_id, True)
         atomdevs.addInPort(port_name)
+        atomdevs.state.port_mappings[port_name] = id
+        port_name = addInputPort("<narrow_cast>", start_port_id)
+        atomdevs.addInPort(port_name)
+        atomdevs.state.port_mappings[port_name] = id
     
     def user_defined_constructor(self):
         pass
@@ -62,12 +66,12 @@ class MainApp(ClassBase):
         ClassBase.__init__(self, name)
         self.input = self.addInPort("input")
         self.glob_outputs["ui"] = self.addOutPort("ui")
-        new_instance = self.constructObject(0, [])
+        new_instance = self.constructObject(0, 0, [])
         self.state.instances[new_instance.instance_id] = new_instance
         self.state.next_instance = self.state.next_instance + 1
     
-    def constructObject(self, id, parameters):
-        new_instance = MainAppInstance(self, id)
+    def constructObject(self, id, start_port_id, parameters):
+        new_instance = MainAppInstance(self, id, start_port_id)
         return new_instance
 
 class Dummy(ObjectManagerState):
@@ -78,6 +82,7 @@ class Dummy(ObjectManagerState):
         instance = {}
         instance["name"] = class_name
         if class_name == "MainApp":
+            self.narrow_cast_id = self.narrow_cast_id + 0
             instance["associations"] = {}
         else:
             raise Exception("Cannot instantiate class " + class_name)
@@ -96,9 +101,7 @@ class Controller(CoupledDEVS):
     def __init__(self, name):
         CoupledDEVS.__init__(self, name)
         self.in_ui = self.addInPort("ui")
-        Ports.addInputPort("ui")
         self.out_ui = self.addOutPort("ui")
-        Ports.addOutputPort("ui")
         self.objectmanager = self.addSubModel(ObjectManager("ObjectManager"))
         self.atomics = []
         self.atomics.append(self.addSubModel(MainApp("MainApp")))

+ 25 - 19
tests/3.2) ClassParameterInitialization/PyDEVS/log.txt

@@ -13,7 +13,7 @@ __  Current Time:   0.000000 __________________________________________
 
 
 	INITIAL CONDITIONS in model <Controller.ObjectManager>
-		Initial State: <target.Dummy object at 0x10652f4a0>
+		Initial State: <target.Dummy object at 0x104a4c7d0>
 		Next scheduled internal transition at time 0.000000
 
 
@@ -30,13 +30,14 @@ __  Current Time:   0.000000 __________________________________________
 			port <obj_manager_in>:
 				[(('MainApp', 0), ('MainApp', 0), (event name: start_instance; port: None; parameters: ['MainApp[0]']))]
 			port <input>:
-			port <private_21_<narrow_cast>>:
+			port <Inport>:
+			port <private_0_<narrow_cast>>:
 		New State: 
 		Next scheduled internal transition at time 0.000000
 
 
 	INTERNAL TRANSITION in model <Controller.ObjectManager>
-		New State: <target.Dummy object at 0x10652f4a0>
+		New State: <target.Dummy object at 0x104a4c7d0>
 		Output Port Configuration:
 			port <port1>:
 				[(('MainApp', 0), ('MainApp', 0), (event name: start_instance; port: None; parameters: ['MainApp[0]']))]
@@ -51,7 +52,7 @@ __  Current Time:   0.000000 __________________________________________
 		Input Port Configuration:
 			port <input>:
 				(('MainApp', 0), ('MainApp', 0), (event name: instance_started; port: None; parameters: ['MainApp[0]']))
-		New State: <target.Dummy object at 0x10652f4a0>
+		New State: <target.Dummy object at 0x104a4c7d0>
 		Next scheduled internal transition at time 0.000000
 
 
@@ -72,7 +73,7 @@ __  Current Time:   0.000000 __________________________________________
 		Input Port Configuration:
 			port <input>:
 				(('MainApp', 0), None, (event name: create_instance; port: None; parameters: [0, 'linkA[0]', 'A', 1, 3.14, 'test', [1, 2, 3], {'1': 1, '2': 2, '3': 3}]))
-		New State: <target.Dummy object at 0x10652f4a0>
+		New State: <target.Dummy object at 0x104a4c7d0>
 		Next scheduled internal transition at time 0.000000
 
 
@@ -92,9 +93,10 @@ __  Current Time:   0.000000 __________________________________________
 	EXTERNAL TRANSITION in model <Controller.A>
 		Input Port Configuration:
 			port <obj_manager_in>:
-				[(('MainApp', 0), ('A', 1), (event name: create_instance; port: None; parameters: [0, 'linkA[0]', 'A', 1, 3.14, 'test', [1, 2, 3], {'1': 1, '2': 2, '3': 3}]))]
+				[(('MainApp', 0), ('A', 1), (event name: create_instance; port: None; parameters: [0, 1, 'linkA[0]', 'A', 1, 3.14, 'test', [1, 2, 3], {'1': 1, '2': 2, '3': 3}]))]
 			port <input>:
-			port <private_22_<narrow_cast>>:
+			port <Inport>:
+			port <private_1_<narrow_cast>>:
 		New State: 
 		Next scheduled internal transition at time 0.000000
 
@@ -104,18 +106,19 @@ __  Current Time:   0.000000 __________________________________________
 			port <obj_manager_in>:
 				[(('MainApp', 0), ('MainApp', 0), (event name: instance_started; port: None; parameters: ['MainApp[0]']))]
 			port <input>:
-			port <private_21_<narrow_cast>>:
+			port <Inport>:
+			port <private_0_<narrow_cast>>:
 		New State: 
 		Next scheduled internal transition at time 0.000000
 
 
 	INTERNAL TRANSITION in model <Controller.ObjectManager>
-		New State: <target.Dummy object at 0x10652f4a0>
+		New State: <target.Dummy object at 0x104a4c7d0>
 		Output Port Configuration:
 			port <port1>:
 				[(('MainApp', 0), ('MainApp', 0), (event name: instance_started; port: None; parameters: ['MainApp[0]']))]
 			port <port2>:
-				[(('MainApp', 0), ('A', 1), (event name: create_instance; port: None; parameters: [0, 'linkA[0]', 'A', 1, 3.14, 'test', [1, 2, 3], {'1': 1, '2': 2, '3': 3}]))]
+				[(('MainApp', 0), ('A', 1), (event name: create_instance; port: None; parameters: [0, 1, 'linkA[0]', 'A', 1, 3.14, 'test', [1, 2, 3], {'1': 1, '2': 2, '3': 3}]))]
 		Next scheduled internal transition at time inf
 
 
@@ -126,7 +129,7 @@ __  Current Time:   0.000000 __________________________________________
 		Input Port Configuration:
 			port <input>:
 				(('A', 1), ('MainApp', 0), (event name: instance_created; port: None; parameters: ['linkA[0]']))
-		New State: <target.Dummy object at 0x10652f4a0>
+		New State: <target.Dummy object at 0x104a4c7d0>
 		Next scheduled internal transition at time 0.000000
 
 
@@ -171,13 +174,14 @@ __  Current Time:   0.000000 __________________________________________
 			port <obj_manager_in>:
 				[(('A', 1), ('MainApp', 0), (event name: instance_created; port: None; parameters: ['linkA[0]']))]
 			port <input>:
-			port <private_21_<narrow_cast>>:
+			port <Inport>:
+			port <private_0_<narrow_cast>>:
 		New State: 
 		Next scheduled internal transition at time 0.000000
 
 
 	INTERNAL TRANSITION in model <Controller.ObjectManager>
-		New State: <target.Dummy object at 0x10652f4a0>
+		New State: <target.Dummy object at 0x104a4c7d0>
 		Output Port Configuration:
 			port <port1>:
 				[(('A', 1), ('MainApp', 0), (event name: instance_created; port: None; parameters: ['linkA[0]']))]
@@ -226,7 +230,7 @@ __  Current Time:   0.000000 __________________________________________
 		Input Port Configuration:
 			port <input>:
 				(('MainApp', 0), None, (event name: start_instance; port: None; parameters: [0, 'linkA[0]']))
-		New State: <target.Dummy object at 0x10652f4a0>
+		New State: <target.Dummy object at 0x104a4c7d0>
 		Next scheduled internal transition at time 0.000000
 
 
@@ -248,13 +252,14 @@ __  Current Time:   0.000000 __________________________________________
 			port <obj_manager_in>:
 				[(('MainApp', 0), ('A', 1), (event name: start_instance; port: None; parameters: ['linkA[0]']))]
 			port <input>:
-			port <private_22_<narrow_cast>>:
+			port <Inport>:
+			port <private_1_<narrow_cast>>:
 		New State: 
 		Next scheduled internal transition at time 0.000000
 
 
 	INTERNAL TRANSITION in model <Controller.ObjectManager>
-		New State: <target.Dummy object at 0x10652f4a0>
+		New State: <target.Dummy object at 0x104a4c7d0>
 		Output Port Configuration:
 			port <port1>:
 			port <port2>:
@@ -293,7 +298,7 @@ __  Current Time:   0.000000 __________________________________________
 		Input Port Configuration:
 			port <input>:
 				(('A', 1), ('MainApp', 0), (event name: instance_started; port: None; parameters: ['linkA[0]']))
-		New State: <target.Dummy object at 0x10652f4a0>
+		New State: <target.Dummy object at 0x104a4c7d0>
 		Next scheduled internal transition at time 0.000000
 
 
@@ -325,13 +330,14 @@ __  Current Time:   0.000000 __________________________________________
 			port <obj_manager_in>:
 				[(('A', 1), ('MainApp', 0), (event name: instance_started; port: None; parameters: ['linkA[0]']))]
 			port <input>:
-			port <private_21_<narrow_cast>>:
+			port <Inport>:
+			port <private_0_<narrow_cast>>:
 		New State: 
 		Next scheduled internal transition at time 0.000000
 
 
 	INTERNAL TRANSITION in model <Controller.ObjectManager>
-		New State: <target.Dummy object at 0x10652f4a0>
+		New State: <target.Dummy object at 0x104a4c7d0>
 		Output Port Configuration:
 			port <port1>:
 				[(('A', 1), ('MainApp', 0), (event name: instance_started; port: None; parameters: ['linkA[0]']))]

+ 19 - 11
tests/3.2) ClassParameterInitialization/PyDEVS/target.py

@@ -12,7 +12,7 @@ from sccd.runtime.DEVS_statecharts_core import *
 # package "Create and Start Instance"
 
 class MainAppInstance(RuntimeClassBase):
-    def __init__(self, atomdevs, id):
+    def __init__(self, atomdevs, id, start_port_id):
         RuntimeClassBase.__init__(self, atomdevs, id)
         self.associations = {}
         self.associations["linkA"] = Association("A", 0, -1)
@@ -28,8 +28,12 @@ class MainAppInstance(RuntimeClassBase):
         
         # call user defined constructor
         MainAppInstance.user_defined_constructor(self)
-        port_name = Ports.addInputPort("<narrow_cast>", self)
+        port_name = addInputPort("Inport", start_port_id, True)
         atomdevs.addInPort(port_name)
+        atomdevs.state.port_mappings[port_name] = id
+        port_name = addInputPort("<narrow_cast>", start_port_id)
+        atomdevs.addInPort(port_name)
+        atomdevs.state.port_mappings[port_name] = id
     
     def user_defined_constructor(self):
         pass
@@ -92,16 +96,16 @@ class MainApp(ClassBase):
         self.input = self.addInPort("input")
         self.glob_outputs["Outport"] = self.addOutPort("Outport")
         self.outputs["linkA"] = self.addOutPort("linkA")
-        new_instance = self.constructObject(0, [])
+        new_instance = self.constructObject(0, 0, [])
         self.state.instances[new_instance.instance_id] = new_instance
         self.state.next_instance = self.state.next_instance + 1
     
-    def constructObject(self, id, parameters):
-        new_instance = MainAppInstance(self, id)
+    def constructObject(self, id, start_port_id, parameters):
+        new_instance = MainAppInstance(self, id, start_port_id)
         return new_instance
 
 class AInstance(RuntimeClassBase):
-    def __init__(self, atomdevs, id, integer, floating_point, astring, alist, adict):
+    def __init__(self, atomdevs, id, start_port_id, integer, floating_point, astring, alist, adict):
         RuntimeClassBase.__init__(self, atomdevs, id)
         self.associations = {}
         
@@ -116,8 +120,12 @@ class AInstance(RuntimeClassBase):
         
         # call user defined constructor
         AInstance.user_defined_constructor(self, integer, floating_point, astring, alist, adict)
-        port_name = Ports.addInputPort("<narrow_cast>", self)
+        port_name = addInputPort("Inport", start_port_id, True)
+        atomdevs.addInPort(port_name)
+        atomdevs.state.port_mappings[port_name] = id
+        port_name = addInputPort("<narrow_cast>", start_port_id)
         atomdevs.addInPort(port_name)
+        atomdevs.state.port_mappings[port_name] = id
     
     def user_defined_constructor(self, integer, floating_point, astring, alist, adict):
         self.integer = integer
@@ -160,8 +168,8 @@ class A(ClassBase):
         self.input = self.addInPort("input")
         self.glob_outputs["Outport"] = self.addOutPort("Outport")
     
-    def constructObject(self, id, parameters):
-        new_instance = AInstance(self, id, parameters[1], parameters[2], parameters[3], parameters[4], parameters[5])
+    def constructObject(self, id, start_port_id, parameters):
+        new_instance = AInstance(self, id, start_port_id, parameters[1], parameters[2], parameters[3], parameters[4], parameters[5])
         return new_instance
 
 class Dummy(ObjectManagerState):
@@ -172,9 +180,11 @@ class Dummy(ObjectManagerState):
         instance = {}
         instance["name"] = class_name
         if class_name == "MainApp":
+            self.narrow_cast_id = self.narrow_cast_id + 0
             instance["associations"] = {}
             instance["associations"]["linkA"] = Association("A", 0, -1)
         elif class_name == "A":
+            self.narrow_cast_id = self.narrow_cast_id + 0
             instance["associations"] = {}
         else:
             raise Exception("Cannot instantiate class " + class_name)
@@ -194,9 +204,7 @@ class Controller(CoupledDEVS):
     def __init__(self, name):
         CoupledDEVS.__init__(self, name)
         self.in_Inport = self.addInPort("Inport")
-        Ports.addInputPort("Inport")
         self.out_Outport = self.addOutPort("Outport")
-        Ports.addOutputPort("Outport")
         self.objectmanager = self.addSubModel(ObjectManager("ObjectManager"))
         self.atomics = []
         self.atomics.append(self.addSubModel(MainApp("MainApp")))

+ 8 - 6
tests/3.20) (Diss)asociateFromOther/PyDEVS/log.txt

@@ -8,7 +8,7 @@ __  Current Time:   0.000000 __________________________________________
 
 
 	INITIAL CONDITIONS in model <Controller.ObjectManager>
-		Initial State: <target.Dummy object at 0x1077630e0>
+		Initial State: <target.Dummy object at 0x104a7eb70>
 		Next scheduled internal transition at time 0.000000
 
 
@@ -25,13 +25,14 @@ __  Current Time:   0.000000 __________________________________________
 			port <obj_manager_in>:
 				[(('MainApp', 0), ('MainApp', 0), (event name: start_instance; port: None; parameters: ['MainApp[0]']))]
 			port <input>:
-			port <private_64_<narrow_cast>>:
+			port <ui>:
+			port <private_0_<narrow_cast>>:
 		New State: 
 		Next scheduled internal transition at time 0.000000
 
 
 	INTERNAL TRANSITION in model <Controller.ObjectManager>
-		New State: <target.Dummy object at 0x1077630e0>
+		New State: <target.Dummy object at 0x104a7eb70>
 		Output Port Configuration:
 			port <port1>:
 				[(('MainApp', 0), ('MainApp', 0), (event name: start_instance; port: None; parameters: ['MainApp[0]']))]
@@ -45,7 +46,7 @@ __  Current Time:   0.000000 __________________________________________
 		Input Port Configuration:
 			port <input>:
 				(('MainApp', 0), ('MainApp', 0), (event name: instance_started; port: None; parameters: ['MainApp[0]']))
-		New State: <target.Dummy object at 0x1077630e0>
+		New State: <target.Dummy object at 0x104a7eb70>
 		Next scheduled internal transition at time 0.000000
 
 
@@ -77,13 +78,14 @@ __  Current Time:   0.000000 __________________________________________
 			port <obj_manager_in>:
 				[(('MainApp', 0), ('MainApp', 0), (event name: instance_started; port: None; parameters: ['MainApp[0]']))]
 			port <input>:
-			port <private_64_<narrow_cast>>:
+			port <ui>:
+			port <private_0_<narrow_cast>>:
 		New State: 
 		Next scheduled internal transition at time 0.000000
 
 
 	INTERNAL TRANSITION in model <Controller.ObjectManager>
-		New State: <target.Dummy object at 0x1077630e0>
+		New State: <target.Dummy object at 0x104a7eb70>
 		Output Port Configuration:
 			port <port1>:
 				[(('MainApp', 0), ('MainApp', 0), (event name: instance_started; port: None; parameters: ['MainApp[0]']))]

+ 10 - 7
tests/3.20) (Diss)asociateFromOther/PyDEVS/target.py

@@ -13,7 +13,7 @@ from sccd.runtime.DEVS_statecharts_core import *
 # package "Dissasociate and associate an instance"
 
 class MainAppInstance(RuntimeClassBase):
-    def __init__(self, atomdevs, id):
+    def __init__(self, atomdevs, id, start_port_id):
         RuntimeClassBase.__init__(self, atomdevs, id)
         self.associations = {}
         
@@ -28,8 +28,12 @@ class MainAppInstance(RuntimeClassBase):
         
         # call user defined constructor
         MainAppInstance.user_defined_constructor(self)
-        port_name = Ports.addInputPort("<narrow_cast>", self)
+        port_name = addInputPort("ui", start_port_id, True)
         atomdevs.addInPort(port_name)
+        atomdevs.state.port_mappings[port_name] = id
+        port_name = addInputPort("<narrow_cast>", start_port_id)
+        atomdevs.addInPort(port_name)
+        atomdevs.state.port_mappings[port_name] = id
     
     def user_defined_constructor(self):
         self.association_name = None
@@ -62,12 +66,12 @@ class MainApp(ClassBase):
         ClassBase.__init__(self, name)
         self.input = self.addInPort("input")
         self.glob_outputs["ui"] = self.addOutPort("ui")
-        new_instance = self.constructObject(0, [])
+        new_instance = self.constructObject(0, 0, [])
         self.state.instances[new_instance.instance_id] = new_instance
         self.state.next_instance = self.state.next_instance + 1
     
-    def constructObject(self, id, parameters):
-        new_instance = MainAppInstance(self, id)
+    def constructObject(self, id, start_port_id, parameters):
+        new_instance = MainAppInstance(self, id, start_port_id)
         return new_instance
 
 class Dummy(ObjectManagerState):
@@ -78,6 +82,7 @@ class Dummy(ObjectManagerState):
         instance = {}
         instance["name"] = class_name
         if class_name == "MainApp":
+            self.narrow_cast_id = self.narrow_cast_id + 0
             instance["associations"] = {}
         else:
             raise Exception("Cannot instantiate class " + class_name)
@@ -96,9 +101,7 @@ class Controller(CoupledDEVS):
     def __init__(self, name):
         CoupledDEVS.__init__(self, name)
         self.in_ui = self.addInPort("ui")
-        Ports.addInputPort("ui")
         self.out_ui = self.addOutPort("ui")
-        Ports.addOutputPort("ui")
         self.objectmanager = self.addSubModel(ObjectManager("ObjectManager"))
         self.atomics = []
         self.atomics.append(self.addSubModel(MainApp("MainApp")))

Rozdílová data souboru nebyla zobrazena, protože soubor je příliš velký
+ 241 - 163
tests/3.3) MultipleClassInstances/PyDEVS/log.txt


+ 19 - 11
tests/3.3) MultipleClassInstances/PyDEVS/target.py

@@ -12,7 +12,7 @@ from sccd.runtime.DEVS_statecharts_core import *
 # package "Create and Start Multiple Instances Of The Same Class"
 
 class MainAppInstance(RuntimeClassBase):
-    def __init__(self, atomdevs, id):
+    def __init__(self, atomdevs, id, start_port_id):
         RuntimeClassBase.__init__(self, atomdevs, id)
         self.associations = {}
         self.associations["linkA"] = Association("A", 0, -1)
@@ -28,8 +28,12 @@ class MainAppInstance(RuntimeClassBase):
         
         # call user defined constructor
         MainAppInstance.user_defined_constructor(self)
-        port_name = Ports.addInputPort("<narrow_cast>", self)
+        port_name = addInputPort("ui", start_port_id, True)
         atomdevs.addInPort(port_name)
+        atomdevs.state.port_mappings[port_name] = id
+        port_name = addInputPort("<narrow_cast>", start_port_id)
+        atomdevs.addInPort(port_name)
+        atomdevs.state.port_mappings[port_name] = id
     
     def user_defined_constructor(self):
         self.instances = 10
@@ -111,16 +115,16 @@ class MainApp(ClassBase):
         self.input = self.addInPort("input")
         self.glob_outputs["ui"] = self.addOutPort("ui")
         self.outputs["linkA"] = self.addOutPort("linkA")
-        new_instance = self.constructObject(0, [])
+        new_instance = self.constructObject(0, 0, [])
         self.state.instances[new_instance.instance_id] = new_instance
         self.state.next_instance = self.state.next_instance + 1
     
-    def constructObject(self, id, parameters):
-        new_instance = MainAppInstance(self, id)
+    def constructObject(self, id, start_port_id, parameters):
+        new_instance = MainAppInstance(self, id, start_port_id)
         return new_instance
 
 class AInstance(RuntimeClassBase):
-    def __init__(self, atomdevs, id, instance_number):
+    def __init__(self, atomdevs, id, start_port_id, instance_number):
         RuntimeClassBase.__init__(self, atomdevs, id)
         self.associations = {}
         
@@ -135,8 +139,12 @@ class AInstance(RuntimeClassBase):
         
         # call user defined constructor
         AInstance.user_defined_constructor(self, instance_number)
-        port_name = Ports.addInputPort("<narrow_cast>", self)
+        port_name = addInputPort("ui", start_port_id, True)
+        atomdevs.addInPort(port_name)
+        atomdevs.state.port_mappings[port_name] = id
+        port_name = addInputPort("<narrow_cast>", start_port_id)
         atomdevs.addInPort(port_name)
+        atomdevs.state.port_mappings[port_name] = id
     
     def user_defined_constructor(self, instance_number):
         self.number = instance_number
@@ -175,8 +183,8 @@ class A(ClassBase):
         self.input = self.addInPort("input")
         self.glob_outputs["ui"] = self.addOutPort("ui")
     
-    def constructObject(self, id, parameters):
-        new_instance = AInstance(self, id, parameters[1])
+    def constructObject(self, id, start_port_id, parameters):
+        new_instance = AInstance(self, id, start_port_id, parameters[1])
         return new_instance
 
 class Dummy(ObjectManagerState):
@@ -187,9 +195,11 @@ class Dummy(ObjectManagerState):
         instance = {}
         instance["name"] = class_name
         if class_name == "MainApp":
+            self.narrow_cast_id = self.narrow_cast_id + 0
             instance["associations"] = {}
             instance["associations"]["linkA"] = Association("A", 0, -1)
         elif class_name == "A":
+            self.narrow_cast_id = self.narrow_cast_id + 0
             instance["associations"] = {}
         else:
             raise Exception("Cannot instantiate class " + class_name)
@@ -209,9 +219,7 @@ class Controller(CoupledDEVS):
     def __init__(self, name):
         CoupledDEVS.__init__(self, name)
         self.in_ui = self.addInPort("ui")
-        Ports.addInputPort("ui")
         self.out_ui = self.addOutPort("ui")
-        Ports.addOutputPort("ui")
         self.objectmanager = self.addSubModel(ObjectManager("ObjectManager"))
         self.atomics = []
         self.atomics.append(self.addSubModel(MainApp("MainApp")))

+ 43 - 33
tests/3.4) MultipleClasses/PyDEVS/log.txt

@@ -18,7 +18,7 @@ __  Current Time:   0.000000 __________________________________________
 
 
 	INITIAL CONDITIONS in model <Controller.ObjectManager>
-		Initial State: <target.Dummy object at 0x10652e2a0>
+		Initial State: <target.Dummy object at 0x104a7fd70>
 		Next scheduled internal transition at time 0.000000
 
 
@@ -35,13 +35,14 @@ __  Current Time:   0.000000 __________________________________________
 			port <obj_manager_in>:
 				[(('MainApp', 0), ('MainApp', 0), (event name: start_instance; port: None; parameters: ['MainApp[0]']))]
 			port <input>:
-			port <private_34_<narrow_cast>>:
+			port <ui>:
+			port <private_0_<narrow_cast>>:
 		New State: 
 		Next scheduled internal transition at time 0.000000
 
 
 	INTERNAL TRANSITION in model <Controller.ObjectManager>
-		New State: <target.Dummy object at 0x10652e2a0>
+		New State: <target.Dummy object at 0x104a7fd70>
 		Output Port Configuration:
 			port <port1>:
 				[(('MainApp', 0), ('MainApp', 0), (event name: start_instance; port: None; parameters: ['MainApp[0]']))]
@@ -57,7 +58,7 @@ __  Current Time:   0.000000 __________________________________________
 		Input Port Configuration:
 			port <input>:
 				(('MainApp', 0), ('MainApp', 0), (event name: instance_started; port: None; parameters: ['MainApp[0]']))
-		New State: <target.Dummy object at 0x10652e2a0>
+		New State: <target.Dummy object at 0x104a7fd70>
 		Next scheduled internal transition at time 0.000000
 
 
@@ -79,7 +80,7 @@ __  Current Time:   0.000000 __________________________________________
 		Input Port Configuration:
 			port <input>:
 				(('MainApp', 0), None, (event name: create_instance; port: None; parameters: [0, 'linkA[0]', 'A']))
-		New State: <target.Dummy object at 0x10652e2a0>
+		New State: <target.Dummy object at 0x104a7fd70>
 		Next scheduled internal transition at time 0.000000
 
 
@@ -100,9 +101,10 @@ __  Current Time:   0.000000 __________________________________________
 	EXTERNAL TRANSITION in model <Controller.A>
 		Input Port Configuration:
 			port <obj_manager_in>:
-				[(('MainApp', 0), ('A', 1), (event name: create_instance; port: None; parameters: [0, 'linkA[0]', 'A']))]
+				[(('MainApp', 0), ('A', 1), (event name: create_instance; port: None; parameters: [0, 1, 'linkA[0]', 'A']))]
 			port <input>:
-			port <private_35_<narrow_cast>>:
+			port <ui>:
+			port <private_1_<narrow_cast>>:
 		New State: 
 		Next scheduled internal transition at time 0.000000
 
@@ -112,18 +114,19 @@ __  Current Time:   0.000000 __________________________________________
 			port <obj_manager_in>:
 				[(('MainApp', 0), ('MainApp', 0), (event name: instance_started; port: None; parameters: ['MainApp[0]']))]
 			port <input>:
-			port <private_34_<narrow_cast>>:
+			port <ui>:
+			port <private_0_<narrow_cast>>:
 		New State: 
 		Next scheduled internal transition at time 0.000000
 
 
 	INTERNAL TRANSITION in model <Controller.ObjectManager>
-		New State: <target.Dummy object at 0x10652e2a0>
+		New State: <target.Dummy object at 0x104a7fd70>
 		Output Port Configuration:
 			port <port1>:
 				[(('MainApp', 0), ('MainApp', 0), (event name: instance_started; port: None; parameters: ['MainApp[0]']))]
 			port <port2>:
-				[(('MainApp', 0), ('A', 1), (event name: create_instance; port: None; parameters: [0, 'linkA[0]', 'A']))]
+				[(('MainApp', 0), ('A', 1), (event name: create_instance; port: None; parameters: [0, 1, 'linkA[0]', 'A']))]
 			port <port3>:
 		Next scheduled internal transition at time inf
 
@@ -135,7 +138,7 @@ __  Current Time:   0.000000 __________________________________________
 		Input Port Configuration:
 			port <input>:
 				(('A', 1), ('MainApp', 0), (event name: instance_created; port: None; parameters: ['linkA[0]']))
-		New State: <target.Dummy object at 0x10652e2a0>
+		New State: <target.Dummy object at 0x104a7fd70>
 		Next scheduled internal transition at time 0.000000
 
 
@@ -183,13 +186,14 @@ __  Current Time:   0.000000 __________________________________________
 			port <obj_manager_in>:
 				[(('A', 1), ('MainApp', 0), (event name: instance_created; port: None; parameters: ['linkA[0]']))]
 			port <input>:
-			port <private_34_<narrow_cast>>:
+			port <ui>:
+			port <private_0_<narrow_cast>>:
 		New State: 
 		Next scheduled internal transition at time 0.000000
 
 
 	INTERNAL TRANSITION in model <Controller.ObjectManager>
-		New State: <target.Dummy object at 0x10652e2a0>
+		New State: <target.Dummy object at 0x104a7fd70>
 		Output Port Configuration:
 			port <port1>:
 				[(('A', 1), ('MainApp', 0), (event name: instance_created; port: None; parameters: ['linkA[0]']))]
@@ -241,7 +245,7 @@ __  Current Time:   0.000000 __________________________________________
 		Input Port Configuration:
 			port <input>:
 				(('MainApp', 0), None, (event name: start_instance; port: None; parameters: [0, 'linkA[0]']))
-		New State: <target.Dummy object at 0x10652e2a0>
+		New State: <target.Dummy object at 0x104a7fd70>
 		Next scheduled internal transition at time 0.000000
 
 
@@ -264,13 +268,14 @@ __  Current Time:   0.000000 __________________________________________
 			port <obj_manager_in>:
 				[(('MainApp', 0), ('A', 1), (event name: start_instance; port: None; parameters: ['linkA[0]']))]
 			port <input>:
-			port <private_35_<narrow_cast>>:
+			port <ui>:
+			port <private_1_<narrow_cast>>:
 		New State: 
 		Next scheduled internal transition at time 0.000000
 
 
 	INTERNAL TRANSITION in model <Controller.ObjectManager>
-		New State: <target.Dummy object at 0x10652e2a0>
+		New State: <target.Dummy object at 0x104a7fd70>
 		Output Port Configuration:
 			port <port1>:
 			port <port2>:
@@ -299,7 +304,7 @@ __  Current Time:   0.000000 __________________________________________
 		Input Port Configuration:
 			port <input>:
 				(('A', 1), ('MainApp', 0), (event name: instance_started; port: None; parameters: ['linkA[0]']))
-		New State: <target.Dummy object at 0x10652e2a0>
+		New State: <target.Dummy object at 0x104a7fd70>
 		Next scheduled internal transition at time 0.000000
 
 
@@ -333,13 +338,14 @@ __  Current Time:   0.000000 __________________________________________
 			port <obj_manager_in>:
 				[(('A', 1), ('MainApp', 0), (event name: instance_started; port: None; parameters: ['linkA[0]']))]
 			port <input>:
-			port <private_34_<narrow_cast>>:
+			port <ui>:
+			port <private_0_<narrow_cast>>:
 		New State: 
 		Next scheduled internal transition at time 0.000000
 
 
 	INTERNAL TRANSITION in model <Controller.ObjectManager>
-		New State: <target.Dummy object at 0x10652e2a0>
+		New State: <target.Dummy object at 0x104a7fd70>
 		Output Port Configuration:
 			port <port1>:
 				[(('A', 1), ('MainApp', 0), (event name: instance_started; port: None; parameters: ['linkA[0]']))]
@@ -391,7 +397,7 @@ __  Current Time:   0.000000 __________________________________________
 		Input Port Configuration:
 			port <input>:
 				(('MainApp', 0), None, (event name: create_instance; port: None; parameters: [0, 'linkB[0]', 'B']))
-		New State: <target.Dummy object at 0x10652e2a0>
+		New State: <target.Dummy object at 0x104a7fd70>
 		Next scheduled internal transition at time 0.000000
 
 
@@ -412,20 +418,21 @@ __  Current Time:   0.000000 __________________________________________
 	EXTERNAL TRANSITION in model <Controller.B>
 		Input Port Configuration:
 			port <obj_manager_in>:
-				[(('MainApp', 0), ('B', 2), (event name: create_instance; port: None; parameters: [0, 'linkB[0]', 'B']))]
+				[(('MainApp', 0), ('B', 2), (event name: create_instance; port: None; parameters: [0, 2, 'linkB[0]', 'B']))]
 			port <input>:
-			port <private_36_<narrow_cast>>:
+			port <ui>:
+			port <private_2_<narrow_cast>>:
 		New State: 
 		Next scheduled internal transition at time 0.000000
 
 
 	INTERNAL TRANSITION in model <Controller.ObjectManager>
-		New State: <target.Dummy object at 0x10652e2a0>
+		New State: <target.Dummy object at 0x104a7fd70>
 		Output Port Configuration:
 			port <port1>:
 			port <port2>:
 			port <port3>:
-				[(('MainApp', 0), ('B', 2), (event name: create_instance; port: None; parameters: [0, 'linkB[0]', 'B']))]
+				[(('MainApp', 0), ('B', 2), (event name: create_instance; port: None; parameters: [0, 2, 'linkB[0]', 'B']))]
 		Next scheduled internal transition at time inf
 
 
@@ -436,7 +443,7 @@ __  Current Time:   0.000000 __________________________________________
 		Input Port Configuration:
 			port <input>:
 				(('B', 2), ('MainApp', 0), (event name: instance_created; port: None; parameters: ['linkB[0]']))
-		New State: <target.Dummy object at 0x10652e2a0>
+		New State: <target.Dummy object at 0x104a7fd70>
 		Next scheduled internal transition at time 0.000000
 
 
@@ -457,13 +464,14 @@ __  Current Time:   0.000000 __________________________________________
 			port <obj_manager_in>:
 				[(('B', 2), ('MainApp', 0), (event name: instance_created; port: None; parameters: ['linkB[0]']))]
 			port <input>:
-			port <private_34_<narrow_cast>>:
+			port <ui>:
+			port <private_0_<narrow_cast>>:
 		New State: 
 		Next scheduled internal transition at time 0.000000
 
 
 	INTERNAL TRANSITION in model <Controller.ObjectManager>
-		New State: <target.Dummy object at 0x10652e2a0>
+		New State: <target.Dummy object at 0x104a7fd70>
 		Output Port Configuration:
 			port <port1>:
 				[(('B', 2), ('MainApp', 0), (event name: instance_created; port: None; parameters: ['linkB[0]']))]
@@ -515,7 +523,7 @@ __  Current Time:   0.000000 __________________________________________
 		Input Port Configuration:
 			port <input>:
 				(('MainApp', 0), None, (event name: start_instance; port: None; parameters: [0, 'linkB[0]']))
-		New State: <target.Dummy object at 0x10652e2a0>
+		New State: <target.Dummy object at 0x104a7fd70>
 		Next scheduled internal transition at time 0.000000
 
 
@@ -538,13 +546,14 @@ __  Current Time:   0.000000 __________________________________________
 			port <obj_manager_in>:
 				[(('MainApp', 0), ('B', 2), (event name: start_instance; port: None; parameters: ['linkB[0]']))]
 			port <input>:
-			port <private_36_<narrow_cast>>:
+			port <ui>:
+			port <private_2_<narrow_cast>>:
 		New State: 
 		Next scheduled internal transition at time 0.000000
 
 
 	INTERNAL TRANSITION in model <Controller.ObjectManager>
-		New State: <target.Dummy object at 0x10652e2a0>
+		New State: <target.Dummy object at 0x104a7fd70>
 		Output Port Configuration:
 			port <port1>:
 			port <port2>:
@@ -572,7 +581,7 @@ __  Current Time:   0.000000 __________________________________________
 		Input Port Configuration:
 			port <input>:
 				(('B', 2), ('MainApp', 0), (event name: instance_started; port: None; parameters: ['linkB[0]']))
-		New State: <target.Dummy object at 0x10652e2a0>
+		New State: <target.Dummy object at 0x104a7fd70>
 		Next scheduled internal transition at time 0.000000
 
 
@@ -604,13 +613,14 @@ __  Current Time:   0.000000 __________________________________________
 			port <obj_manager_in>:
 				[(('B', 2), ('MainApp', 0), (event name: instance_started; port: None; parameters: ['linkB[0]']))]
 			port <input>:
-			port <private_34_<narrow_cast>>:
+			port <ui>:
+			port <private_0_<narrow_cast>>:
 		New State: 
 		Next scheduled internal transition at time 0.000000
 
 
 	INTERNAL TRANSITION in model <Controller.ObjectManager>
-		New State: <target.Dummy object at 0x10652e2a0>
+		New State: <target.Dummy object at 0x104a7fd70>
 		Output Port Configuration:
 			port <port1>:
 				[(('B', 2), ('MainApp', 0), (event name: instance_started; port: None; parameters: ['linkB[0]']))]

+ 28 - 15
tests/3.4) MultipleClasses/PyDEVS/target.py

@@ -12,7 +12,7 @@ from sccd.runtime.DEVS_statecharts_core import *
 # package "Create and Start Instance Of Multiple Classes"
 
 class MainAppInstance(RuntimeClassBase):
-    def __init__(self, atomdevs, id):
+    def __init__(self, atomdevs, id, start_port_id):
         RuntimeClassBase.__init__(self, atomdevs, id)
         self.associations = {}
         self.associations["linkA"] = Association("A", 0, -1)
@@ -29,8 +29,12 @@ class MainAppInstance(RuntimeClassBase):
         
         # call user defined constructor
         MainAppInstance.user_defined_constructor(self)
-        port_name = Ports.addInputPort("<narrow_cast>", self)
+        port_name = addInputPort("ui", start_port_id, True)
         atomdevs.addInPort(port_name)
+        atomdevs.state.port_mappings[port_name] = id
+        port_name = addInputPort("<narrow_cast>", start_port_id)
+        atomdevs.addInPort(port_name)
+        atomdevs.state.port_mappings[port_name] = id
     
     def user_defined_constructor(self):
         pass
@@ -128,16 +132,16 @@ class MainApp(ClassBase):
         self.glob_outputs["ui"] = self.addOutPort("ui")
         self.outputs["linkA"] = self.addOutPort("linkA")
         self.outputs["linkB"] = self.addOutPort("linkB")
-        new_instance = self.constructObject(0, [])
+        new_instance = self.constructObject(0, 0, [])
         self.state.instances[new_instance.instance_id] = new_instance
         self.state.next_instance = self.state.next_instance + 1
     
-    def constructObject(self, id, parameters):
-        new_instance = MainAppInstance(self, id)
+    def constructObject(self, id, start_port_id, parameters):
+        new_instance = MainAppInstance(self, id, start_port_id)
         return new_instance
 
 class AInstance(RuntimeClassBase):
-    def __init__(self, atomdevs, id):
+    def __init__(self, atomdevs, id, start_port_id):
         RuntimeClassBase.__init__(self, atomdevs, id)
         self.associations = {}
         self.associations["linkB"] = Association("B", 0, -1)
@@ -153,8 +157,12 @@ class AInstance(RuntimeClassBase):
         
         # call user defined constructor
         AInstance.user_defined_constructor(self)
-        port_name = Ports.addInputPort("<narrow_cast>", self)
+        port_name = addInputPort("ui", start_port_id, True)
+        atomdevs.addInPort(port_name)
+        atomdevs.state.port_mappings[port_name] = id
+        port_name = addInputPort("<narrow_cast>", start_port_id)
         atomdevs.addInPort(port_name)
+        atomdevs.state.port_mappings[port_name] = id
     
     def user_defined_constructor(self):
         pass
@@ -206,12 +214,12 @@ class A(ClassBase):
         self.glob_outputs["ui"] = self.addOutPort("ui")
         self.outputs["linkB"] = self.addOutPort("linkB")
     
-    def constructObject(self, id, parameters):
-        new_instance = AInstance(self, id)
+    def constructObject(self, id, start_port_id, parameters):
+        new_instance = AInstance(self, id, start_port_id)
         return new_instance
 
 class BInstance(RuntimeClassBase):
-    def __init__(self, atomdevs, id):
+    def __init__(self, atomdevs, id, start_port_id):
         RuntimeClassBase.__init__(self, atomdevs, id)
         self.associations = {}
         
@@ -226,8 +234,12 @@ class BInstance(RuntimeClassBase):
         
         # call user defined constructor
         BInstance.user_defined_constructor(self)
-        port_name = Ports.addInputPort("<narrow_cast>", self)
+        port_name = addInputPort("ui", start_port_id, True)
+        atomdevs.addInPort(port_name)
+        atomdevs.state.port_mappings[port_name] = id
+        port_name = addInputPort("<narrow_cast>", start_port_id)
         atomdevs.addInPort(port_name)
+        atomdevs.state.port_mappings[port_name] = id
     
     def user_defined_constructor(self):
         pass
@@ -278,8 +290,8 @@ class B(ClassBase):
         self.input = self.addInPort("input")
         self.glob_outputs["ui"] = self.addOutPort("ui")
     
-    def constructObject(self, id, parameters):
-        new_instance = BInstance(self, id)
+    def constructObject(self, id, start_port_id, parameters):
+        new_instance = BInstance(self, id, start_port_id)
         return new_instance
 
 class Dummy(ObjectManagerState):
@@ -290,13 +302,16 @@ class Dummy(ObjectManagerState):
         instance = {}
         instance["name"] = class_name
         if class_name == "MainApp":
+            self.narrow_cast_id = self.narrow_cast_id + 0
             instance["associations"] = {}
             instance["associations"]["linkA"] = Association("A", 0, -1)
             instance["associations"]["linkB"] = Association("B", 0, -1)
         elif class_name == "A":
+            self.narrow_cast_id = self.narrow_cast_id + 0
             instance["associations"] = {}
             instance["associations"]["linkB"] = Association("B", 0, -1)
         elif class_name == "B":
+            self.narrow_cast_id = self.narrow_cast_id + 0
             instance["associations"] = {}
         else:
             raise Exception("Cannot instantiate class " + class_name)
@@ -317,9 +332,7 @@ class Controller(CoupledDEVS):
     def __init__(self, name):
         CoupledDEVS.__init__(self, name)
         self.in_ui = self.addInPort("ui")
-        Ports.addInputPort("ui")
         self.out_ui = self.addOutPort("ui")
-        Ports.addOutputPort("ui")
         self.objectmanager = self.addSubModel(ObjectManager("ObjectManager"))
         self.atomics = []
         self.atomics.append(self.addSubModel(MainApp("MainApp")))

+ 31 - 25
tests/3.5) DeleteBeforeStarting/PyDEVS/log.txt

@@ -13,7 +13,7 @@ __  Current Time:   0.000000 __________________________________________
 
 
 	INITIAL CONDITIONS in model <Controller.ObjectManager>
-		Initial State: <target.Dummy object at 0x106374230>
+		Initial State: <target.Dummy object at 0x104a827e0>
 		Next scheduled internal transition at time 0.000000
 
 
@@ -30,13 +30,14 @@ __  Current Time:   0.000000 __________________________________________
 			port <obj_manager_in>:
 				[(('MainApp', 0), ('MainApp', 0), (event name: start_instance; port: None; parameters: ['MainApp[0]']))]
 			port <input>:
-			port <private_37_<narrow_cast>>:
+			port <ui>:
+			port <private_0_<narrow_cast>>:
 		New State: 
 		Next scheduled internal transition at time 0.000000
 
 
 	INTERNAL TRANSITION in model <Controller.ObjectManager>
-		New State: <target.Dummy object at 0x106374230>
+		New State: <target.Dummy object at 0x104a827e0>
 		Output Port Configuration:
 			port <port1>:
 				[(('MainApp', 0), ('MainApp', 0), (event name: start_instance; port: None; parameters: ['MainApp[0]']))]
@@ -51,7 +52,7 @@ __  Current Time:   0.000000 __________________________________________
 		Input Port Configuration:
 			port <input>:
 				(('MainApp', 0), ('MainApp', 0), (event name: instance_started; port: None; parameters: ['MainApp[0]']))
-		New State: <target.Dummy object at 0x106374230>
+		New State: <target.Dummy object at 0x104a827e0>
 		Next scheduled internal transition at time 0.000000
 
 
@@ -72,7 +73,7 @@ __  Current Time:   0.000000 __________________________________________
 		Input Port Configuration:
 			port <input>:
 				(('MainApp', 0), None, (event name: create_instance; port: None; parameters: [0, 'linkA[0]', 'A']))
-		New State: <target.Dummy object at 0x106374230>
+		New State: <target.Dummy object at 0x104a827e0>
 		Next scheduled internal transition at time 0.000000
 
 
@@ -92,9 +93,10 @@ __  Current Time:   0.000000 __________________________________________
 	EXTERNAL TRANSITION in model <Controller.A>
 		Input Port Configuration:
 			port <obj_manager_in>:
-				[(('MainApp', 0), ('A', 1), (event name: create_instance; port: None; parameters: [0, 'linkA[0]', 'A']))]
+				[(('MainApp', 0), ('A', 1), (event name: create_instance; port: None; parameters: [0, 1, 'linkA[0]', 'A']))]
 			port <input>:
-			port <private_38_<narrow_cast>>:
+			port <ui>:
+			port <private_1_<narrow_cast>>:
 		New State: 
 		Next scheduled internal transition at time 0.000000
 
@@ -104,18 +106,19 @@ __  Current Time:   0.000000 __________________________________________
 			port <obj_manager_in>:
 				[(('MainApp', 0), ('MainApp', 0), (event name: instance_started; port: None; parameters: ['MainApp[0]']))]
 			port <input>:
-			port <private_37_<narrow_cast>>:
+			port <ui>:
+			port <private_0_<narrow_cast>>:
 		New State: 
 		Next scheduled internal transition at time 0.000000
 
 
 	INTERNAL TRANSITION in model <Controller.ObjectManager>
-		New State: <target.Dummy object at 0x106374230>
+		New State: <target.Dummy object at 0x104a827e0>
 		Output Port Configuration:
 			port <port1>:
 				[(('MainApp', 0), ('MainApp', 0), (event name: instance_started; port: None; parameters: ['MainApp[0]']))]
 			port <port2>:
-				[(('MainApp', 0), ('A', 1), (event name: create_instance; port: None; parameters: [0, 'linkA[0]', 'A']))]
+				[(('MainApp', 0), ('A', 1), (event name: create_instance; port: None; parameters: [0, 1, 'linkA[0]', 'A']))]
 		Next scheduled internal transition at time inf
 
 
@@ -126,7 +129,7 @@ __  Current Time:   0.000000 __________________________________________
 		Input Port Configuration:
 			port <input>:
 				(('A', 1), ('MainApp', 0), (event name: instance_created; port: None; parameters: ['linkA[0]']))
-		New State: <target.Dummy object at 0x106374230>
+		New State: <target.Dummy object at 0x104a827e0>
 		Next scheduled internal transition at time 0.000000
 
 
@@ -171,13 +174,14 @@ __  Current Time:   0.000000 __________________________________________
 			port <obj_manager_in>:
 				[(('A', 1), ('MainApp', 0), (event name: instance_created; port: None; parameters: ['linkA[0]']))]
 			port <input>:
-			port <private_37_<narrow_cast>>:
+			port <ui>:
+			port <private_0_<narrow_cast>>:
 		New State: 
 		Next scheduled internal transition at time 0.000000
 
 
 	INTERNAL TRANSITION in model <Controller.ObjectManager>
-		New State: <target.Dummy object at 0x106374230>
+		New State: <target.Dummy object at 0x104a827e0>
 		Output Port Configuration:
 			port <port1>:
 				[(('A', 1), ('MainApp', 0), (event name: instance_created; port: None; parameters: ['linkA[0]']))]
@@ -226,7 +230,7 @@ __  Current Time:   0.000000 __________________________________________
 		Input Port Configuration:
 			port <input>:
 				(('MainApp', 0), None, (event name: delete_instance; port: None; parameters: [[1], 'linkA[0]']))
-		New State: <target.Dummy object at 0x106374230>
+		New State: <target.Dummy object at 0x104a827e0>
 		Next scheduled internal transition at time 0.000000
 
 
@@ -246,19 +250,20 @@ __  Current Time:   0.000000 __________________________________________
 	EXTERNAL TRANSITION in model <Controller.A>
 		Input Port Configuration:
 			port <obj_manager_in>:
-				[(('MainApp', 0), ('A', 0), (event name: delete_instance; port: None; parameters: [[1], 'linkA[0]']))]
+				[(('MainApp', 0), ('A', 1), (event name: delete_instance; port: None; parameters: [[1], 'linkA[0]']))]
 			port <input>:
-			port <private_38_<narrow_cast>>:
+			port <ui>:
+			port <private_1_<narrow_cast>>:
 		New State: 
 		Next scheduled internal transition at time 0.000000
 
 
 	INTERNAL TRANSITION in model <Controller.ObjectManager>
-		New State: <target.Dummy object at 0x106374230>
+		New State: <target.Dummy object at 0x104a827e0>
 		Output Port Configuration:
 			port <port1>:
 			port <port2>:
-				[(('MainApp', 0), ('A', 0), (event name: delete_instance; port: None; parameters: [[1], 'linkA[0]']))]
+				[(('MainApp', 0), ('A', 1), (event name: delete_instance; port: None; parameters: [[1], 'linkA[0]']))]
 		Next scheduled internal transition at time inf
 
 
@@ -268,8 +273,8 @@ __  Current Time:   0.000000 __________________________________________
 	EXTERNAL TRANSITION in model <Controller.ObjectManager>
 		Input Port Configuration:
 			port <input>:
-				(('A', 0), ('MainApp', 0), (event name: instance_deleted; port: None; parameters: ['linkA[0]']))
-		New State: <target.Dummy object at 0x106374230>
+				(('A', 1), ('MainApp', 0), (event name: instance_deleted; port: None; parameters: ['linkA[0]']))
+		New State: <target.Dummy object at 0x104a827e0>
 		Next scheduled internal transition at time 0.000000
 
 
@@ -277,7 +282,7 @@ __  Current Time:   0.000000 __________________________________________
 		New State: 
 		Output Port Configuration:
 			port <obj_manager_out>:
-				(('A', 0), ('MainApp', 0), (event name: instance_deleted; port: None; parameters: ['linkA[0]']))
+				(('A', 1), ('MainApp', 0), (event name: instance_deleted; port: None; parameters: ['linkA[0]']))
 			port <ui>:
 		Next scheduled internal transition at time inf
 
@@ -288,18 +293,19 @@ __  Current Time:   0.000000 __________________________________________
 	EXTERNAL TRANSITION in model <Controller.MainApp>
 		Input Port Configuration:
 			port <obj_manager_in>:
-				[(('A', 0), ('MainApp', 0), (event name: instance_deleted; port: None; parameters: ['linkA[0]']))]
+				[(('A', 1), ('MainApp', 0), (event name: instance_deleted; port: None; parameters: ['linkA[0]']))]
 			port <input>:
-			port <private_37_<narrow_cast>>:
+			port <ui>:
+			port <private_0_<narrow_cast>>:
 		New State: 
 		Next scheduled internal transition at time 0.000000
 
 
 	INTERNAL TRANSITION in model <Controller.ObjectManager>
-		New State: <target.Dummy object at 0x106374230>
+		New State: <target.Dummy object at 0x104a827e0>
 		Output Port Configuration:
 			port <port1>:
-				[(('A', 0), ('MainApp', 0), (event name: instance_deleted; port: None; parameters: ['linkA[0]']))]
+				[(('A', 1), ('MainApp', 0), (event name: instance_deleted; port: None; parameters: ['linkA[0]']))]
 			port <port2>:
 		Next scheduled internal transition at time inf
 

+ 19 - 11
tests/3.5) DeleteBeforeStarting/PyDEVS/target.py

@@ -12,7 +12,7 @@ from sccd.runtime.DEVS_statecharts_core import *
 # package "Create and Delete an Instance (other than the MainApp)"
 
 class MainAppInstance(RuntimeClassBase):
-    def __init__(self, atomdevs, id):
+    def __init__(self, atomdevs, id, start_port_id):
         RuntimeClassBase.__init__(self, atomdevs, id)
         self.associations = {}
         self.associations["linkA"] = Association("A", 0, -1)
@@ -28,8 +28,12 @@ class MainAppInstance(RuntimeClassBase):
         
         # call user defined constructor
         MainAppInstance.user_defined_constructor(self)
-        port_name = Ports.addInputPort("<narrow_cast>", self)
+        port_name = addInputPort("ui", start_port_id, True)
         atomdevs.addInPort(port_name)
+        atomdevs.state.port_mappings[port_name] = id
+        port_name = addInputPort("<narrow_cast>", start_port_id)
+        atomdevs.addInPort(port_name)
+        atomdevs.state.port_mappings[port_name] = id
     
     def user_defined_constructor(self):
         pass
@@ -92,16 +96,16 @@ class MainApp(ClassBase):
         self.input = self.addInPort("input")
         self.glob_outputs["ui"] = self.addOutPort("ui")
         self.outputs["linkA"] = self.addOutPort("linkA")
-        new_instance = self.constructObject(0, [])
+        new_instance = self.constructObject(0, 0, [])
         self.state.instances[new_instance.instance_id] = new_instance
         self.state.next_instance = self.state.next_instance + 1
     
-    def constructObject(self, id, parameters):
-        new_instance = MainAppInstance(self, id)
+    def constructObject(self, id, start_port_id, parameters):
+        new_instance = MainAppInstance(self, id, start_port_id)
         return new_instance
 
 class AInstance(RuntimeClassBase):
-    def __init__(self, atomdevs, id):
+    def __init__(self, atomdevs, id, start_port_id):
         RuntimeClassBase.__init__(self, atomdevs, id)
         self.associations = {}
         
@@ -116,8 +120,12 @@ class AInstance(RuntimeClassBase):
         
         # call user defined constructor
         AInstance.user_defined_constructor(self)
-        port_name = Ports.addInputPort("<narrow_cast>", self)
+        port_name = addInputPort("ui", start_port_id, True)
+        atomdevs.addInPort(port_name)
+        atomdevs.state.port_mappings[port_name] = id
+        port_name = addInputPort("<narrow_cast>", start_port_id)
         atomdevs.addInPort(port_name)
+        atomdevs.state.port_mappings[port_name] = id
     
     def user_defined_constructor(self):
         pass
@@ -155,8 +163,8 @@ class A(ClassBase):
         self.input = self.addInPort("input")
         self.glob_outputs["ui"] = self.addOutPort("ui")
     
-    def constructObject(self, id, parameters):
-        new_instance = AInstance(self, id)
+    def constructObject(self, id, start_port_id, parameters):
+        new_instance = AInstance(self, id, start_port_id)
         return new_instance
 
 class Dummy(ObjectManagerState):
@@ -167,9 +175,11 @@ class Dummy(ObjectManagerState):
         instance = {}
         instance["name"] = class_name
         if class_name == "MainApp":
+            self.narrow_cast_id = self.narrow_cast_id + 0
             instance["associations"] = {}
             instance["associations"]["linkA"] = Association("A", 0, -1)
         elif class_name == "A":
+            self.narrow_cast_id = self.narrow_cast_id + 0
             instance["associations"] = {}
         else:
             raise Exception("Cannot instantiate class " + class_name)
@@ -189,9 +199,7 @@ class Controller(CoupledDEVS):
     def __init__(self, name):
         CoupledDEVS.__init__(self, name)
         self.in_ui = self.addInPort("ui")
-        Ports.addInputPort("ui")
         self.out_ui = self.addOutPort("ui")
-        Ports.addOutputPort("ui")
         self.objectmanager = self.addSubModel(ObjectManager("ObjectManager"))
         self.atomics = []
         self.atomics.append(self.addSubModel(MainApp("MainApp")))

+ 49 - 39
tests/3.6) DeleteMultipleBeforeStarting/PyDEVS/log.txt

@@ -13,7 +13,7 @@ __  Current Time:   0.000000 __________________________________________
 
 
 	INITIAL CONDITIONS in model <Controller.ObjectManager>
-		Initial State: <target.Dummy object at 0x1065662a0>
+		Initial State: <target.Dummy object at 0x104a83950>
 		Next scheduled internal transition at time 0.000000
 
 
@@ -30,13 +30,14 @@ __  Current Time:   0.000000 __________________________________________
 			port <obj_manager_in>:
 				[(('MainApp', 0), ('MainApp', 0), (event name: start_instance; port: None; parameters: ['MainApp[0]']))]
 			port <input>:
-			port <private_39_<narrow_cast>>:
+			port <ui>:
+			port <private_0_<narrow_cast>>:
 		New State: 
 		Next scheduled internal transition at time 0.000000
 
 
 	INTERNAL TRANSITION in model <Controller.ObjectManager>
-		New State: <target.Dummy object at 0x1065662a0>
+		New State: <target.Dummy object at 0x104a83950>
 		Output Port Configuration:
 			port <port1>:
 				[(('MainApp', 0), ('MainApp', 0), (event name: start_instance; port: None; parameters: ['MainApp[0]']))]
@@ -51,7 +52,7 @@ __  Current Time:   0.000000 __________________________________________
 		Input Port Configuration:
 			port <input>:
 				(('MainApp', 0), ('MainApp', 0), (event name: instance_started; port: None; parameters: ['MainApp[0]']))
-		New State: <target.Dummy object at 0x1065662a0>
+		New State: <target.Dummy object at 0x104a83950>
 		Next scheduled internal transition at time 0.000000
 
 
@@ -72,7 +73,7 @@ __  Current Time:   0.000000 __________________________________________
 		Input Port Configuration:
 			port <input>:
 				(('MainApp', 0), None, (event name: create_instance; port: None; parameters: [0, 'linkA[0]', 'A']))
-		New State: <target.Dummy object at 0x1065662a0>
+		New State: <target.Dummy object at 0x104a83950>
 		Next scheduled internal transition at time 0.000000
 
 
@@ -92,9 +93,10 @@ __  Current Time:   0.000000 __________________________________________
 	EXTERNAL TRANSITION in model <Controller.A>
 		Input Port Configuration:
 			port <obj_manager_in>:
-				[(('MainApp', 0), ('A', 1), (event name: create_instance; port: None; parameters: [0, 'linkA[0]', 'A']))]
+				[(('MainApp', 0), ('A', 1), (event name: create_instance; port: None; parameters: [0, 1, 'linkA[0]', 'A']))]
 			port <input>:
-			port <private_40_<narrow_cast>>:
+			port <ui>:
+			port <private_1_<narrow_cast>>:
 		New State: 
 		Next scheduled internal transition at time 0.000000
 
@@ -104,18 +106,19 @@ __  Current Time:   0.000000 __________________________________________
 			port <obj_manager_in>:
 				[(('MainApp', 0), ('MainApp', 0), (event name: instance_started; port: None; parameters: ['MainApp[0]']))]
 			port <input>:
-			port <private_39_<narrow_cast>>:
+			port <ui>:
+			port <private_0_<narrow_cast>>:
 		New State: 
 		Next scheduled internal transition at time 0.000000
 
 
 	INTERNAL TRANSITION in model <Controller.ObjectManager>
-		New State: <target.Dummy object at 0x1065662a0>
+		New State: <target.Dummy object at 0x104a83950>
 		Output Port Configuration:
 			port <port1>:
 				[(('MainApp', 0), ('MainApp', 0), (event name: instance_started; port: None; parameters: ['MainApp[0]']))]
 			port <port2>:
-				[(('MainApp', 0), ('A', 1), (event name: create_instance; port: None; parameters: [0, 'linkA[0]', 'A']))]
+				[(('MainApp', 0), ('A', 1), (event name: create_instance; port: None; parameters: [0, 1, 'linkA[0]', 'A']))]
 		Next scheduled internal transition at time inf
 
 
@@ -126,7 +129,7 @@ __  Current Time:   0.000000 __________________________________________
 		Input Port Configuration:
 			port <input>:
 				(('A', 1), ('MainApp', 0), (event name: instance_created; port: None; parameters: ['linkA[0]']))
-		New State: <target.Dummy object at 0x1065662a0>
+		New State: <target.Dummy object at 0x104a83950>
 		Next scheduled internal transition at time 0.000000
 
 
@@ -171,13 +174,14 @@ __  Current Time:   0.000000 __________________________________________
 			port <obj_manager_in>:
 				[(('A', 1), ('MainApp', 0), (event name: instance_created; port: None; parameters: ['linkA[0]']))]
 			port <input>:
-			port <private_39_<narrow_cast>>:
+			port <ui>:
+			port <private_0_<narrow_cast>>:
 		New State: 
 		Next scheduled internal transition at time 0.000000
 
 
 	INTERNAL TRANSITION in model <Controller.ObjectManager>
-		New State: <target.Dummy object at 0x1065662a0>
+		New State: <target.Dummy object at 0x104a83950>
 		Output Port Configuration:
 			port <port1>:
 				[(('A', 1), ('MainApp', 0), (event name: instance_created; port: None; parameters: ['linkA[0]']))]
@@ -226,7 +230,7 @@ __  Current Time:   0.000000 __________________________________________
 		Input Port Configuration:
 			port <input>:
 				(('MainApp', 0), None, (event name: create_instance; port: None; parameters: [0, 'linkA[1]', 'A']))
-		New State: <target.Dummy object at 0x1065662a0>
+		New State: <target.Dummy object at 0x104a83950>
 		Next scheduled internal transition at time 0.000000
 
 
@@ -246,20 +250,22 @@ __  Current Time:   0.000000 __________________________________________
 	EXTERNAL TRANSITION in model <Controller.A>
 		Input Port Configuration:
 			port <obj_manager_in>:
-				[(('MainApp', 0), ('A', 2), (event name: create_instance; port: None; parameters: [0, 'linkA[1]', 'A']))]
+				[(('MainApp', 0), ('A', 2), (event name: create_instance; port: None; parameters: [0, 2, 'linkA[1]', 'A']))]
 			port <input>:
-			port <private_40_<narrow_cast>>:
-			port <private_41_<narrow_cast>>:
+			port <ui>:
+			port <private_1_<narrow_cast>>:
+			port <ui>:
+			port <private_2_<narrow_cast>>:
 		New State: 
 		Next scheduled internal transition at time 0.000000
 
 
 	INTERNAL TRANSITION in model <Controller.ObjectManager>
-		New State: <target.Dummy object at 0x1065662a0>
+		New State: <target.Dummy object at 0x104a83950>
 		Output Port Configuration:
 			port <port1>:
 			port <port2>:
-				[(('MainApp', 0), ('A', 2), (event name: create_instance; port: None; parameters: [0, 'linkA[1]', 'A']))]
+				[(('MainApp', 0), ('A', 2), (event name: create_instance; port: None; parameters: [0, 2, 'linkA[1]', 'A']))]
 		Next scheduled internal transition at time inf
 
 
@@ -270,7 +276,7 @@ __  Current Time:   0.000000 __________________________________________
 		Input Port Configuration:
 			port <input>:
 				(('A', 2), ('MainApp', 0), (event name: instance_created; port: None; parameters: ['linkA[1]']))
-		New State: <target.Dummy object at 0x1065662a0>
+		New State: <target.Dummy object at 0x104a83950>
 		Next scheduled internal transition at time 0.000000
 
 
@@ -291,13 +297,14 @@ __  Current Time:   0.000000 __________________________________________
 			port <obj_manager_in>:
 				[(('A', 2), ('MainApp', 0), (event name: instance_created; port: None; parameters: ['linkA[1]']))]
 			port <input>:
-			port <private_39_<narrow_cast>>:
+			port <ui>:
+			port <private_0_<narrow_cast>>:
 		New State: 
 		Next scheduled internal transition at time 0.000000
 
 
 	INTERNAL TRANSITION in model <Controller.ObjectManager>
-		New State: <target.Dummy object at 0x1065662a0>
+		New State: <target.Dummy object at 0x104a83950>
 		Output Port Configuration:
 			port <port1>:
 				[(('A', 2), ('MainApp', 0), (event name: instance_created; port: None; parameters: ['linkA[1]']))]
@@ -355,7 +362,7 @@ __  Current Time:   0.000000 __________________________________________
 		Input Port Configuration:
 			port <input>:
 				(('MainApp', 0), None, (event name: delete_instance; port: None; parameters: [[2], 'linkA[1]']))
-		New State: <target.Dummy object at 0x1065662a0>
+		New State: <target.Dummy object at 0x104a83950>
 		Next scheduled internal transition at time 0.000000
 
 
@@ -376,7 +383,7 @@ __  Current Time:   0.000000 __________________________________________
 		Input Port Configuration:
 			port <input>:
 				(('MainApp', 0), None, (event name: delete_instance; port: None; parameters: [[1], 'linkA[0]']))
-		New State: <target.Dummy object at 0x1065662a0>
+		New State: <target.Dummy object at 0x104a83950>
 		Next scheduled internal transition at time 0.000000
 
 
@@ -396,20 +403,22 @@ __  Current Time:   0.000000 __________________________________________
 	EXTERNAL TRANSITION in model <Controller.A>
 		Input Port Configuration:
 			port <obj_manager_in>:
-				[(('MainApp', 0), ('A', 0), (event name: delete_instance; port: None; parameters: [[2], 'linkA[1]'])), (('MainApp', 0), ('A', 0), (event name: delete_instance; port: None; parameters: [[1], 'linkA[0]']))]
+				[(('MainApp', 0), ('A', 2), (event name: delete_instance; port: None; parameters: [[2], 'linkA[1]'])), (('MainApp', 0), ('A', 1), (event name: delete_instance; port: None; parameters: [[1], 'linkA[0]']))]
 			port <input>:
-			port <private_40_<narrow_cast>>:
-			port <private_41_<narrow_cast>>:
+			port <ui>:
+			port <private_1_<narrow_cast>>:
+			port <ui>:
+			port <private_2_<narrow_cast>>:
 		New State: 
 		Next scheduled internal transition at time 0.000000
 
 
 	INTERNAL TRANSITION in model <Controller.ObjectManager>
-		New State: <target.Dummy object at 0x1065662a0>
+		New State: <target.Dummy object at 0x104a83950>
 		Output Port Configuration:
 			port <port1>:
 			port <port2>:
-				[(('MainApp', 0), ('A', 0), (event name: delete_instance; port: None; parameters: [[2], 'linkA[1]'])), (('MainApp', 0), ('A', 0), (event name: delete_instance; port: None; parameters: [[1], 'linkA[0]']))]
+				[(('MainApp', 0), ('A', 2), (event name: delete_instance; port: None; parameters: [[2], 'linkA[1]'])), (('MainApp', 0), ('A', 1), (event name: delete_instance; port: None; parameters: [[1], 'linkA[0]']))]
 		Next scheduled internal transition at time inf
 
 
@@ -419,8 +428,8 @@ __  Current Time:   0.000000 __________________________________________
 	EXTERNAL TRANSITION in model <Controller.ObjectManager>
 		Input Port Configuration:
 			port <input>:
-				(('A', 0), ('MainApp', 0), (event name: instance_deleted; port: None; parameters: ['linkA[1]']))
-		New State: <target.Dummy object at 0x1065662a0>
+				(('A', 2), ('MainApp', 0), (event name: instance_deleted; port: None; parameters: ['linkA[1]']))
+		New State: <target.Dummy object at 0x104a83950>
 		Next scheduled internal transition at time 0.000000
 
 
@@ -428,7 +437,7 @@ __  Current Time:   0.000000 __________________________________________
 		New State: 
 		Output Port Configuration:
 			port <obj_manager_out>:
-				(('A', 0), ('MainApp', 0), (event name: instance_deleted; port: None; parameters: ['linkA[1]']))
+				(('A', 2), ('MainApp', 0), (event name: instance_deleted; port: None; parameters: ['linkA[1]']))
 			port <ui>:
 		Next scheduled internal transition at time 0.000000
 
@@ -439,8 +448,8 @@ __  Current Time:   0.000000 __________________________________________
 	EXTERNAL TRANSITION in model <Controller.ObjectManager>
 		Input Port Configuration:
 			port <input>:
-				(('A', 0), ('MainApp', 0), (event name: instance_deleted; port: None; parameters: ['linkA[0]']))
-		New State: <target.Dummy object at 0x1065662a0>
+				(('A', 1), ('MainApp', 0), (event name: instance_deleted; port: None; parameters: ['linkA[0]']))
+		New State: <target.Dummy object at 0x104a83950>
 		Next scheduled internal transition at time 0.000000
 
 
@@ -448,7 +457,7 @@ __  Current Time:   0.000000 __________________________________________
 		New State: 
 		Output Port Configuration:
 			port <obj_manager_out>:
-				(('A', 0), ('MainApp', 0), (event name: instance_deleted; port: None; parameters: ['linkA[0]']))
+				(('A', 1), ('MainApp', 0), (event name: instance_deleted; port: None; parameters: ['linkA[0]']))
 			port <ui>:
 		Next scheduled internal transition at time inf
 
@@ -459,18 +468,19 @@ __  Current Time:   0.000000 __________________________________________
 	EXTERNAL TRANSITION in model <Controller.MainApp>
 		Input Port Configuration:
 			port <obj_manager_in>:
-				[(('A', 0), ('MainApp', 0), (event name: instance_deleted; port: None; parameters: ['linkA[1]'])), (('A', 0), ('MainApp', 0), (event name: instance_deleted; port: None; parameters: ['linkA[0]']))]
+				[(('A', 2), ('MainApp', 0), (event name: instance_deleted; port: None; parameters: ['linkA[1]'])), (('A', 1), ('MainApp', 0), (event name: instance_deleted; port: None; parameters: ['linkA[0]']))]
 			port <input>:
-			port <private_39_<narrow_cast>>:
+			port <ui>:
+			port <private_0_<narrow_cast>>:
 		New State: 
 		Next scheduled internal transition at time 0.000000
 
 
 	INTERNAL TRANSITION in model <Controller.ObjectManager>
-		New State: <target.Dummy object at 0x1065662a0>
+		New State: <target.Dummy object at 0x104a83950>
 		Output Port Configuration:
 			port <port1>:
-				[(('A', 0), ('MainApp', 0), (event name: instance_deleted; port: None; parameters: ['linkA[1]'])), (('A', 0), ('MainApp', 0), (event name: instance_deleted; port: None; parameters: ['linkA[0]']))]
+				[(('A', 2), ('MainApp', 0), (event name: instance_deleted; port: None; parameters: ['linkA[1]'])), (('A', 1), ('MainApp', 0), (event name: instance_deleted; port: None; parameters: ['linkA[0]']))]
 			port <port2>:
 		Next scheduled internal transition at time inf
 

+ 19 - 11
tests/3.6) DeleteMultipleBeforeStarting/PyDEVS/target.py

@@ -12,7 +12,7 @@ from sccd.runtime.DEVS_statecharts_core import *
 # package "Create and Delete Multiple Instances of the same type (other than the MainApp)"
 
 class MainAppInstance(RuntimeClassBase):
-    def __init__(self, atomdevs, id):
+    def __init__(self, atomdevs, id, start_port_id):
         RuntimeClassBase.__init__(self, atomdevs, id)
         self.associations = {}
         self.associations["linkA"] = Association("A", 0, -1)
@@ -28,8 +28,12 @@ class MainAppInstance(RuntimeClassBase):
         
         # call user defined constructor
         MainAppInstance.user_defined_constructor(self)
-        port_name = Ports.addInputPort("<narrow_cast>", self)
+        port_name = addInputPort("ui", start_port_id, True)
         atomdevs.addInPort(port_name)
+        atomdevs.state.port_mappings[port_name] = id
+        port_name = addInputPort("<narrow_cast>", start_port_id)
+        atomdevs.addInPort(port_name)
+        atomdevs.state.port_mappings[port_name] = id
     
     def user_defined_constructor(self):
         pass
@@ -123,16 +127,16 @@ class MainApp(ClassBase):
         self.input = self.addInPort("input")
         self.glob_outputs["ui"] = self.addOutPort("ui")
         self.outputs["linkA"] = self.addOutPort("linkA")
-        new_instance = self.constructObject(0, [])
+        new_instance = self.constructObject(0, 0, [])
         self.state.instances[new_instance.instance_id] = new_instance
         self.state.next_instance = self.state.next_instance + 1
     
-    def constructObject(self, id, parameters):
-        new_instance = MainAppInstance(self, id)
+    def constructObject(self, id, start_port_id, parameters):
+        new_instance = MainAppInstance(self, id, start_port_id)
         return new_instance
 
 class AInstance(RuntimeClassBase):
-    def __init__(self, atomdevs, id):
+    def __init__(self, atomdevs, id, start_port_id):
         RuntimeClassBase.__init__(self, atomdevs, id)
         self.associations = {}
         
@@ -147,8 +151,12 @@ class AInstance(RuntimeClassBase):
         
         # call user defined constructor
         AInstance.user_defined_constructor(self)
-        port_name = Ports.addInputPort("<narrow_cast>", self)
+        port_name = addInputPort("ui", start_port_id, True)
+        atomdevs.addInPort(port_name)
+        atomdevs.state.port_mappings[port_name] = id
+        port_name = addInputPort("<narrow_cast>", start_port_id)
         atomdevs.addInPort(port_name)
+        atomdevs.state.port_mappings[port_name] = id
     
     def user_defined_constructor(self):
         pass
@@ -186,8 +194,8 @@ class A(ClassBase):
         self.input = self.addInPort("input")
         self.glob_outputs["ui"] = self.addOutPort("ui")
     
-    def constructObject(self, id, parameters):
-        new_instance = AInstance(self, id)
+    def constructObject(self, id, start_port_id, parameters):
+        new_instance = AInstance(self, id, start_port_id)
         return new_instance
 
 class Dummy(ObjectManagerState):
@@ -198,9 +206,11 @@ class Dummy(ObjectManagerState):
         instance = {}
         instance["name"] = class_name
         if class_name == "MainApp":
+            self.narrow_cast_id = self.narrow_cast_id + 0
             instance["associations"] = {}
             instance["associations"]["linkA"] = Association("A", 0, -1)
         elif class_name == "A":
+            self.narrow_cast_id = self.narrow_cast_id + 0
             instance["associations"] = {}
         else:
             raise Exception("Cannot instantiate class " + class_name)
@@ -220,9 +230,7 @@ class Controller(CoupledDEVS):
     def __init__(self, name):
         CoupledDEVS.__init__(self, name)
         self.in_ui = self.addInPort("ui")
-        Ports.addInputPort("ui")
         self.out_ui = self.addOutPort("ui")
-        Ports.addOutputPort("ui")
         self.objectmanager = self.addSubModel(ObjectManager("ObjectManager"))
         self.atomics = []
         self.atomics.append(self.addSubModel(MainApp("MainApp")))

+ 40 - 32
tests/3.7) DeleteRunningInstance/PyDEVS/log.txt

@@ -13,7 +13,7 @@ __  Current Time:   0.000000 __________________________________________
 
 
 	INITIAL CONDITIONS in model <Controller.ObjectManager>
-		Initial State: <target.Dummy object at 0x10760b350>
+		Initial State: <target.Dummy object at 0x104a83170>
 		Next scheduled internal transition at time 0.000000
 
 
@@ -30,13 +30,14 @@ __  Current Time:   0.000000 __________________________________________
 			port <obj_manager_in>:
 				[(('MainApp', 0), ('MainApp', 0), (event name: start_instance; port: None; parameters: ['MainApp[0]']))]
 			port <input>:
-			port <private_42_<narrow_cast>>:
+			port <ui>:
+			port <private_0_<narrow_cast>>:
 		New State: 
 		Next scheduled internal transition at time 0.000000
 
 
 	INTERNAL TRANSITION in model <Controller.ObjectManager>
-		New State: <target.Dummy object at 0x10760b350>
+		New State: <target.Dummy object at 0x104a83170>
 		Output Port Configuration:
 			port <port1>:
 				[(('MainApp', 0), ('MainApp', 0), (event name: start_instance; port: None; parameters: ['MainApp[0]']))]
@@ -51,7 +52,7 @@ __  Current Time:   0.000000 __________________________________________
 		Input Port Configuration:
 			port <input>:
 				(('MainApp', 0), ('MainApp', 0), (event name: instance_started; port: None; parameters: ['MainApp[0]']))
-		New State: <target.Dummy object at 0x10760b350>
+		New State: <target.Dummy object at 0x104a83170>
 		Next scheduled internal transition at time 0.000000
 
 
@@ -72,7 +73,7 @@ __  Current Time:   0.000000 __________________________________________
 		Input Port Configuration:
 			port <input>:
 				(('MainApp', 0), None, (event name: create_instance; port: None; parameters: [0, 'linkA[0]', 'A']))
-		New State: <target.Dummy object at 0x10760b350>
+		New State: <target.Dummy object at 0x104a83170>
 		Next scheduled internal transition at time 0.000000
 
 
@@ -92,9 +93,10 @@ __  Current Time:   0.000000 __________________________________________
 	EXTERNAL TRANSITION in model <Controller.A>
 		Input Port Configuration:
 			port <obj_manager_in>:
-				[(('MainApp', 0), ('A', 1), (event name: create_instance; port: None; parameters: [0, 'linkA[0]', 'A']))]
+				[(('MainApp', 0), ('A', 1), (event name: create_instance; port: None; parameters: [0, 1, 'linkA[0]', 'A']))]
 			port <input>:
-			port <private_43_<narrow_cast>>:
+			port <ui>:
+			port <private_1_<narrow_cast>>:
 		New State: 
 		Next scheduled internal transition at time 0.000000
 
@@ -104,18 +106,19 @@ __  Current Time:   0.000000 __________________________________________
 			port <obj_manager_in>:
 				[(('MainApp', 0), ('MainApp', 0), (event name: instance_started; port: None; parameters: ['MainApp[0]']))]
 			port <input>:
-			port <private_42_<narrow_cast>>:
+			port <ui>:
+			port <private_0_<narrow_cast>>:
 		New State: 
 		Next scheduled internal transition at time 0.000000
 
 
 	INTERNAL TRANSITION in model <Controller.ObjectManager>
-		New State: <target.Dummy object at 0x10760b350>
+		New State: <target.Dummy object at 0x104a83170>
 		Output Port Configuration:
 			port <port1>:
 				[(('MainApp', 0), ('MainApp', 0), (event name: instance_started; port: None; parameters: ['MainApp[0]']))]
 			port <port2>:
-				[(('MainApp', 0), ('A', 1), (event name: create_instance; port: None; parameters: [0, 'linkA[0]', 'A']))]
+				[(('MainApp', 0), ('A', 1), (event name: create_instance; port: None; parameters: [0, 1, 'linkA[0]', 'A']))]
 		Next scheduled internal transition at time inf
 
 
@@ -126,7 +129,7 @@ __  Current Time:   0.000000 __________________________________________
 		Input Port Configuration:
 			port <input>:
 				(('A', 1), ('MainApp', 0), (event name: instance_created; port: None; parameters: ['linkA[0]']))
-		New State: <target.Dummy object at 0x10760b350>
+		New State: <target.Dummy object at 0x104a83170>
 		Next scheduled internal transition at time 0.000000
 
 
@@ -171,13 +174,14 @@ __  Current Time:   0.000000 __________________________________________
 			port <obj_manager_in>:
 				[(('A', 1), ('MainApp', 0), (event name: instance_created; port: None; parameters: ['linkA[0]']))]
 			port <input>:
-			port <private_42_<narrow_cast>>:
+			port <ui>:
+			port <private_0_<narrow_cast>>:
 		New State: 
 		Next scheduled internal transition at time 0.000000
 
 
 	INTERNAL TRANSITION in model <Controller.ObjectManager>
-		New State: <target.Dummy object at 0x10760b350>
+		New State: <target.Dummy object at 0x104a83170>
 		Output Port Configuration:
 			port <port1>:
 				[(('A', 1), ('MainApp', 0), (event name: instance_created; port: None; parameters: ['linkA[0]']))]
@@ -226,7 +230,7 @@ __  Current Time:   0.000000 __________________________________________
 		Input Port Configuration:
 			port <input>:
 				(('MainApp', 0), None, (event name: start_instance; port: None; parameters: [0, 'linkA[0]']))
-		New State: <target.Dummy object at 0x10760b350>
+		New State: <target.Dummy object at 0x104a83170>
 		Next scheduled internal transition at time 0.000000
 
 
@@ -248,13 +252,14 @@ __  Current Time:   0.000000 __________________________________________
 			port <obj_manager_in>:
 				[(('MainApp', 0), ('A', 1), (event name: start_instance; port: None; parameters: ['linkA[0]']))]
 			port <input>:
-			port <private_43_<narrow_cast>>:
+			port <ui>:
+			port <private_1_<narrow_cast>>:
 		New State: 
 		Next scheduled internal transition at time 0.000000
 
 
 	INTERNAL TRANSITION in model <Controller.ObjectManager>
-		New State: <target.Dummy object at 0x10760b350>
+		New State: <target.Dummy object at 0x104a83170>
 		Output Port Configuration:
 			port <port1>:
 			port <port2>:
@@ -281,7 +286,7 @@ __  Current Time:   0.000000 __________________________________________
 		Input Port Configuration:
 			port <input>:
 				(('A', 1), ('MainApp', 0), (event name: instance_started; port: None; parameters: ['linkA[0]']))
-		New State: <target.Dummy object at 0x10760b350>
+		New State: <target.Dummy object at 0x104a83170>
 		Next scheduled internal transition at time 0.000000
 
 
@@ -313,13 +318,14 @@ __  Current Time:   0.000000 __________________________________________
 			port <obj_manager_in>:
 				[(('A', 1), ('MainApp', 0), (event name: instance_started; port: None; parameters: ['linkA[0]']))]
 			port <input>:
-			port <private_42_<narrow_cast>>:
+			port <ui>:
+			port <private_0_<narrow_cast>>:
 		New State: 
 		Next scheduled internal transition at time 0.000000
 
 
 	INTERNAL TRANSITION in model <Controller.ObjectManager>
-		New State: <target.Dummy object at 0x10760b350>
+		New State: <target.Dummy object at 0x104a83170>
 		Output Port Configuration:
 			port <port1>:
 				[(('A', 1), ('MainApp', 0), (event name: instance_started; port: None; parameters: ['linkA[0]']))]
@@ -368,7 +374,7 @@ __  Current Time:   0.000000 __________________________________________
 		Input Port Configuration:
 			port <input>:
 				(('MainApp', 0), None, (event name: delete_instance; port: None; parameters: [[1], 'linkA[0]']))
-		New State: <target.Dummy object at 0x10760b350>
+		New State: <target.Dummy object at 0x104a83170>
 		Next scheduled internal transition at time 0.000000
 
 
@@ -388,19 +394,20 @@ __  Current Time:   0.000000 __________________________________________
 	EXTERNAL TRANSITION in model <Controller.A>
 		Input Port Configuration:
 			port <obj_manager_in>:
-				[(('MainApp', 0), ('A', 0), (event name: delete_instance; port: None; parameters: [[1], 'linkA[0]']))]
+				[(('MainApp', 0), ('A', 1), (event name: delete_instance; port: None; parameters: [[1], 'linkA[0]']))]
 			port <input>:
-			port <private_43_<narrow_cast>>:
+			port <ui>:
+			port <private_1_<narrow_cast>>:
 		New State: 
 		Next scheduled internal transition at time 0.000000
 
 
 	INTERNAL TRANSITION in model <Controller.ObjectManager>
-		New State: <target.Dummy object at 0x10760b350>
+		New State: <target.Dummy object at 0x104a83170>
 		Output Port Configuration:
 			port <port1>:
 			port <port2>:
-				[(('MainApp', 0), ('A', 0), (event name: delete_instance; port: None; parameters: [[1], 'linkA[0]']))]
+				[(('MainApp', 0), ('A', 1), (event name: delete_instance; port: None; parameters: [[1], 'linkA[0]']))]
 		Next scheduled internal transition at time inf
 
 
@@ -410,8 +417,8 @@ __  Current Time:   0.000000 __________________________________________
 	EXTERNAL TRANSITION in model <Controller.ObjectManager>
 		Input Port Configuration:
 			port <input>:
-				(('A', 0), ('MainApp', 0), (event name: instance_deleted; port: None; parameters: ['linkA[0]']))
-		New State: <target.Dummy object at 0x10760b350>
+				(('A', 1), ('MainApp', 0), (event name: instance_deleted; port: None; parameters: ['linkA[0]']))
+		New State: <target.Dummy object at 0x104a83170>
 		Next scheduled internal transition at time 0.000000
 
 
@@ -419,7 +426,7 @@ __  Current Time:   0.000000 __________________________________________
 		New State: 
 		Output Port Configuration:
 			port <obj_manager_out>:
-				(('A', 0), ('MainApp', 0), (event name: instance_deleted; port: None; parameters: ['linkA[0]']))
+				(('A', 1), ('MainApp', 0), (event name: instance_deleted; port: None; parameters: ['linkA[0]']))
 			port <ui>:
 		Next scheduled internal transition at time inf
 
@@ -430,18 +437,19 @@ __  Current Time:   0.000000 __________________________________________
 	EXTERNAL TRANSITION in model <Controller.MainApp>
 		Input Port Configuration:
 			port <obj_manager_in>:
-				[(('A', 0), ('MainApp', 0), (event name: instance_deleted; port: None; parameters: ['linkA[0]']))]
+				[(('A', 1), ('MainApp', 0), (event name: instance_deleted; port: None; parameters: ['linkA[0]']))]
 			port <input>:
-			port <private_42_<narrow_cast>>:
+			port <ui>:
+			port <private_0_<narrow_cast>>:
 		New State: 
 		Next scheduled internal transition at time 0.000000
 
 
 	INTERNAL TRANSITION in model <Controller.ObjectManager>
-		New State: <target.Dummy object at 0x10760b350>
+		New State: <target.Dummy object at 0x104a83170>
 		Output Port Configuration:
 			port <port1>:
-				[(('A', 0), ('MainApp', 0), (event name: instance_deleted; port: None; parameters: ['linkA[0]']))]
+				[(('A', 1), ('MainApp', 0), (event name: instance_deleted; port: None; parameters: ['linkA[0]']))]
 			port <port2>:
 		Next scheduled internal transition at time inf
 
@@ -487,7 +495,7 @@ __  Current Time:   0.000000 __________________________________________
 		Input Port Configuration:
 			port <input>:
 				(('MainApp', 0), None, (event name: narrow_cast; port: None; parameters: [0, 'linkA[0]', (event name: sanity_check; port: None)]))
-		New State: <target.Dummy object at 0x10760b350>
+		New State: <target.Dummy object at 0x104a83170>
 		Next scheduled internal transition at time inf
 
 

+ 19 - 11
tests/3.7) DeleteRunningInstance/PyDEVS/target.py

@@ -12,7 +12,7 @@ from sccd.runtime.DEVS_statecharts_core import *
 # package "Create and Delete A Running Instance (other than the MainApp)"
 
 class MainAppInstance(RuntimeClassBase):
-    def __init__(self, atomdevs, id):
+    def __init__(self, atomdevs, id, start_port_id):
         RuntimeClassBase.__init__(self, atomdevs, id)
         self.associations = {}
         self.associations["linkA"] = Association("A", 0, -1)
@@ -28,8 +28,12 @@ class MainAppInstance(RuntimeClassBase):
         
         # call user defined constructor
         MainAppInstance.user_defined_constructor(self)
-        port_name = Ports.addInputPort("<narrow_cast>", self)
+        port_name = addInputPort("ui", start_port_id, True)
         atomdevs.addInPort(port_name)
+        atomdevs.state.port_mappings[port_name] = id
+        port_name = addInputPort("<narrow_cast>", start_port_id)
+        atomdevs.addInPort(port_name)
+        atomdevs.state.port_mappings[port_name] = id
     
     def user_defined_constructor(self):
         pass
@@ -118,16 +122,16 @@ class MainApp(ClassBase):
         self.input = self.addInPort("input")
         self.glob_outputs["ui"] = self.addOutPort("ui")
         self.outputs["linkA"] = self.addOutPort("linkA")
-        new_instance = self.constructObject(0, [])
+        new_instance = self.constructObject(0, 0, [])
         self.state.instances[new_instance.instance_id] = new_instance
         self.state.next_instance = self.state.next_instance + 1
     
-    def constructObject(self, id, parameters):
-        new_instance = MainAppInstance(self, id)
+    def constructObject(self, id, start_port_id, parameters):
+        new_instance = MainAppInstance(self, id, start_port_id)
         return new_instance
 
 class AInstance(RuntimeClassBase):
-    def __init__(self, atomdevs, id):
+    def __init__(self, atomdevs, id, start_port_id):
         RuntimeClassBase.__init__(self, atomdevs, id)
         self.associations = {}
         
@@ -142,8 +146,12 @@ class AInstance(RuntimeClassBase):
         
         # call user defined constructor
         AInstance.user_defined_constructor(self)
-        port_name = Ports.addInputPort("<narrow_cast>", self)
+        port_name = addInputPort("ui", start_port_id, True)
+        atomdevs.addInPort(port_name)
+        atomdevs.state.port_mappings[port_name] = id
+        port_name = addInputPort("<narrow_cast>", start_port_id)
         atomdevs.addInPort(port_name)
+        atomdevs.state.port_mappings[port_name] = id
     
     def user_defined_constructor(self):
         pass
@@ -190,8 +198,8 @@ class A(ClassBase):
         self.input = self.addInPort("input")
         self.glob_outputs["ui"] = self.addOutPort("ui")
     
-    def constructObject(self, id, parameters):
-        new_instance = AInstance(self, id)
+    def constructObject(self, id, start_port_id, parameters):
+        new_instance = AInstance(self, id, start_port_id)
         return new_instance
 
 class Dummy(ObjectManagerState):
@@ -202,9 +210,11 @@ class Dummy(ObjectManagerState):
         instance = {}
         instance["name"] = class_name
         if class_name == "MainApp":
+            self.narrow_cast_id = self.narrow_cast_id + 0
             instance["associations"] = {}
             instance["associations"]["linkA"] = Association("A", 0, -1)
         elif class_name == "A":
+            self.narrow_cast_id = self.narrow_cast_id + 0
             instance["associations"] = {}
         else:
             raise Exception("Cannot instantiate class " + class_name)
@@ -224,9 +234,7 @@ class Controller(CoupledDEVS):
     def __init__(self, name):
         CoupledDEVS.__init__(self, name)
         self.in_ui = self.addInPort("ui")
-        Ports.addInputPort("ui")
         self.out_ui = self.addOutPort("ui")
-        Ports.addOutputPort("ui")
         self.objectmanager = self.addSubModel(ObjectManager("ObjectManager"))
         self.atomics = []
         self.atomics.append(self.addSubModel(MainApp("MainApp")))

+ 40 - 32
tests/3.8) DeleteMultipleRunning/PyDEVS/log.txt

@@ -13,7 +13,7 @@ __  Current Time:   0.000000 __________________________________________
 
 
 	INITIAL CONDITIONS in model <Controller.ObjectManager>
-		Initial State: <target.Dummy object at 0x1076082f0>
+		Initial State: <target.Dummy object at 0x104a81760>
 		Next scheduled internal transition at time 0.000000
 
 
@@ -30,13 +30,14 @@ __  Current Time:   0.000000 __________________________________________
 			port <obj_manager_in>:
 				[(('MainApp', 0), ('MainApp', 0), (event name: start_instance; port: None; parameters: ['MainApp[0]']))]
 			port <input>:
-			port <private_44_<narrow_cast>>:
+			port <ui>:
+			port <private_0_<narrow_cast>>:
 		New State: 
 		Next scheduled internal transition at time 0.000000
 
 
 	INTERNAL TRANSITION in model <Controller.ObjectManager>
-		New State: <target.Dummy object at 0x1076082f0>
+		New State: <target.Dummy object at 0x104a81760>
 		Output Port Configuration:
 			port <port1>:
 				[(('MainApp', 0), ('MainApp', 0), (event name: start_instance; port: None; parameters: ['MainApp[0]']))]
@@ -51,7 +52,7 @@ __  Current Time:   0.000000 __________________________________________
 		Input Port Configuration:
 			port <input>:
 				(('MainApp', 0), ('MainApp', 0), (event name: instance_started; port: None; parameters: ['MainApp[0]']))
-		New State: <target.Dummy object at 0x1076082f0>
+		New State: <target.Dummy object at 0x104a81760>
 		Next scheduled internal transition at time 0.000000
 
 
@@ -72,7 +73,7 @@ __  Current Time:   0.000000 __________________________________________
 		Input Port Configuration:
 			port <input>:
 				(('MainApp', 0), None, (event name: create_instance; port: None; parameters: [0, 'linkA[0]', 'A']))
-		New State: <target.Dummy object at 0x1076082f0>
+		New State: <target.Dummy object at 0x104a81760>
 		Next scheduled internal transition at time 0.000000
 
 
@@ -92,9 +93,10 @@ __  Current Time:   0.000000 __________________________________________
 	EXTERNAL TRANSITION in model <Controller.A>
 		Input Port Configuration:
 			port <obj_manager_in>:
-				[(('MainApp', 0), ('A', 1), (event name: create_instance; port: None; parameters: [0, 'linkA[0]', 'A']))]
+				[(('MainApp', 0), ('A', 1), (event name: create_instance; port: None; parameters: [0, 1, 'linkA[0]', 'A']))]
 			port <input>:
-			port <private_45_<narrow_cast>>:
+			port <ui>:
+			port <private_1_<narrow_cast>>:
 		New State: 
 		Next scheduled internal transition at time 0.000000
 
@@ -104,18 +106,19 @@ __  Current Time:   0.000000 __________________________________________
 			port <obj_manager_in>:
 				[(('MainApp', 0), ('MainApp', 0), (event name: instance_started; port: None; parameters: ['MainApp[0]']))]
 			port <input>:
-			port <private_44_<narrow_cast>>:
+			port <ui>:
+			port <private_0_<narrow_cast>>:
 		New State: 
 		Next scheduled internal transition at time 0.000000
 
 
 	INTERNAL TRANSITION in model <Controller.ObjectManager>
-		New State: <target.Dummy object at 0x1076082f0>
+		New State: <target.Dummy object at 0x104a81760>
 		Output Port Configuration:
 			port <port1>:
 				[(('MainApp', 0), ('MainApp', 0), (event name: instance_started; port: None; parameters: ['MainApp[0]']))]
 			port <port2>:
-				[(('MainApp', 0), ('A', 1), (event name: create_instance; port: None; parameters: [0, 'linkA[0]', 'A']))]
+				[(('MainApp', 0), ('A', 1), (event name: create_instance; port: None; parameters: [0, 1, 'linkA[0]', 'A']))]
 		Next scheduled internal transition at time inf
 
 
@@ -126,7 +129,7 @@ __  Current Time:   0.000000 __________________________________________
 		Input Port Configuration:
 			port <input>:
 				(('A', 1), ('MainApp', 0), (event name: instance_created; port: None; parameters: ['linkA[0]']))
-		New State: <target.Dummy object at 0x1076082f0>
+		New State: <target.Dummy object at 0x104a81760>
 		Next scheduled internal transition at time 0.000000
 
 
@@ -171,13 +174,14 @@ __  Current Time:   0.000000 __________________________________________
 			port <obj_manager_in>:
 				[(('A', 1), ('MainApp', 0), (event name: instance_created; port: None; parameters: ['linkA[0]']))]
 			port <input>:
-			port <private_44_<narrow_cast>>:
+			port <ui>:
+			port <private_0_<narrow_cast>>:
 		New State: 
 		Next scheduled internal transition at time 0.000000
 
 
 	INTERNAL TRANSITION in model <Controller.ObjectManager>
-		New State: <target.Dummy object at 0x1076082f0>
+		New State: <target.Dummy object at 0x104a81760>
 		Output Port Configuration:
 			port <port1>:
 				[(('A', 1), ('MainApp', 0), (event name: instance_created; port: None; parameters: ['linkA[0]']))]
@@ -226,7 +230,7 @@ __  Current Time:   0.000000 __________________________________________
 		Input Port Configuration:
 			port <input>:
 				(('MainApp', 0), None, (event name: start_instance; port: None; parameters: [0, 'linkA[0]']))
-		New State: <target.Dummy object at 0x1076082f0>
+		New State: <target.Dummy object at 0x104a81760>
 		Next scheduled internal transition at time 0.000000
 
 
@@ -248,13 +252,14 @@ __  Current Time:   0.000000 __________________________________________
 			port <obj_manager_in>:
 				[(('MainApp', 0), ('A', 1), (event name: start_instance; port: None; parameters: ['linkA[0]']))]
 			port <input>:
-			port <private_45_<narrow_cast>>:
+			port <ui>:
+			port <private_1_<narrow_cast>>:
 		New State: 
 		Next scheduled internal transition at time 0.000000
 
 
 	INTERNAL TRANSITION in model <Controller.ObjectManager>
-		New State: <target.Dummy object at 0x1076082f0>
+		New State: <target.Dummy object at 0x104a81760>
 		Output Port Configuration:
 			port <port1>:
 			port <port2>:
@@ -281,7 +286,7 @@ __  Current Time:   0.000000 __________________________________________
 		Input Port Configuration:
 			port <input>:
 				(('A', 1), ('MainApp', 0), (event name: instance_started; port: None; parameters: ['linkA[0]']))
-		New State: <target.Dummy object at 0x1076082f0>
+		New State: <target.Dummy object at 0x104a81760>
 		Next scheduled internal transition at time 0.000000
 
 
@@ -313,13 +318,14 @@ __  Current Time:   0.000000 __________________________________________
 			port <obj_manager_in>:
 				[(('A', 1), ('MainApp', 0), (event name: instance_started; port: None; parameters: ['linkA[0]']))]
 			port <input>:
-			port <private_44_<narrow_cast>>:
+			port <ui>:
+			port <private_0_<narrow_cast>>:
 		New State: 
 		Next scheduled internal transition at time 0.000000
 
 
 	INTERNAL TRANSITION in model <Controller.ObjectManager>
-		New State: <target.Dummy object at 0x1076082f0>
+		New State: <target.Dummy object at 0x104a81760>
 		Output Port Configuration:
 			port <port1>:
 				[(('A', 1), ('MainApp', 0), (event name: instance_started; port: None; parameters: ['linkA[0]']))]
@@ -368,7 +374,7 @@ __  Current Time:   0.000000 __________________________________________
 		Input Port Configuration:
 			port <input>:
 				(('MainApp', 0), None, (event name: delete_instance; port: None; parameters: [[1], 'linkA[0]']))
-		New State: <target.Dummy object at 0x1076082f0>
+		New State: <target.Dummy object at 0x104a81760>
 		Next scheduled internal transition at time 0.000000
 
 
@@ -388,19 +394,20 @@ __  Current Time:   0.000000 __________________________________________
 	EXTERNAL TRANSITION in model <Controller.A>
 		Input Port Configuration:
 			port <obj_manager_in>:
-				[(('MainApp', 0), ('A', 0), (event name: delete_instance; port: None; parameters: [[1], 'linkA[0]']))]
+				[(('MainApp', 0), ('A', 1), (event name: delete_instance; port: None; parameters: [[1], 'linkA[0]']))]
 			port <input>:
-			port <private_45_<narrow_cast>>:
+			port <ui>:
+			port <private_1_<narrow_cast>>:
 		New State: 
 		Next scheduled internal transition at time 0.000000
 
 
 	INTERNAL TRANSITION in model <Controller.ObjectManager>
-		New State: <target.Dummy object at 0x1076082f0>
+		New State: <target.Dummy object at 0x104a81760>
 		Output Port Configuration:
 			port <port1>:
 			port <port2>:
-				[(('MainApp', 0), ('A', 0), (event name: delete_instance; port: None; parameters: [[1], 'linkA[0]']))]
+				[(('MainApp', 0), ('A', 1), (event name: delete_instance; port: None; parameters: [[1], 'linkA[0]']))]
 		Next scheduled internal transition at time inf
 
 
@@ -410,8 +417,8 @@ __  Current Time:   0.000000 __________________________________________
 	EXTERNAL TRANSITION in model <Controller.ObjectManager>
 		Input Port Configuration:
 			port <input>:
-				(('A', 0), ('MainApp', 0), (event name: instance_deleted; port: None; parameters: ['linkA[0]']))
-		New State: <target.Dummy object at 0x1076082f0>
+				(('A', 1), ('MainApp', 0), (event name: instance_deleted; port: None; parameters: ['linkA[0]']))
+		New State: <target.Dummy object at 0x104a81760>
 		Next scheduled internal transition at time 0.000000
 
 
@@ -419,7 +426,7 @@ __  Current Time:   0.000000 __________________________________________
 		New State: 
 		Output Port Configuration:
 			port <obj_manager_out>:
-				(('A', 0), ('MainApp', 0), (event name: instance_deleted; port: None; parameters: ['linkA[0]']))
+				(('A', 1), ('MainApp', 0), (event name: instance_deleted; port: None; parameters: ['linkA[0]']))
 			port <ui>:
 		Next scheduled internal transition at time inf
 
@@ -430,18 +437,19 @@ __  Current Time:   0.000000 __________________________________________
 	EXTERNAL TRANSITION in model <Controller.MainApp>
 		Input Port Configuration:
 			port <obj_manager_in>:
-				[(('A', 0), ('MainApp', 0), (event name: instance_deleted; port: None; parameters: ['linkA[0]']))]
+				[(('A', 1), ('MainApp', 0), (event name: instance_deleted; port: None; parameters: ['linkA[0]']))]
 			port <input>:
-			port <private_44_<narrow_cast>>:
+			port <ui>:
+			port <private_0_<narrow_cast>>:
 		New State: 
 		Next scheduled internal transition at time 0.000000
 
 
 	INTERNAL TRANSITION in model <Controller.ObjectManager>
-		New State: <target.Dummy object at 0x1076082f0>
+		New State: <target.Dummy object at 0x104a81760>
 		Output Port Configuration:
 			port <port1>:
-				[(('A', 0), ('MainApp', 0), (event name: instance_deleted; port: None; parameters: ['linkA[0]']))]
+				[(('A', 1), ('MainApp', 0), (event name: instance_deleted; port: None; parameters: ['linkA[0]']))]
 			port <port2>:
 		Next scheduled internal transition at time inf
 
@@ -487,7 +495,7 @@ __  Current Time:   0.000000 __________________________________________
 		Input Port Configuration:
 			port <input>:
 				(('MainApp', 0), None, (event name: narrow_cast; port: None; parameters: [0, 'linkA[0]', (event name: sanity_check; port: None)]))
-		New State: <target.Dummy object at 0x1076082f0>
+		New State: <target.Dummy object at 0x104a81760>
 		Next scheduled internal transition at time inf
 
 

+ 19 - 11
tests/3.8) DeleteMultipleRunning/PyDEVS/target.py

@@ -13,7 +13,7 @@ from sccd.runtime.DEVS_statecharts_core import *
 # package "Create and Delete Multiple Running Instance (other than the MainApp)"
 
 class MainAppInstance(RuntimeClassBase):
-    def __init__(self, atomdevs, id):
+    def __init__(self, atomdevs, id, start_port_id):
         RuntimeClassBase.__init__(self, atomdevs, id)
         self.associations = {}
         self.associations["linkA"] = Association("A", 0, -1)
@@ -29,8 +29,12 @@ class MainAppInstance(RuntimeClassBase):
         
         # call user defined constructor
         MainAppInstance.user_defined_constructor(self)
-        port_name = Ports.addInputPort("<narrow_cast>", self)
+        port_name = addInputPort("ui", start_port_id, True)
         atomdevs.addInPort(port_name)
+        atomdevs.state.port_mappings[port_name] = id
+        port_name = addInputPort("<narrow_cast>", start_port_id)
+        atomdevs.addInPort(port_name)
+        atomdevs.state.port_mappings[port_name] = id
     
     def user_defined_constructor(self):
         pass
@@ -119,16 +123,16 @@ class MainApp(ClassBase):
         self.input = self.addInPort("input")
         self.glob_outputs["ui"] = self.addOutPort("ui")
         self.outputs["linkA"] = self.addOutPort("linkA")
-        new_instance = self.constructObject(0, [])
+        new_instance = self.constructObject(0, 0, [])
         self.state.instances[new_instance.instance_id] = new_instance
         self.state.next_instance = self.state.next_instance + 1
     
-    def constructObject(self, id, parameters):
-        new_instance = MainAppInstance(self, id)
+    def constructObject(self, id, start_port_id, parameters):
+        new_instance = MainAppInstance(self, id, start_port_id)
         return new_instance
 
 class AInstance(RuntimeClassBase):
-    def __init__(self, atomdevs, id):
+    def __init__(self, atomdevs, id, start_port_id):
         RuntimeClassBase.__init__(self, atomdevs, id)
         self.associations = {}
         
@@ -143,8 +147,12 @@ class AInstance(RuntimeClassBase):
         
         # call user defined constructor
         AInstance.user_defined_constructor(self)
-        port_name = Ports.addInputPort("<narrow_cast>", self)
+        port_name = addInputPort("ui", start_port_id, True)
+        atomdevs.addInPort(port_name)
+        atomdevs.state.port_mappings[port_name] = id
+        port_name = addInputPort("<narrow_cast>", start_port_id)
         atomdevs.addInPort(port_name)
+        atomdevs.state.port_mappings[port_name] = id
     
     def user_defined_constructor(self):
         pass
@@ -191,8 +199,8 @@ class A(ClassBase):
         self.input = self.addInPort("input")
         self.glob_outputs["ui"] = self.addOutPort("ui")
     
-    def constructObject(self, id, parameters):
-        new_instance = AInstance(self, id)
+    def constructObject(self, id, start_port_id, parameters):
+        new_instance = AInstance(self, id, start_port_id)
         return new_instance
 
 class Dummy(ObjectManagerState):
@@ -203,9 +211,11 @@ class Dummy(ObjectManagerState):
         instance = {}
         instance["name"] = class_name
         if class_name == "MainApp":
+            self.narrow_cast_id = self.narrow_cast_id + 0
             instance["associations"] = {}
             instance["associations"]["linkA"] = Association("A", 0, -1)
         elif class_name == "A":
+            self.narrow_cast_id = self.narrow_cast_id + 0
             instance["associations"] = {}
         else:
             raise Exception("Cannot instantiate class " + class_name)
@@ -225,9 +235,7 @@ class Controller(CoupledDEVS):
     def __init__(self, name):
         CoupledDEVS.__init__(self, name)
         self.in_ui = self.addInPort("ui")
-        Ports.addInputPort("ui")
         self.out_ui = self.addOutPort("ui")
-        Ports.addOutputPort("ui")
         self.objectmanager = self.addSubModel(ObjectManager("ObjectManager"))
         self.atomics = []
         self.atomics.append(self.addSubModel(MainApp("MainApp")))

+ 45 - 35
tests/3.9) DeletedMessageTest/PyDEVS/log.txt

@@ -13,7 +13,7 @@ __  Current Time:   0.000000 __________________________________________
 
 
 	INITIAL CONDITIONS in model <Controller.ObjectManager>
-		Initial State: <target.Dummy object at 0x10763aed0>
+		Initial State: <target.Dummy object at 0x104a7fdd0>
 		Next scheduled internal transition at time 0.000000
 
 
@@ -30,13 +30,14 @@ __  Current Time:   0.000000 __________________________________________
 			port <obj_manager_in>:
 				[(('MainApp', 0), ('MainApp', 0), (event name: start_instance; port: None; parameters: ['MainApp[0]']))]
 			port <input>:
-			port <private_46_<narrow_cast>>:
+			port <ui>:
+			port <private_0_<narrow_cast>>:
 		New State: 
 		Next scheduled internal transition at time 0.000000
 
 
 	INTERNAL TRANSITION in model <Controller.ObjectManager>
-		New State: <target.Dummy object at 0x10763aed0>
+		New State: <target.Dummy object at 0x104a7fdd0>
 		Output Port Configuration:
 			port <port1>:
 				[(('MainApp', 0), ('MainApp', 0), (event name: start_instance; port: None; parameters: ['MainApp[0]']))]
@@ -51,7 +52,7 @@ __  Current Time:   0.000000 __________________________________________
 		Input Port Configuration:
 			port <input>:
 				(('MainApp', 0), ('MainApp', 0), (event name: instance_started; port: None; parameters: ['MainApp[0]']))
-		New State: <target.Dummy object at 0x10763aed0>
+		New State: <target.Dummy object at 0x104a7fdd0>
 		Next scheduled internal transition at time 0.000000
 
 
@@ -72,7 +73,7 @@ __  Current Time:   0.000000 __________________________________________
 		Input Port Configuration:
 			port <input>:
 				(('MainApp', 0), None, (event name: create_instance; port: None; parameters: [0, 'linkA[0]', 'A']))
-		New State: <target.Dummy object at 0x10763aed0>
+		New State: <target.Dummy object at 0x104a7fdd0>
 		Next scheduled internal transition at time 0.000000
 
 
@@ -92,9 +93,10 @@ __  Current Time:   0.000000 __________________________________________
 	EXTERNAL TRANSITION in model <Controller.A>
 		Input Port Configuration:
 			port <obj_manager_in>:
-				[(('MainApp', 0), ('A', 1), (event name: create_instance; port: None; parameters: [0, 'linkA[0]', 'A']))]
+				[(('MainApp', 0), ('A', 1), (event name: create_instance; port: None; parameters: [0, 1, 'linkA[0]', 'A']))]
 			port <input>:
-			port <private_47_<narrow_cast>>:
+			port <ui>:
+			port <private_1_<narrow_cast>>:
 		New State: 
 		Next scheduled internal transition at time 0.000000
 
@@ -104,18 +106,19 @@ __  Current Time:   0.000000 __________________________________________
 			port <obj_manager_in>:
 				[(('MainApp', 0), ('MainApp', 0), (event name: instance_started; port: None; parameters: ['MainApp[0]']))]
 			port <input>:
-			port <private_46_<narrow_cast>>:
+			port <ui>:
+			port <private_0_<narrow_cast>>:
 		New State: 
 		Next scheduled internal transition at time 0.000000
 
 
 	INTERNAL TRANSITION in model <Controller.ObjectManager>
-		New State: <target.Dummy object at 0x10763aed0>
+		New State: <target.Dummy object at 0x104a7fdd0>
 		Output Port Configuration:
 			port <port1>:
 				[(('MainApp', 0), ('MainApp', 0), (event name: instance_started; port: None; parameters: ['MainApp[0]']))]
 			port <port2>:
-				[(('MainApp', 0), ('A', 1), (event name: create_instance; port: None; parameters: [0, 'linkA[0]', 'A']))]
+				[(('MainApp', 0), ('A', 1), (event name: create_instance; port: None; parameters: [0, 1, 'linkA[0]', 'A']))]
 		Next scheduled internal transition at time inf
 
 
@@ -126,7 +129,7 @@ __  Current Time:   0.000000 __________________________________________
 		Input Port Configuration:
 			port <input>:
 				(('A', 1), ('MainApp', 0), (event name: instance_created; port: None; parameters: ['linkA[0]']))
-		New State: <target.Dummy object at 0x10763aed0>
+		New State: <target.Dummy object at 0x104a7fdd0>
 		Next scheduled internal transition at time 0.000000
 
 
@@ -171,13 +174,14 @@ __  Current Time:   0.000000 __________________________________________
 			port <obj_manager_in>:
 				[(('A', 1), ('MainApp', 0), (event name: instance_created; port: None; parameters: ['linkA[0]']))]
 			port <input>:
-			port <private_46_<narrow_cast>>:
+			port <ui>:
+			port <private_0_<narrow_cast>>:
 		New State: 
 		Next scheduled internal transition at time 0.000000
 
 
 	INTERNAL TRANSITION in model <Controller.ObjectManager>
-		New State: <target.Dummy object at 0x10763aed0>
+		New State: <target.Dummy object at 0x104a7fdd0>
 		Output Port Configuration:
 			port <port1>:
 				[(('A', 1), ('MainApp', 0), (event name: instance_created; port: None; parameters: ['linkA[0]']))]
@@ -226,7 +230,7 @@ __  Current Time:   0.000000 __________________________________________
 		Input Port Configuration:
 			port <input>:
 				(('MainApp', 0), None, (event name: create_instance; port: None; parameters: [0, 'linkA[1]', 'A']))
-		New State: <target.Dummy object at 0x10763aed0>
+		New State: <target.Dummy object at 0x104a7fdd0>
 		Next scheduled internal transition at time 0.000000
 
 
@@ -246,20 +250,22 @@ __  Current Time:   0.000000 __________________________________________
 	EXTERNAL TRANSITION in model <Controller.A>
 		Input Port Configuration:
 			port <obj_manager_in>:
-				[(('MainApp', 0), ('A', 2), (event name: create_instance; port: None; parameters: [0, 'linkA[1]', 'A']))]
+				[(('MainApp', 0), ('A', 2), (event name: create_instance; port: None; parameters: [0, 2, 'linkA[1]', 'A']))]
 			port <input>:
-			port <private_47_<narrow_cast>>:
-			port <private_48_<narrow_cast>>:
+			port <ui>:
+			port <private_1_<narrow_cast>>:
+			port <ui>:
+			port <private_2_<narrow_cast>>:
 		New State: 
 		Next scheduled internal transition at time 0.000000
 
 
 	INTERNAL TRANSITION in model <Controller.ObjectManager>
-		New State: <target.Dummy object at 0x10763aed0>
+		New State: <target.Dummy object at 0x104a7fdd0>
 		Output Port Configuration:
 			port <port1>:
 			port <port2>:
-				[(('MainApp', 0), ('A', 2), (event name: create_instance; port: None; parameters: [0, 'linkA[1]', 'A']))]
+				[(('MainApp', 0), ('A', 2), (event name: create_instance; port: None; parameters: [0, 2, 'linkA[1]', 'A']))]
 		Next scheduled internal transition at time inf
 
 
@@ -270,7 +276,7 @@ __  Current Time:   0.000000 __________________________________________
 		Input Port Configuration:
 			port <input>:
 				(('A', 2), ('MainApp', 0), (event name: instance_created; port: None; parameters: ['linkA[1]']))
-		New State: <target.Dummy object at 0x10763aed0>
+		New State: <target.Dummy object at 0x104a7fdd0>
 		Next scheduled internal transition at time 0.000000
 
 
@@ -291,13 +297,14 @@ __  Current Time:   0.000000 __________________________________________
 			port <obj_manager_in>:
 				[(('A', 2), ('MainApp', 0), (event name: instance_created; port: None; parameters: ['linkA[1]']))]
 			port <input>:
-			port <private_46_<narrow_cast>>:
+			port <ui>:
+			port <private_0_<narrow_cast>>:
 		New State: 
 		Next scheduled internal transition at time 0.000000
 
 
 	INTERNAL TRANSITION in model <Controller.ObjectManager>
-		New State: <target.Dummy object at 0x10763aed0>
+		New State: <target.Dummy object at 0x104a7fdd0>
 		Output Port Configuration:
 			port <port1>:
 				[(('A', 2), ('MainApp', 0), (event name: instance_created; port: None; parameters: ['linkA[1]']))]
@@ -346,7 +353,7 @@ __  Current Time:   0.000000 __________________________________________
 		Input Port Configuration:
 			port <input>:
 				(('MainApp', 0), None, (event name: delete_instance; port: None; parameters: [[1, 2], 'linkA']))
-		New State: <target.Dummy object at 0x10763aed0>
+		New State: <target.Dummy object at 0x104a7fdd0>
 		Next scheduled internal transition at time 0.000000
 
 
@@ -366,20 +373,22 @@ __  Current Time:   0.000000 __________________________________________
 	EXTERNAL TRANSITION in model <Controller.A>
 		Input Port Configuration:
 			port <obj_manager_in>:
-				[(('MainApp', 0), ('A', 0), (event name: delete_instance; port: None; parameters: [[1, 2], 'linkA']))]
+				[(('MainApp', 0), ('A', 2), (event name: delete_instance; port: None; parameters: [[1, 2], 'linkA']))]
 			port <input>:
-			port <private_47_<narrow_cast>>:
-			port <private_48_<narrow_cast>>:
+			port <ui>:
+			port <private_1_<narrow_cast>>:
+			port <ui>:
+			port <private_2_<narrow_cast>>:
 		New State: 
 		Next scheduled internal transition at time 0.000000
 
 
 	INTERNAL TRANSITION in model <Controller.ObjectManager>
-		New State: <target.Dummy object at 0x10763aed0>
+		New State: <target.Dummy object at 0x104a7fdd0>
 		Output Port Configuration:
 			port <port1>:
 			port <port2>:
-				[(('MainApp', 0), ('A', 0), (event name: delete_instance; port: None; parameters: [[1, 2], 'linkA']))]
+				[(('MainApp', 0), ('A', 2), (event name: delete_instance; port: None; parameters: [[1, 2], 'linkA']))]
 		Next scheduled internal transition at time inf
 
 
@@ -389,8 +398,8 @@ __  Current Time:   0.000000 __________________________________________
 	EXTERNAL TRANSITION in model <Controller.ObjectManager>
 		Input Port Configuration:
 			port <input>:
-				(('A', 0), ('MainApp', 0), (event name: instance_deleted; port: None; parameters: ['linkA']))
-		New State: <target.Dummy object at 0x10763aed0>
+				(('A', 2), ('MainApp', 0), (event name: instance_deleted; port: None; parameters: ['linkA']))
+		New State: <target.Dummy object at 0x104a7fdd0>
 		Next scheduled internal transition at time 0.000000
 
 
@@ -398,7 +407,7 @@ __  Current Time:   0.000000 __________________________________________
 		New State: 
 		Output Port Configuration:
 			port <obj_manager_out>:
-				(('A', 0), ('MainApp', 0), (event name: instance_deleted; port: None; parameters: ['linkA']))
+				(('A', 2), ('MainApp', 0), (event name: instance_deleted; port: None; parameters: ['linkA']))
 			port <ui>:
 		Next scheduled internal transition at time inf
 
@@ -409,18 +418,19 @@ __  Current Time:   0.000000 __________________________________________
 	EXTERNAL TRANSITION in model <Controller.MainApp>
 		Input Port Configuration:
 			port <obj_manager_in>:
-				[(('A', 0), ('MainApp', 0), (event name: instance_deleted; port: None; parameters: ['linkA']))]
+				[(('A', 2), ('MainApp', 0), (event name: instance_deleted; port: None; parameters: ['linkA']))]
 			port <input>:
-			port <private_46_<narrow_cast>>:
+			port <ui>:
+			port <private_0_<narrow_cast>>:
 		New State: 
 		Next scheduled internal transition at time 0.000000
 
 
 	INTERNAL TRANSITION in model <Controller.ObjectManager>
-		New State: <target.Dummy object at 0x10763aed0>
+		New State: <target.Dummy object at 0x104a7fdd0>
 		Output Port Configuration:
 			port <port1>:
-				[(('A', 0), ('MainApp', 0), (event name: instance_deleted; port: None; parameters: ['linkA']))]
+				[(('A', 2), ('MainApp', 0), (event name: instance_deleted; port: None; parameters: ['linkA']))]
 			port <port2>:
 		Next scheduled internal transition at time inf
 

+ 19 - 11
tests/3.9) DeletedMessageTest/PyDEVS/target.py

@@ -12,7 +12,7 @@ from sccd.runtime.DEVS_statecharts_core import *
 # package "Create and Delete an Instance (other than the MainApp)"
 
 class MainAppInstance(RuntimeClassBase):
-    def __init__(self, atomdevs, id):
+    def __init__(self, atomdevs, id, start_port_id):
         RuntimeClassBase.__init__(self, atomdevs, id)
         self.associations = {}
         self.associations["linkA"] = Association("A", 0, -1)
@@ -28,8 +28,12 @@ class MainAppInstance(RuntimeClassBase):
         
         # call user defined constructor
         MainAppInstance.user_defined_constructor(self)
-        port_name = Ports.addInputPort("<narrow_cast>", self)
+        port_name = addInputPort("ui", start_port_id, True)
         atomdevs.addInPort(port_name)
+        atomdevs.state.port_mappings[port_name] = id
+        port_name = addInputPort("<narrow_cast>", start_port_id)
+        atomdevs.addInPort(port_name)
+        atomdevs.state.port_mappings[port_name] = id
     
     def user_defined_constructor(self):
         pass
@@ -110,16 +114,16 @@ class MainApp(ClassBase):
         self.input = self.addInPort("input")
         self.glob_outputs["ui"] = self.addOutPort("ui")
         self.outputs["linkA"] = self.addOutPort("linkA")
-        new_instance = self.constructObject(0, [])
+        new_instance = self.constructObject(0, 0, [])
         self.state.instances[new_instance.instance_id] = new_instance
         self.state.next_instance = self.state.next_instance + 1
     
-    def constructObject(self, id, parameters):
-        new_instance = MainAppInstance(self, id)
+    def constructObject(self, id, start_port_id, parameters):
+        new_instance = MainAppInstance(self, id, start_port_id)
         return new_instance
 
 class AInstance(RuntimeClassBase):
-    def __init__(self, atomdevs, id):
+    def __init__(self, atomdevs, id, start_port_id):
         RuntimeClassBase.__init__(self, atomdevs, id)
         self.associations = {}
         
@@ -134,8 +138,12 @@ class AInstance(RuntimeClassBase):
         
         # call user defined constructor
         AInstance.user_defined_constructor(self)
-        port_name = Ports.addInputPort("<narrow_cast>", self)
+        port_name = addInputPort("ui", start_port_id, True)
+        atomdevs.addInPort(port_name)
+        atomdevs.state.port_mappings[port_name] = id
+        port_name = addInputPort("<narrow_cast>", start_port_id)
         atomdevs.addInPort(port_name)
+        atomdevs.state.port_mappings[port_name] = id
     
     def user_defined_constructor(self):
         pass
@@ -173,8 +181,8 @@ class A(ClassBase):
         self.input = self.addInPort("input")
         self.glob_outputs["ui"] = self.addOutPort("ui")
     
-    def constructObject(self, id, parameters):
-        new_instance = AInstance(self, id)
+    def constructObject(self, id, start_port_id, parameters):
+        new_instance = AInstance(self, id, start_port_id)
         return new_instance
 
 class Dummy(ObjectManagerState):
@@ -185,9 +193,11 @@ class Dummy(ObjectManagerState):
         instance = {}
         instance["name"] = class_name
         if class_name == "MainApp":
+            self.narrow_cast_id = self.narrow_cast_id + 0
             instance["associations"] = {}
             instance["associations"]["linkA"] = Association("A", 0, -1)
         elif class_name == "A":
+            self.narrow_cast_id = self.narrow_cast_id + 0
             instance["associations"] = {}
         else:
             raise Exception("Cannot instantiate class " + class_name)
@@ -207,9 +217,7 @@ class Controller(CoupledDEVS):
     def __init__(self, name):
         CoupledDEVS.__init__(self, name)
         self.in_ui = self.addInPort("ui")
-        Ports.addInputPort("ui")
         self.out_ui = self.addOutPort("ui")
-        Ports.addOutputPort("ui")
         self.objectmanager = self.addSubModel(ObjectManager("ObjectManager"))
         self.atomics = []
         self.atomics.append(self.addSubModel(MainApp("MainApp")))

+ 8 - 6
tests/4.0) NarrowCastTest/PyDEVS/log.txt

@@ -8,7 +8,7 @@ __  Current Time:   0.000000 __________________________________________
 
 
 	INITIAL CONDITIONS in model <Controller.ObjectManager>
-		Initial State: <target.Dummy object at 0x1077ac2c0>
+		Initial State: <target.Dummy object at 0x104a7c9b0>
 		Next scheduled internal transition at time 0.000000
 
 
@@ -25,13 +25,14 @@ __  Current Time:   0.000000 __________________________________________
 			port <obj_manager_in>:
 				[(('MainApp', 0), ('MainApp', 0), (event name: start_instance; port: None; parameters: ['MainApp[0]']))]
 			port <input>:
-			port <private_65_<narrow_cast>>:
+			port <ui>:
+			port <private_0_<narrow_cast>>:
 		New State: 
 		Next scheduled internal transition at time 0.000000
 
 
 	INTERNAL TRANSITION in model <Controller.ObjectManager>
-		New State: <target.Dummy object at 0x1077ac2c0>
+		New State: <target.Dummy object at 0x104a7c9b0>
 		Output Port Configuration:
 			port <port1>:
 				[(('MainApp', 0), ('MainApp', 0), (event name: start_instance; port: None; parameters: ['MainApp[0]']))]
@@ -45,7 +46,7 @@ __  Current Time:   0.000000 __________________________________________
 		Input Port Configuration:
 			port <input>:
 				(('MainApp', 0), ('MainApp', 0), (event name: instance_started; port: None; parameters: ['MainApp[0]']))
-		New State: <target.Dummy object at 0x1077ac2c0>
+		New State: <target.Dummy object at 0x104a7c9b0>
 		Next scheduled internal transition at time 0.000000
 
 
@@ -77,13 +78,14 @@ __  Current Time:   0.000000 __________________________________________
 			port <obj_manager_in>:
 				[(('MainApp', 0), ('MainApp', 0), (event name: instance_started; port: None; parameters: ['MainApp[0]']))]
 			port <input>:
-			port <private_65_<narrow_cast>>:
+			port <ui>:
+			port <private_0_<narrow_cast>>:
 		New State: 
 		Next scheduled internal transition at time 0.000000
 
 
 	INTERNAL TRANSITION in model <Controller.ObjectManager>
-		New State: <target.Dummy object at 0x1077ac2c0>
+		New State: <target.Dummy object at 0x104a7c9b0>
 		Output Port Configuration:
 			port <port1>:
 				[(('MainApp', 0), ('MainApp', 0), (event name: instance_started; port: None; parameters: ['MainApp[0]']))]

+ 10 - 7
tests/4.0) NarrowCastTest/PyDEVS/target.py

@@ -12,7 +12,7 @@ from sccd.runtime.DEVS_statecharts_core import *
 # package "Create and Delete an Instance (other than the MainApp)"
 
 class MainAppInstance(RuntimeClassBase):
-    def __init__(self, atomdevs, id):
+    def __init__(self, atomdevs, id, start_port_id):
         RuntimeClassBase.__init__(self, atomdevs, id)
         self.associations = {}
         
@@ -27,8 +27,12 @@ class MainAppInstance(RuntimeClassBase):
         
         # call user defined constructor
         MainAppInstance.user_defined_constructor(self)
-        port_name = Ports.addInputPort("<narrow_cast>", self)
+        port_name = addInputPort("ui", start_port_id, True)
         atomdevs.addInPort(port_name)
+        atomdevs.state.port_mappings[port_name] = id
+        port_name = addInputPort("<narrow_cast>", start_port_id)
+        atomdevs.addInPort(port_name)
+        atomdevs.state.port_mappings[port_name] = id
     
     def user_defined_constructor(self):
         pass
@@ -61,12 +65,12 @@ class MainApp(ClassBase):
         ClassBase.__init__(self, name)
         self.input = self.addInPort("input")
         self.glob_outputs["ui"] = self.addOutPort("ui")
-        new_instance = self.constructObject(0, [])
+        new_instance = self.constructObject(0, 0, [])
         self.state.instances[new_instance.instance_id] = new_instance
         self.state.next_instance = self.state.next_instance + 1
     
-    def constructObject(self, id, parameters):
-        new_instance = MainAppInstance(self, id)
+    def constructObject(self, id, start_port_id, parameters):
+        new_instance = MainAppInstance(self, id, start_port_id)
         return new_instance
 
 class Dummy(ObjectManagerState):
@@ -77,6 +81,7 @@ class Dummy(ObjectManagerState):
         instance = {}
         instance["name"] = class_name
         if class_name == "MainApp":
+            self.narrow_cast_id = self.narrow_cast_id + 0
             instance["associations"] = {}
         else:
             raise Exception("Cannot instantiate class " + class_name)
@@ -95,9 +100,7 @@ class Controller(CoupledDEVS):
     def __init__(self, name):
         CoupledDEVS.__init__(self, name)
         self.in_ui = self.addInPort("ui")
-        Ports.addInputPort("ui")
         self.out_ui = self.addOutPort("ui")
-        Ports.addOutputPort("ui")
         self.objectmanager = self.addSubModel(ObjectManager("ObjectManager"))
         self.atomics = []
         self.atomics.append(self.addSubModel(MainApp("MainApp")))

+ 62 - 46
tests/4.1) BroadcastTest/PyDEVS/log.txt

@@ -13,7 +13,7 @@ __  Current Time:   0.000000 __________________________________________
 
 
 	INITIAL CONDITIONS in model <Controller.ObjectManager>
-		Initial State: <target.Dummy object at 0x1077aee10>
+		Initial State: <target.Dummy object at 0x104a82c30>
 		Next scheduled internal transition at time 0.000000
 
 
@@ -30,13 +30,14 @@ __  Current Time:   0.000000 __________________________________________
 			port <obj_manager_in>:
 				[(('MainApp', 0), ('MainApp', 0), (event name: start_instance; port: None; parameters: ['MainApp[0]']))]
 			port <input>:
-			port <private_66_<narrow_cast>>:
+			port <ui>:
+			port <private_0_<narrow_cast>>:
 		New State: 
 		Next scheduled internal transition at time 0.000000
 
 
 	INTERNAL TRANSITION in model <Controller.ObjectManager>
-		New State: <target.Dummy object at 0x1077aee10>
+		New State: <target.Dummy object at 0x104a82c30>
 		Output Port Configuration:
 			port <port1>:
 				[(('MainApp', 0), ('MainApp', 0), (event name: start_instance; port: None; parameters: ['MainApp[0]']))]
@@ -51,7 +52,7 @@ __  Current Time:   0.000000 __________________________________________
 		Input Port Configuration:
 			port <input>:
 				(('MainApp', 0), ('MainApp', 0), (event name: instance_started; port: None; parameters: ['MainApp[0]']))
-		New State: <target.Dummy object at 0x1077aee10>
+		New State: <target.Dummy object at 0x104a82c30>
 		Next scheduled internal transition at time 0.000000
 
 
@@ -72,7 +73,7 @@ __  Current Time:   0.000000 __________________________________________
 		Input Port Configuration:
 			port <input>:
 				(('MainApp', 0), None, (event name: create_instance; port: None; parameters: [0, 'linkA[0]', 'A']))
-		New State: <target.Dummy object at 0x1077aee10>
+		New State: <target.Dummy object at 0x104a82c30>
 		Next scheduled internal transition at time 0.000000
 
 
@@ -92,9 +93,10 @@ __  Current Time:   0.000000 __________________________________________
 	EXTERNAL TRANSITION in model <Controller.A>
 		Input Port Configuration:
 			port <obj_manager_in>:
-				[(('MainApp', 0), ('A', 1), (event name: create_instance; port: None; parameters: [0, 'linkA[0]', 'A']))]
+				[(('MainApp', 0), ('A', 1), (event name: create_instance; port: None; parameters: [0, 1, 'linkA[0]', 'A']))]
 			port <input>:
-			port <private_67_<narrow_cast>>:
+			port <ui>:
+			port <private_1_<narrow_cast>>:
 		New State: 
 		Next scheduled internal transition at time 0.000000
 
@@ -104,18 +106,19 @@ __  Current Time:   0.000000 __________________________________________
 			port <obj_manager_in>:
 				[(('MainApp', 0), ('MainApp', 0), (event name: instance_started; port: None; parameters: ['MainApp[0]']))]
 			port <input>:
-			port <private_66_<narrow_cast>>:
+			port <ui>:
+			port <private_0_<narrow_cast>>:
 		New State: 
 		Next scheduled internal transition at time 0.000000
 
 
 	INTERNAL TRANSITION in model <Controller.ObjectManager>
-		New State: <target.Dummy object at 0x1077aee10>
+		New State: <target.Dummy object at 0x104a82c30>
 		Output Port Configuration:
 			port <port1>:
 				[(('MainApp', 0), ('MainApp', 0), (event name: instance_started; port: None; parameters: ['MainApp[0]']))]
 			port <port2>:
-				[(('MainApp', 0), ('A', 1), (event name: create_instance; port: None; parameters: [0, 'linkA[0]', 'A']))]
+				[(('MainApp', 0), ('A', 1), (event name: create_instance; port: None; parameters: [0, 1, 'linkA[0]', 'A']))]
 		Next scheduled internal transition at time inf
 
 
@@ -126,7 +129,7 @@ __  Current Time:   0.000000 __________________________________________
 		Input Port Configuration:
 			port <input>:
 				(('A', 1), ('MainApp', 0), (event name: instance_created; port: None; parameters: ['linkA[0]']))
-		New State: <target.Dummy object at 0x1077aee10>
+		New State: <target.Dummy object at 0x104a82c30>
 		Next scheduled internal transition at time 0.000000
 
 
@@ -171,13 +174,14 @@ __  Current Time:   0.000000 __________________________________________
 			port <obj_manager_in>:
 				[(('A', 1), ('MainApp', 0), (event name: instance_created; port: None; parameters: ['linkA[0]']))]
 			port <input>:
-			port <private_66_<narrow_cast>>:
+			port <ui>:
+			port <private_0_<narrow_cast>>:
 		New State: 
 		Next scheduled internal transition at time 0.000000
 
 
 	INTERNAL TRANSITION in model <Controller.ObjectManager>
-		New State: <target.Dummy object at 0x1077aee10>
+		New State: <target.Dummy object at 0x104a82c30>
 		Output Port Configuration:
 			port <port1>:
 				[(('A', 1), ('MainApp', 0), (event name: instance_created; port: None; parameters: ['linkA[0]']))]
@@ -226,7 +230,7 @@ __  Current Time:   0.000000 __________________________________________
 		Input Port Configuration:
 			port <input>:
 				(('MainApp', 0), None, (event name: start_instance; port: None; parameters: [0, 'linkA[0]']))
-		New State: <target.Dummy object at 0x1077aee10>
+		New State: <target.Dummy object at 0x104a82c30>
 		Next scheduled internal transition at time 0.000000
 
 
@@ -247,7 +251,7 @@ __  Current Time:   0.000000 __________________________________________
 		Input Port Configuration:
 			port <input>:
 				(('MainApp', 0), None, (event name: create_instance; port: None; parameters: [0, 'linkA[1]', 'A']))
-		New State: <target.Dummy object at 0x1077aee10>
+		New State: <target.Dummy object at 0x104a82c30>
 		Next scheduled internal transition at time 0.000000
 
 
@@ -267,20 +271,22 @@ __  Current Time:   0.000000 __________________________________________
 	EXTERNAL TRANSITION in model <Controller.A>
 		Input Port Configuration:
 			port <obj_manager_in>:
-				[(('MainApp', 0), ('A', 1), (event name: start_instance; port: None; parameters: ['linkA[0]'])), (('MainApp', 0), ('A', 2), (event name: create_instance; port: None; parameters: [0, 'linkA[1]', 'A']))]
+				[(('MainApp', 0), ('A', 1), (event name: start_instance; port: None; parameters: ['linkA[0]'])), (('MainApp', 0), ('A', 2), (event name: create_instance; port: None; parameters: [0, 2, 'linkA[1]', 'A']))]
 			port <input>:
-			port <private_67_<narrow_cast>>:
-			port <private_68_<narrow_cast>>:
+			port <ui>:
+			port <private_1_<narrow_cast>>:
+			port <ui>:
+			port <private_2_<narrow_cast>>:
 		New State: 
 		Next scheduled internal transition at time 0.000000
 
 
 	INTERNAL TRANSITION in model <Controller.ObjectManager>
-		New State: <target.Dummy object at 0x1077aee10>
+		New State: <target.Dummy object at 0x104a82c30>
 		Output Port Configuration:
 			port <port1>:
 			port <port2>:
-				[(('MainApp', 0), ('A', 1), (event name: start_instance; port: None; parameters: ['linkA[0]'])), (('MainApp', 0), ('A', 2), (event name: create_instance; port: None; parameters: [0, 'linkA[1]', 'A']))]
+				[(('MainApp', 0), ('A', 1), (event name: start_instance; port: None; parameters: ['linkA[0]'])), (('MainApp', 0), ('A', 2), (event name: create_instance; port: None; parameters: [0, 2, 'linkA[1]', 'A']))]
 		Next scheduled internal transition at time inf
 
 
@@ -291,7 +297,7 @@ __  Current Time:   0.000000 __________________________________________
 		Input Port Configuration:
 			port <input>:
 				(('A', 1), ('MainApp', 0), (event name: instance_started; port: None; parameters: ['linkA[0]']))
-		New State: <target.Dummy object at 0x1077aee10>
+		New State: <target.Dummy object at 0x104a82c30>
 		Next scheduled internal transition at time 0.000000
 
 
@@ -311,7 +317,7 @@ __  Current Time:   0.000000 __________________________________________
 		Input Port Configuration:
 			port <input>:
 				(('A', 2), ('MainApp', 0), (event name: instance_created; port: None; parameters: ['linkA[1]']))
-		New State: <target.Dummy object at 0x1077aee10>
+		New State: <target.Dummy object at 0x104a82c30>
 		Next scheduled internal transition at time 0.000000
 
 
@@ -343,13 +349,14 @@ __  Current Time:   0.000000 __________________________________________
 			port <obj_manager_in>:
 				[(('A', 1), ('MainApp', 0), (event name: instance_started; port: None; parameters: ['linkA[0]'])), (('A', 2), ('MainApp', 0), (event name: instance_created; port: None; parameters: ['linkA[1]']))]
 			port <input>:
-			port <private_66_<narrow_cast>>:
+			port <ui>:
+			port <private_0_<narrow_cast>>:
 		New State: 
 		Next scheduled internal transition at time 0.000000
 
 
 	INTERNAL TRANSITION in model <Controller.ObjectManager>
-		New State: <target.Dummy object at 0x1077aee10>
+		New State: <target.Dummy object at 0x104a82c30>
 		Output Port Configuration:
 			port <port1>:
 				[(('A', 1), ('MainApp', 0), (event name: instance_started; port: None; parameters: ['linkA[0]'])), (('A', 2), ('MainApp', 0), (event name: instance_created; port: None; parameters: ['linkA[1]']))]
@@ -410,7 +417,7 @@ __  Current Time:   0.000000 __________________________________________
 		Input Port Configuration:
 			port <input>:
 				(('MainApp', 0), None, (event name: start_instance; port: None; parameters: [0, 'linkA[1]']))
-		New State: <target.Dummy object at 0x1077aee10>
+		New State: <target.Dummy object at 0x104a82c30>
 		Next scheduled internal transition at time 0.000000
 
 
@@ -431,7 +438,7 @@ __  Current Time:   0.000000 __________________________________________
 		Input Port Configuration:
 			port <input>:
 				(('MainApp', 0), None, (event name: create_instance; port: None; parameters: [0, 'linkA[2]', 'A']))
-		New State: <target.Dummy object at 0x1077aee10>
+		New State: <target.Dummy object at 0x104a82c30>
 		Next scheduled internal transition at time 0.000000
 
 
@@ -451,21 +458,24 @@ __  Current Time:   0.000000 __________________________________________
 	EXTERNAL TRANSITION in model <Controller.A>
 		Input Port Configuration:
 			port <obj_manager_in>:
-				[(('MainApp', 0), ('A', 2), (event name: start_instance; port: None; parameters: ['linkA[1]'])), (('MainApp', 0), ('A', 3), (event name: create_instance; port: None; parameters: [0, 'linkA[2]', 'A']))]
+				[(('MainApp', 0), ('A', 2), (event name: start_instance; port: None; parameters: ['linkA[1]'])), (('MainApp', 0), ('A', 3), (event name: create_instance; port: None; parameters: [0, 3, 'linkA[2]', 'A']))]
 			port <input>:
-			port <private_67_<narrow_cast>>:
-			port <private_68_<narrow_cast>>:
-			port <private_69_<narrow_cast>>:
+			port <ui>:
+			port <private_1_<narrow_cast>>:
+			port <ui>:
+			port <private_2_<narrow_cast>>:
+			port <ui>:
+			port <private_3_<narrow_cast>>:
 		New State: 
 		Next scheduled internal transition at time 0.000000
 
 
 	INTERNAL TRANSITION in model <Controller.ObjectManager>
-		New State: <target.Dummy object at 0x1077aee10>
+		New State: <target.Dummy object at 0x104a82c30>
 		Output Port Configuration:
 			port <port1>:
 			port <port2>:
-				[(('MainApp', 0), ('A', 2), (event name: start_instance; port: None; parameters: ['linkA[1]'])), (('MainApp', 0), ('A', 3), (event name: create_instance; port: None; parameters: [0, 'linkA[2]', 'A']))]
+				[(('MainApp', 0), ('A', 2), (event name: start_instance; port: None; parameters: ['linkA[1]'])), (('MainApp', 0), ('A', 3), (event name: create_instance; port: None; parameters: [0, 3, 'linkA[2]', 'A']))]
 		Next scheduled internal transition at time inf
 
 
@@ -476,7 +486,7 @@ __  Current Time:   0.000000 __________________________________________
 		Input Port Configuration:
 			port <input>:
 				(('A', 2), ('MainApp', 0), (event name: instance_started; port: None; parameters: ['linkA[1]']))
-		New State: <target.Dummy object at 0x1077aee10>
+		New State: <target.Dummy object at 0x104a82c30>
 		Next scheduled internal transition at time 0.000000
 
 
@@ -496,7 +506,7 @@ __  Current Time:   0.000000 __________________________________________
 		Input Port Configuration:
 			port <input>:
 				(('A', 3), ('MainApp', 0), (event name: instance_created; port: None; parameters: ['linkA[2]']))
-		New State: <target.Dummy object at 0x1077aee10>
+		New State: <target.Dummy object at 0x104a82c30>
 		Next scheduled internal transition at time 0.000000
 
 
@@ -528,13 +538,14 @@ __  Current Time:   0.000000 __________________________________________
 			port <obj_manager_in>:
 				[(('A', 2), ('MainApp', 0), (event name: instance_started; port: None; parameters: ['linkA[1]'])), (('A', 3), ('MainApp', 0), (event name: instance_created; port: None; parameters: ['linkA[2]']))]
 			port <input>:
-			port <private_66_<narrow_cast>>:
+			port <ui>:
+			port <private_0_<narrow_cast>>:
 		New State: 
 		Next scheduled internal transition at time 0.000000
 
 
 	INTERNAL TRANSITION in model <Controller.ObjectManager>
-		New State: <target.Dummy object at 0x1077aee10>
+		New State: <target.Dummy object at 0x104a82c30>
 		Output Port Configuration:
 			port <port1>:
 				[(('A', 2), ('MainApp', 0), (event name: instance_started; port: None; parameters: ['linkA[1]'])), (('A', 3), ('MainApp', 0), (event name: instance_created; port: None; parameters: ['linkA[2]']))]
@@ -595,7 +606,7 @@ __  Current Time:   0.000000 __________________________________________
 		Input Port Configuration:
 			port <input>:
 				(('MainApp', 0), None, (event name: start_instance; port: None; parameters: [0, 'linkA[2]']))
-		New State: <target.Dummy object at 0x1077aee10>
+		New State: <target.Dummy object at 0x104a82c30>
 		Next scheduled internal transition at time 0.000000
 
 
@@ -616,7 +627,7 @@ __  Current Time:   0.000000 __________________________________________
 		Input Port Configuration:
 			port <input>:
 				(('MainApp', 0), None, (event name: broad_cast; port: None; parameters: [0, (event name: test_broad; port: None)]))
-		New State: <target.Dummy object at 0x1077aee10>
+		New State: <target.Dummy object at 0x104a82c30>
 		Next scheduled internal transition at time 0.000000
 
 
@@ -638,9 +649,12 @@ __  Current Time:   0.000000 __________________________________________
 			port <obj_manager_in>:
 				[(('MainApp', 0), ('A', 3), (event name: start_instance; port: None; parameters: ['linkA[2]'])), (('MainApp', 0), ('A', 0), (event name: broad_cast; port: None; parameters: [0, (event name: test_broad; port: None)]))]
 			port <input>:
-			port <private_67_<narrow_cast>>:
-			port <private_68_<narrow_cast>>:
-			port <private_69_<narrow_cast>>:
+			port <ui>:
+			port <private_1_<narrow_cast>>:
+			port <ui>:
+			port <private_2_<narrow_cast>>:
+			port <ui>:
+			port <private_3_<narrow_cast>>:
 		New State: 
 		Next scheduled internal transition at time 0.000000
 
@@ -650,13 +664,14 @@ __  Current Time:   0.000000 __________________________________________
 			port <obj_manager_in>:
 				[(('MainApp', 0), ('MainApp', 0), (event name: broad_cast; port: None; parameters: [0, (event name: test_broad; port: None)]))]
 			port <input>:
-			port <private_66_<narrow_cast>>:
+			port <ui>:
+			port <private_0_<narrow_cast>>:
 		New State: 
 		Next scheduled internal transition at time 0.000000
 
 
 	INTERNAL TRANSITION in model <Controller.ObjectManager>
-		New State: <target.Dummy object at 0x1077aee10>
+		New State: <target.Dummy object at 0x104a82c30>
 		Output Port Configuration:
 			port <port1>:
 				[(('MainApp', 0), ('MainApp', 0), (event name: broad_cast; port: None; parameters: [0, (event name: test_broad; port: None)]))]
@@ -672,7 +687,7 @@ __  Current Time:   0.000000 __________________________________________
 		Input Port Configuration:
 			port <input>:
 				(('A', 3), ('MainApp', 0), (event name: instance_started; port: None; parameters: ['linkA[2]']))
-		New State: <target.Dummy object at 0x1077aee10>
+		New State: <target.Dummy object at 0x104a82c30>
 		Next scheduled internal transition at time 0.000000
 
 
@@ -780,13 +795,14 @@ __  Current Time:   0.000000 __________________________________________
 			port <obj_manager_in>:
 				[(('A', 3), ('MainApp', 0), (event name: instance_started; port: None; parameters: ['linkA[2]']))]
 			port <input>:
-			port <private_66_<narrow_cast>>:
+			port <ui>:
+			port <private_0_<narrow_cast>>:
 		New State: 
 		Next scheduled internal transition at time 0.000000
 
 
 	INTERNAL TRANSITION in model <Controller.ObjectManager>
-		New State: <target.Dummy object at 0x1077aee10>
+		New State: <target.Dummy object at 0x104a82c30>
 		Output Port Configuration:
 			port <port1>:
 				[(('A', 3), ('MainApp', 0), (event name: instance_started; port: None; parameters: ['linkA[2]']))]

+ 19 - 11
tests/4.1) BroadcastTest/PyDEVS/target.py

@@ -12,7 +12,7 @@ from sccd.runtime.DEVS_statecharts_core import *
 # package "Create and Delete an Instance (other than the MainApp)"
 
 class MainAppInstance(RuntimeClassBase):
-    def __init__(self, atomdevs, id):
+    def __init__(self, atomdevs, id, start_port_id):
         RuntimeClassBase.__init__(self, atomdevs, id)
         self.associations = {}
         self.associations["linkA"] = Association("A", 0, -1)
@@ -28,8 +28,12 @@ class MainAppInstance(RuntimeClassBase):
         
         # call user defined constructor
         MainAppInstance.user_defined_constructor(self)
-        port_name = Ports.addInputPort("<narrow_cast>", self)
+        port_name = addInputPort("ui", start_port_id, True)
         atomdevs.addInPort(port_name)
+        atomdevs.state.port_mappings[port_name] = id
+        port_name = addInputPort("<narrow_cast>", start_port_id)
+        atomdevs.addInPort(port_name)
+        atomdevs.state.port_mappings[port_name] = id
     
     def user_defined_constructor(self):
         pass
@@ -124,16 +128,16 @@ class MainApp(ClassBase):
         self.input = self.addInPort("input")
         self.glob_outputs["ui"] = self.addOutPort("ui")
         self.outputs["linkA"] = self.addOutPort("linkA")
-        new_instance = self.constructObject(0, [])
+        new_instance = self.constructObject(0, 0, [])
         self.state.instances[new_instance.instance_id] = new_instance
         self.state.next_instance = self.state.next_instance + 1
     
-    def constructObject(self, id, parameters):
-        new_instance = MainAppInstance(self, id)
+    def constructObject(self, id, start_port_id, parameters):
+        new_instance = MainAppInstance(self, id, start_port_id)
         return new_instance
 
 class AInstance(RuntimeClassBase):
-    def __init__(self, atomdevs, id):
+    def __init__(self, atomdevs, id, start_port_id):
         RuntimeClassBase.__init__(self, atomdevs, id)
         self.associations = {}
         
@@ -148,8 +152,12 @@ class AInstance(RuntimeClassBase):
         
         # call user defined constructor
         AInstance.user_defined_constructor(self)
-        port_name = Ports.addInputPort("<narrow_cast>", self)
+        port_name = addInputPort("ui", start_port_id, True)
+        atomdevs.addInPort(port_name)
+        atomdevs.state.port_mappings[port_name] = id
+        port_name = addInputPort("<narrow_cast>", start_port_id)
         atomdevs.addInPort(port_name)
+        atomdevs.state.port_mappings[port_name] = id
     
     def user_defined_constructor(self):
         pass
@@ -192,8 +200,8 @@ class A(ClassBase):
         self.input = self.addInPort("input")
         self.glob_outputs["ui"] = self.addOutPort("ui")
     
-    def constructObject(self, id, parameters):
-        new_instance = AInstance(self, id)
+    def constructObject(self, id, start_port_id, parameters):
+        new_instance = AInstance(self, id, start_port_id)
         return new_instance
 
 class Dummy(ObjectManagerState):
@@ -204,9 +212,11 @@ class Dummy(ObjectManagerState):
         instance = {}
         instance["name"] = class_name
         if class_name == "MainApp":
+            self.narrow_cast_id = self.narrow_cast_id + 0
             instance["associations"] = {}
             instance["associations"]["linkA"] = Association("A", 0, -1)
         elif class_name == "A":
+            self.narrow_cast_id = self.narrow_cast_id + 0
             instance["associations"] = {}
         else:
             raise Exception("Cannot instantiate class " + class_name)
@@ -226,9 +236,7 @@ class Controller(CoupledDEVS):
     def __init__(self, name):
         CoupledDEVS.__init__(self, name)
         self.in_ui = self.addInPort("ui")
-        Ports.addInputPort("ui")
         self.out_ui = self.addOutPort("ui")
-        Ports.addOutputPort("ui")
         self.objectmanager = self.addSubModel(ObjectManager("ObjectManager"))
         self.atomics = []
         self.atomics.append(self.addSubModel(MainApp("MainApp")))

+ 8 - 6
tests/5.0) Inheritance/PyDEVS/log.txt

@@ -13,7 +13,7 @@ __  Current Time:   0.000000 __________________________________________
 
 
 	INITIAL CONDITIONS in model <Controller.ObjectManager>
-		Initial State: <target.Dummy object at 0x10772f5c0>
+		Initial State: <target.Dummy object at 0x1053564e0>
 		Next scheduled internal transition at time 0.000000
 
 
@@ -30,13 +30,14 @@ __  Current Time:   0.000000 __________________________________________
 			port <obj_manager_in>:
 				[(('B', 0), ('B', 0), (event name: start_instance; port: None; parameters: ['B[0]']))]
 			port <input>:
-			port <private_70_<narrow_cast>>:
+			port <ui>:
+			port <private_0_<narrow_cast>>:
 		New State: 
 		Next scheduled internal transition at time 0.000000
 
 
 	INTERNAL TRANSITION in model <Controller.ObjectManager>
-		New State: <target.Dummy object at 0x10772f5c0>
+		New State: <target.Dummy object at 0x1053564e0>
 		Output Port Configuration:
 			port <port1>:
 			port <port2>:
@@ -51,7 +52,7 @@ __  Current Time:   0.000000 __________________________________________
 		Input Port Configuration:
 			port <input>:
 				(('B', 0), ('B', 0), (event name: instance_started; port: None; parameters: ['B[0]']))
-		New State: <target.Dummy object at 0x10772f5c0>
+		New State: <target.Dummy object at 0x1053564e0>
 		Next scheduled internal transition at time 0.000000
 
 
@@ -83,13 +84,14 @@ __  Current Time:   0.000000 __________________________________________
 			port <obj_manager_in>:
 				[(('B', 0), ('B', 0), (event name: instance_started; port: None; parameters: ['B[0]']))]
 			port <input>:
-			port <private_70_<narrow_cast>>:
+			port <ui>:
+			port <private_0_<narrow_cast>>:
 		New State: 
 		Next scheduled internal transition at time 0.000000
 
 
 	INTERNAL TRANSITION in model <Controller.ObjectManager>
-		New State: <target.Dummy object at 0x10772f5c0>
+		New State: <target.Dummy object at 0x1053564e0>
 		Output Port Configuration:
 			port <port1>:
 			port <port2>:

+ 19 - 11
tests/5.0) Inheritance/PyDEVS/target.py

@@ -12,7 +12,7 @@ from sccd.runtime.DEVS_statecharts_core import *
 # package "Bouncing_Balls_DEVS_Version"
 
 class AInstance(RuntimeClassBase):
-    def __init__(self, atomdevs, id):
+    def __init__(self, atomdevs, id, start_port_id):
         RuntimeClassBase.__init__(self, atomdevs, id)
         self.associations = {}
         
@@ -27,8 +27,12 @@ class AInstance(RuntimeClassBase):
         
         # call user defined constructor
         AInstance.user_defined_constructor(self)
-        port_name = Ports.addInputPort("<narrow_cast>", self)
+        port_name = addInputPort("ui", start_port_id, True)
         atomdevs.addInPort(port_name)
+        atomdevs.state.port_mappings[port_name] = id
+        port_name = addInputPort("<narrow_cast>", start_port_id)
+        atomdevs.addInPort(port_name)
+        atomdevs.state.port_mappings[port_name] = id
     
     def user_defined_constructor(self):
         self.huh = 21
@@ -62,12 +66,12 @@ class A(ClassBase):
         self.input = self.addInPort("input")
         self.glob_outputs["ui"] = self.addOutPort("ui")
     
-    def constructObject(self, id, parameters):
-        new_instance = AInstance(self, id)
+    def constructObject(self, id, start_port_id, parameters):
+        new_instance = AInstance(self, id, start_port_id)
         return new_instance
 
 class BInstance(AInstance):
-    def __init__(self, atomdevs, id):
+    def __init__(self, atomdevs, id, start_port_id):
         RuntimeClassBase.__init__(self, atomdevs, id)
         self.associations = {}
         
@@ -82,8 +86,12 @@ class BInstance(AInstance):
         
         # call user defined constructor
         BInstance.user_defined_constructor(self)
-        port_name = Ports.addInputPort("<narrow_cast>", self)
+        port_name = addInputPort("ui", start_port_id, True)
+        atomdevs.addInPort(port_name)
+        atomdevs.state.port_mappings[port_name] = id
+        port_name = addInputPort("<narrow_cast>", start_port_id)
         atomdevs.addInPort(port_name)
+        atomdevs.state.port_mappings[port_name] = id
     
     def user_defined_constructor(self):
         AInstance.user_defined_constructor(self)
@@ -122,12 +130,12 @@ class B(ClassBase):
         ClassBase.__init__(self, name)
         self.input = self.addInPort("input")
         self.glob_outputs["ui"] = self.addOutPort("ui")
-        new_instance = self.constructObject(0, [])
+        new_instance = self.constructObject(0, 0, [])
         self.state.instances[new_instance.instance_id] = new_instance
         self.state.next_instance = self.state.next_instance + 1
     
-    def constructObject(self, id, parameters):
-        new_instance = BInstance(self, id)
+    def constructObject(self, id, start_port_id, parameters):
+        new_instance = BInstance(self, id, start_port_id)
         return new_instance
 
 class Dummy(ObjectManagerState):
@@ -138,8 +146,10 @@ class Dummy(ObjectManagerState):
         instance = {}
         instance["name"] = class_name
         if class_name == "A":
+            self.narrow_cast_id = self.narrow_cast_id + 0
             instance["associations"] = {}
         elif class_name == "B":
+            self.narrow_cast_id = self.narrow_cast_id + 0
             instance["associations"] = {}
         else:
             raise Exception("Cannot instantiate class " + class_name)
@@ -159,9 +169,7 @@ class Controller(CoupledDEVS):
     def __init__(self, name):
         CoupledDEVS.__init__(self, name)
         self.in_ui = self.addInPort("ui")
-        Ports.addInputPort("ui")
         self.out_ui = self.addOutPort("ui")
-        Ports.addOutputPort("ui")
         self.objectmanager = self.addSubModel(ObjectManager("ObjectManager"))
         self.atomics = []
         self.atomics.append(self.addSubModel(A("A")))

+ 8 - 6
tests/6.0) /PyDEVS/log.txt

@@ -8,7 +8,7 @@ __  Current Time:   0.000000 __________________________________________
 
 
 	INITIAL CONDITIONS in model <Controller.ObjectManager>
-		Initial State: <target.Dummy object at 0x1076b8d70>
+		Initial State: <target.Dummy object at 0x105357fe0>
 		Next scheduled internal transition at time 0.000000
 
 
@@ -25,13 +25,14 @@ __  Current Time:   0.000000 __________________________________________
 			port <obj_manager_in>:
 				[(('MainApp', 0), ('MainApp', 0), (event name: start_instance; port: None; parameters: ['MainApp[0]']))]
 			port <input>:
-			port <private_71_<narrow_cast>>:
+			port <ui>:
+			port <private_0_<narrow_cast>>:
 		New State: 
 		Next scheduled internal transition at time 0.000000
 
 
 	INTERNAL TRANSITION in model <Controller.ObjectManager>
-		New State: <target.Dummy object at 0x1076b8d70>
+		New State: <target.Dummy object at 0x105357fe0>
 		Output Port Configuration:
 			port <port1>:
 				[(('MainApp', 0), ('MainApp', 0), (event name: start_instance; port: None; parameters: ['MainApp[0]']))]
@@ -45,7 +46,7 @@ __  Current Time:   0.000000 __________________________________________
 		Input Port Configuration:
 			port <input>:
 				(('MainApp', 0), ('MainApp', 0), (event name: instance_started; port: None; parameters: ['MainApp[0]']))
-		New State: <target.Dummy object at 0x1076b8d70>
+		New State: <target.Dummy object at 0x105357fe0>
 		Next scheduled internal transition at time 0.000000
 
 
@@ -77,13 +78,14 @@ __  Current Time:   0.000000 __________________________________________
 			port <obj_manager_in>:
 				[(('MainApp', 0), ('MainApp', 0), (event name: instance_started; port: None; parameters: ['MainApp[0]']))]
 			port <input>:
-			port <private_71_<narrow_cast>>:
+			port <ui>:
+			port <private_0_<narrow_cast>>:
 		New State: 
 		Next scheduled internal transition at time 0.000000
 
 
 	INTERNAL TRANSITION in model <Controller.ObjectManager>
-		New State: <target.Dummy object at 0x1076b8d70>
+		New State: <target.Dummy object at 0x105357fe0>
 		Output Port Configuration:
 			port <port1>:
 				[(('MainApp', 0), ('MainApp', 0), (event name: instance_started; port: None; parameters: ['MainApp[0]']))]

+ 10 - 7
tests/6.0) /PyDEVS/target.py

@@ -12,7 +12,7 @@ from sccd.runtime.DEVS_statecharts_core import *
 # package "Multiple Files"
 
 class MainAppInstance(RuntimeClassBase):
-    def __init__(self, atomdevs, id):
+    def __init__(self, atomdevs, id, start_port_id):
         RuntimeClassBase.__init__(self, atomdevs, id)
         self.associations = {}
         
@@ -27,8 +27,12 @@ class MainAppInstance(RuntimeClassBase):
         
         # call user defined constructor
         MainAppInstance.user_defined_constructor(self)
-        port_name = Ports.addInputPort("<narrow_cast>", self)
+        port_name = addInputPort("ui", start_port_id, True)
         atomdevs.addInPort(port_name)
+        atomdevs.state.port_mappings[port_name] = id
+        port_name = addInputPort("<narrow_cast>", start_port_id)
+        atomdevs.addInPort(port_name)
+        atomdevs.state.port_mappings[port_name] = id
     
     def user_defined_constructor(self):
         pass
@@ -61,12 +65,12 @@ class MainApp(ClassBase):
         ClassBase.__init__(self, name)
         self.input = self.addInPort("input")
         self.glob_outputs["ui"] = self.addOutPort("ui")
-        new_instance = self.constructObject(0, [])
+        new_instance = self.constructObject(0, 0, [])
         self.state.instances[new_instance.instance_id] = new_instance
         self.state.next_instance = self.state.next_instance + 1
     
-    def constructObject(self, id, parameters):
-        new_instance = MainAppInstance(self, id)
+    def constructObject(self, id, start_port_id, parameters):
+        new_instance = MainAppInstance(self, id, start_port_id)
         return new_instance
 
 class Dummy(ObjectManagerState):
@@ -77,6 +81,7 @@ class Dummy(ObjectManagerState):
         instance = {}
         instance["name"] = class_name
         if class_name == "MainApp":
+            self.narrow_cast_id = self.narrow_cast_id + 0
             instance["associations"] = {}
         else:
             raise Exception("Cannot instantiate class " + class_name)
@@ -95,9 +100,7 @@ class Controller(CoupledDEVS):
     def __init__(self, name):
         CoupledDEVS.__init__(self, name)
         self.in_ui = self.addInPort("ui")
-        Ports.addInputPort("ui")
         self.out_ui = self.addOutPort("ui")
-        Ports.addOutputPort("ui")
         self.objectmanager = self.addSubModel(ObjectManager("ObjectManager"))
         self.atomics = []
         self.atomics.append(self.addSubModel(MainApp("MainApp")))