|
|
@@ -1,7 +1,7 @@
|
|
|
"""
|
|
|
-Generated by Statechart compiler by Glenn De Jonghe and Joeri Exelmans
|
|
|
+Generated by Statechart compiler by Glenn De Jonghe, Joeri Exelmans, Simon Van Mierlo, and Yentl Van Tendeloo (for the inspiration)
|
|
|
|
|
|
-Date: Thu Oct 06 13:17:51 2016
|
|
|
+Date: Tue Oct 11 09:55:10 2016
|
|
|
|
|
|
Model author: Sadaf Mustafiz and Bruno Barroca and Claudio Gomes
|
|
|
Model name: FSASimulator
|
|
|
@@ -9,367 +9,179 @@ Model description:
|
|
|
An FSA simulator written in SCCD. It supports after and events.
|
|
|
"""
|
|
|
|
|
|
-from python_runtime.statecharts_core import *
|
|
|
-from python_runtime.libs.ui import *
|
|
|
-from python_runtime.libs.utils import *
|
|
|
+from sccd.runtime.statecharts_core import *
|
|
|
+from sccd.runtime.libs.ui import *
|
|
|
+from sccd.runtime.libs.utils import *
|
|
|
import fsaclasses
|
|
|
|
|
|
# package "FSASimulator"
|
|
|
|
|
|
class FSASimulator(RuntimeClassBase):
|
|
|
- def __init__(self, controller, amodel, events):
|
|
|
- RuntimeClassBase.__init__(self, controller)
|
|
|
-
|
|
|
- self.semantics.big_step_maximality = StatechartSemantics.TakeMany
|
|
|
- self.semantics.internal_event_lifeline = StatechartSemantics.Queue
|
|
|
- self.semantics.input_event_lifeline = StatechartSemantics.FirstComboStep
|
|
|
- self.semantics.priority = StatechartSemantics.SourceParent
|
|
|
- self.semantics.concurrency = StatechartSemantics.Single
|
|
|
-
|
|
|
- # User defined attributes
|
|
|
- self.model = None
|
|
|
- self.timestep = None
|
|
|
- self.eventList = None
|
|
|
- self.currentState = None
|
|
|
- self.selectedTransition = None
|
|
|
- self.elapsed = None
|
|
|
- self.super_step_completed = None
|
|
|
- self.logicalTime = None
|
|
|
- self.currentEvent = None
|
|
|
-
|
|
|
- # Call user defined constructor
|
|
|
- FSASimulator.user_defined_constructor(self, amodel, events)
|
|
|
-
|
|
|
- def user_defined_constructor(self, amodel, events):
|
|
|
- self.model = amodel
|
|
|
- self.eventList = events
|
|
|
-
|
|
|
- def user_defined_destructor(self):
|
|
|
- pass
|
|
|
-
|
|
|
-
|
|
|
- # User defined method
|
|
|
- def processEvent(self, event):
|
|
|
- if (event != None):
|
|
|
- self.eventList.popEvent(event)
|
|
|
- event.processed = True
|
|
|
-
|
|
|
-
|
|
|
- # User defined method
|
|
|
- def getInputEventAt(self, time):
|
|
|
- return self.eventList.getInputAt(time)
|
|
|
-
|
|
|
- def initializeStatechart(self):
|
|
|
- self.current_state[self.Root] = []
|
|
|
- self.current_state[self.Root_DoSimulation] = []
|
|
|
- self.current_state[self.Root_CheckTermination] = []
|
|
|
-
|
|
|
- # Enter default state
|
|
|
- self.enter_Root_Started()
|
|
|
-
|
|
|
- # Unique IDs for all statechart nodes
|
|
|
- Root = 0
|
|
|
- Root_DoSimulation = 1
|
|
|
- Root_CheckTermination = 2
|
|
|
- Root_DoSimulation_MacroStepPrepared = 3
|
|
|
- Root_DoSimulation_MicroStepProcessed = 4
|
|
|
- Root_DoSimulation_MicroStepPrepared = 5
|
|
|
- Root_End = 6
|
|
|
- Root_CheckTermination_MacroStepProcessed = 7
|
|
|
- Root_Started = 8
|
|
|
- Root_Initialized = 9
|
|
|
-
|
|
|
- # Statechart enter/exit action method(s)
|
|
|
-
|
|
|
- def enter_Root_DoSimulation(self):
|
|
|
- self.current_state[self.Root].append(self.Root_DoSimulation)
|
|
|
-
|
|
|
- def exit_Root_DoSimulation(self):
|
|
|
- if self.Root_DoSimulation_MacroStepPrepared in self.current_state[self.Root_DoSimulation]:
|
|
|
- self.exit_Root_DoSimulation_MacroStepPrepared()
|
|
|
- if self.Root_DoSimulation_MicroStepProcessed in self.current_state[self.Root_DoSimulation]:
|
|
|
- self.exit_Root_DoSimulation_MicroStepProcessed()
|
|
|
- if self.Root_DoSimulation_MicroStepPrepared in self.current_state[self.Root_DoSimulation]:
|
|
|
- self.exit_Root_DoSimulation_MicroStepPrepared()
|
|
|
- self.current_state[self.Root] = []
|
|
|
-
|
|
|
- def enter_Root_CheckTermination(self):
|
|
|
- self.current_state[self.Root].append(self.Root_CheckTermination)
|
|
|
-
|
|
|
- def exit_Root_CheckTermination(self):
|
|
|
- if self.Root_CheckTermination_MacroStepProcessed in self.current_state[self.Root_CheckTermination]:
|
|
|
- self.exit_Root_CheckTermination_MacroStepProcessed()
|
|
|
- self.current_state[self.Root] = []
|
|
|
-
|
|
|
- def enter_Root_DoSimulation_MacroStepPrepared(self):
|
|
|
- self.current_state[self.Root_DoSimulation].append(self.Root_DoSimulation_MacroStepPrepared)
|
|
|
-
|
|
|
- def exit_Root_DoSimulation_MacroStepPrepared(self):
|
|
|
- self.current_state[self.Root_DoSimulation] = []
|
|
|
-
|
|
|
- def enter_Root_DoSimulation_MicroStepProcessed(self):
|
|
|
- self.current_state[self.Root_DoSimulation].append(self.Root_DoSimulation_MicroStepProcessed)
|
|
|
-
|
|
|
- def exit_Root_DoSimulation_MicroStepProcessed(self):
|
|
|
- self.current_state[self.Root_DoSimulation] = []
|
|
|
-
|
|
|
- def enter_Root_DoSimulation_MicroStepPrepared(self):
|
|
|
- self.current_state[self.Root_DoSimulation].append(self.Root_DoSimulation_MicroStepPrepared)
|
|
|
-
|
|
|
- def exit_Root_DoSimulation_MicroStepPrepared(self):
|
|
|
- self.current_state[self.Root_DoSimulation] = []
|
|
|
-
|
|
|
- def enter_Root_End(self):
|
|
|
- self.current_state[self.Root].append(self.Root_End)
|
|
|
-
|
|
|
- def exit_Root_End(self):
|
|
|
- self.current_state[self.Root] = []
|
|
|
-
|
|
|
- def enter_Root_CheckTermination_MacroStepProcessed(self):
|
|
|
- self.current_state[self.Root_CheckTermination].append(self.Root_CheckTermination_MacroStepProcessed)
|
|
|
-
|
|
|
- def exit_Root_CheckTermination_MacroStepProcessed(self):
|
|
|
- self.current_state[self.Root_CheckTermination] = []
|
|
|
-
|
|
|
- def enter_Root_Started(self):
|
|
|
- self.current_state[self.Root].append(self.Root_Started)
|
|
|
-
|
|
|
- def exit_Root_Started(self):
|
|
|
- self.current_state[self.Root] = []
|
|
|
-
|
|
|
- def enter_Root_Initialized(self):
|
|
|
- self.current_state[self.Root].append(self.Root_Initialized)
|
|
|
-
|
|
|
- def exit_Root_Initialized(self):
|
|
|
- self.current_state[self.Root] = []
|
|
|
-
|
|
|
- # Statechart enter/exit default method(s)
|
|
|
-
|
|
|
- def enterDefault_Root_DoSimulation(self):
|
|
|
- self.enter_Root_DoSimulation()
|
|
|
- self.enter_Root_DoSimulation_MacroStepPrepared()
|
|
|
-
|
|
|
- def enterDefault_Root_CheckTermination(self):
|
|
|
- self.enter_Root_CheckTermination()
|
|
|
- self.enter_Root_CheckTermination_MacroStepProcessed()
|
|
|
-
|
|
|
- # Statechart transitions
|
|
|
-
|
|
|
- def generateCandidatesChildren_Root(self):
|
|
|
- if self.current_state[self.Root][0] == self.Root_DoSimulation:
|
|
|
- return self.generateCandidates_Root_DoSimulation()
|
|
|
- elif self.current_state[self.Root][0] == self.Root_End:
|
|
|
- return self.generateCandidates_Root_End()
|
|
|
- elif self.current_state[self.Root][0] == self.Root_CheckTermination:
|
|
|
- return self.generateCandidates_Root_CheckTermination()
|
|
|
- elif self.current_state[self.Root][0] == self.Root_Started:
|
|
|
- return self.generateCandidates_Root_Started()
|
|
|
- elif self.current_state[self.Root][0] == self.Root_Initialized:
|
|
|
- return self.generateCandidates_Root_Initialized()
|
|
|
- return False
|
|
|
-
|
|
|
- def generateCandidates_Root(self):
|
|
|
- if not self.combo_step.isArenaChanged(self.Root):
|
|
|
- return self.generateCandidatesChildren_Root()
|
|
|
- else:
|
|
|
- return True
|
|
|
-
|
|
|
- def generateCandidatesChildren_Root_DoSimulation(self):
|
|
|
- if self.current_state[self.Root_DoSimulation][0] == self.Root_DoSimulation_MacroStepPrepared:
|
|
|
- return self.generateCandidates_Root_DoSimulation_MacroStepPrepared()
|
|
|
- elif self.current_state[self.Root_DoSimulation][0] == self.Root_DoSimulation_MicroStepProcessed:
|
|
|
- return self.generateCandidates_Root_DoSimulation_MicroStepProcessed()
|
|
|
- elif self.current_state[self.Root_DoSimulation][0] == self.Root_DoSimulation_MicroStepPrepared:
|
|
|
- return self.generateCandidates_Root_DoSimulation_MicroStepPrepared()
|
|
|
- return False
|
|
|
-
|
|
|
- def generateCandidates_Root_DoSimulation(self):
|
|
|
- if not self.combo_step.isArenaChanged(self.Root_DoSimulation):
|
|
|
- return self.generateCandidatesChildren_Root_DoSimulation()
|
|
|
- else:
|
|
|
- return True
|
|
|
-
|
|
|
- def generateCandidatesCurrent_Root_DoSimulation_MacroStepPrepared(self):
|
|
|
- enabled_events = self.getEnabledEvents()
|
|
|
- self.small_step.addCandidate(self.transition_Root_DoSimulation_MacroStepPrepared_1, [])
|
|
|
- return True
|
|
|
- return False
|
|
|
-
|
|
|
- def generateCandidates_Root_DoSimulation_MacroStepPrepared(self):
|
|
|
- if not self.combo_step.isArenaChanged(self.Root_DoSimulation_MacroStepPrepared):
|
|
|
- return self.generateCandidatesCurrent_Root_DoSimulation_MacroStepPrepared()
|
|
|
- else:
|
|
|
- return True
|
|
|
-
|
|
|
- def transition_Root_DoSimulation_MacroStepPrepared_1(self, parameters):
|
|
|
- self.exit_Root_DoSimulation_MacroStepPrepared()
|
|
|
- print('Going to MicroStepProcessed... ')
|
|
|
- self.combo_step.setArenaChanged(self.Root_DoSimulation)
|
|
|
- self.enter_Root_DoSimulation_MicroStepProcessed()
|
|
|
-
|
|
|
- def generateCandidatesCurrent_Root_DoSimulation_MicroStepProcessed(self):
|
|
|
- enabled_events = self.getEnabledEvents()
|
|
|
- if self.selectedTransition != None:
|
|
|
- self.small_step.addCandidate(self.transition_Root_DoSimulation_MicroStepProcessed_1, [])
|
|
|
- return True
|
|
|
- enabled_events = self.getEnabledEvents()
|
|
|
- if self.selectedTransition == None:
|
|
|
- self.small_step.addCandidate(self.transition_Root_DoSimulation_MicroStepProcessed_2, [])
|
|
|
- return True
|
|
|
- return False
|
|
|
-
|
|
|
- def generateCandidates_Root_DoSimulation_MicroStepProcessed(self):
|
|
|
- if not self.combo_step.isArenaChanged(self.Root_DoSimulation_MicroStepProcessed):
|
|
|
- return self.generateCandidatesCurrent_Root_DoSimulation_MicroStepProcessed()
|
|
|
- else:
|
|
|
- return True
|
|
|
-
|
|
|
- def transition_Root_DoSimulation_MicroStepProcessed_1(self, parameters):
|
|
|
- self.exit_Root_DoSimulation_MicroStepProcessed()
|
|
|
- print('Going to MicroStepPrepared... ')
|
|
|
- self.combo_step.setArenaChanged(self.Root_DoSimulation)
|
|
|
- self.enter_Root_DoSimulation_MicroStepPrepared()
|
|
|
-
|
|
|
- def transition_Root_DoSimulation_MicroStepProcessed_2(self, parameters):
|
|
|
- self.exit_Root_DoSimulation()
|
|
|
- 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)
|
|
|
- self.combo_step.setArenaChanged(self.Root)
|
|
|
- self.enterDefault_Root_CheckTermination()
|
|
|
-
|
|
|
- def generateCandidatesCurrent_Root_DoSimulation_MicroStepPrepared(self):
|
|
|
- enabled_events = self.getEnabledEvents()
|
|
|
- self.small_step.addCandidate(self.transition_Root_DoSimulation_MicroStepPrepared_1, [])
|
|
|
- return True
|
|
|
- return False
|
|
|
-
|
|
|
- def generateCandidates_Root_DoSimulation_MicroStepPrepared(self):
|
|
|
- if not self.combo_step.isArenaChanged(self.Root_DoSimulation_MicroStepPrepared):
|
|
|
- return self.generateCandidatesCurrent_Root_DoSimulation_MicroStepPrepared()
|
|
|
- else:
|
|
|
- return True
|
|
|
-
|
|
|
- def transition_Root_DoSimulation_MicroStepPrepared_1(self, parameters):
|
|
|
- self.exit_Root_DoSimulation_MicroStepPrepared()
|
|
|
- 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('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)
|
|
|
- self.combo_step.setArenaChanged(self.Root_DoSimulation)
|
|
|
- self.enter_Root_DoSimulation_MicroStepProcessed()
|
|
|
-
|
|
|
- def generateCandidates_Root_End(self):
|
|
|
- return False
|
|
|
-
|
|
|
- def generateCandidatesChildren_Root_CheckTermination(self):
|
|
|
- if self.current_state[self.Root_CheckTermination][0] == self.Root_CheckTermination_MacroStepProcessed:
|
|
|
- return self.generateCandidates_Root_CheckTermination_MacroStepProcessed()
|
|
|
- return False
|
|
|
-
|
|
|
- def generateCandidates_Root_CheckTermination(self):
|
|
|
- if not self.combo_step.isArenaChanged(self.Root_CheckTermination):
|
|
|
- return self.generateCandidatesChildren_Root_CheckTermination()
|
|
|
- else:
|
|
|
- return True
|
|
|
-
|
|
|
- def generateCandidatesCurrent_Root_CheckTermination_MacroStepProcessed(self):
|
|
|
- enabled_events = self.getEnabledEvents()
|
|
|
- if self.currentState.final:
|
|
|
- self.small_step.addCandidate(self.transition_Root_CheckTermination_MacroStepProcessed_1, [])
|
|
|
- return True
|
|
|
- enabled_events = self.getEnabledEvents()
|
|
|
- if not self.currentState.final:
|
|
|
- self.small_step.addCandidate(self.transition_Root_CheckTermination_MacroStepProcessed_2, [])
|
|
|
- return True
|
|
|
- return False
|
|
|
-
|
|
|
- def generateCandidates_Root_CheckTermination_MacroStepProcessed(self):
|
|
|
- if not self.combo_step.isArenaChanged(self.Root_CheckTermination_MacroStepProcessed):
|
|
|
- return self.generateCandidatesCurrent_Root_CheckTermination_MacroStepProcessed()
|
|
|
- else:
|
|
|
- return True
|
|
|
-
|
|
|
- def transition_Root_CheckTermination_MacroStepProcessed_1(self, parameters):
|
|
|
- self.exit_Root_CheckTermination()
|
|
|
- print('Going to End... ')
|
|
|
- self.combo_step.setArenaChanged(self.Root)
|
|
|
- self.enter_Root_End()
|
|
|
-
|
|
|
- def transition_Root_CheckTermination_MacroStepProcessed_2(self, parameters):
|
|
|
- self.exit_Root_CheckTermination()
|
|
|
- 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)
|
|
|
- self.combo_step.setArenaChanged(self.Root)
|
|
|
- self.enterDefault_Root_DoSimulation()
|
|
|
-
|
|
|
- def generateCandidatesCurrent_Root_Started(self):
|
|
|
- enabled_events = self.getEnabledEvents()
|
|
|
- self.small_step.addCandidate(self.transition_Root_Started_1, [])
|
|
|
- return True
|
|
|
- return False
|
|
|
-
|
|
|
- def generateCandidates_Root_Started(self):
|
|
|
- if not self.combo_step.isArenaChanged(self.Root_Started):
|
|
|
- return self.generateCandidatesCurrent_Root_Started()
|
|
|
- else:
|
|
|
- return True
|
|
|
-
|
|
|
- def transition_Root_Started_1(self, parameters):
|
|
|
- self.exit_Root_Started()
|
|
|
- print('Going to Initialized... ')
|
|
|
- self.logicalTime = 0
|
|
|
- self.elapsed = 0
|
|
|
- self.timestep = 1.0
|
|
|
- self.currentState = self.model.initialState
|
|
|
- self.combo_step.setArenaChanged(self.Root)
|
|
|
- self.enter_Root_Initialized()
|
|
|
-
|
|
|
- def generateCandidatesCurrent_Root_Initialized(self):
|
|
|
- enabled_events = self.getEnabledEvents()
|
|
|
- self.small_step.addCandidate(self.transition_Root_Initialized_1, [])
|
|
|
- return True
|
|
|
- return False
|
|
|
-
|
|
|
- def generateCandidates_Root_Initialized(self):
|
|
|
- if not self.combo_step.isArenaChanged(self.Root_Initialized):
|
|
|
- return self.generateCandidatesCurrent_Root_Initialized()
|
|
|
- else:
|
|
|
- return True
|
|
|
-
|
|
|
- def transition_Root_Initialized_1(self, parameters):
|
|
|
- self.exit_Root_Initialized()
|
|
|
- print('Going to MacroStepProcessed... ')
|
|
|
- self.combo_step.setArenaChanged(self.Root)
|
|
|
- self.enterDefault_Root_CheckTermination()
|
|
|
-
|
|
|
- # Generate transition candidates for current small step
|
|
|
- def generateCandidates(self):
|
|
|
- self.generateCandidates_Root()
|
|
|
+ def __init__(self, controller, amodel, events):
|
|
|
+ RuntimeClassBase.__init__(self, controller)
|
|
|
+
|
|
|
+ self.semantics.big_step_maximality = StatechartSemantics.TakeMany
|
|
|
+ self.semantics.internal_event_lifeline = StatechartSemantics.Queue
|
|
|
+ self.semantics.input_event_lifeline = StatechartSemantics.FirstComboStep
|
|
|
+ self.semantics.priority = StatechartSemantics.SourceParent
|
|
|
+ self.semantics.concurrency = StatechartSemantics.Single
|
|
|
+
|
|
|
+ # build Statechart structure
|
|
|
+ self.build_statechart_structure()
|
|
|
+
|
|
|
+ # user defined attributes
|
|
|
+ self.elapsed = None
|
|
|
+ self.model = None
|
|
|
+ self.logicalTime = None
|
|
|
+ self.timestep = None
|
|
|
+ self.currentEvent = None
|
|
|
+ self.selectedTransition = None
|
|
|
+ self.eventList = None
|
|
|
+ self.currentState = None
|
|
|
+
|
|
|
+ # call user defined constructor
|
|
|
+ FSASimulator.user_defined_constructor(self, amodel, events)
|
|
|
+
|
|
|
+ def user_defined_constructor(self, amodel, events):
|
|
|
+ self.model = amodel
|
|
|
+ self.eventList = events
|
|
|
+
|
|
|
+ def user_defined_destructor(self):
|
|
|
+ pass
|
|
|
+
|
|
|
+
|
|
|
+ # user defined method
|
|
|
+ def processEvent(self, event):
|
|
|
+ if (event != None):
|
|
|
+ self.eventList.popEvent(event)
|
|
|
+ event.processed = True
|
|
|
+
|
|
|
+
|
|
|
+ # user defined method
|
|
|
+ def getInputEventAt(self, time):
|
|
|
+ return self.eventList.getInputAt(time)
|
|
|
+
|
|
|
+
|
|
|
+ # builds Statechart structure
|
|
|
+ def build_statechart_structure(self):
|
|
|
+
|
|
|
+ # state <root>
|
|
|
+ self.states[""] = State(0, self)
|
|
|
+
|
|
|
+ # state /End
|
|
|
+ self.states["/End"] = State(1, self)
|
|
|
+
|
|
|
+ # state /Processing
|
|
|
+ self.states["/Processing"] = State(2, self)
|
|
|
+
|
|
|
+ # state /Check
|
|
|
+ self.states["/Check"] = State(3, self)
|
|
|
+ self.states["/Check"].setEnter(self._Check_enter)
|
|
|
+
|
|
|
+ # state /Start
|
|
|
+ self.states["/Start"] = State(4, self)
|
|
|
+
|
|
|
+ # add children
|
|
|
+ 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[""].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.currentEvent = self.getInputEventAt(self.logicalTime)
|
|
|
+ self.selectedTransition = self.model.getTransitionFrom(self.currentState, self.currentEvent, self.elapsed)
|
|
|
+
|
|
|
+ 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 _Processing_0_guard(self, parameters):
|
|
|
+ return self.selectedTransition == None
|
|
|
+
|
|
|
+ def _Processing_1_exec(self, parameters):
|
|
|
+ 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)
|
|
|
+
|
|
|
+ def _Processing_1_guard(self, parameters):
|
|
|
+ return self.selectedTransition != None
|
|
|
+
|
|
|
+ def _Check_0_exec(self, parameters):
|
|
|
+ print('going to end... ')
|
|
|
+
|
|
|
+ def _Check_0_guard(self, parameters):
|
|
|
+ return self.currentState.final == True
|
|
|
+
|
|
|
+ def _Check_1_exec(self, parameters):
|
|
|
+ print('going to process... ')
|
|
|
+
|
|
|
+ def _Check_1_guard(self, parameters):
|
|
|
+ return self.currentState.final == False
|
|
|
+
|
|
|
+ def _Start_0_exec(self, parameters):
|
|
|
+ self.logicalTime = 0
|
|
|
+ self.elapsed = 0
|
|
|
+ self.timestep = 1.0
|
|
|
+ self.currentState = self.model.initialState
|
|
|
+
|
|
|
+ def initializeStatechart(self):
|
|
|
+ # enter default state
|
|
|
+ self.default_targets = self.states["/Start"].getEffectiveTargetStates()
|
|
|
+ RuntimeClassBase.initializeStatechart(self)
|
|
|
|
|
|
class ObjectManager(ObjectManagerBase):
|
|
|
- def __init__(self, controller):
|
|
|
- ObjectManagerBase.__init__(self, controller)
|
|
|
-
|
|
|
- def instantiate(self, class_name, construct_params):
|
|
|
- if class_name == "FSASimulator":
|
|
|
- instance = FSASimulator(self.controller, construct_params[0], construct_params[1])
|
|
|
- instance.associations = {}
|
|
|
- return instance
|
|
|
+ def __init__(self, controller):
|
|
|
+ ObjectManagerBase.__init__(self, controller)
|
|
|
+
|
|
|
+ def instantiate(self, class_name, construct_params):
|
|
|
+ if class_name == "FSASimulator":
|
|
|
+ instance = FSASimulator(self.controller, construct_params[0], construct_params[1])
|
|
|
+ instance.associations = {}
|
|
|
+ else:
|
|
|
+ raise Exception("Cannot instantiate class " + class_name)
|
|
|
+ return instance
|
|
|
|
|
|
class Controller(ThreadsControllerBase):
|
|
|
- def __init__(self, amodel, events, keep_running = None):
|
|
|
- if keep_running == None: keep_running = True
|
|
|
- ThreadsControllerBase.__init__(self, ObjectManager(self), keep_running)
|
|
|
- self.object_manager.createInstance("FSASimulator", [amodel, events])
|
|
|
+ def __init__(self, amodel, events, keep_running = None, behind_schedule_callback = None):
|
|
|
+ if keep_running == None: keep_running = True
|
|
|
+ if behind_schedule_callback == None: behind_schedule_callback = None
|
|
|
+ ThreadsControllerBase.__init__(self, ObjectManager(self), keep_running, behind_schedule_callback)
|
|
|
+ self.object_manager.createInstance("FSASimulator", [amodel, events])
|