|
|
@@ -1,7 +1,7 @@
|
|
|
"""
|
|
|
Generated by Statechart compiler by Glenn De Jonghe, Joeri Exelmans, Simon Van Mierlo, and Yentl Van Tendeloo (for the inspiration)
|
|
|
|
|
|
-Date: Tue Oct 11 09:55:10 2016
|
|
|
+Date: Tue Oct 11 13:15:37 2016
|
|
|
|
|
|
Model author: Sadaf Mustafiz and Bruno Barroca and Claudio Gomes
|
|
|
Model name: FSASimulator
|
|
|
@@ -31,6 +31,7 @@ class FSASimulator(RuntimeClassBase):
|
|
|
|
|
|
# user defined attributes
|
|
|
self.elapsed = None
|
|
|
+ self.super_step_completed = None
|
|
|
self.model = None
|
|
|
self.logicalTime = None
|
|
|
self.timestep = None
|
|
|
@@ -68,95 +69,148 @@ class FSASimulator(RuntimeClassBase):
|
|
|
# state <root>
|
|
|
self.states[""] = State(0, self)
|
|
|
|
|
|
- # state /End
|
|
|
- self.states["/End"] = State(1, self)
|
|
|
+ # state /CheckTermination
|
|
|
+ self.states["/CheckTermination"] = State(1, self)
|
|
|
+
|
|
|
+ # state /CheckTermination/MacroStepProcessed
|
|
|
+ self.states["/CheckTermination/MacroStepProcessed"] = State(2, self)
|
|
|
+
|
|
|
+ # state /DoSimulation
|
|
|
+ self.states["/DoSimulation"] = State(3, self)
|
|
|
+
|
|
|
+ # state /DoSimulation/MicroStepPrepared
|
|
|
+ self.states["/DoSimulation/MicroStepPrepared"] = State(4, self)
|
|
|
|
|
|
- # state /Processing
|
|
|
- self.states["/Processing"] = State(2, self)
|
|
|
+ # state /DoSimulation/MicroStepProcessed
|
|
|
+ self.states["/DoSimulation/MicroStepProcessed"] = State(5, self)
|
|
|
|
|
|
- # state /Check
|
|
|
- self.states["/Check"] = State(3, self)
|
|
|
- self.states["/Check"].setEnter(self._Check_enter)
|
|
|
+ # state /DoSimulation/MacroStepPrepared
|
|
|
+ self.states["/DoSimulation/MacroStepPrepared"] = State(6, self)
|
|
|
|
|
|
- # state /Start
|
|
|
- self.states["/Start"] = State(4, self)
|
|
|
+ # state /Initialized
|
|
|
+ self.states["/Initialized"] = State(7, self)
|
|
|
+
|
|
|
+ # state /Started
|
|
|
+ self.states["/Started"] = State(8, self)
|
|
|
+
|
|
|
+ # state /End
|
|
|
+ self.states["/End"] = State(9, self)
|
|
|
|
|
|
# add children
|
|
|
+ self.states[""].addChild(self.states["/CheckTermination"])
|
|
|
+ self.states[""].addChild(self.states["/DoSimulation"])
|
|
|
+ self.states[""].addChild(self.states["/Initialized"])
|
|
|
+ self.states[""].addChild(self.states["/Started"])
|
|
|
self.states[""].addChild(self.states["/End"])
|
|
|
- self.states[""].addChild(self.states["/Processing"])
|
|
|
- self.states[""].addChild(self.states["/Check"])
|
|
|
- self.states[""].addChild(self.states["/Start"])
|
|
|
+ self.states["/CheckTermination"].addChild(self.states["/CheckTermination/MacroStepProcessed"])
|
|
|
+ self.states["/DoSimulation"].addChild(self.states["/DoSimulation/MicroStepPrepared"])
|
|
|
+ self.states["/DoSimulation"].addChild(self.states["/DoSimulation/MicroStepProcessed"])
|
|
|
+ self.states["/DoSimulation"].addChild(self.states["/DoSimulation/MacroStepPrepared"])
|
|
|
self.states[""].fixTree()
|
|
|
- self.states[""].default_state = self.states["/Start"]
|
|
|
-
|
|
|
- # transition /Processing
|
|
|
- _Processing_0 = Transition(self, self.states["/Processing"], [self.states["/Check"]])
|
|
|
- _Processing_0.setAction(self._Processing_0_exec)
|
|
|
- _Processing_0.setTrigger(None)
|
|
|
- _Processing_0.setGuard(self._Processing_0_guard)
|
|
|
- self.states["/Processing"].addTransition(_Processing_0)
|
|
|
- _Processing_1 = Transition(self, self.states["/Processing"], [self.states["/Check"]])
|
|
|
- _Processing_1.setAction(self._Processing_1_exec)
|
|
|
- _Processing_1.setTrigger(None)
|
|
|
- _Processing_1.setGuard(self._Processing_1_guard)
|
|
|
- self.states["/Processing"].addTransition(_Processing_1)
|
|
|
-
|
|
|
- # transition /Check
|
|
|
- _Check_0 = Transition(self, self.states["/Check"], [self.states["/End"]])
|
|
|
- _Check_0.setAction(self._Check_0_exec)
|
|
|
- _Check_0.setTrigger(None)
|
|
|
- _Check_0.setGuard(self._Check_0_guard)
|
|
|
- self.states["/Check"].addTransition(_Check_0)
|
|
|
- _Check_1 = Transition(self, self.states["/Check"], [self.states["/Processing"]])
|
|
|
- _Check_1.setAction(self._Check_1_exec)
|
|
|
- _Check_1.setTrigger(None)
|
|
|
- _Check_1.setGuard(self._Check_1_guard)
|
|
|
- self.states["/Check"].addTransition(_Check_1)
|
|
|
-
|
|
|
- # transition /Start
|
|
|
- _Start_0 = Transition(self, self.states["/Start"], [self.states["/Check"]])
|
|
|
- _Start_0.setAction(self._Start_0_exec)
|
|
|
- _Start_0.setTrigger(None)
|
|
|
- self.states["/Start"].addTransition(_Start_0)
|
|
|
-
|
|
|
- def _Check_enter(self):
|
|
|
+ self.states[""].default_state = self.states["/Started"]
|
|
|
+ self.states["/CheckTermination"].default_state = self.states["/CheckTermination/MacroStepProcessed"]
|
|
|
+ self.states["/DoSimulation"].default_state = self.states["/DoSimulation/MacroStepPrepared"]
|
|
|
+
|
|
|
+ # transition /CheckTermination/MacroStepProcessed
|
|
|
+ _CheckTermination_MacroStepProcessed_0 = Transition(self, self.states["/CheckTermination/MacroStepProcessed"], [self.states["/End"]])
|
|
|
+ _CheckTermination_MacroStepProcessed_0.setAction(self._CheckTermination_MacroStepProcessed_0_exec)
|
|
|
+ _CheckTermination_MacroStepProcessed_0.setTrigger(None)
|
|
|
+ _CheckTermination_MacroStepProcessed_0.setGuard(self._CheckTermination_MacroStepProcessed_0_guard)
|
|
|
+ self.states["/CheckTermination/MacroStepProcessed"].addTransition(_CheckTermination_MacroStepProcessed_0)
|
|
|
+ _CheckTermination_MacroStepProcessed_1 = Transition(self, self.states["/CheckTermination/MacroStepProcessed"], [self.states["/DoSimulation"]])
|
|
|
+ _CheckTermination_MacroStepProcessed_1.setAction(self._CheckTermination_MacroStepProcessed_1_exec)
|
|
|
+ _CheckTermination_MacroStepProcessed_1.setTrigger(None)
|
|
|
+ _CheckTermination_MacroStepProcessed_1.setGuard(self._CheckTermination_MacroStepProcessed_1_guard)
|
|
|
+ self.states["/CheckTermination/MacroStepProcessed"].addTransition(_CheckTermination_MacroStepProcessed_1)
|
|
|
+
|
|
|
+ # transition /DoSimulation/MicroStepPrepared
|
|
|
+ _DoSimulation_MicroStepPrepared_0 = Transition(self, self.states["/DoSimulation/MicroStepPrepared"], [self.states["/DoSimulation/MicroStepProcessed"]])
|
|
|
+ _DoSimulation_MicroStepPrepared_0.setAction(self._DoSimulation_MicroStepPrepared_0_exec)
|
|
|
+ _DoSimulation_MicroStepPrepared_0.setTrigger(None)
|
|
|
+ self.states["/DoSimulation/MicroStepPrepared"].addTransition(_DoSimulation_MicroStepPrepared_0)
|
|
|
+
|
|
|
+ # transition /DoSimulation/MicroStepProcessed
|
|
|
+ _DoSimulation_MicroStepProcessed_0 = Transition(self, self.states["/DoSimulation/MicroStepProcessed"], [self.states["/DoSimulation/MicroStepPrepared"]])
|
|
|
+ _DoSimulation_MicroStepProcessed_0.setAction(self._DoSimulation_MicroStepProcessed_0_exec)
|
|
|
+ _DoSimulation_MicroStepProcessed_0.setTrigger(None)
|
|
|
+ _DoSimulation_MicroStepProcessed_0.setGuard(self._DoSimulation_MicroStepProcessed_0_guard)
|
|
|
+ self.states["/DoSimulation/MicroStepProcessed"].addTransition(_DoSimulation_MicroStepProcessed_0)
|
|
|
+ _DoSimulation_MicroStepProcessed_1 = Transition(self, self.states["/DoSimulation/MicroStepProcessed"], [self.states["/CheckTermination"]])
|
|
|
+ _DoSimulation_MicroStepProcessed_1.setAction(self._DoSimulation_MicroStepProcessed_1_exec)
|
|
|
+ _DoSimulation_MicroStepProcessed_1.setTrigger(None)
|
|
|
+ _DoSimulation_MicroStepProcessed_1.setGuard(self._DoSimulation_MicroStepProcessed_1_guard)
|
|
|
+ self.states["/DoSimulation/MicroStepProcessed"].addTransition(_DoSimulation_MicroStepProcessed_1)
|
|
|
+
|
|
|
+ # transition /DoSimulation/MacroStepPrepared
|
|
|
+ _DoSimulation_MacroStepPrepared_0 = Transition(self, self.states["/DoSimulation/MacroStepPrepared"], [self.states["/DoSimulation/MicroStepProcessed"]])
|
|
|
+ _DoSimulation_MacroStepPrepared_0.setAction(self._DoSimulation_MacroStepPrepared_0_exec)
|
|
|
+ _DoSimulation_MacroStepPrepared_0.setTrigger(None)
|
|
|
+ self.states["/DoSimulation/MacroStepPrepared"].addTransition(_DoSimulation_MacroStepPrepared_0)
|
|
|
+
|
|
|
+ # transition /Initialized
|
|
|
+ _Initialized_0 = Transition(self, self.states["/Initialized"], [self.states["/CheckTermination"]])
|
|
|
+ _Initialized_0.setAction(self._Initialized_0_exec)
|
|
|
+ _Initialized_0.setTrigger(None)
|
|
|
+ self.states["/Initialized"].addTransition(_Initialized_0)
|
|
|
+
|
|
|
+ # transition /Started
|
|
|
+ _Started_0 = Transition(self, self.states["/Started"], [self.states["/Initialized"]])
|
|
|
+ _Started_0.setAction(self._Started_0_exec)
|
|
|
+ _Started_0.setTrigger(None)
|
|
|
+ self.states["/Started"].addTransition(_Started_0)
|
|
|
+
|
|
|
+ def _CheckTermination_MacroStepProcessed_0_exec(self, parameters):
|
|
|
+ print('Going to End... ')
|
|
|
+
|
|
|
+ def _CheckTermination_MacroStepProcessed_0_guard(self, parameters):
|
|
|
+ return self.currentState.final
|
|
|
+
|
|
|
+ def _CheckTermination_MacroStepProcessed_1_exec(self, parameters):
|
|
|
+ print('Going to DoSimulation and reading events... ')
|
|
|
self.currentEvent = self.getInputEventAt(self.logicalTime)
|
|
|
self.selectedTransition = self.model.getTransitionFrom(self.currentState, self.currentEvent, self.elapsed)
|
|
|
+ print(self.currentEvent)
|
|
|
+ print(self.selectedTransition)
|
|
|
|
|
|
- def _Processing_0_exec(self, parameters):
|
|
|
- self.logicalTime = self.logicalTime + self.timestep
|
|
|
- self.elapsed = self.elapsed + self.timestep
|
|
|
- print(self.logicalTime)
|
|
|
- print(self.elapsed)
|
|
|
+ def _CheckTermination_MacroStepProcessed_1_guard(self, parameters):
|
|
|
+ return not self.currentState.final
|
|
|
|
|
|
- def _Processing_0_guard(self, parameters):
|
|
|
- return self.selectedTransition == None
|
|
|
-
|
|
|
- def _Processing_1_exec(self, parameters):
|
|
|
+ def _DoSimulation_MicroStepPrepared_0_exec(self, parameters):
|
|
|
+ print('Going to MicroStepProcessed, taking transition and reading events... ')
|
|
|
+ print('Transition to be taken: ' + str(self.selectedTransition))
|
|
|
self.currentState = self.selectedTransition.target
|
|
|
self.elapsed = 0
|
|
|
self.processEvent(self.currentEvent)
|
|
|
- print('changing to state: ')
|
|
|
- print(self.currentState.getName())
|
|
|
- print(self.logicalTime)
|
|
|
- print(self.elapsed)
|
|
|
+ print('New state: ' + str(self.currentState))
|
|
|
+ self.currentEvent = self.getInputEventAt(self.logicalTime)
|
|
|
+ self.selectedTransition = self.model.getTransitionFrom(self.currentState, self.currentEvent, self.elapsed)
|
|
|
+ print(self.currentEvent)
|
|
|
+ print(self.selectedTransition)
|
|
|
|
|
|
- def _Processing_1_guard(self, parameters):
|
|
|
+ def _DoSimulation_MicroStepProcessed_0_exec(self, parameters):
|
|
|
+ print('Going to MicroStepPrepared... ')
|
|
|
+
|
|
|
+ def _DoSimulation_MicroStepProcessed_0_guard(self, parameters):
|
|
|
return self.selectedTransition != None
|
|
|
|
|
|
- def _Check_0_exec(self, parameters):
|
|
|
- print('going to end... ')
|
|
|
+ def _DoSimulation_MicroStepProcessed_1_exec(self, parameters):
|
|
|
+ print('Going to CheckTermination and advancing time... ')
|
|
|
+ self.logicalTime = self.logicalTime + self.timestep
|
|
|
+ self.elapsed = self.elapsed + self.timestep
|
|
|
+ print(self.logicalTime)
|
|
|
+ print(self.elapsed)
|
|
|
|
|
|
- def _Check_0_guard(self, parameters):
|
|
|
- return self.currentState.final == True
|
|
|
+ def _DoSimulation_MicroStepProcessed_1_guard(self, parameters):
|
|
|
+ return self.selectedTransition == None
|
|
|
|
|
|
- def _Check_1_exec(self, parameters):
|
|
|
- print('going to process... ')
|
|
|
+ def _DoSimulation_MacroStepPrepared_0_exec(self, parameters):
|
|
|
+ print('Going to MicroStepProcessed... ')
|
|
|
|
|
|
- def _Check_1_guard(self, parameters):
|
|
|
- return self.currentState.final == False
|
|
|
+ def _Initialized_0_exec(self, parameters):
|
|
|
+ print('Going to MacroStepProcessed... ')
|
|
|
|
|
|
- def _Start_0_exec(self, parameters):
|
|
|
+ def _Started_0_exec(self, parameters):
|
|
|
+ print('Going to Initialized... ')
|
|
|
self.logicalTime = 0
|
|
|
self.elapsed = 0
|
|
|
self.timestep = 1.0
|
|
|
@@ -164,7 +218,7 @@ class FSASimulator(RuntimeClassBase):
|
|
|
|
|
|
def initializeStatechart(self):
|
|
|
# enter default state
|
|
|
- self.default_targets = self.states["/Start"].getEffectiveTargetStates()
|
|
|
+ self.default_targets = self.states["/Started"].getEffectiveTargetStates()
|
|
|
RuntimeClassBase.initializeStatechart(self)
|
|
|
|
|
|
class ObjectManager(ObjectManagerBase):
|