Bläddra i källkod

weird thing with input trace

sampieters 1 år sedan
förälder
incheckning
b585dd640d

+ 4 - 4
examples/BouncingBalls/PyDEVS/runner.py

@@ -20,14 +20,14 @@ if __name__ == '__main__':
 	tkroot.withdraw()
 	sim = DEVSSimulator(model)
 	sim.setRealTime(True)
-	#sim.setRealTimeInputFile("./examples/BouncingBalls/input_trace.txt")
+	sim.setRealTimeInputFile("./examples/BouncingBalls/input_trace.txt")
 	sim.setRealTimePorts(refs)
 	sim.setVerbose("./examples/BouncingBalls/PyDEVS/trace.txt")
 	sim.setRealTimePlatformTk(tkroot)
 
 	ui = UI(tkroot, sim)
-	model.atomic1.addMyOwnOutputListener(OutputListener(ui))
-	model.atomic2.addMyOwnOutputListener(OutputListener(ui))
-	model.atomic3.addMyOwnOutputListener(OutputListener(ui))
+	#model.atomic1.addMyOwnOutputListener(OutputListener(ui))
+	#model.atomic2.addMyOwnOutputListener(OutputListener(ui))
+	#model.atomic3.addMyOwnOutputListener(OutputListener(ui))
 	sim.simulate()
 	tkroot.mainloop()

+ 46 - 3
examples/BouncingBalls/PyDEVS/target.py

@@ -202,6 +202,8 @@ class MainApp(ObjectManagerBase):
         self.outputs["fields"] = self.addOutPort("fields")
         self.instances[self.next_instance] = MainAppInstance(self)
         self.next_instance = self.next_instance + 1
+        port_name = Ports.addInputPort("<narrow_cast>", 0)
+        self.addInPort(port_name)
     
     def constructObject(self, parameters):
         new_instance = MainAppInstance(self)
@@ -230,7 +232,19 @@ class FieldInstance(RuntimeClassBase):
         
         # call user defined constructor
         FieldInstance.user_defined_constructor(self)
-        self.inports["field_ui"] = ('field_ui', atomdevs.next_instance)
+        #self.inports["field_ui"] = ('field_ui', atomdevs.next_instance)
+
+
+        port_name = Ports.addInputPort("<narrow_cast>", self)
+        atomdevs.addInPort(port_name)
+
+        port_name = Ports.addInputPort("field_ui", self)
+        atomdevs.addInPort(port_name)
+        atomdevs.port_mappings[port_name] = atomdevs.next_instance
+
+
+        self.inports["field_ui"] = port_name
+
     
     def user_defined_constructor(self):
         pass
@@ -470,6 +484,8 @@ class Field(ObjectManagerBase):
         self.outputs["buttons"] = self.addOutPort("buttons")
         self.outputs["parent"] = self.addOutPort("parent")
         self.field_ui = self.addInPort("field_ui")
+
+        self.port_mappings = {}
     
     def constructObject(self, parameters):
         new_instance = FieldInstance(self)
@@ -497,7 +513,16 @@ class ButtonInstance(RuntimeClassBase):
         
         # call user defined constructor
         ButtonInstance.user_defined_constructor(self, window_id, event_name, button_text)
-        self.inports["button_ui"] = ('button_ui', atomdevs.next_instance)
+        #self.inports["button_ui"] = ('button_ui', atomdevs.next_instance)
+
+        port_name = Ports.addInputPort("<narrow_cast>", self)
+        atomdevs.addInPort(port_name)
+
+        port_name = Ports.addInputPort("button_ui", self)
+        atomdevs.addInPort(port_name)
+        atomdevs.port_mappings[port_name] = atomdevs.next_instance
+
+        self.inports["button_ui"] = port_name
     
     def user_defined_constructor(self, window_id, event_name, button_text):
         self.window_id = window_id;
@@ -570,6 +595,8 @@ class Button(ObjectManagerBase):
         self.input = self.addInPort("input")
         self.outputs["parent"] = self.addOutPort("parent")
         self.button_ui = self.addInPort("button_ui")
+
+        self.port_mappings = {}
     
     def constructObject(self, parameters):
         new_instance = ButtonInstance(self, parameters[2], parameters[3], parameters[4])
@@ -596,7 +623,16 @@ class BallInstance(RuntimeClassBase):
         
         # call user defined constructor
         BallInstance.user_defined_constructor(self, canvas_id, x, y)
-        self.inports["ball_ui"] = ('ball_ui', atomdevs.next_instance)
+        #self.inports["ball_ui"] = ('ball_ui', atomdevs.next_instance)
+
+        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
+
+        self.inports["ball_ui"] = port_name
     
     def user_defined_constructor(self, canvas_id, x, y):
         self.canvas_id = canvas_id;
@@ -789,6 +825,8 @@ class Ball(ObjectManagerBase):
         self.input = self.addInPort("input")
         self.outputs["parent"] = self.addOutPort("parent")
         self.ball_ui = self.addInPort("ball_ui")
+
+        self.port_mappings = {}
     
     def constructObject(self, parameters):
         new_instance = BallInstance(self, parameters[2], parameters[3], parameters[4])
@@ -813,6 +851,11 @@ class Controller(CoupledDEVS):
         CoupledDEVS.__init__(self, name)
         self.ui = self.addInPort("ui")
         self.addOutPort("ui")
+
+        Ports.addInputPort("ui")
+        Ports.addOutputPort("ui")
+
+
         self.objectmanager = self.addSubModel(ObjectManager("ObjectManager"))
         self.atomic0 = self.addSubModel(MainApp("MainApp"))
         self.atomic1 = self.addSubModel(Field("Field"))

+ 259 - 25
examples/BouncingBalls/PyDEVS/trace.txt

@@ -35,12 +35,13 @@ __  Current Time:   0.000000 __________________________________________
 			port <obj_manager_in>:
 				('MainApp', 'MainApp', (event name: start_instance; port: None; parameters: ['MainApp[0]']))
 			port <input>:
-		New State: {0: <examples.BouncingBalls.PyDEVS.target.MainAppInstance object at 0x104673ef0>}
+			port <private_0_<narrow_cast>>:
+		New State: {0: <examples.BouncingBalls.PyDEVS.target.MainAppInstance object at 0x1052d92e0>}
 		Next scheduled internal transition at time 0.000000
 
 
 	INTERNAL TRANSITION in model <controller.ObjectManager>
-		New State: <examples.BouncingBalls.PyDEVS.target.ObjectManagerState object at 0x104663470>
+		New State: <examples.BouncingBalls.PyDEVS.target.ObjectManagerState object at 0x105027b90>
 		Output Port Configuration:
 			port <port1>:
 				('MainApp', 'MainApp', (event name: start_instance; port: None; parameters: ['MainApp[0]']))
@@ -57,12 +58,12 @@ __  Current Time:   0.000000 __________________________________________
 		Input Port Configuration:
 			port <input>:
 				('MainApp', 'MainApp', (event name: instance_started; port: None; parameters: ['MainApp[0]']))
-		New State: <examples.BouncingBalls.PyDEVS.target.ObjectManagerState object at 0x104663470>
+		New State: <examples.BouncingBalls.PyDEVS.target.ObjectManagerState object at 0x105027b90>
 		Next scheduled internal transition at time 0.000000
 
 
 	INTERNAL TRANSITION in model <controller.MainApp>
-		New State: {0: <examples.BouncingBalls.PyDEVS.target.MainAppInstance object at 0x104673ef0>}
+		New State: {0: <examples.BouncingBalls.PyDEVS.target.MainAppInstance object at 0x1052d92e0>}
 		Output Port Configuration:
 			port <obj_manager_out>:
 				('MainApp', 'MainApp', (event name: instance_started; port: None; parameters: ['MainApp[0]']))
@@ -78,7 +79,8 @@ __  Current Time:   0.000000 __________________________________________
 			port <obj_manager_in>: 
 				('MainApp', 'MainApp', (event name: instance_started; port: None; parameters: ['MainApp[0]']))
 			port <input>: 
-		New State: {0: <examples.BouncingBalls.PyDEVS.target.MainAppInstance object at 0x104673ef0>}
+			port <private_0_<narrow_cast>>: 
+		New State: {0: <examples.BouncingBalls.PyDEVS.target.MainAppInstance object at 0x1052d92e0>}
 		Output Port Configuration:
 			port <obj_manager_out>:
 			port <fields>:
@@ -86,7 +88,7 @@ __  Current Time:   0.000000 __________________________________________
 
 
 	INTERNAL TRANSITION in model <controller.ObjectManager>
-		New State: <examples.BouncingBalls.PyDEVS.target.ObjectManagerState object at 0x104663470>
+		New State: <examples.BouncingBalls.PyDEVS.target.ObjectManagerState object at 0x105027b90>
 		Output Port Configuration:
 			port <port1>:
 				('MainApp', 'MainApp', (event name: instance_started; port: None; parameters: ['MainApp[0]']))
@@ -103,12 +105,12 @@ __  Current Time:   0.000000 __________________________________________
 		Input Port Configuration:
 			port <input>:
 				('MainApp', 'Field', (event name: create_instance; port: None; parameters: ['fields']))
-		New State: <examples.BouncingBalls.PyDEVS.target.ObjectManagerState object at 0x104663470>
+		New State: <examples.BouncingBalls.PyDEVS.target.ObjectManagerState object at 0x105027b90>
 		Next scheduled internal transition at time 0.000000
 
 
 	INTERNAL TRANSITION in model <controller.MainApp>
-		New State: {0: <examples.BouncingBalls.PyDEVS.target.MainAppInstance object at 0x104673ef0>}
+		New State: {0: <examples.BouncingBalls.PyDEVS.target.MainAppInstance object at 0x1052d92e0>}
 		Output Port Configuration:
 			port <obj_manager_out>:
 				('MainApp', 'Field', (event name: create_instance; port: None; parameters: ['fields']))
@@ -125,12 +127,14 @@ __  Current Time:   0.000000 __________________________________________
 				('MainApp', 'Field', (event name: create_instance; port: None; parameters: ['fields']))
 			port <input>:
 			port <field_ui>:
-		New State: {0: <examples.BouncingBalls.PyDEVS.target.FieldInstance object at 0x10472d370>}
+			port <private_1_<narrow_cast>>:
+			port <private_2_field_ui>:
+		New State: {0: <examples.BouncingBalls.PyDEVS.target.FieldInstance object at 0x1053d96d0>}
 		Next scheduled internal transition at time 0.000000
 
 
 	INTERNAL TRANSITION in model <controller.ObjectManager>
-		New State: <examples.BouncingBalls.PyDEVS.target.ObjectManagerState object at 0x104663470>
+		New State: <examples.BouncingBalls.PyDEVS.target.ObjectManagerState object at 0x105027b90>
 		Output Port Configuration:
 			port <port1>:
 			port <port2>:
@@ -147,12 +151,12 @@ __  Current Time:   0.000000 __________________________________________
 		Input Port Configuration:
 			port <input>:
 				('Field', 'MainApp', (event name: instance_created; port: None; parameters: ['fields[0]']))
-		New State: <examples.BouncingBalls.PyDEVS.target.ObjectManagerState object at 0x104663470>
+		New State: <examples.BouncingBalls.PyDEVS.target.ObjectManagerState object at 0x105027b90>
 		Next scheduled internal transition at time 0.000000
 
 
 	INTERNAL TRANSITION in model <controller.Field>
-		New State: {0: <examples.BouncingBalls.PyDEVS.target.FieldInstance object at 0x10472d370>}
+		New State: {0: <examples.BouncingBalls.PyDEVS.target.FieldInstance object at 0x1053d96d0>}
 		Output Port Configuration:
 			port <obj_manager_out>:
 				('Field', 'MainApp', (event name: instance_created; port: None; parameters: ['fields[0]']))
@@ -170,12 +174,13 @@ __  Current Time:   0.000000 __________________________________________
 			port <obj_manager_in>:
 				('Field', 'MainApp', (event name: instance_created; port: None; parameters: ['fields[0]']))
 			port <input>:
-		New State: {0: <examples.BouncingBalls.PyDEVS.target.MainAppInstance object at 0x104673ef0>}
+			port <private_0_<narrow_cast>>:
+		New State: {0: <examples.BouncingBalls.PyDEVS.target.MainAppInstance object at 0x1052d92e0>}
 		Next scheduled internal transition at time 0.000000
 
 
 	INTERNAL TRANSITION in model <controller.ObjectManager>
-		New State: <examples.BouncingBalls.PyDEVS.target.ObjectManagerState object at 0x104663470>
+		New State: <examples.BouncingBalls.PyDEVS.target.ObjectManagerState object at 0x105027b90>
 		Output Port Configuration:
 			port <port1>:
 				('Field', 'MainApp', (event name: instance_created; port: None; parameters: ['fields[0]']))
@@ -189,7 +194,7 @@ __  Current Time:   0.000000 __________________________________________
 
 
 	INTERNAL TRANSITION in model <controller.MainApp>
-		New State: {0: <examples.BouncingBalls.PyDEVS.target.MainAppInstance object at 0x104673ef0>}
+		New State: {0: <examples.BouncingBalls.PyDEVS.target.MainAppInstance object at 0x1052d92e0>}
 		Output Port Configuration:
 			port <obj_manager_out>:
 			port <fields>:
@@ -200,7 +205,7 @@ __  Current Time:   0.000000 __________________________________________
 
 
 	INTERNAL TRANSITION in model <controller.MainApp>
-		New State: {0: <examples.BouncingBalls.PyDEVS.target.MainAppInstance object at 0x104673ef0>}
+		New State: {0: <examples.BouncingBalls.PyDEVS.target.MainAppInstance object at 0x1052d92e0>}
 		Output Port Configuration:
 			port <obj_manager_out>:
 			port <fields>:
@@ -215,12 +220,12 @@ __  Current Time:   0.000000 __________________________________________
 			port <input>:
 				('MainApp', 'Field', (event name: start_instance; port: None; parameters: ['fields[0]']))
 				('MainApp', 'Field', (event name: set_association_name; port: None; parameters: ['fields[0]']))
-		New State: <examples.BouncingBalls.PyDEVS.target.ObjectManagerState object at 0x104663470>
+		New State: <examples.BouncingBalls.PyDEVS.target.ObjectManagerState object at 0x105027b90>
 		Next scheduled internal transition at time 0.000000
 
 
 	INTERNAL TRANSITION in model <controller.MainApp>
-		New State: {0: <examples.BouncingBalls.PyDEVS.target.MainAppInstance object at 0x104673ef0>}
+		New State: {0: <examples.BouncingBalls.PyDEVS.target.MainAppInstance object at 0x1052d92e0>}
 		Output Port Configuration:
 			port <obj_manager_out>:
 				('MainApp', 'Field', (event name: start_instance; port: None; parameters: ['fields[0]']))
@@ -239,12 +244,14 @@ __  Current Time:   0.000000 __________________________________________
 				('MainApp', 'Field', (event name: set_association_name; port: None; parameters: ['fields[0]']))
 			port <input>:
 			port <field_ui>:
-		New State: {0: <examples.BouncingBalls.PyDEVS.target.FieldInstance object at 0x10472d370>}
+			port <private_1_<narrow_cast>>:
+			port <private_2_field_ui>:
+		New State: {0: <examples.BouncingBalls.PyDEVS.target.FieldInstance object at 0x1053d96d0>}
 		Next scheduled internal transition at time 0.000000
 
 
 	INTERNAL TRANSITION in model <controller.ObjectManager>
-		New State: <examples.BouncingBalls.PyDEVS.target.ObjectManagerState object at 0x104663470>
+		New State: <examples.BouncingBalls.PyDEVS.target.ObjectManagerState object at 0x105027b90>
 		Output Port Configuration:
 			port <port1>:
 			port <port2>:
@@ -262,12 +269,12 @@ __  Current Time:   0.000000 __________________________________________
 		Input Port Configuration:
 			port <input>:
 				('Field', 'MainApp', (event name: instance_started; port: None; parameters: ['fields[0]']))
-		New State: <examples.BouncingBalls.PyDEVS.target.ObjectManagerState object at 0x104663470>
+		New State: <examples.BouncingBalls.PyDEVS.target.ObjectManagerState object at 0x105027b90>
 		Next scheduled internal transition at time 0.000000
 
 
 	INTERNAL TRANSITION in model <controller.Field>
-		New State: {0: <examples.BouncingBalls.PyDEVS.target.FieldInstance object at 0x10472d370>}
+		New State: {0: <examples.BouncingBalls.PyDEVS.target.FieldInstance object at 0x1053d96d0>}
 		Output Port Configuration:
 			port <obj_manager_out>:
 				('Field', 'MainApp', (event name: instance_started; port: None; parameters: ['fields[0]']))
@@ -285,12 +292,13 @@ __  Current Time:   0.000000 __________________________________________
 			port <obj_manager_in>:
 				('Field', 'MainApp', (event name: instance_started; port: None; parameters: ['fields[0]']))
 			port <input>:
-		New State: {0: <examples.BouncingBalls.PyDEVS.target.MainAppInstance object at 0x104673ef0>}
+			port <private_0_<narrow_cast>>:
+		New State: {0: <examples.BouncingBalls.PyDEVS.target.MainAppInstance object at 0x1052d92e0>}
 		Next scheduled internal transition at time 0.000000
 
 
 	INTERNAL TRANSITION in model <controller.ObjectManager>
-		New State: <examples.BouncingBalls.PyDEVS.target.ObjectManagerState object at 0x104663470>
+		New State: <examples.BouncingBalls.PyDEVS.target.ObjectManagerState object at 0x105027b90>
 		Output Port Configuration:
 			port <port1>:
 				('Field', 'MainApp', (event name: instance_started; port: None; parameters: ['fields[0]']))
@@ -304,9 +312,235 @@ __  Current Time:   0.000000 __________________________________________
 
 
 	INTERNAL TRANSITION in model <controller.MainApp>
-		New State: {0: <examples.BouncingBalls.PyDEVS.target.MainAppInstance object at 0x104673ef0>}
+		New State: {0: <examples.BouncingBalls.PyDEVS.target.MainAppInstance object at 0x1052d92e0>}
 		Output Port Configuration:
 			port <obj_manager_out>:
 			port <fields>:
 		Next scheduled internal transition at time inf
 
+
+__  Current Time:   0.821516 __________________________________________ 
+
+
+	EXTERNAL TRANSITION in model <controller.Field>
+		Input Port Configuration:
+			port <obj_manager_in>:
+			port <input>:
+			port <field_ui>:
+				Event("window_created","private_2_field_ui",[0])
+			port <private_1_<narrow_cast>>:
+			port <private_2_field_ui>:
+		New State: {0: <examples.BouncingBalls.PyDEVS.target.FieldInstance object at 0x1053d96d0>}
+		Next scheduled internal transition at time 0.821516
+
+
+__  Current Time:   0.821516 __________________________________________ 
+
+
+	INTERNAL TRANSITION in model <controller.Field>
+		New State: {0: <examples.BouncingBalls.PyDEVS.target.FieldInstance object at 0x1053d96d0>}
+		Output Port Configuration:
+			port <obj_manager_out>:
+			port <balls>:
+			port <buttons>:
+			port <parent>:
+		Next scheduled internal transition at time inf
+
+
+__  Current Time:   2.000396 __________________________________________ 
+
+
+	EXTERNAL TRANSITION in model <controller.Field>
+		Input Port Configuration:
+			port <obj_manager_in>:
+			port <input>:
+			port <field_ui>:
+				Event("canvas_created","private_2_field_ui",[1])
+			port <private_1_<narrow_cast>>:
+			port <private_2_field_ui>:
+		New State: {0: <examples.BouncingBalls.PyDEVS.target.FieldInstance object at 0x1053d96d0>}
+		Next scheduled internal transition at time 2.000396
+
+
+__  Current Time:   2.000396 __________________________________________ 
+
+
+	INTERNAL TRANSITION in model <controller.Field>
+		New State: {0: <examples.BouncingBalls.PyDEVS.target.FieldInstance object at 0x1053d96d0>}
+		Output Port Configuration:
+			port <obj_manager_out>:
+			port <balls>:
+			port <buttons>:
+			port <parent>:
+		Next scheduled internal transition at time 2.000396
+
+
+__  Current Time:   2.000396 __________________________________________ 
+
+
+	INTERNAL TRANSITION in model <controller.Field>
+		New State: {0: <examples.BouncingBalls.PyDEVS.target.FieldInstance object at 0x1053d96d0>}
+		Output Port Configuration:
+			port <obj_manager_out>:
+			port <balls>:
+			port <buttons>:
+			port <parent>:
+		Next scheduled internal transition at time 2.000396
+
+
+__  Current Time:   2.000396 __________________________________________ 
+
+
+	EXTERNAL TRANSITION in model <controller.ObjectManager>
+		Input Port Configuration:
+			port <input>:
+				('Field', 'Button', (event name: create_instance; port: None; parameters: ['buttons', 'Button', 0, 'create_new_field', 'Spawn New Window']))
+		New State: <examples.BouncingBalls.PyDEVS.target.ObjectManagerState object at 0x105027b90>
+		Next scheduled internal transition at time 2.000396
+
+
+	INTERNAL TRANSITION in model <controller.Field>
+		New State: {0: <examples.BouncingBalls.PyDEVS.target.FieldInstance object at 0x1053d96d0>}
+		Output Port Configuration:
+			port <obj_manager_out>:
+				('Field', 'Button', (event name: create_instance; port: None; parameters: ['buttons', 'Button', 0, 'create_new_field', 'Spawn New Window']))
+			port <balls>:
+			port <buttons>:
+			port <parent>:
+		Next scheduled internal transition at time inf
+
+
+__  Current Time:   2.000396 __________________________________________ 
+
+
+	EXTERNAL TRANSITION in model <controller.Button>
+		Input Port Configuration:
+			port <obj_manager_in>:
+				('Field', 'Button', (event name: create_instance; port: None; parameters: ['buttons', 'Button', 0, 'create_new_field', 'Spawn New Window']))
+			port <input>:
+			port <button_ui>:
+			port <private_3_<narrow_cast>>:
+			port <private_4_button_ui>:
+		New State: {0: <examples.BouncingBalls.PyDEVS.target.ButtonInstance object at 0x1053d9040>}
+		Next scheduled internal transition at time 2.000396
+
+
+	INTERNAL TRANSITION in model <controller.ObjectManager>
+		New State: <examples.BouncingBalls.PyDEVS.target.ObjectManagerState object at 0x105027b90>
+		Output Port Configuration:
+			port <port1>:
+			port <port2>:
+			port <port3>:
+				('Field', 'Button', (event name: create_instance; port: None; parameters: ['buttons', 'Button', 0, 'create_new_field', 'Spawn New Window']))
+			port <port4>:
+		Next scheduled internal transition at time inf
+
+
+__  Current Time:   2.000396 __________________________________________ 
+
+
+	EXTERNAL TRANSITION in model <controller.ObjectManager>
+		Input Port Configuration:
+			port <input>:
+				('Button', 'Field', (event name: instance_created; port: None; parameters: ['buttons[0]']))
+		New State: <examples.BouncingBalls.PyDEVS.target.ObjectManagerState object at 0x105027b90>
+		Next scheduled internal transition at time 2.000396
+
+
+	INTERNAL TRANSITION in model <controller.Button>
+		New State: {0: <examples.BouncingBalls.PyDEVS.target.ButtonInstance object at 0x1053d9040>}
+		Output Port Configuration:
+			port <obj_manager_out>:
+				('Button', 'Field', (event name: instance_created; port: None; parameters: ['buttons[0]']))
+			port <parent>:
+		Next scheduled internal transition at time inf
+
+
+__  Current Time:   2.000396 __________________________________________ 
+
+
+	EXTERNAL TRANSITION in model <controller.Field>
+		Input Port Configuration:
+			port <obj_manager_in>:
+				('Button', 'Field', (event name: instance_created; port: None; parameters: ['buttons[0]']))
+			port <input>:
+			port <field_ui>:
+			port <private_1_<narrow_cast>>:
+			port <private_2_field_ui>:
+		New State: {0: <examples.BouncingBalls.PyDEVS.target.FieldInstance object at 0x1053d96d0>}
+		Next scheduled internal transition at time 2.000396
+
+
+	INTERNAL TRANSITION in model <controller.ObjectManager>
+		New State: <examples.BouncingBalls.PyDEVS.target.ObjectManagerState object at 0x105027b90>
+		Output Port Configuration:
+			port <port1>:
+			port <port2>:
+				('Button', 'Field', (event name: instance_created; port: None; parameters: ['buttons[0]']))
+			port <port3>:
+			port <port4>:
+		Next scheduled internal transition at time inf
+
+
+__  Current Time:   2.000396 __________________________________________ 
+
+
+	INTERNAL TRANSITION in model <controller.Field>
+		New State: {0: <examples.BouncingBalls.PyDEVS.target.FieldInstance object at 0x1053d96d0>}
+		Output Port Configuration:
+			port <obj_manager_out>:
+			port <balls>:
+			port <buttons>:
+			port <parent>:
+		Next scheduled internal transition at time 2.000396
+
+
+__  Current Time:   2.000396 __________________________________________ 
+
+
+	INTERNAL TRANSITION in model <controller.Field>
+		New State: {0: <examples.BouncingBalls.PyDEVS.target.FieldInstance object at 0x1053d96d0>}
+		Output Port Configuration:
+			port <obj_manager_out>:
+			port <balls>:
+			port <buttons>:
+			port <parent>:
+		Next scheduled internal transition at time 2.000396
+
+
+__  Current Time:   2.000396 __________________________________________ 
+
+
+	EXTERNAL TRANSITION in model <controller.ObjectManager>
+		Input Port Configuration:
+			port <input>:
+				('Field', 'Button', (event name: start_instance; port: None; parameters: ['buttons[0]']))
+		New State: <examples.BouncingBalls.PyDEVS.target.ObjectManagerState object at 0x105027b90>
+		Next scheduled internal transition at time 2.000396
+
+
+	INTERNAL TRANSITION in model <controller.Field>
+		New State: {0: <examples.BouncingBalls.PyDEVS.target.FieldInstance object at 0x1053d96d0>}
+		Output Port Configuration:
+			port <obj_manager_out>:
+				('Field', 'Button', (event name: start_instance; port: None; parameters: ['buttons[0]']))
+			port <balls>:
+			port <buttons>:
+			port <parent>:
+		Next scheduled internal transition at time inf
+
+
+__  Current Time:   2.000396 __________________________________________ 
+
+
+	EXTERNAL TRANSITION in model <controller.Button>
+		Input Port Configuration:
+			port <obj_manager_in>:
+				('Field', 'Button', (event name: start_instance; port: None; parameters: ['buttons[0]']))
+			port <input>:
+			port <button_ui>:
+			port <private_3_<narrow_cast>>:
+			port <private_4_button_ui>:
+		New State: {0: <examples.BouncingBalls.PyDEVS.target.ButtonInstance object at 0x1053d9040>}
+		Next scheduled internal transition at time 2.000396
+

+ 0 - 219
examples/BouncingBalls/Python/trace.txt

@@ -1,219 +0,0 @@
-__  Current Time:   0.000000 __________________________________________ 
-
-EXIT STATE in model <MainApp>
-		State: /running/root/main_behaviour/initializing
-
-ENTER STATE in model <MainApp>
-		State: /running/root/main_behaviour/running
-
-EXIT STATE in model <MainApp>
-		State: /running/root/cd_behaviour/waiting
-
-ENTER STATE in model <MainApp>
-		State: /running/root/cd_behaviour/creating
-
-
-EXIT STATE in model <MainApp>
-		State: /running/root/cd_behaviour/creating
-
-ENTER STATE in model <MainApp>
-		State: /running/root/cd_behaviour/waiting
-
-__  Current Time:   0.009000 __________________________________________ 
-
-
-INPUT EVENT from port <private_1_<narrow_cast>>
-	\Type: <narrow_cast>
-	\Event: (event name: set_association_name; port: private_1_<narrow_cast>; parameters: ['fields[0]'])
-
-EXIT STATE in model <Field>
-		State: /root/waiting
-
-ENTER STATE in model <Field>
-		State: /root/creating_window
-
-OUTPUT EVENT to port <ui>
-	\Event: (event name: create_window; port: ui; parameters: [800, 600, 'BouncingBalls', 'private_2_field_ui'])
-
-__  Current Time:   0.029000 __________________________________________ 
-
-INPUT EVENT from port <private_2_field_ui>
-	\Type: field_ui
-	\Event: (event name: window_created; port: private_2_field_ui; parameters: [0])
-
-EXIT STATE in model <Field>
-		State: /root/creating_window
-
-ENTER STATE in model <Field>
-		State: /root/creating_canvas
-
-OUTPUT EVENT to port <ui>
-	\Event: (event name: bind_event; port: ui; parameters: [0, 'WM_DELETE_WINDOW', 'window_close', 'private_2_field_ui'])
-
-OUTPUT EVENT to port <ui>
-	\Event: (event name: bind_event; port: ui; parameters: [0, '<Key>', 'key_press', 'private_2_field_ui'])
-
-OUTPUT EVENT to port <ui>
-	\Event: (event name: create_canvas; port: ui; parameters: [0, 800, 550, {'background': '#eee'}, 'private_2_field_ui'])
-
-__  Current Time:   0.085000 __________________________________________ 
-
-INPUT EVENT from port <private_2_field_ui>
-	\Type: field_ui
-	\Event: (event name: canvas_created; port: private_2_field_ui; parameters: [1])
-
-EXIT STATE in model <Field>
-		State: /root/creating_canvas
-
-ENTER STATE in model <Field>
-		State: /root/creating_button
-
-OUTPUT EVENT to port <ui>
-	\Event: (event name: bind_event; port: ui; parameters: [1, '<Button-2>', 'right_click', 'private_2_field_ui'])
-
-OUTPUT EVENT to port <ui>
-	\Event: (event name: bind_event; port: ui; parameters: [1, '<Motion>', 'mouse_move', 'private_2_field_ui'])
-
-OUTPUT EVENT to port <ui>
-	\Event: (event name: bind_event; port: ui; parameters: [1, '<ButtonRelease>', 'mouse_release', 'private_2_field_ui'])
-
-
-EXIT STATE in model <Field>
-		State: /root/creating_button
-
-ENTER STATE in model <Field>
-		State: /root/running
-
-ENTER STATE in model <Field>
-		State: /root/running/main_behaviour
-
-ENTER STATE in model <Field>
-		State: /root/running/main_behaviour/running
-
-ENTER STATE in model <Field>
-		State: /root/running/deleting_behaviour
-
-ENTER STATE in model <Field>
-		State: /root/running/deleting_behaviour/running
-
-ENTER STATE in model <Field>
-		State: /root/running/child_behaviour
-
-ENTER STATE in model <Field>
-		State: /root/running/child_behaviour/listening
-
-ENTER STATE in model <Field>
-		State: /root/running/deleting_balls_behaviour
-
-ENTER STATE in model <Field>
-		State: /root/running/deleting_balls_behaviour/listening
-
-
-OUTPUT EVENT to port <ui>
-	\Event: (event name: create_button; port: ui; parameters: [0, 'create_new_field', 'private_4_button_ui'])
-
-__  Current Time:   0.090000 __________________________________________ 
-
-INPUT EVENT from port <private_4_button_ui>
-	\Type: button_ui
-	\Event: (event name: button_created; port: private_4_button_ui; parameters: [2])
-
-EXIT STATE in model <Button>
-		State: /creating_button
-
-ENTER STATE in model <Button>
-		State: /running
-
-OUTPUT EVENT to port <ui>
-	\Event: (event name: bind_event; port: ui; parameters: [2, '<Button>', 'mouse_click', 'private_4_button_ui'])
-
-__  Current Time:   3.570000 __________________________________________ 
-
-INPUT EVENT from port <private_2_field_ui>
-	\Type: field_ui
-	\Event: (event name: window_close; port: private_2_field_ui)
-
-EXIT STATE in model <Field>
-		State: /root/running/deleting_balls_behaviour/listening
-
-EXIT STATE in model <Field>
-		State: /root/running/child_behaviour/listening
-
-EXIT STATE in model <Field>
-		State: /root/running/deleting_behaviour/running
-
-EXIT STATE in model <Field>
-		State: /root/running/main_behaviour/running
-
-EXIT STATE in model <Field>
-		State: /root/running/deleting_balls_behaviour
-
-EXIT STATE in model <Field>
-		State: /root/running/child_behaviour
-
-EXIT STATE in model <Field>
-		State: /root/running/deleting_behaviour
-
-EXIT STATE in model <Field>
-		State: /root/running/main_behaviour
-
-EXIT STATE in model <Field>
-		State: /root/running
-
-ENTER STATE in model <Field>
-		State: /root/deleting
-
-EXIT STATE in model <Field>
-		State: /root/deleting
-
-ENTER STATE in model <Field>
-		State: /root/deleted
-
-OUTPUT EVENT to port <ui>
-	\Event: (event name: destroy_window; port: ui; parameters: [0])
-
-__  Current Time:   3.572000 __________________________________________ 
-
-
-INPUT EVENT from port <private_0_<narrow_cast>>
-	\Type: <narrow_cast>
-	\Event: (event name: delete_field; port: private_0_<narrow_cast>; parameters: ['fields[0]'])
-
-__  Current Time:   3.572000 __________________________________________ 
-
-EXIT STATE in model <MainApp>
-		State: /running/root/cd_behaviour/waiting
-
-ENTER STATE in model <MainApp>
-		State: /running/root/cd_behaviour/check_nr_of_fields
-
-
-__  Current Time:   3.622000 __________________________________________ 
-
-EXIT STATE in model <MainApp>
-		State: /running/root/cd_behaviour/check_nr_of_fields
-
-ENTER STATE in model <MainApp>
-		State: /running/root/cd_behaviour/stopped
-
-EXIT STATE in model <MainApp>
-		State: /running/root/cd_behaviour/stopped
-
-EXIT STATE in model <MainApp>
-		State: /running/root/main_behaviour/running
-
-EXIT STATE in model <MainApp>
-		State: /running/root/cd_behaviour
-
-EXIT STATE in model <MainApp>
-		State: /running/root/main_behaviour
-
-EXIT STATE in model <MainApp>
-		State: /running/root
-
-ENTER STATE in model <MainApp>
-		State: /running/stopped
-
-OUTPUT EVENT to port <ui>
-	\Event: (event name: destroy_all; port: ui)
-

+ 4 - 4
examples/BouncingBalls/input_trace.txt

@@ -1,4 +1,4 @@
-0.029 field_ui Event("window_created","private_2_field_ui",[0])
-0.085 field_ui Event("canvas_created","private_2_field_ui",[1])
-0.09 button_ui Event("button_created","private_4_button_ui",[2])
-3.57 field_ui Event("window_close","private_2_field_ui",None)
+0.8 field_ui Event("window_created","private_2_field_ui",[0])
+2 field_ui Event("canvas_created","private_2_field_ui",[1])
+3 button_ui Event("button_created","private_4_button_ui",[2])
+4 field_ui Event("window_close","private_2_field_ui")

+ 15 - 2
sccd/runtime/DEVS_loop.py

@@ -1,11 +1,24 @@
 from pypdevs.simulator import Simulator
+import re
+
+def get_port(text):
+	match = re.search(r'private_\d+_(\w+)', text)
+
+	if match:
+		result = match.group(1)
+		return result
+	else:
+		return None
+
 
 class DEVSSimulator(Simulator):
 	def __init__(self, model):
 		Simulator.__init__(self, model)	
 	
 	def addInput(self, event):
-		event_string = f"Event(\"{event.name}\",\"{event.port[0]}\",{event.parameters},{event.port[1]})"
+		port_name = get_port(event.port)
+
+		event_string = f"Event(\"{event.name}\",\"{event.port}\",{event.parameters})"
 		event_string = event_string.replace(" ", "")
-		interrupt_string = f"{event.port[0]} {event_string}"
+		interrupt_string = f"{port_name} {event_string}"
 		self.realtime_interrupt(interrupt_string)

+ 40 - 2
sccd/runtime/DEVS_statecharts_core.py

@@ -9,6 +9,13 @@ import threading
 
 ELSE_GUARD = "ELSE_GUARD"
 
+def get_private_port(text):
+    match = re.search(r'private_\d+_(\w+)', text)
+
+    if match:
+        result = match.group(1)
+        return result
+
 class RuntimeException(Exception):
     """
     Base class for runtime exceptions.
@@ -383,6 +390,7 @@ class RuntimeClassBase(object):
         self.transition_mem = {}
         self.config_mem = {}
 
+
         #self.narrow_cast_port = self.controller.addInputPort("<narrow_cast>", self)
 
         self.semantics = StatechartSemantics()
@@ -1023,7 +1031,7 @@ class ObjectManagerBase(AtomicDEVS):
         raise "Something went wrong "
 
     def extTransition(self, inputs):
-        self.simulated_time = (self.simulated_time + self.elapsed)
+        self.simulated_time += self.elapsed
         self.next_time = 0
         all_inputs = []
         for input_list in inputs.values():
@@ -1031,6 +1039,8 @@ class ObjectManagerBase(AtomicDEVS):
         for input in all_inputs:
             if isinstance(input, str):
                 tem = eval(input)
+                tem.instance = self.port_mappings[tem.port]
+                tem.port = get_private_port(tem.port)
                 self.addInput(tem)
             elif input[2].name == "create_instance":
                 new_instance = self.constructObject(input[2].parameters)
@@ -1158,4 +1168,32 @@ class TheObjectManager(AtomicDEVS):
     def timeAdvance(self):
         if self.State.to_send:
             return 0
-        return INFINITY
+        return 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
+

+ 0 - 2
sccd/runtime/statecharts_core.py

@@ -524,8 +524,6 @@ class ControllerBase(object):
         """
         self.tracers.startTracers()
 
-
-        
     def getSimulatedTime(self):
         return self.simulated_time