| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042 |
- """
- Generated by Statechart compiler by Glenn De Jonghe, Joeri Exelmans, Simon Van Mierlo, and Yentl Van Tendeloo (for the inspiration)
- Date: Wed Nov 09 17:14:30 2016
- Model author: Sadaf Mustafiz and Claudio Gomes and Simon Van Mierlo
- Model name: CBDSimulator_Coordinator
- Model description:
- A debuggeable CBD simulator.
- """
- from sccd.runtime.statecharts_core import *
- from sccd.runtime.libs.ui import *
- from sccd.runtime.libs.utils import *
- from CBD_Controller import CBDController
- import Options
- 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 "CBDSimulator_Coordinator"
- class CBDSimulator_Coordinator(RuntimeClassBase):
- def __init__(self, controller, options, model):
- 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()
-
- # call user defined constructor
- CBDSimulator_Coordinator.user_defined_constructor(self, options, model)
-
- def user_defined_constructor(self, options, model):
- self.options = options
- self.model = model
-
- def user_defined_destructor(self):
- pass
-
-
- # builds Statechart structure
- def build_statechart_structure(self):
-
- # state <root>
- self.states[""] = State(0, "", self)
-
- # state /Main
- self.states["/Main"] = ParallelState(1, "/Main", self)
-
- # state /Main/ModeSelector
- self.states["/Main/ModeSelector"] = State(2, "/Main/ModeSelector", self)
-
- # state /Main/ModeSelector/Paused
- self.states["/Main/ModeSelector/Paused"] = State(3, "/Main/ModeSelector/Paused", self)
-
- # state /Main/ModeSelector/Running
- self.states["/Main/ModeSelector/Running"] = State(4, "/Main/ModeSelector/Running", self)
-
- # state /Main/ModeSelector/Running/Continuous
- self.states["/Main/ModeSelector/Running/Continuous"] = State(5, "/Main/ModeSelector/Running/Continuous", self)
-
- # state /Main/ModeSelector/Running/Realtime
- self.states["/Main/ModeSelector/Running/Realtime"] = State(6, "/Main/ModeSelector/Running/Realtime", self)
-
- # state /Main/ModeSelector/Running/BigStep
- self.states["/Main/ModeSelector/Running/BigStep"] = State(7, "/Main/ModeSelector/Running/BigStep", self)
-
- # state /Main/ModeSelector/Running/SmallStep
- self.states["/Main/ModeSelector/Running/SmallStep"] = State(8, "/Main/ModeSelector/Running/SmallStep", self)
-
- # state /Main/ModeSelector/WaitingForPaused
- self.states["/Main/ModeSelector/WaitingForPaused"] = State(9, "/Main/ModeSelector/WaitingForPaused", self)
-
- # state /Main/ModeSelector/Stopped
- self.states["/Main/ModeSelector/Stopped"] = State(10, "/Main/ModeSelector/Stopped", self)
-
- # state /Main/ChildState
- self.states["/Main/ChildState"] = State(11, "/Main/ChildState", self)
-
- # state /Main/ChildState/Uninitialized
- self.states["/Main/ChildState/Uninitialized"] = State(12, "/Main/ChildState/Uninitialized", self)
-
- # state /Main/ChildState/Initialized
- self.states["/Main/ChildState/Initialized"] = State(13, "/Main/ChildState/Initialized", self)
-
- # state /Main/Initializer
- self.states["/Main/Initializer"] = State(14, "/Main/Initializer", self)
-
- # state /Main/Initializer/Waiting
- self.states["/Main/Initializer/Waiting"] = State(15, "/Main/Initializer/Waiting", self)
-
- # state /Main/Initializer/CreatingChildSimulator
- self.states["/Main/Initializer/CreatingChildSimulator"] = State(16, "/Main/Initializer/CreatingChildSimulator", self)
-
- # state /Main/Initializer/StartingChildSimulator
- self.states["/Main/Initializer/StartingChildSimulator"] = State(17, "/Main/Initializer/StartingChildSimulator", self)
-
- # state /Main/SimulationFlow
- self.states["/Main/SimulationFlow"] = State(18, "/Main/SimulationFlow", self)
-
- # state /Main/SimulationFlow/PrePaused
- self.states["/Main/SimulationFlow/PrePaused"] = State(19, "/Main/SimulationFlow/PrePaused", self)
- self.states["/Main/SimulationFlow/PrePaused"].setEnter(self._Main_SimulationFlow_PrePaused_enter)
- self.states["/Main/SimulationFlow/PrePaused"].setExit(self._Main_SimulationFlow_PrePaused_exit)
-
- # state /Main/SimulationFlow/Paused
- self.states["/Main/SimulationFlow/Paused"] = State(20, "/Main/SimulationFlow/Paused", self)
-
- # state /Main/SimulationFlow/Executing
- self.states["/Main/SimulationFlow/Executing"] = State(21, "/Main/SimulationFlow/Executing", self)
-
- # state /Main/GodEventManager
- self.states["/Main/GodEventManager"] = State(22, "/Main/GodEventManager", self)
-
- # state /Main/GodEventManager/Listening
- self.states["/Main/GodEventManager/Listening"] = State(23, "/Main/GodEventManager/Listening", self)
-
- # state /Main/GodEventManager/Waiting
- self.states["/Main/GodEventManager/Waiting"] = State(24, "/Main/GodEventManager/Waiting", self)
-
- # state /Main/BreakpointManager
- self.states["/Main/BreakpointManager"] = State(25, "/Main/BreakpointManager", self)
-
- # state /Main/BreakpointManager/Listening
- self.states["/Main/BreakpointManager/Listening"] = State(26, "/Main/BreakpointManager/Listening", self)
-
- # state /Main/BreakpointManager/Waiting
- self.states["/Main/BreakpointManager/Waiting"] = State(27, "/Main/BreakpointManager/Waiting", self)
-
- # add children
- self.states[""].addChild(self.states["/Main"])
- self.states["/Main"].addChild(self.states["/Main/ModeSelector"])
- self.states["/Main"].addChild(self.states["/Main/ChildState"])
- self.states["/Main"].addChild(self.states["/Main/Initializer"])
- self.states["/Main"].addChild(self.states["/Main/SimulationFlow"])
- self.states["/Main"].addChild(self.states["/Main/GodEventManager"])
- self.states["/Main"].addChild(self.states["/Main/BreakpointManager"])
- self.states["/Main/ModeSelector"].addChild(self.states["/Main/ModeSelector/Paused"])
- self.states["/Main/ModeSelector"].addChild(self.states["/Main/ModeSelector/Running"])
- self.states["/Main/ModeSelector"].addChild(self.states["/Main/ModeSelector/WaitingForPaused"])
- self.states["/Main/ModeSelector"].addChild(self.states["/Main/ModeSelector/Stopped"])
- self.states["/Main/ModeSelector/Running"].addChild(self.states["/Main/ModeSelector/Running/Continuous"])
- self.states["/Main/ModeSelector/Running"].addChild(self.states["/Main/ModeSelector/Running/Realtime"])
- self.states["/Main/ModeSelector/Running"].addChild(self.states["/Main/ModeSelector/Running/BigStep"])
- self.states["/Main/ModeSelector/Running"].addChild(self.states["/Main/ModeSelector/Running/SmallStep"])
- self.states["/Main/ChildState"].addChild(self.states["/Main/ChildState/Uninitialized"])
- self.states["/Main/ChildState"].addChild(self.states["/Main/ChildState/Initialized"])
- self.states["/Main/Initializer"].addChild(self.states["/Main/Initializer/Waiting"])
- self.states["/Main/Initializer"].addChild(self.states["/Main/Initializer/CreatingChildSimulator"])
- self.states["/Main/Initializer"].addChild(self.states["/Main/Initializer/StartingChildSimulator"])
- self.states["/Main/SimulationFlow"].addChild(self.states["/Main/SimulationFlow/PrePaused"])
- self.states["/Main/SimulationFlow"].addChild(self.states["/Main/SimulationFlow/Paused"])
- self.states["/Main/SimulationFlow"].addChild(self.states["/Main/SimulationFlow/Executing"])
- self.states["/Main/GodEventManager"].addChild(self.states["/Main/GodEventManager/Listening"])
- self.states["/Main/GodEventManager"].addChild(self.states["/Main/GodEventManager/Waiting"])
- self.states["/Main/BreakpointManager"].addChild(self.states["/Main/BreakpointManager/Listening"])
- self.states["/Main/BreakpointManager"].addChild(self.states["/Main/BreakpointManager/Waiting"])
- self.states[""].fixTree()
- self.states[""].default_state = self.states["/Main"]
- self.states["/Main/ModeSelector"].default_state = self.states["/Main/ModeSelector/Paused"]
- self.states["/Main/ModeSelector/Running"].default_state = self.states["/Main/ModeSelector/Running/Continuous"]
- self.states["/Main/ChildState"].default_state = self.states["/Main/ChildState/Uninitialized"]
- self.states["/Main/Initializer"].default_state = self.states["/Main/Initializer/Waiting"]
- self.states["/Main/SimulationFlow"].default_state = self.states["/Main/SimulationFlow/Paused"]
- self.states["/Main/GodEventManager"].default_state = self.states["/Main/GodEventManager/Listening"]
- self.states["/Main/BreakpointManager"].default_state = self.states["/Main/BreakpointManager/Listening"]
-
- # transition /Main/ModeSelector/Paused
- _Main_ModeSelector_Paused_0 = Transition(self, self.states["/Main/ModeSelector/Paused"], [self.states["/Main/ModeSelector/Running/SmallStep"]])
- _Main_ModeSelector_Paused_0.setTrigger(Event("small_step", "user_input"))
- self.states["/Main/ModeSelector/Paused"].addTransition(_Main_ModeSelector_Paused_0)
- _Main_ModeSelector_Paused_1 = Transition(self, self.states["/Main/ModeSelector/Paused"], [self.states["/Main/ModeSelector/Running/BigStep"]])
- _Main_ModeSelector_Paused_1.setTrigger(Event("big_step", "user_input"))
- self.states["/Main/ModeSelector/Paused"].addTransition(_Main_ModeSelector_Paused_1)
- _Main_ModeSelector_Paused_2 = Transition(self, self.states["/Main/ModeSelector/Paused"], [self.states["/Main/ModeSelector/Running/Continuous"]])
- _Main_ModeSelector_Paused_2.setTrigger(Event("continuous", "user_input"))
- self.states["/Main/ModeSelector/Paused"].addTransition(_Main_ModeSelector_Paused_2)
- _Main_ModeSelector_Paused_3 = Transition(self, self.states["/Main/ModeSelector/Paused"], [self.states["/Main/ModeSelector/Running/Realtime"]])
- _Main_ModeSelector_Paused_3.setAction(self._Main_ModeSelector_Paused_3_exec)
- _Main_ModeSelector_Paused_3.setTrigger(Event("realtime", "user_input"))
- self.states["/Main/ModeSelector/Paused"].addTransition(_Main_ModeSelector_Paused_3)
- _Main_ModeSelector_Paused_4 = Transition(self, self.states["/Main/ModeSelector/Paused"], [self.states["/Main/ModeSelector/Paused"]])
- _Main_ModeSelector_Paused_4.setAction(self._Main_ModeSelector_Paused_4_exec)
- _Main_ModeSelector_Paused_4.setTrigger(Event("BigStep.Finished", None))
- self.states["/Main/ModeSelector/Paused"].addTransition(_Main_ModeSelector_Paused_4)
- _Main_ModeSelector_Paused_5 = Transition(self, self.states["/Main/ModeSelector/Paused"], [self.states["/Main/ModeSelector/Paused"]])
- _Main_ModeSelector_Paused_5.setAction(self._Main_ModeSelector_Paused_5_exec)
- _Main_ModeSelector_Paused_5.setTrigger(Event("Simulation.Finished", None))
- self.states["/Main/ModeSelector/Paused"].addTransition(_Main_ModeSelector_Paused_5)
-
- # transition /Main/ModeSelector/Running/Continuous
- _Main_ModeSelector_Running_Continuous_0 = Transition(self, self.states["/Main/ModeSelector/Running/Continuous"], [self.states["/Main/ModeSelector/WaitingForPaused"]])
- _Main_ModeSelector_Running_Continuous_0.setAction(self._Main_ModeSelector_Running_Continuous_0_exec)
- _Main_ModeSelector_Running_Continuous_0.setTrigger(Event("pause", "user_input"))
- self.states["/Main/ModeSelector/Running/Continuous"].addTransition(_Main_ModeSelector_Running_Continuous_0)
- _Main_ModeSelector_Running_Continuous_1 = Transition(self, self.states["/Main/ModeSelector/Running/Continuous"], [self.states["/Main/ModeSelector/Stopped"]])
- _Main_ModeSelector_Running_Continuous_1.setAction(self._Main_ModeSelector_Running_Continuous_1_exec)
- _Main_ModeSelector_Running_Continuous_1.setTrigger(Event("Simulation.Finished", None))
- self.states["/Main/ModeSelector/Running/Continuous"].addTransition(_Main_ModeSelector_Running_Continuous_1)
-
- # transition /Main/ModeSelector/Running/Realtime
- _Main_ModeSelector_Running_Realtime_0 = Transition(self, self.states["/Main/ModeSelector/Running/Realtime"], [self.states["/Main/ModeSelector/WaitingForPaused"]])
- _Main_ModeSelector_Running_Realtime_0.setAction(self._Main_ModeSelector_Running_Realtime_0_exec)
- _Main_ModeSelector_Running_Realtime_0.setTrigger(Event("pause", "user_input"))
- self.states["/Main/ModeSelector/Running/Realtime"].addTransition(_Main_ModeSelector_Running_Realtime_0)
- _Main_ModeSelector_Running_Realtime_1 = Transition(self, self.states["/Main/ModeSelector/Running/Realtime"], [self.states["/Main/ModeSelector/Stopped"]])
- _Main_ModeSelector_Running_Realtime_1.setAction(self._Main_ModeSelector_Running_Realtime_1_exec)
- _Main_ModeSelector_Running_Realtime_1.setTrigger(Event("Simulation.Finished", None))
- self.states["/Main/ModeSelector/Running/Realtime"].addTransition(_Main_ModeSelector_Running_Realtime_1)
- _Main_ModeSelector_Running_Realtime_2 = Transition(self, self.states["/Main/ModeSelector/Running/Realtime"], [self.states["/Main/ModeSelector/Running/Realtime"]])
- _Main_ModeSelector_Running_Realtime_2.setAction(self._Main_ModeSelector_Running_Realtime_2_exec)
- _Main_ModeSelector_Running_Realtime_2.setTrigger(Event("BigStep.Finished", None))
- self.states["/Main/ModeSelector/Running/Realtime"].addTransition(_Main_ModeSelector_Running_Realtime_2)
-
- # transition /Main/ModeSelector/Running/BigStep
- _Main_ModeSelector_Running_BigStep_0 = Transition(self, self.states["/Main/ModeSelector/Running/BigStep"], [self.states["/Main/ModeSelector/Paused"]])
- _Main_ModeSelector_Running_BigStep_0.setAction(self._Main_ModeSelector_Running_BigStep_0_exec)
- _Main_ModeSelector_Running_BigStep_0.setTrigger(Event("BigStep.Finished", None))
- self.states["/Main/ModeSelector/Running/BigStep"].addTransition(_Main_ModeSelector_Running_BigStep_0)
- _Main_ModeSelector_Running_BigStep_1 = Transition(self, self.states["/Main/ModeSelector/Running/BigStep"], [self.states["/Main/ModeSelector/Stopped"]])
- _Main_ModeSelector_Running_BigStep_1.setAction(self._Main_ModeSelector_Running_BigStep_1_exec)
- _Main_ModeSelector_Running_BigStep_1.setTrigger(Event("Simulation.Finished", None))
- self.states["/Main/ModeSelector/Running/BigStep"].addTransition(_Main_ModeSelector_Running_BigStep_1)
-
- # transition /Main/ModeSelector/Running/SmallStep
- _Main_ModeSelector_Running_SmallStep_0 = Transition(self, self.states["/Main/ModeSelector/Running/SmallStep"], [self.states["/Main/ModeSelector/Paused"]])
- _Main_ModeSelector_Running_SmallStep_0.setAction(self._Main_ModeSelector_Running_SmallStep_0_exec)
- _Main_ModeSelector_Running_SmallStep_0.setTrigger(Event("SmallStep.Finished", None))
- self.states["/Main/ModeSelector/Running/SmallStep"].addTransition(_Main_ModeSelector_Running_SmallStep_0)
- _Main_ModeSelector_Running_SmallStep_1 = Transition(self, self.states["/Main/ModeSelector/Running/SmallStep"], [self.states["/Main/ModeSelector/Paused"]])
- _Main_ModeSelector_Running_SmallStep_1.setAction(self._Main_ModeSelector_Running_SmallStep_1_exec)
- _Main_ModeSelector_Running_SmallStep_1.setTrigger(Event("BigStep.Finished", None))
- self.states["/Main/ModeSelector/Running/SmallStep"].addTransition(_Main_ModeSelector_Running_SmallStep_1)
- _Main_ModeSelector_Running_SmallStep_2 = Transition(self, self.states["/Main/ModeSelector/Running/SmallStep"], [self.states["/Main/ModeSelector/Stopped"]])
- _Main_ModeSelector_Running_SmallStep_2.setAction(self._Main_ModeSelector_Running_SmallStep_2_exec)
- _Main_ModeSelector_Running_SmallStep_2.setTrigger(Event("Simulation.Finished", None))
- self.states["/Main/ModeSelector/Running/SmallStep"].addTransition(_Main_ModeSelector_Running_SmallStep_2)
-
- # transition /Main/ModeSelector/WaitingForPaused
- _Main_ModeSelector_WaitingForPaused_0 = Transition(self, self.states["/Main/ModeSelector/WaitingForPaused"], [self.states["/Main/ModeSelector/Paused"]])
- _Main_ModeSelector_WaitingForPaused_0.setAction(self._Main_ModeSelector_WaitingForPaused_0_exec)
- _Main_ModeSelector_WaitingForPaused_0.setTrigger(Event("Simulation.Paused", None))
- self.states["/Main/ModeSelector/WaitingForPaused"].addTransition(_Main_ModeSelector_WaitingForPaused_0)
-
- # transition /Main/ChildState/Uninitialized
- _Main_ChildState_Uninitialized_0 = Transition(self, self.states["/Main/ChildState/Uninitialized"], [self.states["/Main/ChildState/Initialized"]])
- _Main_ChildState_Uninitialized_0.setTrigger(Event("Simulation.Initialized", None))
- self.states["/Main/ChildState/Uninitialized"].addTransition(_Main_ChildState_Uninitialized_0)
-
- # transition /Main/ChildState/Initialized
- _Main_ChildState_Initialized_0 = Transition(self, self.states["/Main/ChildState/Initialized"], [self.states["/Main/ChildState/Uninitialized"]])
- _Main_ChildState_Initialized_0.setAction(self._Main_ChildState_Initialized_0_exec)
- _Main_ChildState_Initialized_0.setTrigger(Event("Simulation.Finished", None))
- self.states["/Main/ChildState/Initialized"].addTransition(_Main_ChildState_Initialized_0)
-
- # transition /Main/Initializer/Waiting
- _Main_Initializer_Waiting_0 = Transition(self, self.states["/Main/Initializer/Waiting"], [self.states["/Main/Initializer/CreatingChildSimulator"]])
- _Main_Initializer_Waiting_0.setAction(self._Main_Initializer_Waiting_0_exec)
- _Main_Initializer_Waiting_0.setTrigger(None)
- _Main_Initializer_Waiting_0.setGuard(self._Main_Initializer_Waiting_0_guard)
- self.states["/Main/Initializer/Waiting"].addTransition(_Main_Initializer_Waiting_0)
-
- # transition /Main/Initializer/CreatingChildSimulator
- _Main_Initializer_CreatingChildSimulator_0 = Transition(self, self.states["/Main/Initializer/CreatingChildSimulator"], [self.states["/Main/Initializer/StartingChildSimulator"]])
- _Main_Initializer_CreatingChildSimulator_0.setAction(self._Main_Initializer_CreatingChildSimulator_0_exec)
- _Main_Initializer_CreatingChildSimulator_0.setTrigger(Event("instance_created", None))
- self.states["/Main/Initializer/CreatingChildSimulator"].addTransition(_Main_Initializer_CreatingChildSimulator_0)
-
- # transition /Main/Initializer/StartingChildSimulator
- _Main_Initializer_StartingChildSimulator_0 = Transition(self, self.states["/Main/Initializer/StartingChildSimulator"], [self.states["/Main/Initializer/Waiting"]])
- _Main_Initializer_StartingChildSimulator_0.setTrigger(Event("Simulation.Initialized", None))
- self.states["/Main/Initializer/StartingChildSimulator"].addTransition(_Main_Initializer_StartingChildSimulator_0)
-
- # transition /Main/SimulationFlow/PrePaused
- _Main_SimulationFlow_PrePaused_0 = Transition(self, self.states["/Main/SimulationFlow/PrePaused"], [self.states["/Main/SimulationFlow/Paused"]])
- _Main_SimulationFlow_PrePaused_0.setTrigger(Event("_0after"))
- self.states["/Main/SimulationFlow/PrePaused"].addTransition(_Main_SimulationFlow_PrePaused_0)
-
- # transition /Main/SimulationFlow/Paused
- _Main_SimulationFlow_Paused_0 = Transition(self, self.states["/Main/SimulationFlow/Paused"], [self.states["/Main/SimulationFlow/Executing"]])
- _Main_SimulationFlow_Paused_0.setAction(self._Main_SimulationFlow_Paused_0_exec)
- _Main_SimulationFlow_Paused_0.setTrigger(None)
- _Main_SimulationFlow_Paused_0.setGuard(self._Main_SimulationFlow_Paused_0_guard)
- self.states["/Main/SimulationFlow/Paused"].addTransition(_Main_SimulationFlow_Paused_0)
- _Main_SimulationFlow_Paused_1 = Transition(self, self.states["/Main/SimulationFlow/Paused"], [self.states["/Main/SimulationFlow/Executing"]])
- _Main_SimulationFlow_Paused_1.setAction(self._Main_SimulationFlow_Paused_1_exec)
- _Main_SimulationFlow_Paused_1.setTrigger(None)
- _Main_SimulationFlow_Paused_1.setGuard(self._Main_SimulationFlow_Paused_1_guard)
- self.states["/Main/SimulationFlow/Paused"].addTransition(_Main_SimulationFlow_Paused_1)
- _Main_SimulationFlow_Paused_2 = Transition(self, self.states["/Main/SimulationFlow/Paused"], [self.states["/Main/SimulationFlow/Executing"]])
- _Main_SimulationFlow_Paused_2.setAction(self._Main_SimulationFlow_Paused_2_exec)
- _Main_SimulationFlow_Paused_2.setTrigger(None)
- _Main_SimulationFlow_Paused_2.setGuard(self._Main_SimulationFlow_Paused_2_guard)
- self.states["/Main/SimulationFlow/Paused"].addTransition(_Main_SimulationFlow_Paused_2)
- _Main_SimulationFlow_Paused_3 = Transition(self, self.states["/Main/SimulationFlow/Paused"], [self.states["/Main/SimulationFlow/Executing"]])
- _Main_SimulationFlow_Paused_3.setAction(self._Main_SimulationFlow_Paused_3_exec)
- _Main_SimulationFlow_Paused_3.setTrigger(None)
- _Main_SimulationFlow_Paused_3.setGuard(self._Main_SimulationFlow_Paused_3_guard)
- self.states["/Main/SimulationFlow/Paused"].addTransition(_Main_SimulationFlow_Paused_3)
-
- # transition /Main/SimulationFlow/Executing
- _Main_SimulationFlow_Executing_0 = Transition(self, self.states["/Main/SimulationFlow/Executing"], [self.states["/Main/SimulationFlow/Paused"]])
- _Main_SimulationFlow_Executing_0.setTrigger(None)
- _Main_SimulationFlow_Executing_0.setGuard(self._Main_SimulationFlow_Executing_0_guard)
- self.states["/Main/SimulationFlow/Executing"].addTransition(_Main_SimulationFlow_Executing_0)
- _Main_SimulationFlow_Executing_1 = Transition(self, self.states["/Main/SimulationFlow/Executing"], [self.states["/Main/SimulationFlow/PrePaused"]])
- _Main_SimulationFlow_Executing_1.setTrigger(Event("Simulation.Finished", None))
- _Main_SimulationFlow_Executing_1.setGuard(self._Main_SimulationFlow_Executing_1_guard)
- self.states["/Main/SimulationFlow/Executing"].addTransition(_Main_SimulationFlow_Executing_1)
-
- # transition /Main/GodEventManager/Listening
- _Main_GodEventManager_Listening_0 = Transition(self, self.states["/Main/GodEventManager/Listening"], [self.states["/Main/GodEventManager/Waiting"]])
- _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/GodEventManager/Waiting
- _Main_GodEventManager_Waiting_0 = Transition(self, self.states["/Main/GodEventManager/Waiting"], [self.states["/Main/GodEventManager/Listening"]])
- _Main_GodEventManager_Waiting_0.setAction(self._Main_GodEventManager_Waiting_0_exec)
- _Main_GodEventManager_Waiting_0.setTrigger(Event("Simulation.GodEventResult", None))
- self.states["/Main/GodEventManager/Waiting"].addTransition(_Main_GodEventManager_Waiting_0)
-
- # transition /Main/BreakpointManager/Listening
- _Main_BreakpointManager_Listening_0 = Transition(self, self.states["/Main/BreakpointManager/Listening"], [self.states["/Main/BreakpointManager/Waiting"]])
- _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/Waiting"]])
- _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/Waiting"]])
- _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/Waiting"]])
- _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/BreakpointManager/Waiting
- _Main_BreakpointManager_Waiting_0 = Transition(self, self.states["/Main/BreakpointManager/Waiting"], [self.states["/Main/BreakpointManager/Listening"]])
- _Main_BreakpointManager_Waiting_0.setAction(self._Main_BreakpointManager_Waiting_0_exec)
- _Main_BreakpointManager_Waiting_0.setTrigger(Event("Breakpoint.AddResult", None))
- self.states["/Main/BreakpointManager/Waiting"].addTransition(_Main_BreakpointManager_Waiting_0)
- _Main_BreakpointManager_Waiting_1 = Transition(self, self.states["/Main/BreakpointManager/Waiting"], [self.states["/Main/BreakpointManager/Listening"]])
- _Main_BreakpointManager_Waiting_1.setAction(self._Main_BreakpointManager_Waiting_1_exec)
- _Main_BreakpointManager_Waiting_1.setTrigger(Event("Breakpoint.DelResult", None))
- self.states["/Main/BreakpointManager/Waiting"].addTransition(_Main_BreakpointManager_Waiting_1)
- _Main_BreakpointManager_Waiting_2 = Transition(self, self.states["/Main/BreakpointManager/Waiting"], [self.states["/Main/BreakpointManager/Listening"]])
- _Main_BreakpointManager_Waiting_2.setAction(self._Main_BreakpointManager_Waiting_2_exec)
- _Main_BreakpointManager_Waiting_2.setTrigger(Event("Breakpoint.ToggleResult", None))
- self.states["/Main/BreakpointManager/Waiting"].addTransition(_Main_BreakpointManager_Waiting_2)
- _Main_BreakpointManager_Waiting_3 = Transition(self, self.states["/Main/BreakpointManager/Waiting"], [self.states["/Main/BreakpointManager/Listening"]])
- _Main_BreakpointManager_Waiting_3.setAction(self._Main_BreakpointManager_Waiting_3_exec)
- _Main_BreakpointManager_Waiting_3.setTrigger(Event("Breakpoint.ListResult", None))
- self.states["/Main/BreakpointManager/Waiting"].addTransition(_Main_BreakpointManager_Waiting_3)
-
- # transition /Main/ModeSelector/Running
- _Main_ModeSelector_Running_0 = Transition(self, self.states["/Main/ModeSelector/Running"], [self.states["/Main/ModeSelector/Paused"]])
- _Main_ModeSelector_Running_0.setAction(self._Main_ModeSelector_Running_0_exec)
- _Main_ModeSelector_Running_0.setTrigger(Event("Simulation.Finished", None))
- self.states["/Main/ModeSelector/Running"].addTransition(_Main_ModeSelector_Running_0)
- _Main_ModeSelector_Running_1 = Transition(self, self.states["/Main/ModeSelector/Running"], [self.states["/Main/ModeSelector/Paused"]])
- _Main_ModeSelector_Running_1.setAction(self._Main_ModeSelector_Running_1_exec)
- _Main_ModeSelector_Running_1.setTrigger(Event("Breakpoint.Triggered", None))
- self.states["/Main/ModeSelector/Running"].addTransition(_Main_ModeSelector_Running_1)
-
- def _Main_SimulationFlow_PrePaused_enter(self):
- self.addTimer(0, self.sccd_yield())
-
- def _Main_SimulationFlow_PrePaused_exit(self):
- self.removeTimer(0)
-
- def _Main_ModeSelector_Running_0_exec(self, parameters):
- clock = parameters[0]
- state = parameters[1]
- self.big_step.outputEvent(Event("Simulation.Finished", "user_output", []))
- self.big_step.outputEvent(Event("State", "user_output", [clock / 1000.0]))
-
- def _Main_ModeSelector_Running_1_exec(self, parameters):
- triggered_bp = parameters[0]
- clock = parameters[1]
- state = parameters[2]
- self.big_step.outputEvent(Event("Breakpoint.Triggered", "user_output", [triggered_bp, clock]))
- self.big_step.outputEvent(Event("State", "user_output", [clock / 1000.0]))
-
- def _Main_ModeSelector_Paused_3_exec(self, parameters):
- realtime_scale = parameters[0]
- self.realtime_scale = float(realtime_scale)
-
- def _Main_ModeSelector_Paused_4_exec(self, parameters):
- clock = parameters[0]
- iteration = parameters[1]
- time_next = parameters[2]
- state = parameters[3]
- self.big_step.outputEvent(Event("BigStep.Finished", "user_output", []))
- self.big_step.outputEvent(Event("State", "user_output", [clock / 1000.0]))
-
- def _Main_ModeSelector_Paused_5_exec(self, parameters):
- clock = parameters[0]
- state = parameters[1]
- self.big_step.outputEvent(Event("Simulation.Finished", "user_output", []))
- self.big_step.outputEvent(Event("State", "user_output", [clock / 1000.0]))
-
- def _Main_ModeSelector_Running_Continuous_0_exec(self, parameters):
- self.big_step.outputEventOM(Event("narrow_cast", None, [self, 'child_simulator', Event("Simulation.Pause", None, [])]))
-
- def _Main_ModeSelector_Running_Continuous_1_exec(self, parameters):
- clock = parameters[0]
- state = parameters[1]
- self.big_step.outputEvent(Event("Simulation.Finished", "user_output", []))
- self.big_step.outputEvent(Event("State", "user_output", [clock / 1000.0]))
-
- def _Main_ModeSelector_Running_Realtime_0_exec(self, parameters):
- self.big_step.outputEventOM(Event("narrow_cast", None, [self, 'child_simulator', Event("Simulation.Pause", None, [])]))
-
- def _Main_ModeSelector_Running_Realtime_1_exec(self, parameters):
- clock = parameters[0]
- state = parameters[1]
- self.big_step.outputEvent(Event("Simulation.Finished", "user_output", []))
- self.big_step.outputEvent(Event("State", "user_output", [clock / 1000.0]))
-
- def _Main_ModeSelector_Running_Realtime_2_exec(self, parameters):
- clock = parameters[0]
- iteration = parameters[1]
- time_next = parameters[2]
- state = parameters[3]
- self.big_step.outputEvent(Event("BigStep.Finished", "user_output", []))
- self.big_step.outputEvent(Event("State", "user_output", [clock / 1000.0]))
-
- def _Main_ModeSelector_Running_BigStep_0_exec(self, parameters):
- clock = parameters[0]
- iteration = parameters[1]
- time_next = parameters[2]
- state = parameters[3]
- self.big_step.outputEvent(Event("BigStep.Finished", "user_output", []))
- self.big_step.outputEvent(Event("State", "user_output", [clock / 1000.0]))
-
- def _Main_ModeSelector_Running_BigStep_1_exec(self, parameters):
- clock = parameters[0]
- state = parameters[1]
- self.big_step.outputEvent(Event("Simulation.Finished", "user_output", []))
- self.big_step.outputEvent(Event("State", "user_output", [clock / 1000.0]))
-
- def _Main_ModeSelector_Running_SmallStep_0_exec(self, parameters):
- current_component_idx = parameters[0]
- state = parameters[1]
- self.big_step.outputEvent(Event("SmallStep.Finished", "user_output", []))
- self.big_step.outputEvent(Event("State", "user_output", [current_component_idx]))
-
- def _Main_ModeSelector_Running_SmallStep_1_exec(self, parameters):
- clock = parameters[0]
- iteration = parameters[1]
- time_next = parameters[2]
- state = parameters[3]
- self.big_step.outputEvent(Event("BigStep.Finished", "user_output", []))
- self.big_step.outputEvent(Event("State", "user_output", [clock / 1000.0]))
-
- def _Main_ModeSelector_Running_SmallStep_2_exec(self, parameters):
- clock = parameters[0]
- state = parameters[1]
- self.big_step.outputEvent(Event("Simulation.Finished", "user_output", []))
- self.big_step.outputEvent(Event("State", "user_output", [clock / 1000.0]))
-
- def _Main_ModeSelector_WaitingForPaused_0_exec(self, parameters):
- clock = parameters[0]
- state = parameters[1]
- self.big_step.outputEvent(Event("Simulation.Paused", "user_output", []))
- self.big_step.outputEvent(Event("State", "user_output", [clock / 1000.0]))
-
- def _Main_ChildState_Initialized_0_exec(self, parameters):
- self.big_step.outputEventOM(Event("delete_instance", None, [self, 'child_simulator']))
-
- def _Main_Initializer_Waiting_0_exec(self, parameters):
- self.big_step.outputEventOM(Event("create_instance", None, [self, 'child_simulator', 'CBDSimulator_Simulation', self.options, self.model]))
-
- def _Main_Initializer_Waiting_0_guard(self, parameters):
- return self.inState(["/Main/ChildState/Uninitialized"])
-
- def _Main_Initializer_CreatingChildSimulator_0_exec(self, parameters):
- self.big_step.outputEventOM(Event("start_instance", None, [self, 'child_simulator']))
-
- def _Main_SimulationFlow_Paused_0_exec(self, parameters):
- self.big_step.outputEventOM(Event("narrow_cast", None, [self, 'child_simulator', Event("Simulation.Execute", None, [])]))
-
- def _Main_SimulationFlow_Paused_0_guard(self, parameters):
- return self.inState(["/Main/ModeSelector/Running/Continuous"]) and self.inState(["/Main/ChildState/Initialized"])
-
- def _Main_SimulationFlow_Paused_1_exec(self, parameters):
- self.big_step.outputEventOM(Event("narrow_cast", None, [self, 'child_simulator', Event("Simulation.ExecuteRealtime", None, [self.realtime_scale])]))
-
- def _Main_SimulationFlow_Paused_1_guard(self, parameters):
- return self.inState(["/Main/ModeSelector/Running/Realtime"]) and self.inState(["/Main/ChildState/Initialized"])
-
- def _Main_SimulationFlow_Paused_2_exec(self, parameters):
- self.big_step.outputEventOM(Event("narrow_cast", None, [self, 'child_simulator', Event("BigStep.Execute", None, [])]))
-
- def _Main_SimulationFlow_Paused_2_guard(self, parameters):
- return self.inState(["/Main/ModeSelector/Running/BigStep"]) and self.inState(["/Main/ChildState/Initialized"])
-
- def _Main_SimulationFlow_Paused_3_exec(self, parameters):
- self.big_step.outputEventOM(Event("narrow_cast", None, [self, 'child_simulator', Event("SmallStep.Execute", None, [])]))
-
- def _Main_SimulationFlow_Paused_3_guard(self, parameters):
- return self.inState(["/Main/ModeSelector/Running/SmallStep"]) and self.inState(["/Main/ChildState/Initialized"])
-
- def _Main_SimulationFlow_Executing_0_guard(self, parameters):
- return self.inState(["/Main/ModeSelector/Paused"])
-
- def _Main_SimulationFlow_Executing_1_guard(self, parameters):
- return self.inState(["/Main/ModeSelector/Running/Continuous"]) or self.inState(["/Main/ModeSelector/Running/Realtime"])
-
- def _Main_GodEventManager_Listening_0_exec(self, parameters):
- block_name = parameters[0]
- new_val = parameters[1]
- self.big_step.outputEventOM(Event("narrow_cast", None, [self, 'child_simulator', Event("Simulation.GodEvent", None, [block_name, new_val])]))
-
- def _Main_GodEventManager_Listening_0_guard(self, parameters):
- block_name = parameters[0]
- new_val = parameters[1]
- return self.inState(["/Main/ModeSelector/Paused"])
-
- def _Main_GodEventManager_Waiting_0_exec(self, parameters):
- result = parameters[0]
- self.big_step.outputEvent(Event("GodEventResult", "user_output", [result]))
-
- def _Main_BreakpointManager_Listening_0_exec(self, parameters):
- name = parameters[0]
- function = parameters[1]
- enabled = parameters[2]
- disable_on_trigger = parameters[3]
- self.big_step.outputEventOM(Event("narrow_cast", None, [self, 'child_simulator', Event("Breakpoint.Add", None, [name, function, enabled, disable_on_trigger])]))
-
- def _Main_BreakpointManager_Listening_1_exec(self, parameters):
- name = parameters[0]
- self.big_step.outputEventOM(Event("narrow_cast", None, [self, 'child_simulator', Event("Breakpoint.Del", None, [name])]))
-
- def _Main_BreakpointManager_Listening_2_exec(self, parameters):
- name = parameters[0]
- self.big_step.outputEventOM(Event("narrow_cast", None, [self, 'child_simulator', Event("Breakpoint.Toggle", None, [name])]))
-
- def _Main_BreakpointManager_Listening_3_exec(self, parameters):
- self.big_step.outputEventOM(Event("narrow_cast", None, [self, 'child_simulator', Event("Breakpoint.List", None, [])]))
-
- def _Main_BreakpointManager_Waiting_0_exec(self, parameters):
- result = parameters[0]
- self.big_step.outputEvent(Event("Breakpoint.AddResult", "user_output", [result]))
-
- def _Main_BreakpointManager_Waiting_1_exec(self, parameters):
- result = parameters[0]
- self.big_step.outputEvent(Event("Breakpoint.DelResult", "user_output", [result]))
-
- def _Main_BreakpointManager_Waiting_2_exec(self, parameters):
- result = parameters[0]
- self.big_step.outputEvent(Event("Breakpoint.ToggleResult", "user_output", [result]))
-
- def _Main_BreakpointManager_Waiting_3_exec(self, parameters):
- result = parameters[0]
- self.big_step.outputEvent(Event("Breakpoint.ListResult", "user_output", [result]))
-
- def initializeStatechart(self):
- # enter default state
- self.default_targets = self.states["/Main"].getEffectiveTargetStates()
- RuntimeClassBase.initializeStatechart(self)
- class CBDSimulator_Simulation(RuntimeClassBase):
- def __init__(self, controller, options, model):
- 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()
-
- # call user defined constructor
- CBDSimulator_Simulation.user_defined_constructor(self, options, model)
-
- def user_defined_constructor(self, options, model):
- self.options = options
- self.delta = self.options.getDeltaT() * 1000.0 # in miliseconds for real-time simulation
- self.model = model
- self.initialized = False
-
- def user_defined_destructor(self):
- pass
-
-
- # user defined method
- def initialize(self):
- self.iteration = 0
- self.clock = 0
- self.time_next = self.delta
- self.cbd_controller = CBDController(self.model, self.delta / 1000.0)
- self.cbd_controller.initSimulation()
- self.state = {b.getBlockName(): b.getSignal() for b in self.model.getBlocks()}
- self.initialized = True
-
-
- # user defined method
- def endCondition(self):
- return self.initialized and self.iteration >= self.options.getMaxIterations()
-
-
- # user defined method
- def finalize(self):
- from bokeh.plotting import figure, output_file, show
- times = []
- values = []
- for timeValuePair in self.model.getSignal("neg"):
- times.append(timeValuePair.time)
- values.append(timeValuePair.value)
-
- output_file("./plot.html", title="Plot")
- p = figure(title="Something vs Otherthing", x_axis_label="Time", y_axis_label="Values")
- p.line(times, values, legend="Something", line_width=1, line_color="red")
- show(p)
- print 'Simulation finalized.'
-
-
- # user defined method
- def initializeDebugger(self):
- self.breakpoints = []
- self.triggered_bp = None
-
-
- # 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}):
- # 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, block_name, new_val):
- if not self.initialized:
- return -1
- if block_name not in self.state:
- return -1
- for b in self.model.getBlocks():
- if b.getBlockName() == block_name:
- b.setSignal(new_val)
- self.state = {b.getBlockName(): b.getSignal() for b in self.model.getBlocks()}
- return 0
-
-
- # builds Statechart structure
- def build_statechart_structure(self):
-
- # state <root>
- self.states[""] = State(0, "", self)
-
- # state /Main
- self.states["/Main"] = ParallelState(1, "/Main", self)
-
- # state /Main/ModeSelector
- self.states["/Main/ModeSelector"] = State(2, "/Main/ModeSelector", self)
-
- # state /Main/ModeSelector/Paused
- self.states["/Main/ModeSelector/Paused"] = State(3, "/Main/ModeSelector/Paused", self)
-
- # state /Main/ModeSelector/Running
- self.states["/Main/ModeSelector/Running"] = State(4, "/Main/ModeSelector/Running", self)
-
- # state /Main/ModeSelector/Running/Continuous
- self.states["/Main/ModeSelector/Running/Continuous"] = State(5, "/Main/ModeSelector/Running/Continuous", self)
-
- # state /Main/ModeSelector/Running/Realtime
- self.states["/Main/ModeSelector/Running/Realtime"] = State(6, "/Main/ModeSelector/Running/Realtime", self)
-
- # state /Main/ModeSelector/Running/BigStep
- self.states["/Main/ModeSelector/Running/BigStep"] = State(7, "/Main/ModeSelector/Running/BigStep", self)
-
- # state /Main/ModeSelector/Running/SmallStep
- self.states["/Main/ModeSelector/Running/SmallStep"] = State(8, "/Main/ModeSelector/Running/SmallStep", self)
-
- # state /Main/ChildState
- self.states["/Main/ChildState"] = State(9, "/Main/ChildState", self)
-
- # state /Main/ChildState/Uninitialized
- self.states["/Main/ChildState/Uninitialized"] = State(10, "/Main/ChildState/Uninitialized", self)
-
- # state /Main/ChildState/Initialized
- self.states["/Main/ChildState/Initialized"] = State(11, "/Main/ChildState/Initialized", self)
-
- # state /Main/Initializer
- self.states["/Main/Initializer"] = State(12, "/Main/Initializer", self)
-
- # state /Main/Initializer/Waiting
- self.states["/Main/Initializer/Waiting"] = State(13, "/Main/Initializer/Waiting", self)
-
- # state /Main/Initializer/CreatingChildSimulator
- self.states["/Main/Initializer/CreatingChildSimulator"] = State(14, "/Main/Initializer/CreatingChildSimulator", self)
-
- # state /Main/Initializer/StartingChildSimulator
- self.states["/Main/Initializer/StartingChildSimulator"] = State(15, "/Main/Initializer/StartingChildSimulator", self)
-
- # state /Main/Initializer/Running
- self.states["/Main/Initializer/Running"] = State(16, "/Main/Initializer/Running", self)
-
- # state /Main/Initializer/SettleBeforeWaiting
- self.states["/Main/Initializer/SettleBeforeWaiting"] = State(17, "/Main/Initializer/SettleBeforeWaiting", self)
- self.states["/Main/Initializer/SettleBeforeWaiting"].setEnter(self._Main_Initializer_SettleBeforeWaiting_enter)
- self.states["/Main/Initializer/SettleBeforeWaiting"].setExit(self._Main_Initializer_SettleBeforeWaiting_exit)
-
- # state /Main/SimulationFlow
- self.states["/Main/SimulationFlow"] = State(18, "/Main/SimulationFlow", self)
-
- # state /Main/SimulationFlow/Started
- self.states["/Main/SimulationFlow/Started"] = State(19, "/Main/SimulationFlow/Started", self)
-
- # state /Main/SimulationFlow/Initialized
- self.states["/Main/SimulationFlow/Initialized"] = State(20, "/Main/SimulationFlow/Initialized", self)
-
- # state /Main/SimulationFlow/InitializeDebugger
- self.states["/Main/SimulationFlow/InitializeDebugger"] = State(21, "/Main/SimulationFlow/InitializeDebugger", self)
-
- # state /Main/SimulationFlow/Waiting
- self.states["/Main/SimulationFlow/Waiting"] = State(22, "/Main/SimulationFlow/Waiting", self)
-
- # state /Main/SimulationFlow/SettleBeforeCheckTermination
- self.states["/Main/SimulationFlow/SettleBeforeCheckTermination"] = State(23, "/Main/SimulationFlow/SettleBeforeCheckTermination", self)
- self.states["/Main/SimulationFlow/SettleBeforeCheckTermination"].setEnter(self._Main_SimulationFlow_SettleBeforeCheckTermination_enter)
- self.states["/Main/SimulationFlow/SettleBeforeCheckTermination"].setExit(self._Main_SimulationFlow_SettleBeforeCheckTermination_exit)
-
- # state /Main/SimulationFlow/CheckTermination
- self.states["/Main/SimulationFlow/CheckTermination"] = State(24, "/Main/SimulationFlow/CheckTermination", self)
-
- # state /Main/SimulationFlow/WaitingRealtime
- self.states["/Main/SimulationFlow/WaitingRealtime"] = State(25, "/Main/SimulationFlow/WaitingRealtime", self)
- self.states["/Main/SimulationFlow/WaitingRealtime"].setEnter(self._Main_SimulationFlow_WaitingRealtime_enter)
- self.states["/Main/SimulationFlow/WaitingRealtime"].setExit(self._Main_SimulationFlow_WaitingRealtime_exit)
-
- # state /Main/SimulationFlow/Executing
- self.states["/Main/SimulationFlow/Executing"] = State(26, "/Main/SimulationFlow/Executing", self)
-
- # state /Main/SimulationFlow/Stopped
- self.states["/Main/SimulationFlow/Stopped"] = State(27, "/Main/SimulationFlow/Stopped", self)
-
- # state /Main/GodEventManager
- self.states["/Main/GodEventManager"] = State(28, "/Main/GodEventManager", self)
-
- # state /Main/GodEventManager/Listening
- self.states["/Main/GodEventManager/Listening"] = State(29, "/Main/GodEventManager/Listening", self)
-
- # state /Main/BreakpointManager
- self.states["/Main/BreakpointManager"] = State(30, "/Main/BreakpointManager", self)
-
- # state /Main/BreakpointManager/Listening
- self.states["/Main/BreakpointManager/Listening"] = State(31, "/Main/BreakpointManager/Listening", self)
-
- # state /Stopped
- self.states["/Stopped"] = State(32, "/Stopped", self)
-
- # add children
- self.states[""].addChild(self.states["/Main"])
- self.states[""].addChild(self.states["/Stopped"])
- self.states["/Main"].addChild(self.states["/Main/ModeSelector"])
- self.states["/Main"].addChild(self.states["/Main/ChildState"])
- self.states["/Main"].addChild(self.states["/Main/Initializer"])
- self.states["/Main"].addChild(self.states["/Main/SimulationFlow"])
- self.states["/Main"].addChild(self.states["/Main/GodEventManager"])
- self.states["/Main"].addChild(self.states["/Main/BreakpointManager"])
- self.states["/Main/ModeSelector"].addChild(self.states["/Main/ModeSelector/Paused"])
- self.states["/Main/ModeSelector"].addChild(self.states["/Main/ModeSelector/Running"])
- self.states["/Main/ModeSelector/Running"].addChild(self.states["/Main/ModeSelector/Running/Continuous"])
- self.states["/Main/ModeSelector/Running"].addChild(self.states["/Main/ModeSelector/Running/Realtime"])
- self.states["/Main/ModeSelector/Running"].addChild(self.states["/Main/ModeSelector/Running/BigStep"])
- self.states["/Main/ModeSelector/Running"].addChild(self.states["/Main/ModeSelector/Running/SmallStep"])
- self.states["/Main/ChildState"].addChild(self.states["/Main/ChildState/Uninitialized"])
- self.states["/Main/ChildState"].addChild(self.states["/Main/ChildState/Initialized"])
- self.states["/Main/Initializer"].addChild(self.states["/Main/Initializer/Waiting"])
- self.states["/Main/Initializer"].addChild(self.states["/Main/Initializer/CreatingChildSimulator"])
- self.states["/Main/Initializer"].addChild(self.states["/Main/Initializer/StartingChildSimulator"])
- self.states["/Main/Initializer"].addChild(self.states["/Main/Initializer/Running"])
- self.states["/Main/Initializer"].addChild(self.states["/Main/Initializer/SettleBeforeWaiting"])
- 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/Waiting"])
- self.states["/Main/SimulationFlow"].addChild(self.states["/Main/SimulationFlow/SettleBeforeCheckTermination"])
- self.states["/Main/SimulationFlow"].addChild(self.states["/Main/SimulationFlow/CheckTermination"])
- self.states["/Main/SimulationFlow"].addChild(self.states["/Main/SimulationFlow/WaitingRealtime"])
- self.states["/Main/SimulationFlow"].addChild(self.states["/Main/SimulationFlow/Executing"])
- self.states["/Main/SimulationFlow"].addChild(self.states["/Main/SimulationFlow/Stopped"])
- self.states["/Main/GodEventManager"].addChild(self.states["/Main/GodEventManager/Listening"])
- self.states["/Main/BreakpointManager"].addChild(self.states["/Main/BreakpointManager/Listening"])
- self.states[""].fixTree()
- self.states[""].default_state = self.states["/Main"]
- self.states["/Main/ModeSelector"].default_state = self.states["/Main/ModeSelector/Paused"]
- self.states["/Main/ModeSelector/Running"].default_state = self.states["/Main/ModeSelector/Running/Continuous"]
- self.states["/Main/ChildState"].default_state = self.states["/Main/ChildState/Uninitialized"]
- self.states["/Main/Initializer"].default_state = self.states["/Main/Initializer/Waiting"]
- self.states["/Main/SimulationFlow"].default_state = self.states["/Main/SimulationFlow/Started"]
- self.states["/Main/GodEventManager"].default_state = self.states["/Main/GodEventManager/Listening"]
- self.states["/Main/BreakpointManager"].default_state = self.states["/Main/BreakpointManager/Listening"]
-
- # transition /Main/ModeSelector/Paused
- _Main_ModeSelector_Paused_0 = Transition(self, self.states["/Main/ModeSelector/Paused"], [self.states["/Main/ModeSelector/Running/SmallStep"]])
- _Main_ModeSelector_Paused_0.setAction(self._Main_ModeSelector_Paused_0_exec)
- _Main_ModeSelector_Paused_0.setTrigger(Event("SmallStep.Execute", None))
- self.states["/Main/ModeSelector/Paused"].addTransition(_Main_ModeSelector_Paused_0)
- _Main_ModeSelector_Paused_1 = Transition(self, self.states["/Main/ModeSelector/Paused"], [self.states["/Main/ModeSelector/Running/BigStep"]])
- _Main_ModeSelector_Paused_1.setAction(self._Main_ModeSelector_Paused_1_exec)
- _Main_ModeSelector_Paused_1.setTrigger(Event("BigStep.Execute", None))
- self.states["/Main/ModeSelector/Paused"].addTransition(_Main_ModeSelector_Paused_1)
- _Main_ModeSelector_Paused_2 = Transition(self, self.states["/Main/ModeSelector/Paused"], [self.states["/Main/ModeSelector/Running/Continuous"]])
- _Main_ModeSelector_Paused_2.setTrigger(Event("Simulation.Execute", None))
- self.states["/Main/ModeSelector/Paused"].addTransition(_Main_ModeSelector_Paused_2)
- _Main_ModeSelector_Paused_3 = Transition(self, self.states["/Main/ModeSelector/Paused"], [self.states["/Main/ModeSelector/Running/Realtime"]])
- _Main_ModeSelector_Paused_3.setAction(self._Main_ModeSelector_Paused_3_exec)
- _Main_ModeSelector_Paused_3.setTrigger(Event("Simulation.ExecuteRealtime", None))
- self.states["/Main/ModeSelector/Paused"].addTransition(_Main_ModeSelector_Paused_3)
- _Main_ModeSelector_Paused_4 = Transition(self, self.states["/Main/ModeSelector/Paused"], [self.states["/Main/ModeSelector/Paused"]])
- _Main_ModeSelector_Paused_4.setAction(self._Main_ModeSelector_Paused_4_exec)
- _Main_ModeSelector_Paused_4.setTrigger(Event("BigStep.Finished", None))
- self.states["/Main/ModeSelector/Paused"].addTransition(_Main_ModeSelector_Paused_4)
-
- # transition /Main/ModeSelector/Running/Continuous
- _Main_ModeSelector_Running_Continuous_0 = Transition(self, self.states["/Main/ModeSelector/Running/Continuous"], [self.states["/Main/ModeSelector/Paused"]])
- _Main_ModeSelector_Running_Continuous_0.setTrigger(Event("Simulation.Pause", None))
- self.states["/Main/ModeSelector/Running/Continuous"].addTransition(_Main_ModeSelector_Running_Continuous_0)
-
- # transition /Main/ModeSelector/Running/Realtime
- _Main_ModeSelector_Running_Realtime_0 = Transition(self, self.states["/Main/ModeSelector/Running/Realtime"], [self.states["/Main/ModeSelector/Paused"]])
- _Main_ModeSelector_Running_Realtime_0.setTrigger(Event("Simulation.Pause", None))
- self.states["/Main/ModeSelector/Running/Realtime"].addTransition(_Main_ModeSelector_Running_Realtime_0)
- _Main_ModeSelector_Running_Realtime_1 = Transition(self, self.states["/Main/ModeSelector/Running/Realtime"], [self.states["/Main/ModeSelector/Running/Realtime"]])
- _Main_ModeSelector_Running_Realtime_1.setAction(self._Main_ModeSelector_Running_Realtime_1_exec)
- _Main_ModeSelector_Running_Realtime_1.setTrigger(Event("BigStep.Finished", None))
- self.states["/Main/ModeSelector/Running/Realtime"].addTransition(_Main_ModeSelector_Running_Realtime_1)
-
- # transition /Main/ModeSelector/Running/BigStep
- _Main_ModeSelector_Running_BigStep_0 = Transition(self, self.states["/Main/ModeSelector/Running/BigStep"], [self.states["/Main/ModeSelector/Paused"]])
- _Main_ModeSelector_Running_BigStep_0.setAction(self._Main_ModeSelector_Running_BigStep_0_exec)
- _Main_ModeSelector_Running_BigStep_0.setTrigger(Event("BigStep.Finished", None))
- self.states["/Main/ModeSelector/Running/BigStep"].addTransition(_Main_ModeSelector_Running_BigStep_0)
-
- # transition /Main/ModeSelector/Running/SmallStep
- _Main_ModeSelector_Running_SmallStep_0 = Transition(self, self.states["/Main/ModeSelector/Running/SmallStep"], [self.states["/Main/ModeSelector/Paused"]])
- _Main_ModeSelector_Running_SmallStep_0.setAction(self._Main_ModeSelector_Running_SmallStep_0_exec)
- _Main_ModeSelector_Running_SmallStep_0.setTrigger(Event("SmallStep.Finished", None))
- self.states["/Main/ModeSelector/Running/SmallStep"].addTransition(_Main_ModeSelector_Running_SmallStep_0)
-
- # transition /Main/ChildState/Uninitialized
- _Main_ChildState_Uninitialized_0 = Transition(self, self.states["/Main/ChildState/Uninitialized"], [self.states["/Main/ChildState/Initialized"]])
- _Main_ChildState_Uninitialized_0.setTrigger(Event("BigStep.Initialized", None))
- self.states["/Main/ChildState/Uninitialized"].addTransition(_Main_ChildState_Uninitialized_0)
-
- # transition /Main/ChildState/Initialized
- _Main_ChildState_Initialized_0 = Transition(self, self.states["/Main/ChildState/Initialized"], [self.states["/Main/ChildState/Uninitialized"]])
- _Main_ChildState_Initialized_0.setAction(self._Main_ChildState_Initialized_0_exec)
- _Main_ChildState_Initialized_0.setTrigger(Event("BigStep.Finished", None))
- self.states["/Main/ChildState/Initialized"].addTransition(_Main_ChildState_Initialized_0)
-
- # transition /Main/Initializer/Waiting
- _Main_Initializer_Waiting_0 = Transition(self, self.states["/Main/Initializer/Waiting"], [self.states["/Main/Initializer/CreatingChildSimulator"]])
- _Main_Initializer_Waiting_0.setAction(self._Main_Initializer_Waiting_0_exec)
- _Main_Initializer_Waiting_0.setTrigger(None)
- _Main_Initializer_Waiting_0.setGuard(self._Main_Initializer_Waiting_0_guard)
- self.states["/Main/Initializer/Waiting"].addTransition(_Main_Initializer_Waiting_0)
-
- # transition /Main/Initializer/CreatingChildSimulator
- _Main_Initializer_CreatingChildSimulator_0 = Transition(self, self.states["/Main/Initializer/CreatingChildSimulator"], [self.states["/Main/Initializer/StartingChildSimulator"]])
- _Main_Initializer_CreatingChildSimulator_0.setAction(self._Main_Initializer_CreatingChildSimulator_0_exec)
- _Main_Initializer_CreatingChildSimulator_0.setTrigger(Event("instance_created", None))
- self.states["/Main/Initializer/CreatingChildSimulator"].addTransition(_Main_Initializer_CreatingChildSimulator_0)
-
- # transition /Main/Initializer/StartingChildSimulator
- _Main_Initializer_StartingChildSimulator_0 = Transition(self, self.states["/Main/Initializer/StartingChildSimulator"], [self.states["/Main/Initializer/Running"]])
- _Main_Initializer_StartingChildSimulator_0.setTrigger(Event("BigStep.Initialized", None))
- self.states["/Main/Initializer/StartingChildSimulator"].addTransition(_Main_Initializer_StartingChildSimulator_0)
-
- # transition /Main/Initializer/Running
- _Main_Initializer_Running_0 = Transition(self, self.states["/Main/Initializer/Running"], [self.states["/Main/Initializer/SettleBeforeWaiting"]])
- _Main_Initializer_Running_0.setTrigger(Event("BigStep.Finished", None))
- self.states["/Main/Initializer/Running"].addTransition(_Main_Initializer_Running_0)
-
- # transition /Main/Initializer/SettleBeforeWaiting
- _Main_Initializer_SettleBeforeWaiting_0 = Transition(self, self.states["/Main/Initializer/SettleBeforeWaiting"], [self.states["/Main/Initializer/Waiting"]])
- _Main_Initializer_SettleBeforeWaiting_0.setTrigger(Event("_0after"))
- self.states["/Main/Initializer/SettleBeforeWaiting"].addTransition(_Main_Initializer_SettleBeforeWaiting_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/Waiting"]])
- _Main_SimulationFlow_InitializeDebugger_0.setAction(self._Main_SimulationFlow_InitializeDebugger_0_exec)
- _Main_SimulationFlow_InitializeDebugger_0.setTrigger(None)
- self.states["/Main/SimulationFlow/InitializeDebugger"].addTransition(_Main_SimulationFlow_InitializeDebugger_0)
-
- # transition /Main/SimulationFlow/Waiting
- _Main_SimulationFlow_Waiting_0 = Transition(self, self.states["/Main/SimulationFlow/Waiting"], [self.states["/Main/SimulationFlow/CheckTermination"]])
- _Main_SimulationFlow_Waiting_0.setTrigger(None)
- _Main_SimulationFlow_Waiting_0.setGuard(self._Main_SimulationFlow_Waiting_0_guard)
- self.states["/Main/SimulationFlow/Waiting"].addTransition(_Main_SimulationFlow_Waiting_0)
-
- # transition /Main/SimulationFlow/SettleBeforeCheckTermination
- _Main_SimulationFlow_SettleBeforeCheckTermination_0 = Transition(self, self.states["/Main/SimulationFlow/SettleBeforeCheckTermination"], [self.states["/Main/SimulationFlow/CheckTermination"]])
- _Main_SimulationFlow_SettleBeforeCheckTermination_0.setTrigger(Event("_1after"))
- self.states["/Main/SimulationFlow/SettleBeforeCheckTermination"].addTransition(_Main_SimulationFlow_SettleBeforeCheckTermination_0)
- _Main_SimulationFlow_SettleBeforeCheckTermination_1 = Transition(self, self.states["/Main/SimulationFlow/SettleBeforeCheckTermination"], [self.states["/Main/SimulationFlow/CheckTermination"]])
- _Main_SimulationFlow_SettleBeforeCheckTermination_1.setAction(self._Main_SimulationFlow_SettleBeforeCheckTermination_1_exec)
- _Main_SimulationFlow_SettleBeforeCheckTermination_1.setTrigger(None)
- _Main_SimulationFlow_SettleBeforeCheckTermination_1.setGuard(self._Main_SimulationFlow_SettleBeforeCheckTermination_1_guard)
- self.states["/Main/SimulationFlow/SettleBeforeCheckTermination"].addTransition(_Main_SimulationFlow_SettleBeforeCheckTermination_1)
-
- # transition /Main/SimulationFlow/CheckTermination
- _Main_SimulationFlow_CheckTermination_0 = Transition(self, self.states["/Main/SimulationFlow/CheckTermination"], [self.states["/Main/SimulationFlow/Executing"]])
- _Main_SimulationFlow_CheckTermination_0.setAction(self._Main_SimulationFlow_CheckTermination_0_exec)
- _Main_SimulationFlow_CheckTermination_0.setTrigger(None)
- _Main_SimulationFlow_CheckTermination_0.setGuard(self._Main_SimulationFlow_CheckTermination_0_guard)
- self.states["/Main/SimulationFlow/CheckTermination"].addTransition(_Main_SimulationFlow_CheckTermination_0)
- _Main_SimulationFlow_CheckTermination_1 = Transition(self, self.states["/Main/SimulationFlow/CheckTermination"], [self.states["/Main/SimulationFlow/Executing"]])
- _Main_SimulationFlow_CheckTermination_1.setAction(self._Main_SimulationFlow_CheckTermination_1_exec)
- _Main_SimulationFlow_CheckTermination_1.setTrigger(None)
- _Main_SimulationFlow_CheckTermination_1.setGuard(self._Main_SimulationFlow_CheckTermination_1_guard)
- self.states["/Main/SimulationFlow/CheckTermination"].addTransition(_Main_SimulationFlow_CheckTermination_1)
- _Main_SimulationFlow_CheckTermination_2 = Transition(self, self.states["/Main/SimulationFlow/CheckTermination"], [self.states["/Main/SimulationFlow/WaitingRealtime"]])
- _Main_SimulationFlow_CheckTermination_2.setTrigger(None)
- _Main_SimulationFlow_CheckTermination_2.setGuard(self._Main_SimulationFlow_CheckTermination_2_guard)
- self.states["/Main/SimulationFlow/CheckTermination"].addTransition(_Main_SimulationFlow_CheckTermination_2)
- _Main_SimulationFlow_CheckTermination_3 = Transition(self, self.states["/Main/SimulationFlow/CheckTermination"], [self.states["/Main/SimulationFlow/Stopped"]])
- _Main_SimulationFlow_CheckTermination_3.setAction(self._Main_SimulationFlow_CheckTermination_3_exec)
- _Main_SimulationFlow_CheckTermination_3.setTrigger(None)
- _Main_SimulationFlow_CheckTermination_3.setGuard(self._Main_SimulationFlow_CheckTermination_3_guard)
- self.states["/Main/SimulationFlow/CheckTermination"].addTransition(_Main_SimulationFlow_CheckTermination_3)
-
- # transition /Main/SimulationFlow/WaitingRealtime
- _Main_SimulationFlow_WaitingRealtime_0 = Transition(self, self.states["/Main/SimulationFlow/WaitingRealtime"], [self.states["/Main/SimulationFlow/CheckTermination"]])
- _Main_SimulationFlow_WaitingRealtime_0.setAction(self._Main_SimulationFlow_WaitingRealtime_0_exec)
- _Main_SimulationFlow_WaitingRealtime_0.setTrigger(Event("_2after"))
- _Main_SimulationFlow_WaitingRealtime_0.setGuard(self._Main_SimulationFlow_WaitingRealtime_0_guard)
- self.states["/Main/SimulationFlow/WaitingRealtime"].addTransition(_Main_SimulationFlow_WaitingRealtime_0)
- _Main_SimulationFlow_WaitingRealtime_1 = Transition(self, self.states["/Main/SimulationFlow/WaitingRealtime"], [self.states["/Main/SimulationFlow/CheckTermination"]])
- _Main_SimulationFlow_WaitingRealtime_1.setAction(self._Main_SimulationFlow_WaitingRealtime_1_exec)
- _Main_SimulationFlow_WaitingRealtime_1.setTrigger(None)
- _Main_SimulationFlow_WaitingRealtime_1.setGuard(self._Main_SimulationFlow_WaitingRealtime_1_guard)
- self.states["/Main/SimulationFlow/WaitingRealtime"].addTransition(_Main_SimulationFlow_WaitingRealtime_1)
- _Main_SimulationFlow_WaitingRealtime_2 = Transition(self, self.states["/Main/SimulationFlow/WaitingRealtime"], [self.states["/Main/SimulationFlow/Executing"]])
- _Main_SimulationFlow_WaitingRealtime_2.setAction(self._Main_SimulationFlow_WaitingRealtime_2_exec)
- _Main_SimulationFlow_WaitingRealtime_2.setTrigger(None)
- _Main_SimulationFlow_WaitingRealtime_2.setGuard(self._Main_SimulationFlow_WaitingRealtime_2_guard)
- self.states["/Main/SimulationFlow/WaitingRealtime"].addTransition(_Main_SimulationFlow_WaitingRealtime_2)
-
- # transition /Main/SimulationFlow/Executing
- _Main_SimulationFlow_Executing_0 = Transition(self, self.states["/Main/SimulationFlow/Executing"], [self.states["/Main/SimulationFlow/SettleBeforeCheckTermination"]])
- _Main_SimulationFlow_Executing_0.setAction(self._Main_SimulationFlow_Executing_0_exec)
- _Main_SimulationFlow_Executing_0.setTrigger(Event("BigStep.Finished", None))
- self.states["/Main/SimulationFlow/Executing"].addTransition(_Main_SimulationFlow_Executing_0)
-
- # 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("Simulation.GodEvent", None))
- _Main_GodEventManager_Listening_0.setGuard(self._Main_GodEventManager_Listening_0_guard)
- self.states["/Main/GodEventManager/Listening"].addTransition(_Main_GodEventManager_Listening_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("Breakpoint.Add", None))
- 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("Breakpoint.Del", None))
- 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("Breakpoint.Toggle", None))
- 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("Breakpoint.List", None))
- self.states["/Main/BreakpointManager/Listening"].addTransition(_Main_BreakpointManager_Listening_3)
-
- # transition /Main/ModeSelector/Running
- _Main_ModeSelector_Running_0 = Transition(self, self.states["/Main/ModeSelector/Running"], [self.states["/Main/ModeSelector/Paused"]])
- _Main_ModeSelector_Running_0.setTrigger(Event("Simulation.Finished", None))
- self.states["/Main/ModeSelector/Running"].addTransition(_Main_ModeSelector_Running_0)
- _Main_ModeSelector_Running_1 = Transition(self, self.states["/Main/ModeSelector/Running"], [self.states["/Main/ModeSelector/Paused"]])
- _Main_ModeSelector_Running_1.setAction(self._Main_ModeSelector_Running_1_exec)
- _Main_ModeSelector_Running_1.setTrigger(None)
- _Main_ModeSelector_Running_1.setGuard(self._Main_ModeSelector_Running_1_guard)
- self.states["/Main/ModeSelector/Running"].addTransition(_Main_ModeSelector_Running_1)
-
- def _Main_Initializer_SettleBeforeWaiting_enter(self):
- self.addTimer(0, self.sccd_yield())
-
- def _Main_Initializer_SettleBeforeWaiting_exit(self):
- self.removeTimer(0)
-
- def _Main_SimulationFlow_SettleBeforeCheckTermination_enter(self):
- self.addTimer(1, self.sccd_yield())
-
- def _Main_SimulationFlow_SettleBeforeCheckTermination_exit(self):
- self.removeTimer(1)
-
- def _Main_SimulationFlow_WaitingRealtime_enter(self):
- self.addTimer(2, self.sccd_yield())
-
- def _Main_SimulationFlow_WaitingRealtime_exit(self):
- self.removeTimer(2)
-
- def _Main_ModeSelector_Running_1_exec(self, parameters):
- self.big_step.outputEventOM(Event("narrow_cast", None, [self, 'parent', Event("Breakpoint.Triggered", None, [self.triggered_bp, self.clock, self.state])]))
-
- def _Main_ModeSelector_Running_1_guard(self, parameters):
- return self.breakpointTriggers(self.inState(["/Main/ModeSelector/Running/Realtime"]))
-
- def _Main_ModeSelector_Paused_0_exec(self, parameters):
- self.big_step.outputEventOM(Event("narrow_cast", None, [self, 'child_simulator', Event("SmallStep.Execute", None, [])]))
-
- def _Main_ModeSelector_Paused_1_exec(self, parameters):
- self.big_step.outputEventOM(Event("narrow_cast", None, [self, 'child_simulator', Event("BigStep.Execute", None, [])]))
-
- def _Main_ModeSelector_Paused_3_exec(self, parameters):
- realtime_scale = parameters[0]
- self.realtime_scale = float(realtime_scale)
- # 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_ModeSelector_Paused_4_exec(self, parameters):
- clock = parameters[0]
- iteration = parameters[1]
- time_next = parameters[2]
- state = parameters[3]
- self.big_step.outputEventOM(Event("narrow_cast", None, [self, 'parent', Event("BigStep.Finished", None, [clock, iteration, time_next, state])]))
-
- def _Main_ModeSelector_Running_Realtime_1_exec(self, parameters):
- clock = parameters[0]
- iteration = parameters[1]
- time_next = parameters[2]
- state = parameters[3]
- self.big_step.outputEventOM(Event("narrow_cast", None, [self, 'parent', Event("BigStep.Finished", None, [clock, iteration, time_next, state])]))
-
- def _Main_ModeSelector_Running_BigStep_0_exec(self, parameters):
- clock = parameters[0]
- iteration = parameters[1]
- time_next = parameters[2]
- state = parameters[3]
- self.big_step.outputEventOM(Event("narrow_cast", None, [self, 'parent', Event("BigStep.Finished", None, [clock, iteration, time_next, state])]))
-
- def _Main_ModeSelector_Running_SmallStep_0_exec(self, parameters):
- current_component_idx = parameters[0]
- state = parameters[1]
- self.big_step.outputEventOM(Event("narrow_cast", None, [self, 'parent', Event("SmallStep.Finished", None, [current_component_idx, state])]))
-
- def _Main_ChildState_Initialized_0_exec(self, parameters):
- self.big_step.outputEventOM(Event("delete_instance", None, [self, 'child_simulator']))
-
- def _Main_Initializer_Waiting_0_exec(self, parameters):
- self.big_step.outputEventOM(Event("create_instance", None, [self, 'child_simulator', 'CBDSimulator_BigStep', self.cbd_controller, self.clock, self.iteration, self.time_next, self.delta, self.state]))
-
- def _Main_Initializer_Waiting_0_guard(self, parameters):
- return self.inState(["/Main/ModeSelector/Running"]) and self.inState(["/Main/ChildState/Uninitialized"]) and not self.endCondition()
-
- def _Main_Initializer_CreatingChildSimulator_0_exec(self, parameters):
- self.big_step.outputEventOM(Event("start_instance", None, [self, 'child_simulator']))
-
- def _Main_SimulationFlow_Started_0_exec(self, parameters):
- self.initialize()
-
- def _Main_SimulationFlow_InitializeDebugger_0_exec(self, parameters):
- self.initializeDebugger()
- self.big_step.outputEventOM(Event("narrow_cast", None, [self, 'parent', Event("Simulation.Initialized", None, [])]))
-
- def _Main_SimulationFlow_Waiting_0_guard(self, parameters):
- return self.inState(["/Main/ModeSelector/Running"])
-
- def _Main_SimulationFlow_SettleBeforeCheckTermination_1_exec(self, parameters):
- self.big_step.outputEventOM(Event("narrow_cast", None, [self, 'parent', Event("Simulation.Paused", None, [self.clock, self.state])]))
-
- def _Main_SimulationFlow_SettleBeforeCheckTermination_1_guard(self, parameters):
- return self.inState(["/Main/ModeSelector/Paused"])
-
- def _Main_SimulationFlow_CheckTermination_0_exec(self, parameters):
- self.big_step.outputEventOM(Event("narrow_cast", None, [self, 'child_simulator', Event("BigStep.Execute", None, [])]))
-
- def _Main_SimulationFlow_CheckTermination_0_guard(self, parameters):
- return (self.inState(["/Main/ModeSelector/Running/Continuous"]) or self.inState(["/Main/ModeSelector/Running/BigStep"])) and self.inState(["/Main/ChildState/Initialized"]) and not self.endCondition()
-
- def _Main_SimulationFlow_CheckTermination_1_exec(self, parameters):
- self.big_step.outputEventOM(Event("narrow_cast", None, [self, 'child_simulator', Event("SmallStep.Execute", None, [])]))
-
- def _Main_SimulationFlow_CheckTermination_1_guard(self, parameters):
- return self.inState(["/Main/ModeSelector/Running/SmallStep"]) and self.inState(["/Main/ChildState/Initialized"]) and not self.endCondition()
-
- def _Main_SimulationFlow_CheckTermination_2_guard(self, parameters):
- return self.inState(["/Main/ModeSelector/Running/Realtime"]) and self.inState(["/Main/ChildState/Initialized"]) and not self.endCondition()
-
- def _Main_SimulationFlow_CheckTermination_3_exec(self, parameters):
- # print 'simulation executed'
- self.finalize()
- self.raiseInternalEvent(Event("Simulation.Finished", None, []))
- self.big_step.outputEventOM(Event("narrow_cast", None, [self, 'parent', Event("Simulation.Finished", None, [self.clock, self.state])]))
-
- def _Main_SimulationFlow_CheckTermination_3_guard(self, parameters):
- return self.endCondition()
-
- def _Main_SimulationFlow_WaitingRealtime_0_exec(self, parameters):
- self.syncSimulatedTime()
-
- def _Main_SimulationFlow_WaitingRealtime_0_guard(self, parameters):
- return self.inState(["/Main/ModeSelector/Running"])
-
- def _Main_SimulationFlow_WaitingRealtime_1_exec(self, parameters):
- self.big_step.outputEventOM(Event("narrow_cast", None, [self, 'parent', Event("Simulation.Paused", None, [self.clock, self.state])]))
-
- def _Main_SimulationFlow_WaitingRealtime_1_guard(self, parameters):
- return self.inState(["/Main/ModeSelector/Paused"]) and (not ((self.waitTime() / 1000.0) <= self.sccd_yield()))
-
- def _Main_SimulationFlow_WaitingRealtime_2_exec(self, parameters):
- self.big_step.outputEventOM(Event("narrow_cast", None, [self, 'child_simulator', Event("BigStep.Execute", None, [])]))
-
- def _Main_SimulationFlow_WaitingRealtime_2_guard(self, parameters):
- return self.waitTime() / 1000.0 <= self.sccd_yield()
-
- def _Main_SimulationFlow_Executing_0_exec(self, parameters):
- clock = parameters[0]
- iteration = parameters[1]
- time_next = parameters[2]
- state = parameters[3]
- self.clock = clock
- self.iteration = iteration
- self.time_next = time_next
- self.state = state
-
- def _Main_GodEventManager_Listening_0_exec(self, parameters):
- block_name = parameters[0]
- new_val = parameters[1]
- result = self.godEvent(block_name, new_val)
- self.big_step.outputEventOM(Event("narrow_cast", None, [self, 'parent', Event("Simulation.GodEventResult", None, [result])]))
-
- def _Main_GodEventManager_Listening_0_guard(self, parameters):
- block_name = parameters[0]
- new_val = parameters[1]
- return self.inState(["/Main/ModeSelector/Paused"])
-
- 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.outputEventOM(Event("narrow_cast", None, [self, 'parent', Event("Breakpoint.AddResult", None, [result])]))
-
- def _Main_BreakpointManager_Listening_1_exec(self, parameters):
- name = parameters[0]
- result = self.delBreakpoint(name)
- self.big_step.outputEventOM(Event("narrow_cast", None, [self, 'parent', Event("Breakpoint.DelResult", None, [result])]))
-
- def _Main_BreakpointManager_Listening_2_exec(self, parameters):
- name = parameters[0]
- result = self.toggleBreakpoint(name)
- self.big_step.outputEventOM(Event("narrow_cast", None, [self, 'parent', Event("Breakpoint.ToggleResult", None, [result])]))
-
- def _Main_BreakpointManager_Listening_3_exec(self, parameters):
- self.big_step.outputEventOM(Event("narrow_cast", None, [self, 'parent', Event("Breakpoint.ListResult", None, [[bp.name for bp in self.breakpoints]])]))
-
- def initializeStatechart(self):
- # enter default state
- self.default_targets = self.states["/Main"].getEffectiveTargetStates()
- RuntimeClassBase.initializeStatechart(self)
- class CBDSimulator_BigStep(RuntimeClassBase):
- def __init__(self, controller, cbd_controller, clock, iteration, time_next, delta, state):
- 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()
-
- # call user defined constructor
- CBDSimulator_BigStep.user_defined_constructor(self, cbd_controller, clock, iteration, time_next, delta, state)
-
- def user_defined_constructor(self, cbd_controller, clock, iteration, time_next, delta, state):
- self.cbd_controller = cbd_controller
- self.clock = clock
- self.iteration = iteration
- self.time_next = time_next
- self.delta = delta
- self.state = state
-
- def user_defined_destructor(self):
- pass
-
-
- # user defined method
- def initialize(self):
- self.current_component_idx = 0
- self.dependency_graph = self.cbd_controller.createDepGraph(self.iteration)
- self.strong_component_list = self.cbd_controller.createStrongComponents(self.dependency_graph, self.iteration)
-
-
- # user defined method
- def initializeDebugger(self):
- pass
-
-
- # user defined method
- def endCondition(self):
- return self.current_component_idx >= len(self.strong_component_list)
-
-
- # user defined method
- def finalize(self):
- self.advanceTime()
-
-
- # user defined method
- def advanceTime(self):
- self.clock = self.time_next
- self.iteration = self.iteration + 1
- self.cbd_controller.advanceTimeStep()
- self.time_next = self.clock + self.delta
-
-
- # builds Statechart structure
- def build_statechart_structure(self):
-
- # state <root>
- self.states[""] = State(0, "", self)
-
- # state /Main
- self.states["/Main"] = ParallelState(1, "/Main", self)
-
- # state /Main/ModeSelector
- self.states["/Main/ModeSelector"] = State(2, "/Main/ModeSelector", self)
-
- # state /Main/ModeSelector/Paused
- self.states["/Main/ModeSelector/Paused"] = State(3, "/Main/ModeSelector/Paused", self)
-
- # state /Main/ModeSelector/Running
- self.states["/Main/ModeSelector/Running"] = State(4, "/Main/ModeSelector/Running", self)
-
- # state /Main/ModeSelector/Running/Continuous
- self.states["/Main/ModeSelector/Running/Continuous"] = State(5, "/Main/ModeSelector/Running/Continuous", self)
-
- # state /Main/ModeSelector/Running/SmallStep
- self.states["/Main/ModeSelector/Running/SmallStep"] = State(6, "/Main/ModeSelector/Running/SmallStep", self)
-
- # state /Main/ChildState
- self.states["/Main/ChildState"] = State(7, "/Main/ChildState", self)
-
- # state /Main/ChildState/Uninitialized
- self.states["/Main/ChildState/Uninitialized"] = State(8, "/Main/ChildState/Uninitialized", self)
-
- # state /Main/ChildState/Initialized
- self.states["/Main/ChildState/Initialized"] = State(9, "/Main/ChildState/Initialized", self)
-
- # state /Main/Initializer
- self.states["/Main/Initializer"] = State(10, "/Main/Initializer", self)
-
- # state /Main/Initializer/Waiting
- self.states["/Main/Initializer/Waiting"] = State(11, "/Main/Initializer/Waiting", self)
-
- # state /Main/Initializer/CreatingChildSimulator
- self.states["/Main/Initializer/CreatingChildSimulator"] = State(12, "/Main/Initializer/CreatingChildSimulator", self)
-
- # state /Main/Initializer/StartingChildSimulator
- self.states["/Main/Initializer/StartingChildSimulator"] = State(13, "/Main/Initializer/StartingChildSimulator", self)
-
- # state /Main/Initializer/Running
- self.states["/Main/Initializer/Running"] = State(14, "/Main/Initializer/Running", self)
-
- # state /Main/Initializer/SettleBeforeWaiting
- self.states["/Main/Initializer/SettleBeforeWaiting"] = State(15, "/Main/Initializer/SettleBeforeWaiting", self)
- self.states["/Main/Initializer/SettleBeforeWaiting"].setEnter(self._Main_Initializer_SettleBeforeWaiting_enter)
- self.states["/Main/Initializer/SettleBeforeWaiting"].setExit(self._Main_Initializer_SettleBeforeWaiting_exit)
-
- # state /Main/SimulationFlow
- self.states["/Main/SimulationFlow"] = State(16, "/Main/SimulationFlow", self)
-
- # state /Main/SimulationFlow/Started
- self.states["/Main/SimulationFlow/Started"] = State(17, "/Main/SimulationFlow/Started", self)
-
- # state /Main/SimulationFlow/Initialized
- self.states["/Main/SimulationFlow/Initialized"] = State(18, "/Main/SimulationFlow/Initialized", self)
-
- # state /Main/SimulationFlow/InitializeDebugger
- self.states["/Main/SimulationFlow/InitializeDebugger"] = State(19, "/Main/SimulationFlow/InitializeDebugger", self)
-
- # state /Main/SimulationFlow/Waiting
- self.states["/Main/SimulationFlow/Waiting"] = State(20, "/Main/SimulationFlow/Waiting", self)
-
- # state /Main/SimulationFlow/SettleBeforeCheckTermination
- self.states["/Main/SimulationFlow/SettleBeforeCheckTermination"] = State(21, "/Main/SimulationFlow/SettleBeforeCheckTermination", self)
- self.states["/Main/SimulationFlow/SettleBeforeCheckTermination"].setEnter(self._Main_SimulationFlow_SettleBeforeCheckTermination_enter)
- self.states["/Main/SimulationFlow/SettleBeforeCheckTermination"].setExit(self._Main_SimulationFlow_SettleBeforeCheckTermination_exit)
-
- # state /Main/SimulationFlow/CheckTermination
- self.states["/Main/SimulationFlow/CheckTermination"] = State(22, "/Main/SimulationFlow/CheckTermination", self)
-
- # state /Main/SimulationFlow/Executing
- self.states["/Main/SimulationFlow/Executing"] = State(23, "/Main/SimulationFlow/Executing", self)
-
- # state /Main/SimulationFlow/Stopped
- self.states["/Main/SimulationFlow/Stopped"] = State(24, "/Main/SimulationFlow/Stopped", self)
-
- # state /Stopped
- self.states["/Stopped"] = State(25, "/Stopped", self)
-
- # add children
- self.states[""].addChild(self.states["/Main"])
- self.states[""].addChild(self.states["/Stopped"])
- self.states["/Main"].addChild(self.states["/Main/ModeSelector"])
- self.states["/Main"].addChild(self.states["/Main/ChildState"])
- self.states["/Main"].addChild(self.states["/Main/Initializer"])
- self.states["/Main"].addChild(self.states["/Main/SimulationFlow"])
- self.states["/Main/ModeSelector"].addChild(self.states["/Main/ModeSelector/Paused"])
- self.states["/Main/ModeSelector"].addChild(self.states["/Main/ModeSelector/Running"])
- self.states["/Main/ModeSelector/Running"].addChild(self.states["/Main/ModeSelector/Running/Continuous"])
- self.states["/Main/ModeSelector/Running"].addChild(self.states["/Main/ModeSelector/Running/SmallStep"])
- self.states["/Main/ChildState"].addChild(self.states["/Main/ChildState/Uninitialized"])
- self.states["/Main/ChildState"].addChild(self.states["/Main/ChildState/Initialized"])
- self.states["/Main/Initializer"].addChild(self.states["/Main/Initializer/Waiting"])
- self.states["/Main/Initializer"].addChild(self.states["/Main/Initializer/CreatingChildSimulator"])
- self.states["/Main/Initializer"].addChild(self.states["/Main/Initializer/StartingChildSimulator"])
- self.states["/Main/Initializer"].addChild(self.states["/Main/Initializer/Running"])
- self.states["/Main/Initializer"].addChild(self.states["/Main/Initializer/SettleBeforeWaiting"])
- 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/Waiting"])
- self.states["/Main/SimulationFlow"].addChild(self.states["/Main/SimulationFlow/SettleBeforeCheckTermination"])
- self.states["/Main/SimulationFlow"].addChild(self.states["/Main/SimulationFlow/CheckTermination"])
- self.states["/Main/SimulationFlow"].addChild(self.states["/Main/SimulationFlow/Executing"])
- self.states["/Main/SimulationFlow"].addChild(self.states["/Main/SimulationFlow/Stopped"])
- self.states[""].fixTree()
- self.states[""].default_state = self.states["/Main"]
- self.states["/Main/ModeSelector"].default_state = self.states["/Main/ModeSelector/Paused"]
- self.states["/Main/ModeSelector/Running"].default_state = self.states["/Main/ModeSelector/Running/Continuous"]
- self.states["/Main/ChildState"].default_state = self.states["/Main/ChildState/Uninitialized"]
- self.states["/Main/Initializer"].default_state = self.states["/Main/Initializer/Waiting"]
- self.states["/Main/SimulationFlow"].default_state = self.states["/Main/SimulationFlow/Started"]
-
- # transition /Main/ModeSelector/Paused
- _Main_ModeSelector_Paused_0 = Transition(self, self.states["/Main/ModeSelector/Paused"], [self.states["/Main/ModeSelector/Running/SmallStep"]])
- _Main_ModeSelector_Paused_0.setAction(self._Main_ModeSelector_Paused_0_exec)
- _Main_ModeSelector_Paused_0.setTrigger(Event("SmallStep.Execute", None))
- self.states["/Main/ModeSelector/Paused"].addTransition(_Main_ModeSelector_Paused_0)
- _Main_ModeSelector_Paused_1 = Transition(self, self.states["/Main/ModeSelector/Paused"], [self.states["/Main/ModeSelector/Running/Continuous"]])
- _Main_ModeSelector_Paused_1.setTrigger(Event("BigStep.Execute", None))
- self.states["/Main/ModeSelector/Paused"].addTransition(_Main_ModeSelector_Paused_1)
-
- # transition /Main/ModeSelector/Running/SmallStep
- _Main_ModeSelector_Running_SmallStep_0 = Transition(self, self.states["/Main/ModeSelector/Running/SmallStep"], [self.states["/Main/ModeSelector/Paused"]])
- _Main_ModeSelector_Running_SmallStep_0.setAction(self._Main_ModeSelector_Running_SmallStep_0_exec)
- _Main_ModeSelector_Running_SmallStep_0.setTrigger(Event("SmallStep.Finished", None))
- self.states["/Main/ModeSelector/Running/SmallStep"].addTransition(_Main_ModeSelector_Running_SmallStep_0)
-
- # transition /Main/ChildState/Uninitialized
- _Main_ChildState_Uninitialized_0 = Transition(self, self.states["/Main/ChildState/Uninitialized"], [self.states["/Main/ChildState/Initialized"]])
- _Main_ChildState_Uninitialized_0.setTrigger(Event("SmallStep.Initialized", None))
- self.states["/Main/ChildState/Uninitialized"].addTransition(_Main_ChildState_Uninitialized_0)
-
- # transition /Main/ChildState/Initialized
- _Main_ChildState_Initialized_0 = Transition(self, self.states["/Main/ChildState/Initialized"], [self.states["/Main/ChildState/Uninitialized"]])
- _Main_ChildState_Initialized_0.setAction(self._Main_ChildState_Initialized_0_exec)
- _Main_ChildState_Initialized_0.setTrigger(Event("SmallStep.Finished", None))
- self.states["/Main/ChildState/Initialized"].addTransition(_Main_ChildState_Initialized_0)
-
- # transition /Main/Initializer/Waiting
- _Main_Initializer_Waiting_0 = Transition(self, self.states["/Main/Initializer/Waiting"], [self.states["/Main/Initializer/CreatingChildSimulator"]])
- _Main_Initializer_Waiting_0.setAction(self._Main_Initializer_Waiting_0_exec)
- _Main_Initializer_Waiting_0.setTrigger(None)
- _Main_Initializer_Waiting_0.setGuard(self._Main_Initializer_Waiting_0_guard)
- self.states["/Main/Initializer/Waiting"].addTransition(_Main_Initializer_Waiting_0)
-
- # transition /Main/Initializer/CreatingChildSimulator
- _Main_Initializer_CreatingChildSimulator_0 = Transition(self, self.states["/Main/Initializer/CreatingChildSimulator"], [self.states["/Main/Initializer/StartingChildSimulator"]])
- _Main_Initializer_CreatingChildSimulator_0.setAction(self._Main_Initializer_CreatingChildSimulator_0_exec)
- _Main_Initializer_CreatingChildSimulator_0.setTrigger(Event("instance_created", None))
- self.states["/Main/Initializer/CreatingChildSimulator"].addTransition(_Main_Initializer_CreatingChildSimulator_0)
-
- # transition /Main/Initializer/StartingChildSimulator
- _Main_Initializer_StartingChildSimulator_0 = Transition(self, self.states["/Main/Initializer/StartingChildSimulator"], [self.states["/Main/Initializer/Running"]])
- _Main_Initializer_StartingChildSimulator_0.setTrigger(Event("SmallStep.Initialized", None))
- self.states["/Main/Initializer/StartingChildSimulator"].addTransition(_Main_Initializer_StartingChildSimulator_0)
-
- # transition /Main/Initializer/Running
- _Main_Initializer_Running_0 = Transition(self, self.states["/Main/Initializer/Running"], [self.states["/Main/Initializer/SettleBeforeWaiting"]])
- _Main_Initializer_Running_0.setTrigger(Event("SmallStep.Finished", None))
- self.states["/Main/Initializer/Running"].addTransition(_Main_Initializer_Running_0)
-
- # transition /Main/Initializer/SettleBeforeWaiting
- _Main_Initializer_SettleBeforeWaiting_0 = Transition(self, self.states["/Main/Initializer/SettleBeforeWaiting"], [self.states["/Main/Initializer/Waiting"]])
- _Main_Initializer_SettleBeforeWaiting_0.setTrigger(Event("_0after"))
- self.states["/Main/Initializer/SettleBeforeWaiting"].addTransition(_Main_Initializer_SettleBeforeWaiting_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/Waiting"]])
- _Main_SimulationFlow_InitializeDebugger_0.setAction(self._Main_SimulationFlow_InitializeDebugger_0_exec)
- _Main_SimulationFlow_InitializeDebugger_0.setTrigger(None)
- self.states["/Main/SimulationFlow/InitializeDebugger"].addTransition(_Main_SimulationFlow_InitializeDebugger_0)
-
- # transition /Main/SimulationFlow/Waiting
- _Main_SimulationFlow_Waiting_0 = Transition(self, self.states["/Main/SimulationFlow/Waiting"], [self.states["/Main/SimulationFlow/CheckTermination"]])
- _Main_SimulationFlow_Waiting_0.setTrigger(None)
- _Main_SimulationFlow_Waiting_0.setGuard(self._Main_SimulationFlow_Waiting_0_guard)
- self.states["/Main/SimulationFlow/Waiting"].addTransition(_Main_SimulationFlow_Waiting_0)
-
- # transition /Main/SimulationFlow/SettleBeforeCheckTermination
- _Main_SimulationFlow_SettleBeforeCheckTermination_0 = Transition(self, self.states["/Main/SimulationFlow/SettleBeforeCheckTermination"], [self.states["/Main/SimulationFlow/CheckTermination"]])
- _Main_SimulationFlow_SettleBeforeCheckTermination_0.setTrigger(Event("_1after"))
- self.states["/Main/SimulationFlow/SettleBeforeCheckTermination"].addTransition(_Main_SimulationFlow_SettleBeforeCheckTermination_0)
-
- # transition /Main/SimulationFlow/CheckTermination
- _Main_SimulationFlow_CheckTermination_0 = Transition(self, self.states["/Main/SimulationFlow/CheckTermination"], [self.states["/Main/SimulationFlow/Executing"]])
- _Main_SimulationFlow_CheckTermination_0.setAction(self._Main_SimulationFlow_CheckTermination_0_exec)
- _Main_SimulationFlow_CheckTermination_0.setTrigger(None)
- _Main_SimulationFlow_CheckTermination_0.setGuard(self._Main_SimulationFlow_CheckTermination_0_guard)
- self.states["/Main/SimulationFlow/CheckTermination"].addTransition(_Main_SimulationFlow_CheckTermination_0)
- _Main_SimulationFlow_CheckTermination_1 = Transition(self, self.states["/Main/SimulationFlow/CheckTermination"], [self.states["/Main/SimulationFlow/Stopped"]])
- _Main_SimulationFlow_CheckTermination_1.setAction(self._Main_SimulationFlow_CheckTermination_1_exec)
- _Main_SimulationFlow_CheckTermination_1.setTrigger(None)
- _Main_SimulationFlow_CheckTermination_1.setGuard(self._Main_SimulationFlow_CheckTermination_1_guard)
- self.states["/Main/SimulationFlow/CheckTermination"].addTransition(_Main_SimulationFlow_CheckTermination_1)
-
- # transition /Main/SimulationFlow/Executing
- _Main_SimulationFlow_Executing_0 = Transition(self, self.states["/Main/SimulationFlow/Executing"], [self.states["/Main/SimulationFlow/SettleBeforeCheckTermination"]])
- _Main_SimulationFlow_Executing_0.setAction(self._Main_SimulationFlow_Executing_0_exec)
- _Main_SimulationFlow_Executing_0.setTrigger(Event("SmallStep.Finished", None))
- self.states["/Main/SimulationFlow/Executing"].addTransition(_Main_SimulationFlow_Executing_0)
-
- # transition /Main/ModeSelector/Running
- _Main_ModeSelector_Running_0 = Transition(self, self.states["/Main/ModeSelector/Running"], [self.states["/Main/ModeSelector/Paused"]])
- _Main_ModeSelector_Running_0.setTrigger(Event("BigStep.Finished", None))
- self.states["/Main/ModeSelector/Running"].addTransition(_Main_ModeSelector_Running_0)
-
- def _Main_Initializer_SettleBeforeWaiting_enter(self):
- self.addTimer(0, self.sccd_yield())
-
- def _Main_Initializer_SettleBeforeWaiting_exit(self):
- self.removeTimer(0)
-
- def _Main_SimulationFlow_SettleBeforeCheckTermination_enter(self):
- self.addTimer(1, self.sccd_yield())
-
- def _Main_SimulationFlow_SettleBeforeCheckTermination_exit(self):
- self.removeTimer(1)
-
- def _Main_ModeSelector_Paused_0_exec(self, parameters):
- self.big_step.outputEventOM(Event("narrow_cast", None, [self, 'child_simulator', Event("SmallStep.Execute", None, [])]))
-
- def _Main_ModeSelector_Running_SmallStep_0_exec(self, parameters):
- new_current_component_idx = parameters[0]
- new_state = parameters[1]
- self.big_step.outputEventOM(Event("narrow_cast", None, [self, 'parent', Event("SmallStep.Finished", None, [new_current_component_idx, new_state])]))
-
- def _Main_ChildState_Initialized_0_exec(self, parameters):
- self.big_step.outputEventOM(Event("delete_instance", None, [self, 'child_simulator']))
-
- def _Main_Initializer_Waiting_0_exec(self, parameters):
- self.big_step.outputEventOM(Event("create_instance", None, [self, 'child_simulator', 'CBDSimulator_SmallStep', self.cbd_controller, self.strong_component_list, self.current_component_idx, self.dependency_graph, self.iteration, self.state]))
-
- def _Main_Initializer_Waiting_0_guard(self, parameters):
- return self.inState(["/Main/ModeSelector/Running"]) and self.inState(["/Main/ChildState/Uninitialized"]) and not self.endCondition()
-
- def _Main_Initializer_CreatingChildSimulator_0_exec(self, parameters):
- self.big_step.outputEventOM(Event("start_instance", None, [self, 'child_simulator']))
-
- def _Main_SimulationFlow_Started_0_exec(self, parameters):
- self.initialize()
-
- def _Main_SimulationFlow_InitializeDebugger_0_exec(self, parameters):
- self.initializeDebugger()
- self.big_step.outputEventOM(Event("narrow_cast", None, [self, 'parent', Event("BigStep.Initialized", None, [])]))
-
- def _Main_SimulationFlow_Waiting_0_guard(self, parameters):
- return self.inState(["/Main/ModeSelector/Running"])
-
- def _Main_SimulationFlow_CheckTermination_0_exec(self, parameters):
- self.big_step.outputEventOM(Event("narrow_cast", None, [self, 'child_simulator', Event("SmallStep.Execute", None, [])]))
-
- def _Main_SimulationFlow_CheckTermination_0_guard(self, parameters):
- return (self.inState(["/Main/ModeSelector/Running/Continuous"]) or self.inState(["/Main/ModeSelector/Running/SmallStep"])) and self.inState(["/Main/ChildState/Initialized"]) and not self.endCondition()
-
- def _Main_SimulationFlow_CheckTermination_1_exec(self, parameters):
- # print '>>> big step executed <<<'
- self.finalize()
- self.raiseInternalEvent(Event("BigStep.Finished", None, []))
- self.big_step.outputEventOM(Event("narrow_cast", None, [self, 'parent', Event("BigStep.Finished", None, [self.clock, self.iteration, self.time_next, self.state])]))
-
- def _Main_SimulationFlow_CheckTermination_1_guard(self, parameters):
- return self.endCondition()
-
- def _Main_SimulationFlow_Executing_0_exec(self, parameters):
- new_current_component_idx = parameters[0]
- new_state = parameters[1]
- self.current_component_idx = new_current_component_idx
- self.state = new_state
-
- def initializeStatechart(self):
- # enter default state
- self.default_targets = self.states["/Main"].getEffectiveTargetStates()
- RuntimeClassBase.initializeStatechart(self)
- class CBDSimulator_SmallStep(RuntimeClassBase):
- def __init__(self, controller, cbd_controller, strong_component_list, current_component_idx, dependency_graph, iteration, state):
- 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()
-
- # call user defined constructor
- CBDSimulator_SmallStep.user_defined_constructor(self, cbd_controller, strong_component_list, current_component_idx, dependency_graph, iteration, state)
-
- def user_defined_constructor(self, cbd_controller, strong_component_list, current_component_idx, dependency_graph, iteration, state):
- self.cbd_controller = cbd_controller
- self.strong_component_list = strong_component_list
- self.current_component_idx = current_component_idx
- self.dependency_graph = dependency_graph
- self.iteration = iteration
- self.state = state
-
- def user_defined_destructor(self):
- pass
-
-
- # user defined method
- def initialize(self):
- self.small_step_executed = False
-
-
- # user defined method
- def initializeDebugger(self):
- pass
-
-
- # user defined method
- def endCondition(self):
- return self.small_step_executed
-
-
- # user defined method
- def finalize(self):
- self.current_component_idx += 1
-
-
- # builds Statechart structure
- def build_statechart_structure(self):
-
- # state <root>
- self.states[""] = State(0, "", self)
-
- # state /Main
- self.states["/Main"] = ParallelState(1, "/Main", self)
-
- # state /Main/ModeSelector
- self.states["/Main/ModeSelector"] = State(2, "/Main/ModeSelector", self)
-
- # state /Main/ModeSelector/Paused
- self.states["/Main/ModeSelector/Paused"] = State(3, "/Main/ModeSelector/Paused", self)
-
- # state /Main/ModeSelector/Running
- self.states["/Main/ModeSelector/Running"] = State(4, "/Main/ModeSelector/Running", self)
-
- # state /Main/ModeSelector/Running/Continuous
- self.states["/Main/ModeSelector/Running/Continuous"] = State(5, "/Main/ModeSelector/Running/Continuous", self)
-
- # state /Main/ChildState
- self.states["/Main/ChildState"] = State(6, "/Main/ChildState", self)
-
- # state /Main/ChildState/Uninitialized
- self.states["/Main/ChildState/Uninitialized"] = State(7, "/Main/ChildState/Uninitialized", self)
-
- # state /Main/ChildState/Initialized
- self.states["/Main/ChildState/Initialized"] = State(8, "/Main/ChildState/Initialized", self)
-
- # state /Main/Initializer
- self.states["/Main/Initializer"] = State(9, "/Main/Initializer", self)
-
- # state /Main/Initializer/Waiting
- self.states["/Main/Initializer/Waiting"] = State(10, "/Main/Initializer/Waiting", self)
-
- # state /Main/Initializer/CreatingChildSimulator
- self.states["/Main/Initializer/CreatingChildSimulator"] = State(11, "/Main/Initializer/CreatingChildSimulator", self)
-
- # state /Main/Initializer/StartingChildSimulator
- self.states["/Main/Initializer/StartingChildSimulator"] = State(12, "/Main/Initializer/StartingChildSimulator", self)
-
- # state /Main/Initializer/Running
- self.states["/Main/Initializer/Running"] = State(13, "/Main/Initializer/Running", self)
-
- # state /Main/Initializer/SettleBeforeWaiting
- self.states["/Main/Initializer/SettleBeforeWaiting"] = State(14, "/Main/Initializer/SettleBeforeWaiting", self)
- self.states["/Main/Initializer/SettleBeforeWaiting"].setEnter(self._Main_Initializer_SettleBeforeWaiting_enter)
- self.states["/Main/Initializer/SettleBeforeWaiting"].setExit(self._Main_Initializer_SettleBeforeWaiting_exit)
-
- # state /Main/SimulationFlow
- self.states["/Main/SimulationFlow"] = State(15, "/Main/SimulationFlow", self)
-
- # state /Main/SimulationFlow/Started
- self.states["/Main/SimulationFlow/Started"] = State(16, "/Main/SimulationFlow/Started", self)
-
- # state /Main/SimulationFlow/Initialized
- self.states["/Main/SimulationFlow/Initialized"] = State(17, "/Main/SimulationFlow/Initialized", self)
-
- # state /Main/SimulationFlow/InitializeDebugger
- self.states["/Main/SimulationFlow/InitializeDebugger"] = State(18, "/Main/SimulationFlow/InitializeDebugger", self)
-
- # state /Main/SimulationFlow/Waiting
- self.states["/Main/SimulationFlow/Waiting"] = State(19, "/Main/SimulationFlow/Waiting", self)
-
- # state /Main/SimulationFlow/SettleBeforeCheckTermination
- self.states["/Main/SimulationFlow/SettleBeforeCheckTermination"] = State(20, "/Main/SimulationFlow/SettleBeforeCheckTermination", self)
- self.states["/Main/SimulationFlow/SettleBeforeCheckTermination"].setEnter(self._Main_SimulationFlow_SettleBeforeCheckTermination_enter)
- self.states["/Main/SimulationFlow/SettleBeforeCheckTermination"].setExit(self._Main_SimulationFlow_SettleBeforeCheckTermination_exit)
-
- # state /Main/SimulationFlow/CheckTermination
- self.states["/Main/SimulationFlow/CheckTermination"] = State(21, "/Main/SimulationFlow/CheckTermination", self)
-
- # state /Main/SimulationFlow/Executing
- self.states["/Main/SimulationFlow/Executing"] = State(22, "/Main/SimulationFlow/Executing", self)
-
- # state /Main/SimulationFlow/Stopped
- self.states["/Main/SimulationFlow/Stopped"] = State(23, "/Main/SimulationFlow/Stopped", self)
-
- # state /Stopped
- self.states["/Stopped"] = State(24, "/Stopped", self)
-
- # add children
- self.states[""].addChild(self.states["/Main"])
- self.states[""].addChild(self.states["/Stopped"])
- self.states["/Main"].addChild(self.states["/Main/ModeSelector"])
- self.states["/Main"].addChild(self.states["/Main/ChildState"])
- self.states["/Main"].addChild(self.states["/Main/Initializer"])
- self.states["/Main"].addChild(self.states["/Main/SimulationFlow"])
- self.states["/Main/ModeSelector"].addChild(self.states["/Main/ModeSelector/Paused"])
- self.states["/Main/ModeSelector"].addChild(self.states["/Main/ModeSelector/Running"])
- self.states["/Main/ModeSelector/Running"].addChild(self.states["/Main/ModeSelector/Running/Continuous"])
- self.states["/Main/ChildState"].addChild(self.states["/Main/ChildState/Uninitialized"])
- self.states["/Main/ChildState"].addChild(self.states["/Main/ChildState/Initialized"])
- self.states["/Main/Initializer"].addChild(self.states["/Main/Initializer/Waiting"])
- self.states["/Main/Initializer"].addChild(self.states["/Main/Initializer/CreatingChildSimulator"])
- self.states["/Main/Initializer"].addChild(self.states["/Main/Initializer/StartingChildSimulator"])
- self.states["/Main/Initializer"].addChild(self.states["/Main/Initializer/Running"])
- self.states["/Main/Initializer"].addChild(self.states["/Main/Initializer/SettleBeforeWaiting"])
- 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/Waiting"])
- self.states["/Main/SimulationFlow"].addChild(self.states["/Main/SimulationFlow/SettleBeforeCheckTermination"])
- self.states["/Main/SimulationFlow"].addChild(self.states["/Main/SimulationFlow/CheckTermination"])
- self.states["/Main/SimulationFlow"].addChild(self.states["/Main/SimulationFlow/Executing"])
- self.states["/Main/SimulationFlow"].addChild(self.states["/Main/SimulationFlow/Stopped"])
- self.states[""].fixTree()
- self.states[""].default_state = self.states["/Main"]
- self.states["/Main/ModeSelector"].default_state = self.states["/Main/ModeSelector/Paused"]
- self.states["/Main/ModeSelector/Running"].default_state = self.states["/Main/ModeSelector/Running/Continuous"]
- self.states["/Main/ChildState"].default_state = self.states["/Main/ChildState/Uninitialized"]
- self.states["/Main/Initializer"].default_state = self.states["/Main/Initializer/Waiting"]
- self.states["/Main/SimulationFlow"].default_state = self.states["/Main/SimulationFlow/Started"]
-
- # transition /Main/ModeSelector/Paused
- _Main_ModeSelector_Paused_0 = Transition(self, self.states["/Main/ModeSelector/Paused"], [self.states["/Main/ModeSelector/Running/Continuous"]])
- _Main_ModeSelector_Paused_0.setTrigger(Event("SmallStep.Execute", None))
- self.states["/Main/ModeSelector/Paused"].addTransition(_Main_ModeSelector_Paused_0)
-
- # transition /Main/ChildState/Uninitialized
- _Main_ChildState_Uninitialized_0 = Transition(self, self.states["/Main/ChildState/Uninitialized"], [self.states["/Main/ChildState/Initialized"]])
- _Main_ChildState_Uninitialized_0.setTrigger(Event("Block.Initialized", None))
- self.states["/Main/ChildState/Uninitialized"].addTransition(_Main_ChildState_Uninitialized_0)
-
- # transition /Main/ChildState/Initialized
- _Main_ChildState_Initialized_0 = Transition(self, self.states["/Main/ChildState/Initialized"], [self.states["/Main/ChildState/Uninitialized"]])
- _Main_ChildState_Initialized_0.setAction(self._Main_ChildState_Initialized_0_exec)
- _Main_ChildState_Initialized_0.setTrigger(Event("Block.Finished", None))
- self.states["/Main/ChildState/Initialized"].addTransition(_Main_ChildState_Initialized_0)
-
- # transition /Main/Initializer/Waiting
- _Main_Initializer_Waiting_0 = Transition(self, self.states["/Main/Initializer/Waiting"], [self.states["/Main/Initializer/CreatingChildSimulator"]])
- _Main_Initializer_Waiting_0.setAction(self._Main_Initializer_Waiting_0_exec)
- _Main_Initializer_Waiting_0.setTrigger(None)
- _Main_Initializer_Waiting_0.setGuard(self._Main_Initializer_Waiting_0_guard)
- self.states["/Main/Initializer/Waiting"].addTransition(_Main_Initializer_Waiting_0)
-
- # transition /Main/Initializer/CreatingChildSimulator
- _Main_Initializer_CreatingChildSimulator_0 = Transition(self, self.states["/Main/Initializer/CreatingChildSimulator"], [self.states["/Main/Initializer/StartingChildSimulator"]])
- _Main_Initializer_CreatingChildSimulator_0.setAction(self._Main_Initializer_CreatingChildSimulator_0_exec)
- _Main_Initializer_CreatingChildSimulator_0.setTrigger(Event("instance_created", None))
- self.states["/Main/Initializer/CreatingChildSimulator"].addTransition(_Main_Initializer_CreatingChildSimulator_0)
-
- # transition /Main/Initializer/StartingChildSimulator
- _Main_Initializer_StartingChildSimulator_0 = Transition(self, self.states["/Main/Initializer/StartingChildSimulator"], [self.states["/Main/Initializer/Running"]])
- _Main_Initializer_StartingChildSimulator_0.setTrigger(Event("Block.Initialized", None))
- self.states["/Main/Initializer/StartingChildSimulator"].addTransition(_Main_Initializer_StartingChildSimulator_0)
-
- # transition /Main/Initializer/Running
- _Main_Initializer_Running_0 = Transition(self, self.states["/Main/Initializer/Running"], [self.states["/Main/Initializer/SettleBeforeWaiting"]])
- _Main_Initializer_Running_0.setTrigger(Event("Block.Finished", None))
- self.states["/Main/Initializer/Running"].addTransition(_Main_Initializer_Running_0)
-
- # transition /Main/Initializer/SettleBeforeWaiting
- _Main_Initializer_SettleBeforeWaiting_0 = Transition(self, self.states["/Main/Initializer/SettleBeforeWaiting"], [self.states["/Main/Initializer/Waiting"]])
- _Main_Initializer_SettleBeforeWaiting_0.setTrigger(Event("_0after"))
- self.states["/Main/Initializer/SettleBeforeWaiting"].addTransition(_Main_Initializer_SettleBeforeWaiting_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/Waiting"]])
- _Main_SimulationFlow_InitializeDebugger_0.setAction(self._Main_SimulationFlow_InitializeDebugger_0_exec)
- _Main_SimulationFlow_InitializeDebugger_0.setTrigger(None)
- self.states["/Main/SimulationFlow/InitializeDebugger"].addTransition(_Main_SimulationFlow_InitializeDebugger_0)
-
- # transition /Main/SimulationFlow/Waiting
- _Main_SimulationFlow_Waiting_0 = Transition(self, self.states["/Main/SimulationFlow/Waiting"], [self.states["/Main/SimulationFlow/CheckTermination"]])
- _Main_SimulationFlow_Waiting_0.setTrigger(None)
- _Main_SimulationFlow_Waiting_0.setGuard(self._Main_SimulationFlow_Waiting_0_guard)
- self.states["/Main/SimulationFlow/Waiting"].addTransition(_Main_SimulationFlow_Waiting_0)
-
- # transition /Main/SimulationFlow/SettleBeforeCheckTermination
- _Main_SimulationFlow_SettleBeforeCheckTermination_0 = Transition(self, self.states["/Main/SimulationFlow/SettleBeforeCheckTermination"], [self.states["/Main/SimulationFlow/CheckTermination"]])
- _Main_SimulationFlow_SettleBeforeCheckTermination_0.setTrigger(Event("_1after"))
- self.states["/Main/SimulationFlow/SettleBeforeCheckTermination"].addTransition(_Main_SimulationFlow_SettleBeforeCheckTermination_0)
-
- # transition /Main/SimulationFlow/CheckTermination
- _Main_SimulationFlow_CheckTermination_0 = Transition(self, self.states["/Main/SimulationFlow/CheckTermination"], [self.states["/Main/SimulationFlow/Executing"]])
- _Main_SimulationFlow_CheckTermination_0.setAction(self._Main_SimulationFlow_CheckTermination_0_exec)
- _Main_SimulationFlow_CheckTermination_0.setTrigger(None)
- _Main_SimulationFlow_CheckTermination_0.setGuard(self._Main_SimulationFlow_CheckTermination_0_guard)
- self.states["/Main/SimulationFlow/CheckTermination"].addTransition(_Main_SimulationFlow_CheckTermination_0)
- _Main_SimulationFlow_CheckTermination_1 = Transition(self, self.states["/Main/SimulationFlow/CheckTermination"], [self.states["/Main/SimulationFlow/Stopped"]])
- _Main_SimulationFlow_CheckTermination_1.setAction(self._Main_SimulationFlow_CheckTermination_1_exec)
- _Main_SimulationFlow_CheckTermination_1.setTrigger(None)
- _Main_SimulationFlow_CheckTermination_1.setGuard(self._Main_SimulationFlow_CheckTermination_1_guard)
- self.states["/Main/SimulationFlow/CheckTermination"].addTransition(_Main_SimulationFlow_CheckTermination_1)
-
- # transition /Main/SimulationFlow/Executing
- _Main_SimulationFlow_Executing_0 = Transition(self, self.states["/Main/SimulationFlow/Executing"], [self.states["/Main/SimulationFlow/SettleBeforeCheckTermination"]])
- _Main_SimulationFlow_Executing_0.setAction(self._Main_SimulationFlow_Executing_0_exec)
- _Main_SimulationFlow_Executing_0.setTrigger(Event("Block.Finished", None))
- self.states["/Main/SimulationFlow/Executing"].addTransition(_Main_SimulationFlow_Executing_0)
-
- # transition /Main/ModeSelector/Running
- _Main_ModeSelector_Running_0 = Transition(self, self.states["/Main/ModeSelector/Running"], [self.states["/Main/ModeSelector/Paused"]])
- _Main_ModeSelector_Running_0.setTrigger(Event("SmallStep.Finished", None))
- self.states["/Main/ModeSelector/Running"].addTransition(_Main_ModeSelector_Running_0)
-
- def _Main_Initializer_SettleBeforeWaiting_enter(self):
- self.addTimer(0, self.sccd_yield())
-
- def _Main_Initializer_SettleBeforeWaiting_exit(self):
- self.removeTimer(0)
-
- def _Main_SimulationFlow_SettleBeforeCheckTermination_enter(self):
- self.addTimer(1, self.sccd_yield())
-
- def _Main_SimulationFlow_SettleBeforeCheckTermination_exit(self):
- self.removeTimer(1)
-
- def _Main_ChildState_Initialized_0_exec(self, parameters):
- self.big_step.outputEventOM(Event("delete_instance", None, [self, 'child_simulator']))
-
- def _Main_Initializer_Waiting_0_exec(self, parameters):
- self.big_step.outputEventOM(Event("create_instance", None, [self, 'child_simulator', 'CBDSimulator_Block', self.cbd_controller, self.strong_component_list[self.current_component_idx], self.cbd_controller.componentIsCycle(self.strong_component_list[self.current_component_idx], self.dependency_graph), self.iteration]))
-
- def _Main_Initializer_Waiting_0_guard(self, parameters):
- return self.inState(["/Main/ModeSelector/Running"]) and self.inState(["/Main/ChildState/Uninitialized"]) and not self.endCondition()
-
- def _Main_Initializer_CreatingChildSimulator_0_exec(self, parameters):
- self.big_step.outputEventOM(Event("start_instance", None, [self, 'child_simulator']))
-
- def _Main_SimulationFlow_Started_0_exec(self, parameters):
- self.initialize()
-
- def _Main_SimulationFlow_InitializeDebugger_0_exec(self, parameters):
- self.initializeDebugger()
- self.big_step.outputEventOM(Event("narrow_cast", None, [self, 'parent', Event("SmallStep.Initialized", None, [])]))
-
- def _Main_SimulationFlow_Waiting_0_guard(self, parameters):
- return self.inState(["/Main/ModeSelector/Running"])
-
- def _Main_SimulationFlow_CheckTermination_0_exec(self, parameters):
- self.big_step.outputEventOM(Event("narrow_cast", None, [self, 'child_simulator', Event("Block.Execute", None, [])]))
-
- def _Main_SimulationFlow_CheckTermination_0_guard(self, parameters):
- return self.inState(["/Main/ModeSelector/Running/Continuous"]) and self.inState(["/Main/ChildState/Initialized"]) and not self.endCondition()
-
- def _Main_SimulationFlow_CheckTermination_1_exec(self, parameters):
- # print '>>> small step executed <<<'
- self.finalize()
- self.raiseInternalEvent(Event("SmallStep.Finished", None, []))
- self.big_step.outputEventOM(Event("narrow_cast", None, [self, 'parent', Event("SmallStep.Finished", None, [self.current_component_idx, self.state])]))
-
- def _Main_SimulationFlow_CheckTermination_1_guard(self, parameters):
- return self.endCondition()
-
- def _Main_SimulationFlow_Executing_0_exec(self, parameters):
- new_state = parameters[0]
- self.small_step_executed = True
- self.state = new_state
-
- def initializeStatechart(self):
- # enter default state
- self.default_targets = self.states["/Main"].getEffectiveTargetStates()
- RuntimeClassBase.initializeStatechart(self)
- class CBDSimulator_Block(RuntimeClassBase):
- def __init__(self, controller, cbd_controller, block_to_compute, is_cycle, iteration):
- 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()
-
- # call user defined constructor
- CBDSimulator_Block.user_defined_constructor(self, cbd_controller, block_to_compute, is_cycle, iteration)
-
- def user_defined_constructor(self, cbd_controller, block_to_compute, is_cycle, iteration):
- self.cbd_controller = cbd_controller
- self.block_to_compute = block_to_compute
- self.is_cycle = is_cycle
- self.iteration = iteration
-
- def user_defined_destructor(self):
- pass
-
-
- # user defined method
- def computeBlock(self):
- if self.is_cycle:
- self.cbd_controller.computeNextAlgebraicLoop(self.block_to_compute, self.iteration)
- else:
- self.cbd_controller.computeNextBlock(self.block_to_compute, self.iteration)
-
-
- # builds Statechart structure
- def build_statechart_structure(self):
-
- # state <root>
- self.states[""] = State(0, "", self)
-
- # state /Started
- self.states["/Started"] = State(1, "/Started", self)
-
- # state /Waiting
- self.states["/Waiting"] = State(2, "/Waiting", self)
-
- # state /Stopped
- self.states["/Stopped"] = State(3, "/Stopped", self)
-
- # add children
- self.states[""].addChild(self.states["/Started"])
- self.states[""].addChild(self.states["/Waiting"])
- self.states[""].addChild(self.states["/Stopped"])
- self.states[""].fixTree()
- self.states[""].default_state = self.states["/Started"]
-
- # transition /Started
- _Started_0 = Transition(self, self.states["/Started"], [self.states["/Waiting"]])
- _Started_0.setAction(self._Started_0_exec)
- _Started_0.setTrigger(None)
- self.states["/Started"].addTransition(_Started_0)
-
- # transition /Waiting
- _Waiting_0 = Transition(self, self.states["/Waiting"], [self.states["/Stopped"]])
- _Waiting_0.setAction(self._Waiting_0_exec)
- _Waiting_0.setTrigger(Event("Block.Execute", None))
- self.states["/Waiting"].addTransition(_Waiting_0)
-
- def _Started_0_exec(self, parameters):
- self.big_step.outputEventOM(Event("narrow_cast", None, [self, 'parent', Event("Block.Initialized", None, [])]))
-
- def _Waiting_0_exec(self, parameters):
- self.computeBlock()
- self.big_step.outputEventOM(Event("narrow_cast", None, [self, 'parent', Event("Block.Finished", None, [{b.getBlockName(): b.getSignal() for b in self.cbd_controller.model.getBlocks()}])]))
-
- def initializeStatechart(self):
- # enter default state
- self.default_targets = self.states["/Started"].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 == "CBDSimulator_Coordinator":
- instance = CBDSimulator_Coordinator(self.controller, construct_params[0], construct_params[1])
- instance.associations = {}
- instance.associations["child_simulator"] = Association("CBDSimulator_Simulation", 0, 1)
- elif class_name == "CBDSimulator_Simulation":
- instance = CBDSimulator_Simulation(self.controller, construct_params[0], construct_params[1])
- instance.associations = {}
- instance.associations["parent"] = Association("CBDSimulator_Coordinator", 1, 1)
- instance.associations["child_simulator"] = Association("CBDSimulator_BigStep", 0, 1)
- elif class_name == "CBDSimulator_BigStep":
- instance = CBDSimulator_BigStep(self.controller, construct_params[0], construct_params[1], construct_params[2], construct_params[3], construct_params[4], construct_params[5])
- instance.associations = {}
- instance.associations["parent"] = Association("CBDSimulator_Simulation", 1, 1)
- instance.associations["child_simulator"] = Association("CBDSimulator_SmallStep", 0, 1)
- elif class_name == "CBDSimulator_SmallStep":
- instance = CBDSimulator_SmallStep(self.controller, construct_params[0], construct_params[1], construct_params[2], construct_params[3], construct_params[4], construct_params[5])
- instance.associations = {}
- instance.associations["parent"] = Association("CBDSimulator_BigStep", 1, 1)
- instance.associations["child_simulator"] = Association("CBDSimulator_Block", 0, 1)
- elif class_name == "CBDSimulator_Block":
- instance = CBDSimulator_Block(self.controller, construct_params[0], construct_params[1], construct_params[2], construct_params[3])
- instance.associations = {}
- instance.associations["parent"] = Association("CBDSimulator_SmallStep", 1, 1)
- else:
- raise Exception("Cannot instantiate class " + class_name)
- return instance
- class Controller(ThreadsControllerBase):
- def __init__(self, options, model, 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("CBDSimulator_Coordinator", [options, model])
|