"""
Generated by Statechart compiler by Glenn De Jonghe, Joeri Exelmans, Simon Van Mierlo, and Yentl Van Tendeloo (for the inspiration)

Date:   Mon Oct 24 14:22:28 2016

Model author: Sadaf Mustafiz and Bruno Barroca and Claudio Gomes and Simon Van Mierlo
Model name:   FSASimulator
Model description:
A debuggeable FSA simulator. It supports after and events.
"""

from sccd.runtime.statecharts_core import *
from sccd.runtime.libs.ui import *
from sccd.runtime.libs.utils import *
import fsaclasses
import sccd.runtime.accurate_time as accurate_time

class Breakpoint:
    def __init__(self, name, function, enabled, disable_on_trigger):
        self.name = name
        self.function = function
        self.enabled = enabled
        self.disable_on_trigger = disable_on_trigger

# package "FSASimulator"

class FSASimulator(RuntimeClassBase):
    def __init__(self, controller, model, events):
        RuntimeClassBase.__init__(self, controller)
        
        self.semantics.big_step_maximality = StatechartSemantics.TakeMany
        self.semantics.internal_event_lifeline = StatechartSemantics.NextComboStep
        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.delta = None
        self.clock = None
        self.model = None
        self.state = None
        self.currentEvent = None
        self.selectedTransition = None
        self.eventList = None
        
        # call user defined constructor
        FSASimulator.user_defined_constructor(self, model, events)
    
    def user_defined_constructor(self, model, events):
        self.model = model
        self.eventList = events
    
    def user_defined_destructor(self):
        pass
    
    
    # user defined method
    def initialize(self):
        self.clock = 0
        self.elapsed = 0
        self.delta = 1.0 * 1000.0 # in miliseconds for real-time simulation
        self.time_next = self.delta
        self.state = self.model.initialState
    
    
    # user defined method
    def initializeDebugger(self):
        self.breakpoints = []
        self.triggered_bp = None
    
    
    # user defined method
    def endCondition(self):
        return self.state and self.state.final
    
    
    # user defined method
    def advanceTime(self):
        self.clock = self.time_next
        self.elapsed = self.elapsed + self.delta
        self.time_next = self.clock + self.delta
    
    
    # user defined method
    def finalize(self):
        print 'Simulation finalized.'
    
    
    # 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)
    
    
    # user defined method
    def waitTime(self):
        # First, we convert from wall-clock time to simulated time.
        # This means the elapsed time in wall-clock time needs to be scaled according to the realtime scale (for example, if the realtime scale is 2, an elapsed time of 1 second in wall-clock time is equal to an elapsed time of 2 seconds in simulated time).
        simulated_diff = (accurate_time.time() - self.realtime_start_time) * self.realtime_scale
        # time_next and simulated_diff are both in simulated time: so now scale back to wall-clock time by dividing.
        # This function returns an amount of miliseconds.
        return ((self.time_next - simulated_diff) / self.realtime_scale)
    
    
    # user defined method
    def syncSimulatedTime(self):
        diff = accurate_time.time() - self.realtime_start_time
        self.clock = diff * self.realtime_scale
    
    
    # user defined method
    def addBreakpoint(self, name, function, enabled = None, disable_on_trigger = None):
        if enabled == None: enabled = true
        if disable_on_trigger == None: disable_on_trigger = true
        if len([bp for bp in self.breakpoints if bp.name == name]) > 0:
            return -1
        self.breakpoints.append(Breakpoint(name, function, enabled, disable_on_trigger))
        return 0
    
    
    # user defined method
    def delBreakpoint(self, name):
        if len([bp for bp in self.breakpoints if bp.name == name]) == 0:
            return -1
        self.breakpoints = [bp for bp in self.breakpoints if bp.name != name]
        return 0
    
    
    # user defined method
    def toggleBreakpoint(self, name):
        if len([bp for bp in self.breakpoints if bp.name == name]) == 0:
            return -1
        for bp in self.breakpoints:
            if bp.name == name:
                bp.enabled = enabled
                break
        return 0
    
    
    # user defined method
    def breakpointTriggers(self, is_realtime_simulation):
        self.triggered_bp = None
        for bp in self.breakpoints:
            if not bp.enabled:
                continue
            # include the function in the scope...
            exec(bp.function)
            # ... and execute it, note that the breakpoint thus has to start with "def breakpoint("
            # note that we pass self.time_next instead of self.simulated_time in the case of as-fast-as-possible simulation (or stepping)
            # this is to make sure that the simulation is stopped BEFORE the specified time is reached, and not AFTER (because we don't necessarily implement 'step back')
            # in case of realtime simulation, we do pass the current simulated time, since we can stop at (more or less) exactly the right time
            if breakpoint({'clock': (self.clock if is_realtime_simulation else self.time_next) / 1000.0, 'state': self.state, 'event': self.currentEvent}):
                # triggered!
                self.triggered_bp = bp.name
                if bp.disable_on_trigger:
                    bp.enabled = False
                return True
            else:
                # not triggered, so continue
                continue
        return False
    
    
    # user defined method
    def godEvent(self, new_state):
        filtered_states = [s for s in self.model.states if s.name == new_state]
        if not len(filtered_states) == 1:
            return -1
        self.state = filtered_states[0]
        return 0
    
    
    # builds Statechart structure
    def build_statechart_structure(self):
        
        # state <root>
        self.states[""] = State(0, self)
        
        # state /Main
        self.states["/Main"] = ParallelState(1, self)
        
        # state /Main/SimulationState
        self.states["/Main/SimulationState"] = State(2, self)
        
        # state /Main/SimulationState/Paused
        self.states["/Main/SimulationState/Paused"] = State(3, self)
        
        # state /Main/SimulationState/PrePaused
        self.states["/Main/SimulationState/PrePaused"] = State(4, self)
        self.states["/Main/SimulationState/PrePaused"].setEnter(self._Main_SimulationState_PrePaused_enter)
        self.states["/Main/SimulationState/PrePaused"].setExit(self._Main_SimulationState_PrePaused_exit)
        
        # state /Main/SimulationState/PreBreakpointTriggered
        self.states["/Main/SimulationState/PreBreakpointTriggered"] = State(5, self)
        self.states["/Main/SimulationState/PreBreakpointTriggered"].setEnter(self._Main_SimulationState_PreBreakpointTriggered_enter)
        self.states["/Main/SimulationState/PreBreakpointTriggered"].setExit(self._Main_SimulationState_PreBreakpointTriggered_exit)
        
        # state /Main/SimulationState/Running
        self.states["/Main/SimulationState/Running"] = State(6, self)
        
        # state /Main/SimulationState/Running/Continuous
        self.states["/Main/SimulationState/Running/Continuous"] = State(7, self)
        
        # state /Main/SimulationState/Running/BigStep
        self.states["/Main/SimulationState/Running/BigStep"] = State(8, self)
        
        # state /Main/SimulationState/Running/BigStepDone
        self.states["/Main/SimulationState/Running/BigStepDone"] = State(9, self)
        self.states["/Main/SimulationState/Running/BigStepDone"].setEnter(self._Main_SimulationState_Running_BigStepDone_enter)
        self.states["/Main/SimulationState/Running/BigStepDone"].setExit(self._Main_SimulationState_Running_BigStepDone_exit)
        
        # state /Main/SimulationState/Running/SmallStep
        self.states["/Main/SimulationState/Running/SmallStep"] = State(10, self)
        
        # state /Main/SimulationState/Running/SmallStepDone
        self.states["/Main/SimulationState/Running/SmallStepDone"] = State(11, self)
        self.states["/Main/SimulationState/Running/SmallStepDone"].setEnter(self._Main_SimulationState_Running_SmallStepDone_enter)
        self.states["/Main/SimulationState/Running/SmallStepDone"].setExit(self._Main_SimulationState_Running_SmallStepDone_exit)
        
        # state /Main/SimulationState/Running/Realtime
        self.states["/Main/SimulationState/Running/Realtime"] = State(12, self)
        self.states["/Main/SimulationState/Running/Realtime"].setEnter(self._Main_SimulationState_Running_Realtime_enter)
        
        # state /Main/SimulationState/PreStopped
        self.states["/Main/SimulationState/PreStopped"] = State(13, self)
        self.states["/Main/SimulationState/PreStopped"].setEnter(self._Main_SimulationState_PreStopped_enter)
        self.states["/Main/SimulationState/PreStopped"].setExit(self._Main_SimulationState_PreStopped_exit)
        
        # state /Main/SimulationState/TerminationConditionRaised
        self.states["/Main/SimulationState/TerminationConditionRaised"] = State(14, self)
        self.states["/Main/SimulationState/TerminationConditionRaised"].setEnter(self._Main_SimulationState_TerminationConditionRaised_enter)
        self.states["/Main/SimulationState/TerminationConditionRaised"].setExit(self._Main_SimulationState_TerminationConditionRaised_exit)
        
        # state /Main/SimulationState/Stopped
        self.states["/Main/SimulationState/Stopped"] = State(15, self)
        
        # state /Main/SimulationFlow
        self.states["/Main/SimulationFlow"] = State(16, self)
        
        # state /Main/SimulationFlow/Started
        self.states["/Main/SimulationFlow/Started"] = State(17, self)
        
        # state /Main/SimulationFlow/Initialized
        self.states["/Main/SimulationFlow/Initialized"] = State(18, self)
        
        # state /Main/SimulationFlow/InitializeDebugger
        self.states["/Main/SimulationFlow/InitializeDebugger"] = State(19, self)
        self.states["/Main/SimulationFlow/InitializeDebugger"].setEnter(self._Main_SimulationFlow_InitializeDebugger_enter)
        
        # state /Main/SimulationFlow/CheckTermination
        self.states["/Main/SimulationFlow/CheckTermination"] = State(20, self)
        
        # state /Main/SimulationFlow/CheckTermination/MacroStepProcessed
        self.states["/Main/SimulationFlow/CheckTermination/MacroStepProcessed"] = State(21, self)
        
        # state /Main/SimulationFlow/Waiting
        self.states["/Main/SimulationFlow/Waiting"] = State(22, self)
        self.states["/Main/SimulationFlow/Waiting"].setEnter(self._Main_SimulationFlow_Waiting_enter)
        self.states["/Main/SimulationFlow/Waiting"].setExit(self._Main_SimulationFlow_Waiting_exit)
        
        # state /Main/SimulationFlow/DoSimulation
        self.states["/Main/SimulationFlow/DoSimulation"] = State(23, self)
        
        # state /Main/SimulationFlow/DoSimulation/MacroStepPrepared
        self.states["/Main/SimulationFlow/DoSimulation/MacroStepPrepared"] = State(24, self)
        self.states["/Main/SimulationFlow/DoSimulation/MacroStepPrepared"].setEnter(self._Main_SimulationFlow_DoSimulation_MacroStepPrepared_enter)
        
        # state /Main/SimulationFlow/DoSimulation/MicroStepProcessed
        self.states["/Main/SimulationFlow/DoSimulation/MicroStepProcessed"] = State(25, self)
        self.states["/Main/SimulationFlow/DoSimulation/MicroStepProcessed"].setEnter(self._Main_SimulationFlow_DoSimulation_MicroStepProcessed_enter)
        self.states["/Main/SimulationFlow/DoSimulation/MicroStepProcessed"].setExit(self._Main_SimulationFlow_DoSimulation_MicroStepProcessed_exit)
        
        # state /Main/SimulationFlow/DoSimulation/PreMicroStepPrepared
        self.states["/Main/SimulationFlow/DoSimulation/PreMicroStepPrepared"] = State(26, self)
        
        # state /Main/SimulationFlow/DoSimulation/MicroStepPrepared
        self.states["/Main/SimulationFlow/DoSimulation/MicroStepPrepared"] = State(27, self)
        
        # state /Main/SimulationFlow/Stopped
        self.states["/Main/SimulationFlow/Stopped"] = State(28, self)
        
        # state /Main/BreakpointManager
        self.states["/Main/BreakpointManager"] = State(29, self)
        
        # state /Main/BreakpointManager/Listening
        self.states["/Main/BreakpointManager/Listening"] = State(30, self)
        
        # state /Main/GodEventManager
        self.states["/Main/GodEventManager"] = State(31, self)
        
        # state /Main/GodEventManager/Listening
        self.states["/Main/GodEventManager/Listening"] = State(32, self)
        
        # state /Main/UserOutput
        self.states["/Main/UserOutput"] = State(33, self)
        
        # state /Main/UserOutput/Waiting
        self.states["/Main/UserOutput/Waiting"] = State(34, self)
        
        # state /SimulationComplete
        self.states["/SimulationComplete"] = State(35, self)
        
        # add children
        self.states[""].addChild(self.states["/Main"])
        self.states[""].addChild(self.states["/SimulationComplete"])
        self.states["/Main"].addChild(self.states["/Main/SimulationState"])
        self.states["/Main"].addChild(self.states["/Main/SimulationFlow"])
        self.states["/Main"].addChild(self.states["/Main/BreakpointManager"])
        self.states["/Main"].addChild(self.states["/Main/GodEventManager"])
        self.states["/Main"].addChild(self.states["/Main/UserOutput"])
        self.states["/Main/SimulationState"].addChild(self.states["/Main/SimulationState/Paused"])
        self.states["/Main/SimulationState"].addChild(self.states["/Main/SimulationState/PrePaused"])
        self.states["/Main/SimulationState"].addChild(self.states["/Main/SimulationState/PreBreakpointTriggered"])
        self.states["/Main/SimulationState"].addChild(self.states["/Main/SimulationState/Running"])
        self.states["/Main/SimulationState"].addChild(self.states["/Main/SimulationState/PreStopped"])
        self.states["/Main/SimulationState"].addChild(self.states["/Main/SimulationState/TerminationConditionRaised"])
        self.states["/Main/SimulationState"].addChild(self.states["/Main/SimulationState/Stopped"])
        self.states["/Main/SimulationState/Running"].addChild(self.states["/Main/SimulationState/Running/Continuous"])
        self.states["/Main/SimulationState/Running"].addChild(self.states["/Main/SimulationState/Running/BigStep"])
        self.states["/Main/SimulationState/Running"].addChild(self.states["/Main/SimulationState/Running/BigStepDone"])
        self.states["/Main/SimulationState/Running"].addChild(self.states["/Main/SimulationState/Running/SmallStep"])
        self.states["/Main/SimulationState/Running"].addChild(self.states["/Main/SimulationState/Running/SmallStepDone"])
        self.states["/Main/SimulationState/Running"].addChild(self.states["/Main/SimulationState/Running/Realtime"])
        self.states["/Main/SimulationFlow"].addChild(self.states["/Main/SimulationFlow/Started"])
        self.states["/Main/SimulationFlow"].addChild(self.states["/Main/SimulationFlow/Initialized"])
        self.states["/Main/SimulationFlow"].addChild(self.states["/Main/SimulationFlow/InitializeDebugger"])
        self.states["/Main/SimulationFlow"].addChild(self.states["/Main/SimulationFlow/CheckTermination"])
        self.states["/Main/SimulationFlow"].addChild(self.states["/Main/SimulationFlow/Waiting"])
        self.states["/Main/SimulationFlow"].addChild(self.states["/Main/SimulationFlow/DoSimulation"])
        self.states["/Main/SimulationFlow"].addChild(self.states["/Main/SimulationFlow/Stopped"])
        self.states["/Main/SimulationFlow/CheckTermination"].addChild(self.states["/Main/SimulationFlow/CheckTermination/MacroStepProcessed"])
        self.states["/Main/SimulationFlow/DoSimulation"].addChild(self.states["/Main/SimulationFlow/DoSimulation/MacroStepPrepared"])
        self.states["/Main/SimulationFlow/DoSimulation"].addChild(self.states["/Main/SimulationFlow/DoSimulation/MicroStepProcessed"])
        self.states["/Main/SimulationFlow/DoSimulation"].addChild(self.states["/Main/SimulationFlow/DoSimulation/PreMicroStepPrepared"])
        self.states["/Main/SimulationFlow/DoSimulation"].addChild(self.states["/Main/SimulationFlow/DoSimulation/MicroStepPrepared"])
        self.states["/Main/BreakpointManager"].addChild(self.states["/Main/BreakpointManager/Listening"])
        self.states["/Main/GodEventManager"].addChild(self.states["/Main/GodEventManager/Listening"])
        self.states["/Main/UserOutput"].addChild(self.states["/Main/UserOutput/Waiting"])
        self.states[""].fixTree()
        self.states[""].default_state = self.states["/Main"]
        self.states["/Main/SimulationState"].default_state = self.states["/Main/SimulationState/Paused"]
        self.states["/Main/SimulationState/Running"].default_state = self.states["/Main/SimulationState/Running/Continuous"]
        self.states["/Main/SimulationFlow"].default_state = self.states["/Main/SimulationFlow/Started"]
        self.states["/Main/SimulationFlow/CheckTermination"].default_state = self.states["/Main/SimulationFlow/CheckTermination/MacroStepProcessed"]
        self.states["/Main/SimulationFlow/DoSimulation"].default_state = self.states["/Main/SimulationFlow/DoSimulation/MacroStepPrepared"]
        self.states["/Main/BreakpointManager"].default_state = self.states["/Main/BreakpointManager/Listening"]
        self.states["/Main/GodEventManager"].default_state = self.states["/Main/GodEventManager/Listening"]
        self.states["/Main/UserOutput"].default_state = self.states["/Main/UserOutput/Waiting"]
        
        # transition /Main/SimulationState/Paused
        _Main_SimulationState_Paused_0 = Transition(self, self.states["/Main/SimulationState/Paused"], [self.states["/Main/SimulationState/Running/Continuous"]])
        _Main_SimulationState_Paused_0.setTrigger(Event("continuous", "user_input"))
        self.states["/Main/SimulationState/Paused"].addTransition(_Main_SimulationState_Paused_0)
        _Main_SimulationState_Paused_1 = Transition(self, self.states["/Main/SimulationState/Paused"], [self.states["/Main/SimulationState/Running/Realtime"]])
        _Main_SimulationState_Paused_1.setAction(self._Main_SimulationState_Paused_1_exec)
        _Main_SimulationState_Paused_1.setTrigger(Event("realtime", "user_input"))
        self.states["/Main/SimulationState/Paused"].addTransition(_Main_SimulationState_Paused_1)
        _Main_SimulationState_Paused_2 = Transition(self, self.states["/Main/SimulationState/Paused"], [self.states["/Main/SimulationState/Running/BigStep"]])
        _Main_SimulationState_Paused_2.setTrigger(Event("big_step", "user_input"))
        self.states["/Main/SimulationState/Paused"].addTransition(_Main_SimulationState_Paused_2)
        _Main_SimulationState_Paused_3 = Transition(self, self.states["/Main/SimulationState/Paused"], [self.states["/Main/SimulationState/Running/SmallStep"]])
        _Main_SimulationState_Paused_3.setTrigger(Event("small_step", "user_input"))
        self.states["/Main/SimulationState/Paused"].addTransition(_Main_SimulationState_Paused_3)
        _Main_SimulationState_Paused_4 = Transition(self, self.states["/Main/SimulationState/Paused"], [self.states["/Main/SimulationState/PreStopped"]])
        _Main_SimulationState_Paused_4.setTrigger(None)
        _Main_SimulationState_Paused_4.setGuard(self._Main_SimulationState_Paused_4_guard)
        self.states["/Main/SimulationState/Paused"].addTransition(_Main_SimulationState_Paused_4)
        
        # transition /Main/SimulationState/PrePaused
        _Main_SimulationState_PrePaused_0 = Transition(self, self.states["/Main/SimulationState/PrePaused"], [self.states["/Main/SimulationState/Paused"]])
        _Main_SimulationState_PrePaused_0.setAction(self._Main_SimulationState_PrePaused_0_exec)
        _Main_SimulationState_PrePaused_0.setTrigger(Event("_0after"))
        self.states["/Main/SimulationState/PrePaused"].addTransition(_Main_SimulationState_PrePaused_0)
        
        # transition /Main/SimulationState/PreBreakpointTriggered
        _Main_SimulationState_PreBreakpointTriggered_0 = Transition(self, self.states["/Main/SimulationState/PreBreakpointTriggered"], [self.states["/Main/SimulationState/Paused"]])
        _Main_SimulationState_PreBreakpointTriggered_0.setAction(self._Main_SimulationState_PreBreakpointTriggered_0_exec)
        _Main_SimulationState_PreBreakpointTriggered_0.setTrigger(Event("_1after"))
        self.states["/Main/SimulationState/PreBreakpointTriggered"].addTransition(_Main_SimulationState_PreBreakpointTriggered_0)
        
        # transition /Main/SimulationState/Running/BigStep
        _Main_SimulationState_Running_BigStep_0 = Transition(self, self.states["/Main/SimulationState/Running/BigStep"], [self.states["/Main/SimulationState/Running/BigStepDone"]])
        _Main_SimulationState_Running_BigStep_0.setTrigger(Event("big_step_done", None))
        self.states["/Main/SimulationState/Running/BigStep"].addTransition(_Main_SimulationState_Running_BigStep_0)
        
        # transition /Main/SimulationState/Running/BigStepDone
        _Main_SimulationState_Running_BigStepDone_0 = Transition(self, self.states["/Main/SimulationState/Running/BigStepDone"], [self.states["/Main/SimulationState/Paused"]])
        _Main_SimulationState_Running_BigStepDone_0.setTrigger(Event("_2after"))
        self.states["/Main/SimulationState/Running/BigStepDone"].addTransition(_Main_SimulationState_Running_BigStepDone_0)
        
        # transition /Main/SimulationState/Running/SmallStep
        _Main_SimulationState_Running_SmallStep_0 = Transition(self, self.states["/Main/SimulationState/Running/SmallStep"], [self.states["/Main/SimulationState/Running/SmallStepDone"]])
        _Main_SimulationState_Running_SmallStep_0.setTrigger(Event("small_step_done", None))
        self.states["/Main/SimulationState/Running/SmallStep"].addTransition(_Main_SimulationState_Running_SmallStep_0)
        
        # transition /Main/SimulationState/Running/SmallStepDone
        _Main_SimulationState_Running_SmallStepDone_0 = Transition(self, self.states["/Main/SimulationState/Running/SmallStepDone"], [self.states["/Main/SimulationState/Paused"]])
        _Main_SimulationState_Running_SmallStepDone_0.setTrigger(Event("_3after"))
        self.states["/Main/SimulationState/Running/SmallStepDone"].addTransition(_Main_SimulationState_Running_SmallStepDone_0)
        
        # transition /Main/SimulationState/PreStopped
        _Main_SimulationState_PreStopped_0 = Transition(self, self.states["/Main/SimulationState/PreStopped"], [self.states["/Main/SimulationState/TerminationConditionRaised"]])
        _Main_SimulationState_PreStopped_0.setAction(self._Main_SimulationState_PreStopped_0_exec)
        _Main_SimulationState_PreStopped_0.setTrigger(Event("_4after"))
        self.states["/Main/SimulationState/PreStopped"].addTransition(_Main_SimulationState_PreStopped_0)
        
        # transition /Main/SimulationState/TerminationConditionRaised
        _Main_SimulationState_TerminationConditionRaised_0 = Transition(self, self.states["/Main/SimulationState/TerminationConditionRaised"], [self.states["/Main/SimulationState/Stopped"]])
        _Main_SimulationState_TerminationConditionRaised_0.setTrigger(Event("_5after"))
        self.states["/Main/SimulationState/TerminationConditionRaised"].addTransition(_Main_SimulationState_TerminationConditionRaised_0)
        
        # transition /Main/SimulationFlow/Started
        _Main_SimulationFlow_Started_0 = Transition(self, self.states["/Main/SimulationFlow/Started"], [self.states["/Main/SimulationFlow/Initialized"]])
        _Main_SimulationFlow_Started_0.setAction(self._Main_SimulationFlow_Started_0_exec)
        _Main_SimulationFlow_Started_0.setTrigger(None)
        self.states["/Main/SimulationFlow/Started"].addTransition(_Main_SimulationFlow_Started_0)
        
        # transition /Main/SimulationFlow/Initialized
        _Main_SimulationFlow_Initialized_0 = Transition(self, self.states["/Main/SimulationFlow/Initialized"], [self.states["/Main/SimulationFlow/InitializeDebugger"]])
        _Main_SimulationFlow_Initialized_0.setTrigger(None)
        self.states["/Main/SimulationFlow/Initialized"].addTransition(_Main_SimulationFlow_Initialized_0)
        
        # transition /Main/SimulationFlow/InitializeDebugger
        _Main_SimulationFlow_InitializeDebugger_0 = Transition(self, self.states["/Main/SimulationFlow/InitializeDebugger"], [self.states["/Main/SimulationFlow/CheckTermination"]])
        _Main_SimulationFlow_InitializeDebugger_0.setTrigger(None)
        self.states["/Main/SimulationFlow/InitializeDebugger"].addTransition(_Main_SimulationFlow_InitializeDebugger_0)
        
        # transition /Main/SimulationFlow/CheckTermination/MacroStepProcessed
        _Main_SimulationFlow_CheckTermination_MacroStepProcessed_0 = Transition(self, self.states["/Main/SimulationFlow/CheckTermination/MacroStepProcessed"], [self.states["/Main/SimulationFlow/DoSimulation"]])
        _Main_SimulationFlow_CheckTermination_MacroStepProcessed_0.setTrigger(None)
        _Main_SimulationFlow_CheckTermination_MacroStepProcessed_0.setGuard(self._Main_SimulationFlow_CheckTermination_MacroStepProcessed_0_guard)
        self.states["/Main/SimulationFlow/CheckTermination/MacroStepProcessed"].addTransition(_Main_SimulationFlow_CheckTermination_MacroStepProcessed_0)
        _Main_SimulationFlow_CheckTermination_MacroStepProcessed_1 = Transition(self, self.states["/Main/SimulationFlow/CheckTermination/MacroStepProcessed"], [self.states["/Main/SimulationFlow/Waiting"]])
        _Main_SimulationFlow_CheckTermination_MacroStepProcessed_1.setTrigger(None)
        _Main_SimulationFlow_CheckTermination_MacroStepProcessed_1.setGuard(self._Main_SimulationFlow_CheckTermination_MacroStepProcessed_1_guard)
        self.states["/Main/SimulationFlow/CheckTermination/MacroStepProcessed"].addTransition(_Main_SimulationFlow_CheckTermination_MacroStepProcessed_1)
        _Main_SimulationFlow_CheckTermination_MacroStepProcessed_2 = Transition(self, self.states["/Main/SimulationFlow/CheckTermination/MacroStepProcessed"], [self.states["/Main/SimulationFlow/Stopped"]])
        _Main_SimulationFlow_CheckTermination_MacroStepProcessed_2.setTrigger(None)
        _Main_SimulationFlow_CheckTermination_MacroStepProcessed_2.setGuard(self._Main_SimulationFlow_CheckTermination_MacroStepProcessed_2_guard)
        self.states["/Main/SimulationFlow/CheckTermination/MacroStepProcessed"].addTransition(_Main_SimulationFlow_CheckTermination_MacroStepProcessed_2)
        
        # transition /Main/SimulationFlow/Waiting
        _Main_SimulationFlow_Waiting_0 = Transition(self, self.states["/Main/SimulationFlow/Waiting"], [self.states["/Main/SimulationFlow/CheckTermination"]])
        _Main_SimulationFlow_Waiting_0.setAction(self._Main_SimulationFlow_Waiting_0_exec)
        _Main_SimulationFlow_Waiting_0.setTrigger(Event("_6after"))
        self.states["/Main/SimulationFlow/Waiting"].addTransition(_Main_SimulationFlow_Waiting_0)
        _Main_SimulationFlow_Waiting_1 = Transition(self, self.states["/Main/SimulationFlow/Waiting"], [self.states["/Main/SimulationFlow/DoSimulation"]])
        _Main_SimulationFlow_Waiting_1.setTrigger(None)
        _Main_SimulationFlow_Waiting_1.setGuard(self._Main_SimulationFlow_Waiting_1_guard)
        self.states["/Main/SimulationFlow/Waiting"].addTransition(_Main_SimulationFlow_Waiting_1)
        
        # transition /Main/SimulationFlow/DoSimulation/MacroStepPrepared
        _Main_SimulationFlow_DoSimulation_MacroStepPrepared_0 = Transition(self, self.states["/Main/SimulationFlow/DoSimulation/MacroStepPrepared"], [self.states["/Main/SimulationFlow/DoSimulation/MicroStepProcessed"]])
        _Main_SimulationFlow_DoSimulation_MacroStepPrepared_0.setTrigger(None)
        self.states["/Main/SimulationFlow/DoSimulation/MacroStepPrepared"].addTransition(_Main_SimulationFlow_DoSimulation_MacroStepPrepared_0)
        
        # transition /Main/SimulationFlow/DoSimulation/MicroStepProcessed
        _Main_SimulationFlow_DoSimulation_MicroStepProcessed_0 = Transition(self, self.states["/Main/SimulationFlow/DoSimulation/MicroStepProcessed"], [self.states["/Main/SimulationFlow/DoSimulation/PreMicroStepPrepared"]])
        _Main_SimulationFlow_DoSimulation_MicroStepProcessed_0.setTrigger(Event("_7after"))
        _Main_SimulationFlow_DoSimulation_MicroStepProcessed_0.setGuard(self._Main_SimulationFlow_DoSimulation_MicroStepProcessed_0_guard)
        self.states["/Main/SimulationFlow/DoSimulation/MicroStepProcessed"].addTransition(_Main_SimulationFlow_DoSimulation_MicroStepProcessed_0)
        _Main_SimulationFlow_DoSimulation_MicroStepProcessed_1 = Transition(self, self.states["/Main/SimulationFlow/DoSimulation/MicroStepProcessed"], [self.states["/Main/SimulationFlow/CheckTermination"]])
        _Main_SimulationFlow_DoSimulation_MicroStepProcessed_1.setAction(self._Main_SimulationFlow_DoSimulation_MicroStepProcessed_1_exec)
        _Main_SimulationFlow_DoSimulation_MicroStepProcessed_1.setTrigger(Event("_8after"))
        _Main_SimulationFlow_DoSimulation_MicroStepProcessed_1.setGuard(self._Main_SimulationFlow_DoSimulation_MicroStepProcessed_1_guard)
        self.states["/Main/SimulationFlow/DoSimulation/MicroStepProcessed"].addTransition(_Main_SimulationFlow_DoSimulation_MicroStepProcessed_1)
        
        # transition /Main/SimulationFlow/DoSimulation/PreMicroStepPrepared
        _Main_SimulationFlow_DoSimulation_PreMicroStepPrepared_0 = Transition(self, self.states["/Main/SimulationFlow/DoSimulation/PreMicroStepPrepared"], [self.states["/Main/SimulationFlow/DoSimulation/MicroStepPrepared"]])
        _Main_SimulationFlow_DoSimulation_PreMicroStepPrepared_0.setTrigger(None)
        _Main_SimulationFlow_DoSimulation_PreMicroStepPrepared_0.setGuard(self._Main_SimulationFlow_DoSimulation_PreMicroStepPrepared_0_guard)
        self.states["/Main/SimulationFlow/DoSimulation/PreMicroStepPrepared"].addTransition(_Main_SimulationFlow_DoSimulation_PreMicroStepPrepared_0)
        
        # transition /Main/SimulationFlow/DoSimulation/MicroStepPrepared
        _Main_SimulationFlow_DoSimulation_MicroStepPrepared_0 = Transition(self, self.states["/Main/SimulationFlow/DoSimulation/MicroStepPrepared"], [self.states["/Main/SimulationFlow/DoSimulation/MicroStepProcessed"]])
        _Main_SimulationFlow_DoSimulation_MicroStepPrepared_0.setAction(self._Main_SimulationFlow_DoSimulation_MicroStepPrepared_0_exec)
        _Main_SimulationFlow_DoSimulation_MicroStepPrepared_0.setTrigger(None)
        self.states["/Main/SimulationFlow/DoSimulation/MicroStepPrepared"].addTransition(_Main_SimulationFlow_DoSimulation_MicroStepPrepared_0)
        
        # transition /Main/BreakpointManager/Listening
        _Main_BreakpointManager_Listening_0 = Transition(self, self.states["/Main/BreakpointManager/Listening"], [self.states["/Main/BreakpointManager/Listening"]])
        _Main_BreakpointManager_Listening_0.setAction(self._Main_BreakpointManager_Listening_0_exec)
        _Main_BreakpointManager_Listening_0.setTrigger(Event("add_breakpoint", "user_input"))
        self.states["/Main/BreakpointManager/Listening"].addTransition(_Main_BreakpointManager_Listening_0)
        _Main_BreakpointManager_Listening_1 = Transition(self, self.states["/Main/BreakpointManager/Listening"], [self.states["/Main/BreakpointManager/Listening"]])
        _Main_BreakpointManager_Listening_1.setAction(self._Main_BreakpointManager_Listening_1_exec)
        _Main_BreakpointManager_Listening_1.setTrigger(Event("del_breakpoint", "user_input"))
        self.states["/Main/BreakpointManager/Listening"].addTransition(_Main_BreakpointManager_Listening_1)
        _Main_BreakpointManager_Listening_2 = Transition(self, self.states["/Main/BreakpointManager/Listening"], [self.states["/Main/BreakpointManager/Listening"]])
        _Main_BreakpointManager_Listening_2.setAction(self._Main_BreakpointManager_Listening_2_exec)
        _Main_BreakpointManager_Listening_2.setTrigger(Event("toggle_breakpoint", "user_input"))
        self.states["/Main/BreakpointManager/Listening"].addTransition(_Main_BreakpointManager_Listening_2)
        _Main_BreakpointManager_Listening_3 = Transition(self, self.states["/Main/BreakpointManager/Listening"], [self.states["/Main/BreakpointManager/Listening"]])
        _Main_BreakpointManager_Listening_3.setAction(self._Main_BreakpointManager_Listening_3_exec)
        _Main_BreakpointManager_Listening_3.setTrigger(Event("list_breakpoints", "user_input"))
        self.states["/Main/BreakpointManager/Listening"].addTransition(_Main_BreakpointManager_Listening_3)
        
        # transition /Main/GodEventManager/Listening
        _Main_GodEventManager_Listening_0 = Transition(self, self.states["/Main/GodEventManager/Listening"], [self.states["/Main/GodEventManager/Listening"]])
        _Main_GodEventManager_Listening_0.setAction(self._Main_GodEventManager_Listening_0_exec)
        _Main_GodEventManager_Listening_0.setTrigger(Event("god_event", "user_input"))
        _Main_GodEventManager_Listening_0.setGuard(self._Main_GodEventManager_Listening_0_guard)
        self.states["/Main/GodEventManager/Listening"].addTransition(_Main_GodEventManager_Listening_0)
        
        # transition /Main/UserOutput/Waiting
        _Main_UserOutput_Waiting_0 = Transition(self, self.states["/Main/UserOutput/Waiting"], [self.states["/Main/UserOutput/Waiting"]])
        _Main_UserOutput_Waiting_0.setAction(self._Main_UserOutput_Waiting_0_exec)
        _Main_UserOutput_Waiting_0.setTrigger(Event("termination_condition", None))
        self.states["/Main/UserOutput/Waiting"].addTransition(_Main_UserOutput_Waiting_0)
        _Main_UserOutput_Waiting_1 = Transition(self, self.states["/Main/UserOutput/Waiting"], [self.states["/Main/UserOutput/Waiting"]])
        _Main_UserOutput_Waiting_1.setAction(self._Main_UserOutput_Waiting_1_exec)
        _Main_UserOutput_Waiting_1.setTrigger(Event("paused", None))
        self.states["/Main/UserOutput/Waiting"].addTransition(_Main_UserOutput_Waiting_1)
        _Main_UserOutput_Waiting_2 = Transition(self, self.states["/Main/UserOutput/Waiting"], [self.states["/Main/UserOutput/Waiting"]])
        _Main_UserOutput_Waiting_2.setAction(self._Main_UserOutput_Waiting_2_exec)
        _Main_UserOutput_Waiting_2.setTrigger(Event("big_step_done", None))
        _Main_UserOutput_Waiting_2.setGuard(self._Main_UserOutput_Waiting_2_guard)
        self.states["/Main/UserOutput/Waiting"].addTransition(_Main_UserOutput_Waiting_2)
        _Main_UserOutput_Waiting_3 = Transition(self, self.states["/Main/UserOutput/Waiting"], [self.states["/Main/UserOutput/Waiting"]])
        _Main_UserOutput_Waiting_3.setAction(self._Main_UserOutput_Waiting_3_exec)
        _Main_UserOutput_Waiting_3.setTrigger(Event("small_step_done", None))
        _Main_UserOutput_Waiting_3.setGuard(self._Main_UserOutput_Waiting_3_guard)
        self.states["/Main/UserOutput/Waiting"].addTransition(_Main_UserOutput_Waiting_3)
        _Main_UserOutput_Waiting_4 = Transition(self, self.states["/Main/UserOutput/Waiting"], [self.states["/Main/UserOutput/Waiting"]])
        _Main_UserOutput_Waiting_4.setAction(self._Main_UserOutput_Waiting_4_exec)
        _Main_UserOutput_Waiting_4.setTrigger(Event("breakpoint_triggered", None))
        self.states["/Main/UserOutput/Waiting"].addTransition(_Main_UserOutput_Waiting_4)
        
        # transition /Main
        _Main_0 = Transition(self, self.states["/Main"], [self.states["/SimulationComplete"]])
        _Main_0.setAction(self._Main_0_exec)
        _Main_0.setTrigger(None)
        _Main_0.setGuard(self._Main_0_guard)
        self.states["/Main"].addTransition(_Main_0)
        
        # transition /Main/SimulationState/Running
        _Main_SimulationState_Running_0 = Transition(self, self.states["/Main/SimulationState/Running"], [self.states["/Main/SimulationState/PreStopped"]])
        _Main_SimulationState_Running_0.setTrigger(None)
        _Main_SimulationState_Running_0.setGuard(self._Main_SimulationState_Running_0_guard)
        self.states["/Main/SimulationState/Running"].addTransition(_Main_SimulationState_Running_0)
        _Main_SimulationState_Running_1 = Transition(self, self.states["/Main/SimulationState/Running"], [self.states["/Main/SimulationState/PrePaused"]])
        _Main_SimulationState_Running_1.setTrigger(Event("pause", "user_input"))
        self.states["/Main/SimulationState/Running"].addTransition(_Main_SimulationState_Running_1)
        _Main_SimulationState_Running_2 = Transition(self, self.states["/Main/SimulationState/Running"], [self.states["/Main/SimulationState/PreBreakpointTriggered"]])
        _Main_SimulationState_Running_2.setTrigger(None)
        _Main_SimulationState_Running_2.setGuard(self._Main_SimulationState_Running_2_guard)
        self.states["/Main/SimulationState/Running"].addTransition(_Main_SimulationState_Running_2)
    
    def _Main_SimulationState_PrePaused_enter(self):
        self.addTimer(0, self.sccd_yield() * 2)
    
    def _Main_SimulationState_PrePaused_exit(self):
        self.removeTimer(0)
    
    def _Main_SimulationState_PreBreakpointTriggered_enter(self):
        self.addTimer(1, self.sccd_yield() * 2)
    
    def _Main_SimulationState_PreBreakpointTriggered_exit(self):
        self.removeTimer(1)
    
    def _Main_SimulationState_Running_BigStepDone_enter(self):
        self.addTimer(2, self.sccd_yield())
    
    def _Main_SimulationState_Running_BigStepDone_exit(self):
        self.removeTimer(2)
    
    def _Main_SimulationState_Running_SmallStepDone_enter(self):
        self.addTimer(3, self.sccd_yield())
    
    def _Main_SimulationState_Running_SmallStepDone_exit(self):
        self.removeTimer(3)
    
    def _Main_SimulationState_Running_Realtime_enter(self):
        # If the simulation was paused, we need to reset the start time of the simulation.
        # The start time of the simulation is equal to the point in wall-clock time where simulated time is 0.
        # If the simulation was paused, we have to recompute this point in time: it is the difference of the wall-clock time and the simulated time.
        # If the scale was changed after the pause, this point of course moves backwards (for scales smaller than 1) or forwards (for scales larger than 1)
        self.realtime_start_time = accurate_time.time() - (self.clock / self.realtime_scale)
    
    def _Main_SimulationState_PreStopped_enter(self):
        self.addTimer(4, self.sccd_yield() * 2)
    
    def _Main_SimulationState_PreStopped_exit(self):
        self.removeTimer(4)
    
    def _Main_SimulationState_TerminationConditionRaised_enter(self):
        self.addTimer(5, self.sccd_yield())
    
    def _Main_SimulationState_TerminationConditionRaised_exit(self):
        self.removeTimer(5)
    
    def _Main_SimulationFlow_InitializeDebugger_enter(self):
        self.initializeDebugger()
    
    def _Main_SimulationFlow_Waiting_enter(self):
        self.addTimer(6, self.sccd_yield())
    
    def _Main_SimulationFlow_Waiting_exit(self):
        self.removeTimer(6)
    
    def _Main_SimulationFlow_DoSimulation_MacroStepPrepared_enter(self):
        self.currentEvent = self.getInputEventAt(self.clock / 1000.0)
        self.selectedTransition = self.model.getTransitionFrom(self.state, self.currentEvent, self.elapsed)
    
    def _Main_SimulationFlow_DoSimulation_MicroStepProcessed_enter(self):
        self.addTimer(7, self.sccd_yield() * 3)
        self.addTimer(8, self.sccd_yield())
    
    def _Main_SimulationFlow_DoSimulation_MicroStepProcessed_exit(self):
        self.removeTimer(7)
        self.removeTimer(8)
    
    def _Main_0_exec(self, parameters):
        self.finalize()
    
    def _Main_0_guard(self, parameters):
        return self.inState(["/Main/SimulationState/Stopped"]) and self.inState(["/Main/SimulationFlow/Stopped"])
    
    def _Main_SimulationState_Running_0_guard(self, parameters):
        return self.endCondition()
    
    def _Main_SimulationState_Running_2_guard(self, parameters):
        return self.breakpointTriggers(self.inState(["/Main/SimulationState/Running/Realtime"]))
    
    def _Main_SimulationState_Paused_1_exec(self, parameters):
        realtime_scale = parameters[0]
        self.realtime_scale = float(realtime_scale)
    
    def _Main_SimulationState_Paused_4_guard(self, parameters):
        return self.endCondition()
    
    def _Main_SimulationState_PrePaused_0_exec(self, parameters):
        self.raiseInternalEvent(Event("paused", None, []))
    
    def _Main_SimulationState_PreBreakpointTriggered_0_exec(self, parameters):
        self.raiseInternalEvent(Event("breakpoint_triggered", None, []))
    
    def _Main_SimulationState_PreStopped_0_exec(self, parameters):
        self.raiseInternalEvent(Event("termination_condition", None, []))
    
    def _Main_SimulationFlow_Started_0_exec(self, parameters):
        self.initialize()
    
    def _Main_SimulationFlow_CheckTermination_MacroStepProcessed_0_guard(self, parameters):
        return self.inState(["/Main/SimulationState/Running/Continuous"]) or self.inState(["/Main/SimulationState/Running/BigStep"]) or self.inState(["/Main/SimulationState/Running/SmallStep"])
    
    def _Main_SimulationFlow_CheckTermination_MacroStepProcessed_1_guard(self, parameters):
        return self.inState(["/Main/SimulationState/Running/Realtime"])
    
    def _Main_SimulationFlow_CheckTermination_MacroStepProcessed_2_guard(self, parameters):
        return self.inState(["/Main/SimulationState/Stopped"])
    
    def _Main_SimulationFlow_Waiting_0_exec(self, parameters):
        self.syncSimulatedTime()
    
    def _Main_SimulationFlow_Waiting_1_guard(self, parameters):
        return self.waitTime() / 1000.0 <= self.sccd_yield()
    
    def _Main_SimulationFlow_DoSimulation_MicroStepProcessed_0_guard(self, parameters):
        return self.selectedTransition != None
    
    def _Main_SimulationFlow_DoSimulation_MicroStepProcessed_1_exec(self, parameters):
        self.advanceTime()
        self.raiseInternalEvent(Event("big_step_done", None, []))
    
    def _Main_SimulationFlow_DoSimulation_MicroStepProcessed_1_guard(self, parameters):
        return self.selectedTransition == None
    
    def _Main_SimulationFlow_DoSimulation_PreMicroStepPrepared_0_guard(self, parameters):
        return self.inState(["/Main/SimulationState/Running"])
    
    def _Main_SimulationFlow_DoSimulation_MicroStepPrepared_0_exec(self, parameters):
        self.state = self.selectedTransition.target
        self.elapsed = 0
        self.processEvent(self.currentEvent)
        self.currentEvent = self.getInputEventAt(self.clock / 1000.0)
        self.selectedTransition = self.model.getTransitionFrom(self.state, self.currentEvent, self.elapsed)
        self.raiseInternalEvent(Event("small_step_done", None, []))
    
    def _Main_BreakpointManager_Listening_0_exec(self, parameters):
        name = parameters[0]
        function = parameters[1]
        enabled = parameters[2]
        disable_on_trigger = parameters[3]
        result = self.addBreakpoint(name, function, bool(enabled), bool(disable_on_trigger))
        self.big_step.outputEvent(Event("add_breakpoint_result", "user_output", [result]))
    
    def _Main_BreakpointManager_Listening_1_exec(self, parameters):
        name = parameters[0]
        result = self.delBreakpoint(name)
        self.big_step.outputEvent(Event("del_breakpoint_result", "user_output", [result]))
    
    def _Main_BreakpointManager_Listening_2_exec(self, parameters):
        name = parameters[0]
        result = self.toggleBreakpoint(name)
        self.big_step.outputEvent(Event("toggle_breakpoint_result", "user_output", [result]))
    
    def _Main_BreakpointManager_Listening_3_exec(self, parameters):
        self.big_step.outputEvent(Event("list_breakpoints_result", "user_output", [[bp.name for bp in self.breakpoints]]))
    
    def _Main_GodEventManager_Listening_0_exec(self, parameters):
        new_state = parameters[0]
        result = self.godEvent(new_state)
        self.big_step.outputEvent(Event("god_event_result", "user_output", [result]))
        self.big_step.outputEvent(Event("current_state", "user_output", [self.clock / 1000.0, self.state]))
    
    def _Main_GodEventManager_Listening_0_guard(self, parameters):
        new_state = parameters[0]
        return self.inState(["/Main/SimulationState/Paused"])
    
    def _Main_UserOutput_Waiting_0_exec(self, parameters):
        self.big_step.outputEvent(Event("terminated", "user_output", []))
        self.big_step.outputEvent(Event("current_state", "user_output", [self.clock / 1000.0, self.state]))
    
    def _Main_UserOutput_Waiting_1_exec(self, parameters):
        self.big_step.outputEvent(Event("paused", "user_output", []))
        self.big_step.outputEvent(Event("current_state", "user_output", [self.clock / 1000.0, self.state]))
    
    def _Main_UserOutput_Waiting_2_exec(self, parameters):
        self.big_step.outputEvent(Event("big_step_done", "user_output", []))
        self.big_step.outputEvent(Event("current_state", "user_output", [self.clock / 1000.0, self.state]))
    
    def _Main_UserOutput_Waiting_2_guard(self, parameters):
        return self.inState(["/Main/SimulationState/Running/Realtime"]) or self.inState(["/Main/SimulationState/Running/BigStep"]) or self.inState(["/Main/SimulationState/Running/BigStepDone"])
    
    def _Main_UserOutput_Waiting_3_exec(self, parameters):
        self.big_step.outputEvent(Event("small_step_done", "user_output", []))
        self.big_step.outputEvent(Event("current_state", "user_output", [self.clock / 1000.0, self.state]))
    
    def _Main_UserOutput_Waiting_3_guard(self, parameters):
        return self.inState(["/Main/SimulationState/Running/SmallStep"]) or self.inState(["/Main/SimulationState/Running/SmallStepDone"])
    
    def _Main_UserOutput_Waiting_4_exec(self, parameters):
        self.big_step.outputEvent(Event("breakpoint_triggered", "user_output", [self.triggered_bp]))
        self.big_step.outputEvent(Event("current_state", "user_output", [self.clock / 1000.0, self.state]))
    
    def initializeStatechart(self):
        # enter default state
        self.default_targets = self.states["/Main"].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 = {}
        else:
            raise Exception("Cannot instantiate class " + class_name)
        return instance

class Controller(ThreadsControllerBase):
    def __init__(self, model, 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.addInputPort("user_input")
        self.addInputPort("user_output")
        self.object_manager.createInstance("FSASimulator", [model, events])