sccd.py 93 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930
  1. """
  2. Generated by Statechart compiler by Glenn De Jonghe and Joeri Exelmans
  3. Date: Thu Mar 17 11:16:46 2016
  4. Model author: Simon Van Mierlo/Yentl Van Tendeloo
  5. Model name: Dynamic Structure DEVS simulator
  6. Model description:
  7. A restricted PythonPDEVS simulator modelled in SCCD for classic, dynamic structure DEVS models.
  8. """
  9. from python_runtime.statecharts_core import *
  10. import cPickle as pickle
  11. import time
  12. import copy
  13. # We basically just interface with the basesimulator
  14. from scheduler import Scheduler
  15. from DEVS import directConnect, CoupledDEVS, AtomicDEVS, RootDEVS
  16. from classicDEVSWrapper import ClassicDEVSWrapper
  17. from tracer import trace
  18. class Breakpoint(object):
  19. def __init__(self, breakpoint_id, function, enabled, disable_on_trigger):
  20. self.id = breakpoint_id
  21. self.function = function
  22. self.enabled = enabled
  23. self.disable_on_trigger = disable_on_trigger
  24. # package "Dynamic Structure DEVS simulator"
  25. class SCCDSimulator(RuntimeClassBase):
  26. def __init__(self, controller, model):
  27. RuntimeClassBase.__init__(self, controller)
  28. self.semantics.big_step_maximality = StatechartSemantics.TakeMany
  29. self.semantics.internal_event_lifeline = StatechartSemantics.Queue
  30. self.semantics.input_event_lifeline = StatechartSemantics.FirstComboStep
  31. self.semantics.priority = StatechartSemantics.SourceParent
  32. self.semantics.concurrency = StatechartSemantics.Single
  33. # Call user defined constructor
  34. SCCDSimulator.user_defined_constructor(self, model)
  35. def user_defined_constructor(self, model):
  36. self.model = model
  37. self.save_model = pickle.dumps(self.model, pickle.HIGHEST_PROTOCOL)
  38. self.listeners_by_string = {}
  39. self.initialize_simulation()
  40. def user_defined_destructor(self):
  41. pass
  42. # User defined method
  43. def initialize_simulation(self):
  44. # Simulation variables
  45. self.termination_time = None
  46. self.termination_condition = None
  47. self.simulation_time = (0.0, 0)
  48. self.listeners = {}
  49. self.root_model = self.model
  50. self.realtime_scale = 1.0
  51. # Values to be set during simulation
  52. self.realtime_starttime = None
  53. self.inject_queue = []
  54. # Model initialization
  55. self.model_ids = []
  56. self.model.finalize(name="", model_counter=0, model_ids=self.model_ids, locations={None: []}, select_hierarchy=[])
  57. # User defined method
  58. def serialize(self, type, object):
  59. if type == "imminents":
  60. return [m.getModelFullName() for m in object]
  61. elif type == "imminent":
  62. return object.getModelFullName()
  63. elif type == "outbag":
  64. return {m.getPortFullName(): [object[m]] for m in object}
  65. elif type == "inbags":
  66. return {m.getPortFullName(): ([object[m][0].getPortFullName(), object[m][1]] if (object[m][0] is not None) else [object[m][1]]) for m in object}
  67. elif type == "new_tn" or type == "new_states":
  68. return {m.getModelFullName(): object[m] for m in object if m.model_id is not None}
  69. elif type == "transitioning":
  70. return {m.getModelFullName(): {1: "INTERNAL", 2: "EXTERNAL"}[object[m]] for m in object if m.model_id is not None}
  71. elif type == "transitioned":
  72. return {m: {1: "INTERNAL", 2: "EXTERNAL"}[object[m]] for m in object if m.model_id is not None}
  73. # User defined method
  74. def find_port_with_name(self, name):
  75. for model in self.model.component_set:
  76. if name.startswith(model.getModelFullName()):
  77. # Found a potential model
  78. # We can't simply check for equality, as portnames might contain dots too
  79. for port in model.IPorts:
  80. if port.getPortFullName() == name:
  81. # Now everything matches
  82. return port
  83. # Nothing found
  84. return None
  85. # User defined method
  86. def find_model_with_name(self, name):
  87. for model in self.model.component_set:
  88. if name == model.getModelFullName():
  89. # Found exact match
  90. return model
  91. return None
  92. # User defined method
  93. def calculate_after(self):
  94. try:
  95. # Process in parts of 100 milliseconds to repeatedly check the termination condition
  96. if self.interrupt_string:
  97. nexttime = 0.0
  98. else:
  99. nexttime = (self.time_next[0] - (time.time() - self.realtime_starttime) / self.realtime_scale) * self.realtime_scale
  100. x = min(0.1, nexttime)
  101. return x
  102. except TypeError, AttributeError:
  103. # We are probably not simulating in realtime...
  104. return float('inf')
  105. # User defined method
  106. def parse_options(self, configuration):
  107. self.termination_condition = None if "termination_condition" not in configuration else configuration["termination_condition"]
  108. self.termination_time = None if "termination_time" not in configuration else configuration["termination_time"]
  109. self.realtime_scale = 1.0 if "realtime_scale" not in configuration else 1.0/configuration["realtime_scale"]
  110. # Subtract the current simulation time to allow for pausing
  111. self.realtime_starttime = (time.time() - self.simulation_time[0]*self.realtime_scale)
  112. # Reset the time used in the waiting, as it might not get recomputed
  113. self.the_time = 0.00001
  114. # User defined method
  115. def should_terminate(self, realtime):
  116. # Now that it includes breakpoints, results are to be interpretted as follows:
  117. # -2 --> continue simulation
  118. # -1 --> termination condition
  119. # else --> breakpoint
  120. if realtime:
  121. check_time = self.simulation_time
  122. else:
  123. self.compute_timeNext()
  124. check_time = self.time_next
  125. # Just access the 'transitioned' dictionary
  126. # Kind of dirty though...
  127. if self.transitioning is None:
  128. transitioned = set()
  129. else:
  130. transitioned = self.transitioning
  131. outbag = self.outbag if self.outbag is not None else {}
  132. inbags = self.inbags if self.inbags is not None else {}
  133. if check_time[0] == float('inf'):
  134. # Always terminate if we have reached infinity
  135. terminate = True
  136. elif self.termination_condition is not None:
  137. terminate = self.termination_condition(check_time, self.root_model, transitioned)
  138. else:
  139. terminate = self.termination_time < check_time[0]
  140. if terminate:
  141. # Always terminate, so don't check breakpoints
  142. return -1
  143. else:
  144. # Have to check breakpoints for termination
  145. for bp in self.breakpoints:
  146. if not bp.enabled:
  147. continue
  148. # Include the function in the scope
  149. exec(bp.function)
  150. # And execute it, note that the breakpoint thus has to start with "def breakpoint("
  151. # TODO: report to the user if a breakpoint is invalid (catching exceptions).
  152. if breakpoint(check_time, self.root_model, self.serialize('transitioned', transitioned), outbag, inbags):
  153. # Triggered!
  154. return bp.id
  155. else:
  156. # Not triggered, so continue
  157. continue
  158. return -2
  159. # User defined method
  160. def find_internal_imminents(self):
  161. self.imminents = self.model.scheduler.getImminent(self.simulation_time)
  162. self.reschedule = set(self.imminents)
  163. self.transition_times.append(self.simulation_time)
  164. for model in self.imminents:
  165. model.time_next = (model.time_next[0], model.time_next[1] + 1)
  166. # User defined method
  167. def select_imminent(self):
  168. self.imminent = None
  169. if len(self.imminents) > 1:
  170. # Perform all selects
  171. self.imminents.sort()
  172. pending = self.imminents
  173. level = 1
  174. while len(pending) > 1:
  175. # Take the model each time, as we need to make sure that the selectHierarchy is valid everywhere
  176. model = pending[0]
  177. # Make a set first to remove duplicates
  178. colliding = list(set([m.select_hierarchy[level] for m in pending]))
  179. chosen = model.select_hierarchy[level-1].select(
  180. sorted(colliding, key=lambda i:i.getModelFullName()))
  181. pending = [m for m in pending
  182. if m.select_hierarchy[level] == chosen]
  183. level += 1
  184. self.imminent = pending[0]
  185. else:
  186. self.imminent = self.imminents[0]
  187. self.imminent.time_next = (self.imminent.time_next[0], self.imminent.time_next[1] - 1)
  188. # User defined method
  189. def compute_outputfunction(self):
  190. self.outbag = ClassicDEVSWrapper(self.imminent).outputFnc()
  191. # User defined method
  192. def route_messages(self):
  193. self.inbags = {}
  194. for outport in self.outbag:
  195. payload = self.outbag[outport]
  196. for inport, z in outport.routing_outline:
  197. if z is not None:
  198. payload = [z(pickle.loads(pickle.dumps(m))) for m in payload]
  199. self.inbags[inport] = [outport, payload]
  200. # User defined method
  201. def process_injects(self):
  202. while self.inject_queue:
  203. if self.inject_queue[0]["time"] > self.simulation_time:
  204. break
  205. config = self.inject_queue.pop(0)
  206. portname = config["port"]
  207. event = config["event"]
  208. port = self.find_port_with_name(portname)
  209. if port == None:
  210. break
  211. self.inbags[port] = [None, [event]]
  212. if self.interrupt_string:
  213. portname, event_value = self.interrupt_string.split(" ")
  214. for inport, z in self.root_model.ports[portname].routing_outline:
  215. ev = event_value if z is None else z(event_value)
  216. self.inbags[inport] = [self.root_model.ports[portname], [ev]]
  217. self.interrupt_string = None
  218. # User defined method
  219. def find_all_imminents(self):
  220. # Internal codes:
  221. # 1 --> internal transition
  222. # 2 --> external transition
  223. # 3 --> confluent transition
  224. # These codes are a legacy of efficient PyPDEVS, but is kept here for consistency
  225. self.transitioning = {self.imminent: 1}
  226. for inport in self.inbags:
  227. aDEVS = inport.host_DEVS
  228. aDEVS.my_input[inport] = self.inbags[inport][1]
  229. self.transitioning[aDEVS] = 2
  230. self.reschedule.add(aDEVS)
  231. self.transitioning = {ClassicDEVSWrapper(m): self.transitioning[m]
  232. for m in self.transitioning}
  233. for m in self.transitioning:
  234. m.server = self
  235. self.dc_altered = set()
  236. # User defined method
  237. def compute_transitions(self):
  238. self.new_states = {}
  239. for aDEVS in self.transitioning:
  240. aDEVS.my_input = {key: pickle.loads(pickle.dumps(aDEVS.my_input[key], pickle.HIGHEST_PROTOCOL)) for key in aDEVS.my_input}
  241. if self.transitioning[aDEVS] == 1:
  242. aDEVS.state = aDEVS.intTransition()
  243. elif self.transitioning[aDEVS] == 2:
  244. aDEVS.elapsed = self.simulation_time[0] - aDEVS.time_last[0]
  245. aDEVS.state = aDEVS.extTransition(aDEVS.my_input)
  246. aDEVS.old_states.append((self.simulation_time, pickle.dumps(aDEVS.state)))
  247. aDEVS.my_input = {}
  248. self.new_states[aDEVS] = aDEVS.state
  249. # User defined method
  250. def compute_ta(self):
  251. self.new_tn = {}
  252. t, age = self.simulation_time
  253. for aDEVS in self.transitioning:
  254. ta = aDEVS.timeAdvance()
  255. aDEVS.time_last = self.simulation_time
  256. aDEVS.time_next = (t + ta, 1 if ta else (age + 1))
  257. self.new_tn[aDEVS] = aDEVS.time_next
  258. trace(self.trace_file, self.transitioning[aDEVS], aDEVS)
  259. self.model.scheduler.massReschedule(self.reschedule)
  260. self.time_next = self.model.scheduler.readFirst()
  261. # User defined method
  262. def dsAddPort(self, port):
  263. self.dc_altered.add(port)
  264. self.structural_changes.setdefault('CREATED_PORTS', []).append((port.getPortFullName(), port.is_input))
  265. # User defined method
  266. def dsRemovePort(self, port):
  267. for iport in port.inline:
  268. iport.outline = [p for p in iport.outline if p != port]
  269. self.dsDisconnectPorts(iport, port);
  270. for oport in port.outline:
  271. oport.inline = [p for p in oport.inline if p != port]
  272. self.dsDisconnectPorts(port, oport);
  273. self.dc_altered.add(port)
  274. self.structural_changes.setdefault('DELETED_PORTS', []).append(port.getPortFullName())
  275. # User defined method
  276. def dsDisconnectPorts(self, p1, p2):
  277. self.dc_altered.add(p1)
  278. self.structural_changes.setdefault('DISCONNECTED_PORTS', []).append((p1.getPortFullName(), p2.getPortFullName()))
  279. # User defined method
  280. def dsConnectPorts(self, p1, p2):
  281. self.dc_altered.add(p1)
  282. self.structural_changes.setdefault('CONNECTED_PORTS', []).append((p1.getPortFullName(), p2.getPortFullName()))
  283. # User defined method
  284. def dsUnscheduleModel(self, model):
  285. if isinstance(model, CoupledDEVS):
  286. for m in model.component_set:
  287. self.dsUnscheduleModel(m, False)
  288. elif isinstance(model, AtomicDEVS):
  289. self.model.component_set.remove(model)
  290. self.model.models.remove(model)
  291. # The model is removed, so remove it from the scheduler
  292. self.model.scheduler.unschedule(model)
  293. self.model_ids[model.model_id] = None
  294. self.model.local_model_ids.remove(model.model_id)
  295. else:
  296. raise DEVSException("Unknown model to schedule: %s" % model)
  297. for port in model.IPorts:
  298. self.dsRemovePort(port)
  299. for port in model.OPorts:
  300. self.dsRemovePort(port)
  301. self.structural_changes.setdefault('DELETED_MODELS', []).append(model.getModelFullName())
  302. # User defined method
  303. def dsScheduleModel(self, model):
  304. if isinstance(model, CoupledDEVS):
  305. model.full_name = model.parent.full_name + "." + model.getModelName()
  306. for m in model.component_set:
  307. self.dsScheduleModel(m)
  308. elif isinstance(model, AtomicDEVS):
  309. model.model_id = len(self.model_ids)
  310. model.full_name = model.parent.full_name + "." + model.getModelName()
  311. self.model_ids.append(model)
  312. self.model.component_set.append(model)
  313. self.model.models.append(model)
  314. self.model.local_model_ids.add(model.model_id)
  315. model.time_last = (self.simulation_time[0] - model.elapsed, 1)
  316. ta = model.timeAdvance()
  317. if ta < 0:
  318. raise DEVSException("Negative time advance in atomic model '" + \
  319. model.getModelFullName() + "' with value " + \
  320. str(ta) + " at initialisation")
  321. model.time_next = (model.time_last[0] + ta, 1)
  322. model.old_states.append((self.simulation_time, pickle.dumps(model.state)))
  323. p = model.parent
  324. model.select_hierarchy = [model]
  325. while p != None:
  326. model.select_hierarchy = [p] + model.select_hierarchy
  327. p = p.parent
  328. if model.time_next[0] == self.simulation_time[0]:
  329. model.time_next = (model.time_next[0], self.simulation_time[1])
  330. # If scheduled for 'now', update the age manually
  331. # It is a new model, so add it to the scheduler too
  332. self.model.scheduler.schedule(model)
  333. else:
  334. raise DEVSException("Unknown model to schedule: %s" % model)
  335. self.structural_changes.setdefault('CREATED_MODELS', []).append(model.getModelFullName())
  336. self.structural_changes.setdefault('CREATED_PORTS', []).extend([(port.getPortFullName(), port.is_input) for port in model.ports.itervalues()])
  337. # User defined method
  338. def getSelfProxy(self):
  339. return self
  340. # User defined method
  341. def process_structure_changes(self):
  342. dsdevs_dict = {}
  343. iterlist = [aDEVS.parent for aDEVS in self.transitioning
  344. if aDEVS.modelTransition(dsdevs_dict)]
  345. # Contains all models that are already checked, to prevent duplicate checking.
  346. # This was not necessary for atomic models, as they are guaranteed to only be called
  347. # once, as they have no children to induce a structural change on them
  348. checked = set()
  349. while iterlist:
  350. new_iterlist = []
  351. for cDEVS in iterlist:
  352. cDEVS.server = self
  353. if cDEVS is None:
  354. # Problematic
  355. #assert warning("Root DEVS returned True in the modelTransition method; ignoring")
  356. continue
  357. if cDEVS in checked:
  358. continue
  359. checked.add(cDEVS)
  360. if cDEVS.modelTransition(dsdevs_dict):
  361. new_iterlist.append(cDEVS.parent)
  362. cDEVS.server = None
  363. # Don't update the iterlist while we are iterating over it
  364. iterlist = new_iterlist
  365. if self.dc_altered:
  366. self.model.redoDirectConnection(self.dc_altered)
  367. for m in self.transitioning:
  368. m.server = None
  369. # User defined method
  370. def flush_file(self):
  371. if self.trace_file is not None:
  372. self.trace_file.flush()
  373. # User defined method
  374. def process_breakpoints(self, realtime):
  375. breakpoint_id = self.should_terminate(realtime)
  376. for breakpoint in self.breakpoints:
  377. if breakpoint.id == breakpoint_id:
  378. if breakpoint.disable_on_trigger:
  379. breakpoint.enabled = False
  380. return breakpoint_id
  381. # User defined method
  382. def compute_timeNext(self):
  383. model_timeNext = self.model.scheduler.readFirst()
  384. if len(self.inject_queue) > 0:
  385. self.time_next = min(model_timeNext, self.inject_queue[0]["time"])
  386. else:
  387. self.time_next = model_timeNext
  388. # User defined method
  389. def rollback_step(self):
  390. if len(self.transition_times) == 0:
  391. return
  392. new_time = self.transition_times.pop()
  393. for model in self.model.component_set:
  394. if model.old_states[-1][0] == new_time:
  395. # Remove the current state
  396. del model.old_states[-1]
  397. # Set the new (old...) state
  398. new_state = model.old_states[-1]
  399. model.state = pickle.loads(new_state[1])
  400. model.time_last = new_state[0]
  401. ta = model.timeAdvance()
  402. model.time_next = (model.time_last[0] + ta, model.time_last[1] + 1 if ta == 0 else 0)
  403. self.model.scheduler.massReschedule([model])
  404. self.simulation_time = self.transition_times[-1] if len(self.transition_times) > 0 else (0.0, 0)
  405. def initializeStatechart(self):
  406. self.current_state[self.Root] = []
  407. self.current_state[self.Root_main] = []
  408. self.current_state[self.Root_main_injection_monitor] = []
  409. self.current_state[self.Root_main_tracer_monitor] = []
  410. self.current_state[self.Root_main_realtime_interrupt_monitor] = []
  411. self.current_state[self.Root_main_simulation_flow] = []
  412. self.current_state[self.Root_main_simulation_flow_check_termination] = []
  413. self.current_state[self.Root_main_simulation_flow_do_simulation] = []
  414. self.current_state[self.Root_main_simulation_state] = []
  415. self.current_state[self.Root_main_breakpoint_manager] = []
  416. self.current_state[self.Root_main_listeners] = []
  417. self.current_state[self.Root_main_reset] = []
  418. # Enter default state
  419. self.enter_Root_initializing()
  420. # Unique IDs for all statechart nodes
  421. Root = 0
  422. Root_main = 1
  423. Root_main_injection_monitor = 2
  424. Root_main_tracer_monitor = 3
  425. Root_main_realtime_interrupt_monitor = 4
  426. Root_main_simulation_flow = 5
  427. Root_main_simulation_flow_check_termination = 6
  428. Root_main_simulation_flow_do_simulation = 7
  429. Root_main_simulation_state = 8
  430. Root_main_breakpoint_manager = 9
  431. Root_main_listeners = 10
  432. Root_main_reset = 11
  433. Root_initializing = 12
  434. Root_main_injection_monitor_inject = 13
  435. Root_main_tracer_monitor_trace = 14
  436. Root_main_realtime_interrupt_monitor_realtime_interrupt = 15
  437. Root_main_simulation_flow_initialize = 16
  438. Root_main_simulation_flow_check_termination_workaround = 17
  439. Root_main_simulation_flow_check_termination_wait = 18
  440. Root_main_simulation_flow_check_termination_small_step_check = 19
  441. Root_main_simulation_flow_check_termination_check_termination = 20
  442. Root_main_simulation_flow_do_simulation_init = 21
  443. Root_main_simulation_flow_do_simulation_found_internal_imminents = 22
  444. Root_main_simulation_flow_do_simulation_selected_imminent = 23
  445. Root_main_simulation_flow_do_simulation_computed_outputfunction = 24
  446. Root_main_simulation_flow_do_simulation_routed_messages = 25
  447. Root_main_simulation_flow_do_simulation_found_all_imminents = 26
  448. Root_main_simulation_flow_do_simulation_computed_transitions = 27
  449. Root_main_simulation_flow_do_simulation_computed_ta = 28
  450. Root_main_simulation_state_paused = 29
  451. Root_main_simulation_state_continuous = 30
  452. Root_main_simulation_state_realtime = 31
  453. Root_main_simulation_state_big_step = 32
  454. Root_main_breakpoint_manager_breakpoint_manage = 33
  455. Root_main_listeners_listening = 34
  456. Root_main_reset_reset = 35
  457. # Statechart enter/exit action method(s)
  458. def enter_Root_main(self):
  459. self.current_state[self.Root].append(self.Root_main)
  460. def exit_Root_main(self):
  461. self.exit_Root_main_injection_monitor()
  462. self.exit_Root_main_tracer_monitor()
  463. self.exit_Root_main_realtime_interrupt_monitor()
  464. self.exit_Root_main_simulation_flow()
  465. self.exit_Root_main_simulation_state()
  466. self.exit_Root_main_breakpoint_manager()
  467. self.exit_Root_main_listeners()
  468. self.exit_Root_main_reset()
  469. self.current_state[self.Root] = []
  470. def enter_Root_main_injection_monitor(self):
  471. self.current_state[self.Root_main].append(self.Root_main_injection_monitor)
  472. def exit_Root_main_injection_monitor(self):
  473. if self.Root_main_injection_monitor_inject in self.current_state[self.Root_main_injection_monitor]:
  474. self.exit_Root_main_injection_monitor_inject()
  475. self.current_state[self.Root_main] = []
  476. def enter_Root_main_tracer_monitor(self):
  477. self.current_state[self.Root_main].append(self.Root_main_tracer_monitor)
  478. def exit_Root_main_tracer_monitor(self):
  479. if self.Root_main_tracer_monitor_trace in self.current_state[self.Root_main_tracer_monitor]:
  480. self.exit_Root_main_tracer_monitor_trace()
  481. self.current_state[self.Root_main] = []
  482. def enter_Root_main_realtime_interrupt_monitor(self):
  483. self.current_state[self.Root_main].append(self.Root_main_realtime_interrupt_monitor)
  484. def exit_Root_main_realtime_interrupt_monitor(self):
  485. if self.Root_main_realtime_interrupt_monitor_realtime_interrupt in self.current_state[self.Root_main_realtime_interrupt_monitor]:
  486. self.exit_Root_main_realtime_interrupt_monitor_realtime_interrupt()
  487. self.current_state[self.Root_main] = []
  488. def enter_Root_main_simulation_flow(self):
  489. self.current_state[self.Root_main].append(self.Root_main_simulation_flow)
  490. def exit_Root_main_simulation_flow(self):
  491. if self.Root_main_simulation_flow_initialize in self.current_state[self.Root_main_simulation_flow]:
  492. self.exit_Root_main_simulation_flow_initialize()
  493. if self.Root_main_simulation_flow_check_termination in self.current_state[self.Root_main_simulation_flow]:
  494. self.exit_Root_main_simulation_flow_check_termination()
  495. if self.Root_main_simulation_flow_do_simulation in self.current_state[self.Root_main_simulation_flow]:
  496. self.exit_Root_main_simulation_flow_do_simulation()
  497. self.current_state[self.Root_main] = []
  498. def enter_Root_main_simulation_flow_check_termination(self):
  499. self.current_state[self.Root_main_simulation_flow].append(self.Root_main_simulation_flow_check_termination)
  500. def exit_Root_main_simulation_flow_check_termination(self):
  501. if self.Root_main_simulation_flow_check_termination_workaround in self.current_state[self.Root_main_simulation_flow_check_termination]:
  502. self.exit_Root_main_simulation_flow_check_termination_workaround()
  503. if self.Root_main_simulation_flow_check_termination_wait in self.current_state[self.Root_main_simulation_flow_check_termination]:
  504. self.exit_Root_main_simulation_flow_check_termination_wait()
  505. if self.Root_main_simulation_flow_check_termination_small_step_check in self.current_state[self.Root_main_simulation_flow_check_termination]:
  506. self.exit_Root_main_simulation_flow_check_termination_small_step_check()
  507. if self.Root_main_simulation_flow_check_termination_check_termination in self.current_state[self.Root_main_simulation_flow_check_termination]:
  508. self.exit_Root_main_simulation_flow_check_termination_check_termination()
  509. self.simulation_time = self.time_next
  510. self.current_state[self.Root_main_simulation_flow] = []
  511. def enter_Root_main_simulation_flow_do_simulation(self):
  512. self.current_state[self.Root_main_simulation_flow].append(self.Root_main_simulation_flow_do_simulation)
  513. def exit_Root_main_simulation_flow_do_simulation(self):
  514. if self.Root_main_simulation_flow_do_simulation_init in self.current_state[self.Root_main_simulation_flow_do_simulation]:
  515. self.exit_Root_main_simulation_flow_do_simulation_init()
  516. if self.Root_main_simulation_flow_do_simulation_found_internal_imminents in self.current_state[self.Root_main_simulation_flow_do_simulation]:
  517. self.exit_Root_main_simulation_flow_do_simulation_found_internal_imminents()
  518. if self.Root_main_simulation_flow_do_simulation_selected_imminent in self.current_state[self.Root_main_simulation_flow_do_simulation]:
  519. self.exit_Root_main_simulation_flow_do_simulation_selected_imminent()
  520. if self.Root_main_simulation_flow_do_simulation_computed_outputfunction in self.current_state[self.Root_main_simulation_flow_do_simulation]:
  521. self.exit_Root_main_simulation_flow_do_simulation_computed_outputfunction()
  522. if self.Root_main_simulation_flow_do_simulation_routed_messages in self.current_state[self.Root_main_simulation_flow_do_simulation]:
  523. self.exit_Root_main_simulation_flow_do_simulation_routed_messages()
  524. if self.Root_main_simulation_flow_do_simulation_found_all_imminents in self.current_state[self.Root_main_simulation_flow_do_simulation]:
  525. self.exit_Root_main_simulation_flow_do_simulation_found_all_imminents()
  526. if self.Root_main_simulation_flow_do_simulation_computed_transitions in self.current_state[self.Root_main_simulation_flow_do_simulation]:
  527. self.exit_Root_main_simulation_flow_do_simulation_computed_transitions()
  528. if self.Root_main_simulation_flow_do_simulation_computed_ta in self.current_state[self.Root_main_simulation_flow_do_simulation]:
  529. self.exit_Root_main_simulation_flow_do_simulation_computed_ta()
  530. self.current_state[self.Root_main_simulation_flow] = []
  531. def enter_Root_main_simulation_state(self):
  532. self.current_state[self.Root_main].append(self.Root_main_simulation_state)
  533. def exit_Root_main_simulation_state(self):
  534. if self.Root_main_simulation_state_paused in self.current_state[self.Root_main_simulation_state]:
  535. self.exit_Root_main_simulation_state_paused()
  536. if self.Root_main_simulation_state_continuous in self.current_state[self.Root_main_simulation_state]:
  537. self.exit_Root_main_simulation_state_continuous()
  538. if self.Root_main_simulation_state_realtime in self.current_state[self.Root_main_simulation_state]:
  539. self.exit_Root_main_simulation_state_realtime()
  540. if self.Root_main_simulation_state_big_step in self.current_state[self.Root_main_simulation_state]:
  541. self.exit_Root_main_simulation_state_big_step()
  542. self.current_state[self.Root_main] = []
  543. def enter_Root_main_breakpoint_manager(self):
  544. self.current_state[self.Root_main].append(self.Root_main_breakpoint_manager)
  545. def exit_Root_main_breakpoint_manager(self):
  546. if self.Root_main_breakpoint_manager_breakpoint_manage in self.current_state[self.Root_main_breakpoint_manager]:
  547. self.exit_Root_main_breakpoint_manager_breakpoint_manage()
  548. self.current_state[self.Root_main] = []
  549. def enter_Root_main_listeners(self):
  550. self.current_state[self.Root_main].append(self.Root_main_listeners)
  551. def exit_Root_main_listeners(self):
  552. if self.Root_main_listeners_listening in self.current_state[self.Root_main_listeners]:
  553. self.exit_Root_main_listeners_listening()
  554. self.current_state[self.Root_main] = []
  555. def enter_Root_main_reset(self):
  556. self.current_state[self.Root_main].append(self.Root_main_reset)
  557. def exit_Root_main_reset(self):
  558. if self.Root_main_reset_reset in self.current_state[self.Root_main_reset]:
  559. self.exit_Root_main_reset_reset()
  560. self.current_state[self.Root_main] = []
  561. def enter_Root_initializing(self):
  562. self.current_state[self.Root].append(self.Root_initializing)
  563. def exit_Root_initializing(self):
  564. self.current_state[self.Root] = []
  565. def enter_Root_main_injection_monitor_inject(self):
  566. self.current_state[self.Root_main_injection_monitor].append(self.Root_main_injection_monitor_inject)
  567. def exit_Root_main_injection_monitor_inject(self):
  568. self.current_state[self.Root_main_injection_monitor] = []
  569. def enter_Root_main_tracer_monitor_trace(self):
  570. self.current_state[self.Root_main_tracer_monitor].append(self.Root_main_tracer_monitor_trace)
  571. def exit_Root_main_tracer_monitor_trace(self):
  572. self.current_state[self.Root_main_tracer_monitor] = []
  573. def enter_Root_main_realtime_interrupt_monitor_realtime_interrupt(self):
  574. self.current_state[self.Root_main_realtime_interrupt_monitor].append(self.Root_main_realtime_interrupt_monitor_realtime_interrupt)
  575. def exit_Root_main_realtime_interrupt_monitor_realtime_interrupt(self):
  576. self.current_state[self.Root_main_realtime_interrupt_monitor] = []
  577. def enter_Root_main_simulation_flow_initialize(self):
  578. self.structural_changes = {'CREATED_MODELS': [], 'CREATED_PORTS': [], 'CONNECTED_PORTS': []}
  579. queue = [self.root_model]
  580. while queue:
  581. item = queue.pop()
  582. self.structural_changes['CREATED_MODELS'].append(item.getModelFullName())
  583. self.structural_changes['CREATED_PORTS'].extend([(port.getPortFullName(), port.is_input) for port in item.ports.itervalues()])
  584. self.structural_changes['CONNECTED_PORTS'].extend([(outport.getPortFullName(), inport.getPortFullName()) for outport in item.OPorts for inport in outport.outline])
  585. if isinstance(item, CoupledDEVS):
  586. self.structural_changes['CONNECTED_PORTS'].extend([(inport.getPortFullName(), inport2.getPortFullName()) for inport in item.IPorts for inport2 in inport.outline])
  587. queue.extend(item.component_set)
  588. self.current_state[self.Root_main_simulation_flow].append(self.Root_main_simulation_flow_initialize)
  589. def exit_Root_main_simulation_flow_initialize(self):
  590. self.current_state[self.Root_main_simulation_flow] = []
  591. def enter_Root_main_simulation_flow_check_termination_workaround(self):
  592. self.timers[0] = 0
  593. self.current_state[self.Root_main_simulation_flow_check_termination].append(self.Root_main_simulation_flow_check_termination_workaround)
  594. def exit_Root_main_simulation_flow_check_termination_workaround(self):
  595. self.timers.pop(0, None)
  596. self.current_state[self.Root_main_simulation_flow_check_termination] = []
  597. def enter_Root_main_simulation_flow_check_termination_wait(self):
  598. self.timers[1] = self.calculate_after()
  599. self.current_state[self.Root_main_simulation_flow_check_termination].append(self.Root_main_simulation_flow_check_termination_wait)
  600. def exit_Root_main_simulation_flow_check_termination_wait(self):
  601. self.timers.pop(1, None)
  602. diff = time.time() - self.realtime_starttime
  603. self.simulation_time = (diff / self.realtime_scale, 1)
  604. self.current_state[self.Root_main_simulation_flow_check_termination] = []
  605. def enter_Root_main_simulation_flow_check_termination_small_step_check(self):
  606. self.current_state[self.Root_main_simulation_flow_check_termination].append(self.Root_main_simulation_flow_check_termination_small_step_check)
  607. def exit_Root_main_simulation_flow_check_termination_small_step_check(self):
  608. self.current_state[self.Root_main_simulation_flow_check_termination] = []
  609. def enter_Root_main_simulation_flow_check_termination_check_termination(self):
  610. self.compute_timeNext()
  611. self.the_time = self.calculate_after()
  612. self.current_state[self.Root_main_simulation_flow_check_termination].append(self.Root_main_simulation_flow_check_termination_check_termination)
  613. def exit_Root_main_simulation_flow_check_termination_check_termination(self):
  614. self.current_state[self.Root_main_simulation_flow_check_termination] = []
  615. def enter_Root_main_simulation_flow_do_simulation_init(self):
  616. self.current_state[self.Root_main_simulation_flow_do_simulation].append(self.Root_main_simulation_flow_do_simulation_init)
  617. def exit_Root_main_simulation_flow_do_simulation_init(self):
  618. self.find_internal_imminents()
  619. self.current_state[self.Root_main_simulation_flow_do_simulation] = []
  620. def enter_Root_main_simulation_flow_do_simulation_found_internal_imminents(self):
  621. self.current_state[self.Root_main_simulation_flow_do_simulation].append(self.Root_main_simulation_flow_do_simulation_found_internal_imminents)
  622. def exit_Root_main_simulation_flow_do_simulation_found_internal_imminents(self):
  623. self.select_imminent()
  624. self.current_state[self.Root_main_simulation_flow_do_simulation] = []
  625. def enter_Root_main_simulation_flow_do_simulation_selected_imminent(self):
  626. self.current_state[self.Root_main_simulation_flow_do_simulation].append(self.Root_main_simulation_flow_do_simulation_selected_imminent)
  627. def exit_Root_main_simulation_flow_do_simulation_selected_imminent(self):
  628. self.compute_outputfunction()
  629. self.current_state[self.Root_main_simulation_flow_do_simulation] = []
  630. def enter_Root_main_simulation_flow_do_simulation_computed_outputfunction(self):
  631. self.current_state[self.Root_main_simulation_flow_do_simulation].append(self.Root_main_simulation_flow_do_simulation_computed_outputfunction)
  632. def exit_Root_main_simulation_flow_do_simulation_computed_outputfunction(self):
  633. self.route_messages()
  634. self.process_injects()
  635. self.current_state[self.Root_main_simulation_flow_do_simulation] = []
  636. def enter_Root_main_simulation_flow_do_simulation_routed_messages(self):
  637. self.current_state[self.Root_main_simulation_flow_do_simulation].append(self.Root_main_simulation_flow_do_simulation_routed_messages)
  638. def exit_Root_main_simulation_flow_do_simulation_routed_messages(self):
  639. self.find_all_imminents()
  640. self.current_state[self.Root_main_simulation_flow_do_simulation] = []
  641. def enter_Root_main_simulation_flow_do_simulation_found_all_imminents(self):
  642. self.current_state[self.Root_main_simulation_flow_do_simulation].append(self.Root_main_simulation_flow_do_simulation_found_all_imminents)
  643. def exit_Root_main_simulation_flow_do_simulation_found_all_imminents(self):
  644. self.compute_transitions()
  645. self.current_state[self.Root_main_simulation_flow_do_simulation] = []
  646. def enter_Root_main_simulation_flow_do_simulation_computed_transitions(self):
  647. self.current_state[self.Root_main_simulation_flow_do_simulation].append(self.Root_main_simulation_flow_do_simulation_computed_transitions)
  648. def exit_Root_main_simulation_flow_do_simulation_computed_transitions(self):
  649. self.compute_ta()
  650. self.current_state[self.Root_main_simulation_flow_do_simulation] = []
  651. def enter_Root_main_simulation_flow_do_simulation_computed_ta(self):
  652. self.current_state[self.Root_main_simulation_flow_do_simulation].append(self.Root_main_simulation_flow_do_simulation_computed_ta)
  653. def exit_Root_main_simulation_flow_do_simulation_computed_ta(self):
  654. self.process_structure_changes()
  655. self.current_state[self.Root_main_simulation_flow_do_simulation] = []
  656. def enter_Root_main_simulation_state_paused(self):
  657. self.current_state[self.Root_main_simulation_state].append(self.Root_main_simulation_state_paused)
  658. def exit_Root_main_simulation_state_paused(self):
  659. self.current_state[self.Root_main_simulation_state] = []
  660. def enter_Root_main_simulation_state_continuous(self):
  661. self.listeners = {getattr(self.root_model, portname): listener for (portname, listener) in self.listeners_by_string.iteritems()}
  662. self.model.listeners = self.listeners
  663. self.model.component_set = directConnect(self.model.models, self.listeners)
  664. self.current_state[self.Root_main_simulation_state].append(self.Root_main_simulation_state_continuous)
  665. def exit_Root_main_simulation_state_continuous(self):
  666. self.current_state[self.Root_main_simulation_state] = []
  667. def enter_Root_main_simulation_state_realtime(self):
  668. self.listeners = {getattr(self.root_model, portname): listener for (portname, listener) in self.listeners_by_string.iteritems()}
  669. self.model.listeners = self.listeners
  670. self.model.component_set = directConnect(self.model.models, self.listeners)
  671. self.current_state[self.Root_main_simulation_state].append(self.Root_main_simulation_state_realtime)
  672. def exit_Root_main_simulation_state_realtime(self):
  673. self.current_state[self.Root_main_simulation_state] = []
  674. def enter_Root_main_simulation_state_big_step(self):
  675. self.listeners = {getattr(self.root_model, portname): listener for (portname, listener) in self.listeners_by_string.iteritems()}
  676. self.model.listeners = self.listeners
  677. self.model.component_set = directConnect(self.model.models, self.listeners)
  678. self.current_state[self.Root_main_simulation_state].append(self.Root_main_simulation_state_big_step)
  679. def exit_Root_main_simulation_state_big_step(self):
  680. self.current_state[self.Root_main_simulation_state] = []
  681. def enter_Root_main_breakpoint_manager_breakpoint_manage(self):
  682. self.current_state[self.Root_main_breakpoint_manager].append(self.Root_main_breakpoint_manager_breakpoint_manage)
  683. def exit_Root_main_breakpoint_manager_breakpoint_manage(self):
  684. self.current_state[self.Root_main_breakpoint_manager] = []
  685. def enter_Root_main_listeners_listening(self):
  686. self.current_state[self.Root_main_listeners].append(self.Root_main_listeners_listening)
  687. def exit_Root_main_listeners_listening(self):
  688. self.current_state[self.Root_main_listeners] = []
  689. def enter_Root_main_reset_reset(self):
  690. self.current_state[self.Root_main_reset].append(self.Root_main_reset_reset)
  691. def exit_Root_main_reset_reset(self):
  692. self.current_state[self.Root_main_reset] = []
  693. # Statechart enter/exit default method(s)
  694. def enterDefault_Root_main(self):
  695. self.enter_Root_main()
  696. self.enterDefault_Root_main_injection_monitor()
  697. self.enterDefault_Root_main_tracer_monitor()
  698. self.enterDefault_Root_main_realtime_interrupt_monitor()
  699. self.enterDefault_Root_main_simulation_flow()
  700. self.enterDefault_Root_main_simulation_state()
  701. self.enterDefault_Root_main_breakpoint_manager()
  702. self.enterDefault_Root_main_listeners()
  703. self.enterDefault_Root_main_reset()
  704. def enterDefault_Root_main_injection_monitor(self):
  705. self.enter_Root_main_injection_monitor()
  706. self.enter_Root_main_injection_monitor_inject()
  707. def enterDefault_Root_main_tracer_monitor(self):
  708. self.enter_Root_main_tracer_monitor()
  709. self.enter_Root_main_tracer_monitor_trace()
  710. def enterDefault_Root_main_realtime_interrupt_monitor(self):
  711. self.enter_Root_main_realtime_interrupt_monitor()
  712. self.enter_Root_main_realtime_interrupt_monitor_realtime_interrupt()
  713. def enterDefault_Root_main_simulation_flow(self):
  714. self.enter_Root_main_simulation_flow()
  715. self.enter_Root_main_simulation_flow_initialize()
  716. def enterDefault_Root_main_simulation_flow_check_termination(self):
  717. self.enter_Root_main_simulation_flow_check_termination()
  718. self.enter_Root_main_simulation_flow_check_termination_workaround()
  719. def enterDefault_Root_main_simulation_flow_do_simulation(self):
  720. self.enter_Root_main_simulation_flow_do_simulation()
  721. self.enter_Root_main_simulation_flow_do_simulation_init()
  722. def enterDefault_Root_main_simulation_state(self):
  723. self.enter_Root_main_simulation_state()
  724. self.enter_Root_main_simulation_state_paused()
  725. def enterDefault_Root_main_breakpoint_manager(self):
  726. self.enter_Root_main_breakpoint_manager()
  727. self.enter_Root_main_breakpoint_manager_breakpoint_manage()
  728. def enterDefault_Root_main_listeners(self):
  729. self.enter_Root_main_listeners()
  730. self.enter_Root_main_listeners_listening()
  731. def enterDefault_Root_main_reset(self):
  732. self.enter_Root_main_reset()
  733. self.enter_Root_main_reset_reset()
  734. # Statechart transitions
  735. def generateCandidatesChildren_Root(self):
  736. if self.current_state[self.Root][0] == self.Root_initializing:
  737. return self.generateCandidates_Root_initializing()
  738. elif self.current_state[self.Root][0] == self.Root_main:
  739. return self.generateCandidates_Root_main()
  740. return False
  741. def generateCandidates_Root(self):
  742. if not self.combo_step.isArenaChanged(self.Root):
  743. return self.generateCandidatesChildren_Root()
  744. else:
  745. return True
  746. def generateCandidatesCurrent_Root_initializing(self):
  747. enabled_events = self.getEnabledEvents()
  748. self.small_step.addCandidate(self.transition_Root_initializing_1, [])
  749. return True
  750. return False
  751. def generateCandidates_Root_initializing(self):
  752. if not self.combo_step.isArenaChanged(self.Root_initializing):
  753. return self.generateCandidatesCurrent_Root_initializing()
  754. else:
  755. return True
  756. def transition_Root_initializing_1(self, parameters):
  757. self.exit_Root_initializing()
  758. # Direct connection
  759. if isinstance(self.model, CoupledDEVS):
  760. self.model.component_set = directConnect(self.model.component_set, self.listeners)
  761. self.model = RootDEVS(self.model.component_set, self.model.component_set, None)
  762. self.model.listeners = self.listeners
  763. for m in self.model.component_set:
  764. m.time_last = (-m.elapsed, 1)
  765. ta = m.timeAdvance()
  766. m.time_next = (m.time_last[0] + ta, 1)
  767. m.old_states = [(m.time_last, pickle.dumps(m.state))]
  768. elif isinstance(self.model, AtomicDEVS):
  769. for p in self.model.IPorts:
  770. p.routing_inline = []
  771. p.routing_outline = []
  772. for p in self.model.OPorts:
  773. p.routing_inline = []
  774. p.routing_outline = []
  775. self.model = RootDEVS([self.model], [self.model], None)
  776. self.model.time_last = (-self.model.elapsed, 1)
  777. ta = self.model.timeAdvance()
  778. self.model.time_next = (self.model.time_last[0] + ta, 1)
  779. # Fixed configuration options
  780. self.model.scheduler = Scheduler(self.model.component_set, 1e-6, len(self.model.component_set))
  781. self.time_next = self.model.scheduler.readFirst()
  782. # Cached values
  783. self.imminents = None
  784. self.outbag = None
  785. self.inbags = None
  786. self.transitioning = None
  787. self.new_states = None
  788. self.new_tn = None
  789. # Verbose trace file
  790. self.trace_file = None
  791. # Breakpoint management
  792. self.breakpoints = []
  793. # For a reset
  794. # self.save_model = {model: (model.elapsed, pickle.dumps(model.state, pickle.HIGHEST_PROTOCOL)) for model in self.model.component_set}
  795. # self.save_model = pickle.dumps(self.model, pickle.HIGHEST_PROTOCOL)
  796. self.transition_times = []
  797. self.interrupt_string = None
  798. self.combo_step.setArenaChanged(self.Root)
  799. self.enterDefault_Root_main()
  800. def generateCandidatesChildren_Root_main(self):
  801. branch_done = False
  802. branch_done = (self.generateCandidates_Root_main_injection_monitor() or branch_done)
  803. branch_done = (self.generateCandidates_Root_main_tracer_monitor() or branch_done)
  804. branch_done = (self.generateCandidates_Root_main_realtime_interrupt_monitor() or branch_done)
  805. branch_done = (self.generateCandidates_Root_main_simulation_flow() or branch_done)
  806. branch_done = (self.generateCandidates_Root_main_simulation_state() or branch_done)
  807. branch_done = (self.generateCandidates_Root_main_breakpoint_manager() or branch_done)
  808. branch_done = (self.generateCandidates_Root_main_listeners() or branch_done)
  809. branch_done = (self.generateCandidates_Root_main_reset() or branch_done)
  810. return branch_done
  811. def generateCandidates_Root_main(self):
  812. if not self.combo_step.isArenaChanged(self.Root_main):
  813. return self.generateCandidatesChildren_Root_main()
  814. else:
  815. return True
  816. def generateCandidatesChildren_Root_main_injection_monitor(self):
  817. if self.current_state[self.Root_main_injection_monitor][0] == self.Root_main_injection_monitor_inject:
  818. return self.generateCandidates_Root_main_injection_monitor_inject()
  819. return False
  820. def generateCandidates_Root_main_injection_monitor(self):
  821. if not self.combo_step.isArenaChanged(self.Root_main_injection_monitor):
  822. return self.generateCandidatesChildren_Root_main_injection_monitor()
  823. else:
  824. return True
  825. def generateCandidatesCurrent_Root_main_injection_monitor_inject(self):
  826. enabled_events = self.getEnabledEvents()
  827. for e in enabled_events:
  828. if (e.name == "inject") and (e.port == "request"):
  829. self.small_step.addCandidate(self.transition_Root_main_injection_monitor_inject_1, e.parameters)
  830. return True
  831. return False
  832. def generateCandidates_Root_main_injection_monitor_inject(self):
  833. if not self.combo_step.isArenaChanged(self.Root_main_injection_monitor_inject):
  834. return self.generateCandidatesCurrent_Root_main_injection_monitor_inject()
  835. else:
  836. return True
  837. def transition_Root_main_injection_monitor_inject_1(self, parameters):
  838. configuration = parameters[0]
  839. self.exit_Root_main_injection_monitor_inject()
  840. configuration["time"] = (configuration["time"], 1)
  841. self.inject_queue.append(configuration)
  842. self.inject_queue.sort(key=lambda i: i["time"])
  843. self.big_step.outputEvent(Event("inject_ok", "reply", []))
  844. self.combo_step.setArenaChanged(self.Root_main_injection_monitor)
  845. self.enter_Root_main_injection_monitor_inject()
  846. def generateCandidatesChildren_Root_main_tracer_monitor(self):
  847. if self.current_state[self.Root_main_tracer_monitor][0] == self.Root_main_tracer_monitor_trace:
  848. return self.generateCandidates_Root_main_tracer_monitor_trace()
  849. return False
  850. def generateCandidates_Root_main_tracer_monitor(self):
  851. if not self.combo_step.isArenaChanged(self.Root_main_tracer_monitor):
  852. return self.generateCandidatesChildren_Root_main_tracer_monitor()
  853. else:
  854. return True
  855. def generateCandidatesCurrent_Root_main_tracer_monitor_trace(self):
  856. enabled_events = self.getEnabledEvents()
  857. for e in enabled_events:
  858. if (e.name == "trace") and (e.port == "request"):
  859. self.small_step.addCandidate(self.transition_Root_main_tracer_monitor_trace_1, e.parameters)
  860. return True
  861. return False
  862. def generateCandidates_Root_main_tracer_monitor_trace(self):
  863. if not self.combo_step.isArenaChanged(self.Root_main_tracer_monitor_trace):
  864. return self.generateCandidatesCurrent_Root_main_tracer_monitor_trace()
  865. else:
  866. return True
  867. def transition_Root_main_tracer_monitor_trace_1(self, parameters):
  868. filename = parameters[0]
  869. self.exit_Root_main_tracer_monitor_trace()
  870. if filename is not None:
  871. self.trace_file = open(filename, 'w')
  872. else:
  873. self.trace_file = None
  874. self.big_step.outputEvent(Event("trace_config_ok", "reply", []))
  875. self.combo_step.setArenaChanged(self.Root_main_tracer_monitor)
  876. self.enter_Root_main_tracer_monitor_trace()
  877. def generateCandidatesChildren_Root_main_realtime_interrupt_monitor(self):
  878. if self.current_state[self.Root_main_realtime_interrupt_monitor][0] == self.Root_main_realtime_interrupt_monitor_realtime_interrupt:
  879. return self.generateCandidates_Root_main_realtime_interrupt_monitor_realtime_interrupt()
  880. return False
  881. def generateCandidates_Root_main_realtime_interrupt_monitor(self):
  882. if not self.combo_step.isArenaChanged(self.Root_main_realtime_interrupt_monitor):
  883. return self.generateCandidatesChildren_Root_main_realtime_interrupt_monitor()
  884. else:
  885. return True
  886. def generateCandidatesCurrent_Root_main_realtime_interrupt_monitor_realtime_interrupt(self):
  887. enabled_events = self.getEnabledEvents()
  888. for e in enabled_events:
  889. if (e.name == "realtime_interrupt") and (e.port == "request"):
  890. self.small_step.addCandidate(self.transition_Root_main_realtime_interrupt_monitor_realtime_interrupt_1, e.parameters)
  891. return True
  892. return False
  893. def generateCandidates_Root_main_realtime_interrupt_monitor_realtime_interrupt(self):
  894. if not self.combo_step.isArenaChanged(self.Root_main_realtime_interrupt_monitor_realtime_interrupt):
  895. return self.generateCandidatesCurrent_Root_main_realtime_interrupt_monitor_realtime_interrupt()
  896. else:
  897. return True
  898. def transition_Root_main_realtime_interrupt_monitor_realtime_interrupt_1(self, parameters):
  899. interrupt_string = parameters[0]
  900. self.exit_Root_main_realtime_interrupt_monitor_realtime_interrupt()
  901. self.interrupt_string = interrupt_string
  902. self.combo_step.setArenaChanged(self.Root_main_realtime_interrupt_monitor)
  903. self.enter_Root_main_realtime_interrupt_monitor_realtime_interrupt()
  904. def generateCandidatesChildren_Root_main_simulation_flow(self):
  905. if self.current_state[self.Root_main_simulation_flow][0] == self.Root_main_simulation_flow_initialize:
  906. return self.generateCandidates_Root_main_simulation_flow_initialize()
  907. elif self.current_state[self.Root_main_simulation_flow][0] == self.Root_main_simulation_flow_check_termination:
  908. return self.generateCandidates_Root_main_simulation_flow_check_termination()
  909. elif self.current_state[self.Root_main_simulation_flow][0] == self.Root_main_simulation_flow_do_simulation:
  910. return self.generateCandidates_Root_main_simulation_flow_do_simulation()
  911. return False
  912. def generateCandidates_Root_main_simulation_flow(self):
  913. if not self.combo_step.isArenaChanged(self.Root_main_simulation_flow):
  914. return self.generateCandidatesChildren_Root_main_simulation_flow()
  915. else:
  916. return True
  917. def generateCandidatesCurrent_Root_main_simulation_flow_initialize(self):
  918. enabled_events = self.getEnabledEvents()
  919. self.small_step.addCandidate(self.transition_Root_main_simulation_flow_initialize_1, [])
  920. return True
  921. return False
  922. def generateCandidates_Root_main_simulation_flow_initialize(self):
  923. if not self.combo_step.isArenaChanged(self.Root_main_simulation_flow_initialize):
  924. return self.generateCandidatesCurrent_Root_main_simulation_flow_initialize()
  925. else:
  926. return True
  927. def transition_Root_main_simulation_flow_initialize_1(self, parameters):
  928. self.exit_Root_main_simulation_flow_initialize()
  929. self.big_step.outputEvent(Event("all_states_reset", "reply", [self.simulation_time, {m.getModelFullName(): (m.time_next, m.state) for m in self.model.component_set}, self.structural_changes, self.breakpoints]))
  930. self.structural_changes = {}
  931. self.combo_step.setArenaChanged(self.Root_main_simulation_flow)
  932. self.enterDefault_Root_main_simulation_flow_check_termination()
  933. def generateCandidatesChildren_Root_main_simulation_flow_check_termination(self):
  934. if self.current_state[self.Root_main_simulation_flow_check_termination][0] == self.Root_main_simulation_flow_check_termination_workaround:
  935. return self.generateCandidates_Root_main_simulation_flow_check_termination_workaround()
  936. elif self.current_state[self.Root_main_simulation_flow_check_termination][0] == self.Root_main_simulation_flow_check_termination_wait:
  937. return self.generateCandidates_Root_main_simulation_flow_check_termination_wait()
  938. elif self.current_state[self.Root_main_simulation_flow_check_termination][0] == self.Root_main_simulation_flow_check_termination_small_step_check:
  939. return self.generateCandidates_Root_main_simulation_flow_check_termination_small_step_check()
  940. elif self.current_state[self.Root_main_simulation_flow_check_termination][0] == self.Root_main_simulation_flow_check_termination_check_termination:
  941. return self.generateCandidates_Root_main_simulation_flow_check_termination_check_termination()
  942. return False
  943. def generateCandidates_Root_main_simulation_flow_check_termination(self):
  944. if not self.combo_step.isArenaChanged(self.Root_main_simulation_flow_check_termination):
  945. return self.generateCandidatesChildren_Root_main_simulation_flow_check_termination()
  946. else:
  947. return True
  948. def generateCandidatesCurrent_Root_main_simulation_flow_check_termination_workaround(self):
  949. enabled_events = self.getEnabledEvents()
  950. for e in enabled_events:
  951. if e.name == "_0after":
  952. self.small_step.addCandidate(self.transition_Root_main_simulation_flow_check_termination_workaround_1, e.parameters)
  953. return True
  954. return False
  955. def generateCandidates_Root_main_simulation_flow_check_termination_workaround(self):
  956. if not self.combo_step.isArenaChanged(self.Root_main_simulation_flow_check_termination_workaround):
  957. return self.generateCandidatesCurrent_Root_main_simulation_flow_check_termination_workaround()
  958. else:
  959. return True
  960. def transition_Root_main_simulation_flow_check_termination_workaround_1(self, parameters):
  961. self.exit_Root_main_simulation_flow_check_termination_workaround()
  962. self.combo_step.setArenaChanged(self.Root_main_simulation_flow_check_termination)
  963. self.enter_Root_main_simulation_flow_check_termination_check_termination()
  964. def generateCandidatesCurrent_Root_main_simulation_flow_check_termination_wait(self):
  965. enabled_events = self.getEnabledEvents()
  966. if self.inState([self.Root_main_simulation_state_paused]):
  967. self.small_step.addCandidate(self.transition_Root_main_simulation_flow_check_termination_wait_1, [])
  968. return True
  969. enabled_events = self.getEnabledEvents()
  970. for e in enabled_events:
  971. if e.name == "_1after":
  972. self.small_step.addCandidate(self.transition_Root_main_simulation_flow_check_termination_wait_2, e.parameters)
  973. return True
  974. return False
  975. def generateCandidates_Root_main_simulation_flow_check_termination_wait(self):
  976. if not self.combo_step.isArenaChanged(self.Root_main_simulation_flow_check_termination_wait):
  977. return self.generateCandidatesCurrent_Root_main_simulation_flow_check_termination_wait()
  978. else:
  979. return True
  980. def transition_Root_main_simulation_flow_check_termination_wait_1(self, parameters):
  981. self.exit_Root_main_simulation_flow_check_termination_wait()
  982. self.combo_step.setArenaChanged(self.Root_main_simulation_flow_check_termination)
  983. self.enter_Root_main_simulation_flow_check_termination_check_termination()
  984. def transition_Root_main_simulation_flow_check_termination_wait_2(self, parameters):
  985. self.exit_Root_main_simulation_flow_check_termination_wait()
  986. self.combo_step.setArenaChanged(self.Root_main_simulation_flow_check_termination)
  987. self.enter_Root_main_simulation_flow_check_termination_check_termination()
  988. def generateCandidatesCurrent_Root_main_simulation_flow_check_termination_small_step_check(self):
  989. enabled_events = self.getEnabledEvents()
  990. if self.should_terminate(False) == -2:
  991. self.small_step.addCandidate(self.transition_Root_main_simulation_flow_check_termination_small_step_check_1, [])
  992. return True
  993. enabled_events = self.getEnabledEvents()
  994. if self.should_terminate(False) == -1:
  995. self.small_step.addCandidate(self.transition_Root_main_simulation_flow_check_termination_small_step_check_2, [])
  996. return True
  997. enabled_events = self.getEnabledEvents()
  998. if self.should_terminate(False) > -1:
  999. self.small_step.addCandidate(self.transition_Root_main_simulation_flow_check_termination_small_step_check_3, [])
  1000. return True
  1001. return False
  1002. def generateCandidates_Root_main_simulation_flow_check_termination_small_step_check(self):
  1003. if not self.combo_step.isArenaChanged(self.Root_main_simulation_flow_check_termination_small_step_check):
  1004. return self.generateCandidatesCurrent_Root_main_simulation_flow_check_termination_small_step_check()
  1005. else:
  1006. return True
  1007. def transition_Root_main_simulation_flow_check_termination_small_step_check_1(self, parameters):
  1008. self.exit_Root_main_simulation_flow_check_termination()
  1009. self.combo_step.setArenaChanged(self.Root_main_simulation_flow)
  1010. self.enterDefault_Root_main_simulation_flow_do_simulation()
  1011. def transition_Root_main_simulation_flow_check_termination_small_step_check_2(self, parameters):
  1012. self.exit_Root_main_simulation_flow_check_termination_small_step_check()
  1013. self.raiseInternalEvent(Event("termination_condition", None, []))
  1014. self.combo_step.setArenaChanged(self.Root_main_simulation_flow_check_termination)
  1015. self.enter_Root_main_simulation_flow_check_termination_check_termination()
  1016. def transition_Root_main_simulation_flow_check_termination_small_step_check_3(self, parameters):
  1017. self.exit_Root_main_simulation_flow_check_termination_small_step_check()
  1018. breakpoint_id = self.process_breakpoints(False)
  1019. self.big_step.outputEvent(Event("breakpoint_triggered", "reply", [breakpoint_id, self.serialize('transitioning', self.transitioning), self.serialize('outbag', self.outbag), self.serialize('inbags', self.inbags)]))
  1020. self.raiseInternalEvent(Event("termination_condition", None, []))
  1021. self.combo_step.setArenaChanged(self.Root_main_simulation_flow_check_termination)
  1022. self.enter_Root_main_simulation_flow_check_termination_check_termination()
  1023. def generateCandidatesCurrent_Root_main_simulation_flow_check_termination_check_termination(self):
  1024. enabled_events = self.getEnabledEvents()
  1025. if self.inState([self.Root_main_simulation_state_continuous]) and (self.should_terminate(False) == -2):
  1026. self.small_step.addCandidate(self.transition_Root_main_simulation_flow_check_termination_check_termination_1, [])
  1027. return True
  1028. enabled_events = self.getEnabledEvents()
  1029. if self.inState([self.Root_main_simulation_state_big_step]) and (self.should_terminate(False) == -2):
  1030. self.small_step.addCandidate(self.transition_Root_main_simulation_flow_check_termination_check_termination_2, [])
  1031. return True
  1032. enabled_events = self.getEnabledEvents()
  1033. if self.inState([self.Root_main_simulation_state_realtime]) and (self.should_terminate(True) == -2) and (self.the_time > 0.0):
  1034. self.small_step.addCandidate(self.transition_Root_main_simulation_flow_check_termination_check_termination_3, [])
  1035. return True
  1036. enabled_events = self.getEnabledEvents()
  1037. if self.inState([self.Root_main_simulation_state_realtime]) and (self.should_terminate(True) == -2) and (self.the_time <= 0.0):
  1038. self.small_step.addCandidate(self.transition_Root_main_simulation_flow_check_termination_check_termination_4, [])
  1039. return True
  1040. enabled_events = self.getEnabledEvents()
  1041. if (not self.inState([self.Root_main_simulation_state_paused]) and self.inState([self.Root_main_simulation_state_realtime]) and (self.should_terminate(True) == -1)):
  1042. self.small_step.addCandidate(self.transition_Root_main_simulation_flow_check_termination_check_termination_5, [])
  1043. return True
  1044. enabled_events = self.getEnabledEvents()
  1045. if (not self.inState([self.Root_main_simulation_state_paused]) and not self.inState([self.Root_main_simulation_state_realtime]) and (self.should_terminate(False) == -1)):
  1046. self.small_step.addCandidate(self.transition_Root_main_simulation_flow_check_termination_check_termination_6, [])
  1047. return True
  1048. enabled_events = self.getEnabledEvents()
  1049. if (not self.inState([self.Root_main_simulation_state_paused])) and self.inState([self.Root_main_simulation_state_realtime]) and (self.should_terminate(True) > -1):
  1050. self.small_step.addCandidate(self.transition_Root_main_simulation_flow_check_termination_check_termination_7, [])
  1051. return True
  1052. enabled_events = self.getEnabledEvents()
  1053. if (not self.inState([self.Root_main_simulation_state_paused])) and not self.inState([self.Root_main_simulation_state_realtime]) and (self.should_terminate(False) > -1):
  1054. self.small_step.addCandidate(self.transition_Root_main_simulation_flow_check_termination_check_termination_8, [])
  1055. return True
  1056. enabled_events = self.getEnabledEvents()
  1057. for e in enabled_events:
  1058. if (e.name == "small_step") and (e.port == "request"):
  1059. self.small_step.addCandidate(self.transition_Root_main_simulation_flow_check_termination_check_termination_9, e.parameters)
  1060. return True
  1061. enabled_events = self.getEnabledEvents()
  1062. for e in enabled_events:
  1063. if (e.name == "god_event") and (e.port == "request"):
  1064. parameters = e.parameters
  1065. configuration = parameters[0]
  1066. if self.inState([self.Root_main_simulation_state_paused]):
  1067. self.small_step.addCandidate(self.transition_Root_main_simulation_flow_check_termination_check_termination_10, e.parameters)
  1068. return True
  1069. return False
  1070. def generateCandidates_Root_main_simulation_flow_check_termination_check_termination(self):
  1071. if not self.combo_step.isArenaChanged(self.Root_main_simulation_flow_check_termination_check_termination):
  1072. return self.generateCandidatesCurrent_Root_main_simulation_flow_check_termination_check_termination()
  1073. else:
  1074. return True
  1075. def transition_Root_main_simulation_flow_check_termination_check_termination_1(self, parameters):
  1076. self.exit_Root_main_simulation_flow_check_termination()
  1077. self.combo_step.setArenaChanged(self.Root_main_simulation_flow)
  1078. self.enterDefault_Root_main_simulation_flow_do_simulation()
  1079. def transition_Root_main_simulation_flow_check_termination_check_termination_2(self, parameters):
  1080. self.exit_Root_main_simulation_flow_check_termination()
  1081. self.combo_step.setArenaChanged(self.Root_main_simulation_flow)
  1082. self.enterDefault_Root_main_simulation_flow_do_simulation()
  1083. def transition_Root_main_simulation_flow_check_termination_check_termination_3(self, parameters):
  1084. self.exit_Root_main_simulation_flow_check_termination_check_termination()
  1085. self.combo_step.setArenaChanged(self.Root_main_simulation_flow_check_termination)
  1086. self.enter_Root_main_simulation_flow_check_termination_wait()
  1087. def transition_Root_main_simulation_flow_check_termination_check_termination_4(self, parameters):
  1088. self.exit_Root_main_simulation_flow_check_termination()
  1089. self.combo_step.setArenaChanged(self.Root_main_simulation_flow)
  1090. self.enterDefault_Root_main_simulation_flow_do_simulation()
  1091. def transition_Root_main_simulation_flow_check_termination_check_termination_5(self, parameters):
  1092. self.exit_Root_main_simulation_flow_check_termination_check_termination()
  1093. self.raiseInternalEvent(Event("termination_condition", None, []))
  1094. self.combo_step.setArenaChanged(self.Root_main_simulation_flow_check_termination)
  1095. self.enter_Root_main_simulation_flow_check_termination_workaround()
  1096. def transition_Root_main_simulation_flow_check_termination_check_termination_6(self, parameters):
  1097. self.exit_Root_main_simulation_flow_check_termination_check_termination()
  1098. self.raiseInternalEvent(Event("termination_condition", None, []))
  1099. self.combo_step.setArenaChanged(self.Root_main_simulation_flow_check_termination)
  1100. self.enter_Root_main_simulation_flow_check_termination_workaround()
  1101. def transition_Root_main_simulation_flow_check_termination_check_termination_7(self, parameters):
  1102. self.exit_Root_main_simulation_flow_check_termination_check_termination()
  1103. breakpoint_id = self.process_breakpoints(True)
  1104. self.big_step.outputEvent(Event("breakpoint_triggered", "reply", [breakpoint_id, self.serialize('transitioning', self.transitioning), self.serialize('outbag', self.outbag), self.serialize('inbags', self.inbags)]))
  1105. self.raiseInternalEvent(Event("termination_condition", None, []))
  1106. self.combo_step.setArenaChanged(self.Root_main_simulation_flow_check_termination)
  1107. self.enter_Root_main_simulation_flow_check_termination_workaround()
  1108. def transition_Root_main_simulation_flow_check_termination_check_termination_8(self, parameters):
  1109. self.exit_Root_main_simulation_flow_check_termination_check_termination()
  1110. breakpoint_id = self.process_breakpoints(False)
  1111. self.big_step.outputEvent(Event("breakpoint_triggered", "reply", [breakpoint_id, self.serialize('transitioning', self.transitioning), self.serialize('outbag', self.outbag), self.serialize('inbags', self.inbags)]))
  1112. self.raiseInternalEvent(Event("termination_condition", None, []))
  1113. self.combo_step.setArenaChanged(self.Root_main_simulation_flow_check_termination)
  1114. self.enter_Root_main_simulation_flow_check_termination_workaround()
  1115. def transition_Root_main_simulation_flow_check_termination_check_termination_9(self, parameters):
  1116. configuration = parameters[0]
  1117. self.exit_Root_main_simulation_flow_check_termination_check_termination()
  1118. self.parse_options(configuration)
  1119. self.listeners = {getattr(self.root_model, portname): listener for (portname, listener) in self.listeners_by_string.iteritems()}
  1120. if not (len(self.listeners) == len(self.model.listeners)):
  1121. self.model.listeners = self.listeners
  1122. self.model.component_set = directConnect(self.model.models, self.listeners)
  1123. self.combo_step.setArenaChanged(self.Root_main_simulation_flow_check_termination)
  1124. self.enter_Root_main_simulation_flow_check_termination_small_step_check()
  1125. def transition_Root_main_simulation_flow_check_termination_check_termination_10(self, parameters):
  1126. configuration = parameters[0]
  1127. self.exit_Root_main_simulation_flow_check_termination_check_termination()
  1128. modelname = configuration["model"]
  1129. state_attribute = configuration["attribute"]
  1130. new_value = configuration["value"]
  1131. model = self.find_model_with_name(modelname)
  1132. setattr(model.state, state_attribute, new_value)
  1133. # Call the timeadvance method again and compute new ta
  1134. ta = model.timeAdvance()
  1135. model.time_next = (model.time_last[0] + ta, 1 if ta else (model.time_last[1] + 1))
  1136. self.model.scheduler.massReschedule([model])
  1137. # self.simulation_time = self.model.scheduler.readFirst()
  1138. self.big_step.outputEvent(Event("god_event_ok", "reply", [{model.getModelFullName(): model.state}]))
  1139. self.big_step.outputEvent(Event("new_tn", "reply", [self.simulation_time, {model.getModelFullName(): model.time_next}]))
  1140. self.combo_step.setArenaChanged(self.Root_main_simulation_flow_check_termination)
  1141. self.enter_Root_main_simulation_flow_check_termination_workaround()
  1142. def generateCandidatesChildren_Root_main_simulation_flow_do_simulation(self):
  1143. if self.current_state[self.Root_main_simulation_flow_do_simulation][0] == self.Root_main_simulation_flow_do_simulation_init:
  1144. return self.generateCandidates_Root_main_simulation_flow_do_simulation_init()
  1145. elif self.current_state[self.Root_main_simulation_flow_do_simulation][0] == self.Root_main_simulation_flow_do_simulation_found_internal_imminents:
  1146. return self.generateCandidates_Root_main_simulation_flow_do_simulation_found_internal_imminents()
  1147. elif self.current_state[self.Root_main_simulation_flow_do_simulation][0] == self.Root_main_simulation_flow_do_simulation_selected_imminent:
  1148. return self.generateCandidates_Root_main_simulation_flow_do_simulation_selected_imminent()
  1149. elif self.current_state[self.Root_main_simulation_flow_do_simulation][0] == self.Root_main_simulation_flow_do_simulation_computed_outputfunction:
  1150. return self.generateCandidates_Root_main_simulation_flow_do_simulation_computed_outputfunction()
  1151. elif self.current_state[self.Root_main_simulation_flow_do_simulation][0] == self.Root_main_simulation_flow_do_simulation_routed_messages:
  1152. return self.generateCandidates_Root_main_simulation_flow_do_simulation_routed_messages()
  1153. elif self.current_state[self.Root_main_simulation_flow_do_simulation][0] == self.Root_main_simulation_flow_do_simulation_found_all_imminents:
  1154. return self.generateCandidates_Root_main_simulation_flow_do_simulation_found_all_imminents()
  1155. elif self.current_state[self.Root_main_simulation_flow_do_simulation][0] == self.Root_main_simulation_flow_do_simulation_computed_transitions:
  1156. return self.generateCandidates_Root_main_simulation_flow_do_simulation_computed_transitions()
  1157. elif self.current_state[self.Root_main_simulation_flow_do_simulation][0] == self.Root_main_simulation_flow_do_simulation_computed_ta:
  1158. return self.generateCandidates_Root_main_simulation_flow_do_simulation_computed_ta()
  1159. return False
  1160. def generateCandidates_Root_main_simulation_flow_do_simulation(self):
  1161. if not self.combo_step.isArenaChanged(self.Root_main_simulation_flow_do_simulation):
  1162. return self.generateCandidatesChildren_Root_main_simulation_flow_do_simulation()
  1163. else:
  1164. return True
  1165. def generateCandidatesCurrent_Root_main_simulation_flow_do_simulation_init(self):
  1166. enabled_events = self.getEnabledEvents()
  1167. if not self.inState([self.Root_main_simulation_state_paused]):
  1168. self.small_step.addCandidate(self.transition_Root_main_simulation_flow_do_simulation_init_1, [])
  1169. return True
  1170. enabled_events = self.getEnabledEvents()
  1171. if self.inState([self.Root_main_simulation_state_paused]):
  1172. self.small_step.addCandidate(self.transition_Root_main_simulation_flow_do_simulation_init_2, [])
  1173. return True
  1174. return False
  1175. def generateCandidates_Root_main_simulation_flow_do_simulation_init(self):
  1176. if not self.combo_step.isArenaChanged(self.Root_main_simulation_flow_do_simulation_init):
  1177. return self.generateCandidatesCurrent_Root_main_simulation_flow_do_simulation_init()
  1178. else:
  1179. return True
  1180. def transition_Root_main_simulation_flow_do_simulation_init_1(self, parameters):
  1181. self.exit_Root_main_simulation_flow_do_simulation_init()
  1182. self.combo_step.setArenaChanged(self.Root_main_simulation_flow_do_simulation)
  1183. self.enter_Root_main_simulation_flow_do_simulation_found_internal_imminents()
  1184. def transition_Root_main_simulation_flow_do_simulation_init_2(self, parameters):
  1185. self.exit_Root_main_simulation_flow_do_simulation_init()
  1186. self.big_step.outputEvent(Event("imminents", "reply", [self.simulation_time, self.serialize('imminents', self.imminents)]))
  1187. self.combo_step.setArenaChanged(self.Root_main_simulation_flow_do_simulation)
  1188. self.enter_Root_main_simulation_flow_do_simulation_found_internal_imminents()
  1189. def generateCandidatesCurrent_Root_main_simulation_flow_do_simulation_found_internal_imminents(self):
  1190. enabled_events = self.getEnabledEvents()
  1191. if not self.inState([self.Root_main_simulation_state_paused]):
  1192. self.small_step.addCandidate(self.transition_Root_main_simulation_flow_do_simulation_found_internal_imminents_1, [])
  1193. return True
  1194. enabled_events = self.getEnabledEvents()
  1195. for e in enabled_events:
  1196. if (e.name == "small_step") and (e.port == "request"):
  1197. self.small_step.addCandidate(self.transition_Root_main_simulation_flow_do_simulation_found_internal_imminents_2, e.parameters)
  1198. return True
  1199. return False
  1200. def generateCandidates_Root_main_simulation_flow_do_simulation_found_internal_imminents(self):
  1201. if not self.combo_step.isArenaChanged(self.Root_main_simulation_flow_do_simulation_found_internal_imminents):
  1202. return self.generateCandidatesCurrent_Root_main_simulation_flow_do_simulation_found_internal_imminents()
  1203. else:
  1204. return True
  1205. def transition_Root_main_simulation_flow_do_simulation_found_internal_imminents_1(self, parameters):
  1206. self.exit_Root_main_simulation_flow_do_simulation_found_internal_imminents()
  1207. self.combo_step.setArenaChanged(self.Root_main_simulation_flow_do_simulation)
  1208. self.enter_Root_main_simulation_flow_do_simulation_selected_imminent()
  1209. def transition_Root_main_simulation_flow_do_simulation_found_internal_imminents_2(self, parameters):
  1210. self.exit_Root_main_simulation_flow_do_simulation_found_internal_imminents()
  1211. self.big_step.outputEvent(Event("selected_imminent", "reply", [self.simulation_time, self.serialize('imminent', self.imminent)]))
  1212. self.combo_step.setArenaChanged(self.Root_main_simulation_flow_do_simulation)
  1213. self.enter_Root_main_simulation_flow_do_simulation_selected_imminent()
  1214. def generateCandidatesCurrent_Root_main_simulation_flow_do_simulation_selected_imminent(self):
  1215. enabled_events = self.getEnabledEvents()
  1216. if not self.inState([self.Root_main_simulation_state_paused]):
  1217. self.small_step.addCandidate(self.transition_Root_main_simulation_flow_do_simulation_selected_imminent_1, [])
  1218. return True
  1219. enabled_events = self.getEnabledEvents()
  1220. for e in enabled_events:
  1221. if (e.name == "small_step") and (e.port == "request"):
  1222. self.small_step.addCandidate(self.transition_Root_main_simulation_flow_do_simulation_selected_imminent_2, e.parameters)
  1223. return True
  1224. return False
  1225. def generateCandidates_Root_main_simulation_flow_do_simulation_selected_imminent(self):
  1226. if not self.combo_step.isArenaChanged(self.Root_main_simulation_flow_do_simulation_selected_imminent):
  1227. return self.generateCandidatesCurrent_Root_main_simulation_flow_do_simulation_selected_imminent()
  1228. else:
  1229. return True
  1230. def transition_Root_main_simulation_flow_do_simulation_selected_imminent_1(self, parameters):
  1231. self.exit_Root_main_simulation_flow_do_simulation_selected_imminent()
  1232. self.combo_step.setArenaChanged(self.Root_main_simulation_flow_do_simulation)
  1233. self.enter_Root_main_simulation_flow_do_simulation_computed_outputfunction()
  1234. def transition_Root_main_simulation_flow_do_simulation_selected_imminent_2(self, parameters):
  1235. self.exit_Root_main_simulation_flow_do_simulation_selected_imminent()
  1236. self.big_step.outputEvent(Event("outbag", "reply", [self.simulation_time, self.serialize('outbag', self.outbag)]))
  1237. self.combo_step.setArenaChanged(self.Root_main_simulation_flow_do_simulation)
  1238. self.enter_Root_main_simulation_flow_do_simulation_computed_outputfunction()
  1239. def generateCandidatesCurrent_Root_main_simulation_flow_do_simulation_computed_outputfunction(self):
  1240. enabled_events = self.getEnabledEvents()
  1241. if not self.inState([self.Root_main_simulation_state_paused]):
  1242. self.small_step.addCandidate(self.transition_Root_main_simulation_flow_do_simulation_computed_outputfunction_1, [])
  1243. return True
  1244. enabled_events = self.getEnabledEvents()
  1245. for e in enabled_events:
  1246. if (e.name == "small_step") and (e.port == "request"):
  1247. self.small_step.addCandidate(self.transition_Root_main_simulation_flow_do_simulation_computed_outputfunction_2, e.parameters)
  1248. return True
  1249. return False
  1250. def generateCandidates_Root_main_simulation_flow_do_simulation_computed_outputfunction(self):
  1251. if not self.combo_step.isArenaChanged(self.Root_main_simulation_flow_do_simulation_computed_outputfunction):
  1252. return self.generateCandidatesCurrent_Root_main_simulation_flow_do_simulation_computed_outputfunction()
  1253. else:
  1254. return True
  1255. def transition_Root_main_simulation_flow_do_simulation_computed_outputfunction_1(self, parameters):
  1256. self.exit_Root_main_simulation_flow_do_simulation_computed_outputfunction()
  1257. self.combo_step.setArenaChanged(self.Root_main_simulation_flow_do_simulation)
  1258. self.enter_Root_main_simulation_flow_do_simulation_routed_messages()
  1259. def transition_Root_main_simulation_flow_do_simulation_computed_outputfunction_2(self, parameters):
  1260. self.exit_Root_main_simulation_flow_do_simulation_computed_outputfunction()
  1261. self.big_step.outputEvent(Event("inbags", "reply", [self.simulation_time, self.serialize('inbags', self.inbags)]))
  1262. self.combo_step.setArenaChanged(self.Root_main_simulation_flow_do_simulation)
  1263. self.enter_Root_main_simulation_flow_do_simulation_routed_messages()
  1264. def generateCandidatesCurrent_Root_main_simulation_flow_do_simulation_routed_messages(self):
  1265. enabled_events = self.getEnabledEvents()
  1266. if not self.inState([self.Root_main_simulation_state_paused]):
  1267. self.small_step.addCandidate(self.transition_Root_main_simulation_flow_do_simulation_routed_messages_1, [])
  1268. return True
  1269. enabled_events = self.getEnabledEvents()
  1270. for e in enabled_events:
  1271. if (e.name == "small_step") and (e.port == "request"):
  1272. self.small_step.addCandidate(self.transition_Root_main_simulation_flow_do_simulation_routed_messages_2, e.parameters)
  1273. return True
  1274. return False
  1275. def generateCandidates_Root_main_simulation_flow_do_simulation_routed_messages(self):
  1276. if not self.combo_step.isArenaChanged(self.Root_main_simulation_flow_do_simulation_routed_messages):
  1277. return self.generateCandidatesCurrent_Root_main_simulation_flow_do_simulation_routed_messages()
  1278. else:
  1279. return True
  1280. def transition_Root_main_simulation_flow_do_simulation_routed_messages_1(self, parameters):
  1281. self.exit_Root_main_simulation_flow_do_simulation_routed_messages()
  1282. self.combo_step.setArenaChanged(self.Root_main_simulation_flow_do_simulation)
  1283. self.enter_Root_main_simulation_flow_do_simulation_found_all_imminents()
  1284. def transition_Root_main_simulation_flow_do_simulation_routed_messages_2(self, parameters):
  1285. self.exit_Root_main_simulation_flow_do_simulation_routed_messages()
  1286. self.big_step.outputEvent(Event("transitioning", "reply", [self.simulation_time, self.serialize('transitioning', self.transitioning)]))
  1287. self.combo_step.setArenaChanged(self.Root_main_simulation_flow_do_simulation)
  1288. self.enter_Root_main_simulation_flow_do_simulation_found_all_imminents()
  1289. def generateCandidatesCurrent_Root_main_simulation_flow_do_simulation_found_all_imminents(self):
  1290. enabled_events = self.getEnabledEvents()
  1291. if not self.inState([self.Root_main_simulation_state_paused]):
  1292. self.small_step.addCandidate(self.transition_Root_main_simulation_flow_do_simulation_found_all_imminents_1, [])
  1293. return True
  1294. enabled_events = self.getEnabledEvents()
  1295. for e in enabled_events:
  1296. if (e.name == "small_step") and (e.port == "request"):
  1297. self.small_step.addCandidate(self.transition_Root_main_simulation_flow_do_simulation_found_all_imminents_2, e.parameters)
  1298. return True
  1299. return False
  1300. def generateCandidates_Root_main_simulation_flow_do_simulation_found_all_imminents(self):
  1301. if not self.combo_step.isArenaChanged(self.Root_main_simulation_flow_do_simulation_found_all_imminents):
  1302. return self.generateCandidatesCurrent_Root_main_simulation_flow_do_simulation_found_all_imminents()
  1303. else:
  1304. return True
  1305. def transition_Root_main_simulation_flow_do_simulation_found_all_imminents_1(self, parameters):
  1306. self.exit_Root_main_simulation_flow_do_simulation_found_all_imminents()
  1307. self.combo_step.setArenaChanged(self.Root_main_simulation_flow_do_simulation)
  1308. self.enter_Root_main_simulation_flow_do_simulation_computed_transitions()
  1309. def transition_Root_main_simulation_flow_do_simulation_found_all_imminents_2(self, parameters):
  1310. self.exit_Root_main_simulation_flow_do_simulation_found_all_imminents()
  1311. self.big_step.outputEvent(Event("new_internal_states", "reply", [self.simulation_time, self.serialize('new_states', self.new_states)]))
  1312. self.combo_step.setArenaChanged(self.Root_main_simulation_flow_do_simulation)
  1313. self.enter_Root_main_simulation_flow_do_simulation_computed_transitions()
  1314. def generateCandidatesCurrent_Root_main_simulation_flow_do_simulation_computed_transitions(self):
  1315. enabled_events = self.getEnabledEvents()
  1316. if not self.inState([self.Root_main_simulation_state_paused]):
  1317. self.small_step.addCandidate(self.transition_Root_main_simulation_flow_do_simulation_computed_transitions_1, [])
  1318. return True
  1319. enabled_events = self.getEnabledEvents()
  1320. for e in enabled_events:
  1321. if (e.name == "small_step") and (e.port == "request"):
  1322. self.small_step.addCandidate(self.transition_Root_main_simulation_flow_do_simulation_computed_transitions_2, e.parameters)
  1323. return True
  1324. return False
  1325. def generateCandidates_Root_main_simulation_flow_do_simulation_computed_transitions(self):
  1326. if not self.combo_step.isArenaChanged(self.Root_main_simulation_flow_do_simulation_computed_transitions):
  1327. return self.generateCandidatesCurrent_Root_main_simulation_flow_do_simulation_computed_transitions()
  1328. else:
  1329. return True
  1330. def transition_Root_main_simulation_flow_do_simulation_computed_transitions_1(self, parameters):
  1331. self.exit_Root_main_simulation_flow_do_simulation_computed_transitions()
  1332. self.combo_step.setArenaChanged(self.Root_main_simulation_flow_do_simulation)
  1333. self.enter_Root_main_simulation_flow_do_simulation_computed_ta()
  1334. def transition_Root_main_simulation_flow_do_simulation_computed_transitions_2(self, parameters):
  1335. self.exit_Root_main_simulation_flow_do_simulation_computed_transitions()
  1336. self.big_step.outputEvent(Event("new_tn", "reply", [self.simulation_time, self.serialize('new_tn', self.new_tn)]))
  1337. self.combo_step.setArenaChanged(self.Root_main_simulation_flow_do_simulation)
  1338. self.enter_Root_main_simulation_flow_do_simulation_computed_ta()
  1339. def generateCandidatesCurrent_Root_main_simulation_flow_do_simulation_computed_ta(self):
  1340. enabled_events = self.getEnabledEvents()
  1341. if self.inState([self.Root_main_simulation_state_continuous]):
  1342. self.small_step.addCandidate(self.transition_Root_main_simulation_flow_do_simulation_computed_ta_1, [])
  1343. return True
  1344. enabled_events = self.getEnabledEvents()
  1345. if self.inState([self.Root_main_simulation_state_realtime]) or self.inState([self.Root_main_simulation_state_big_step]):
  1346. self.small_step.addCandidate(self.transition_Root_main_simulation_flow_do_simulation_computed_ta_2, [])
  1347. return True
  1348. enabled_events = self.getEnabledEvents()
  1349. for e in enabled_events:
  1350. if (e.name == "small_step") and (e.port == "request"):
  1351. self.small_step.addCandidate(self.transition_Root_main_simulation_flow_do_simulation_computed_ta_3, e.parameters)
  1352. return True
  1353. return False
  1354. def generateCandidates_Root_main_simulation_flow_do_simulation_computed_ta(self):
  1355. if not self.combo_step.isArenaChanged(self.Root_main_simulation_flow_do_simulation_computed_ta):
  1356. return self.generateCandidatesCurrent_Root_main_simulation_flow_do_simulation_computed_ta()
  1357. else:
  1358. return True
  1359. def transition_Root_main_simulation_flow_do_simulation_computed_ta_1(self, parameters):
  1360. self.exit_Root_main_simulation_flow_do_simulation()
  1361. self.combo_step.setArenaChanged(self.Root_main_simulation_flow)
  1362. self.enterDefault_Root_main_simulation_flow_check_termination()
  1363. def transition_Root_main_simulation_flow_do_simulation_computed_ta_2(self, parameters):
  1364. self.exit_Root_main_simulation_flow_do_simulation()
  1365. self.raiseInternalEvent(Event("big_step_done", None, []))
  1366. self.big_step.outputEvent(Event("new_states", "reply", [self.simulation_time, self.serialize('new_states', self.new_states), self.serialize('new_tn', self.new_tn), self.structural_changes]))
  1367. self.structural_changes = {}
  1368. self.combo_step.setArenaChanged(self.Root_main_simulation_flow)
  1369. self.enterDefault_Root_main_simulation_flow_check_termination()
  1370. def transition_Root_main_simulation_flow_do_simulation_computed_ta_3(self, parameters):
  1371. self.exit_Root_main_simulation_flow_do_simulation()
  1372. self.big_step.outputEvent(Event("structural_changes", "reply", [self.simulation_time, self.structural_changes]))
  1373. self.structural_changes = {}
  1374. self.combo_step.setArenaChanged(self.Root_main_simulation_flow)
  1375. self.enterDefault_Root_main_simulation_flow_check_termination()
  1376. def generateCandidatesChildren_Root_main_simulation_state(self):
  1377. if self.current_state[self.Root_main_simulation_state][0] == self.Root_main_simulation_state_paused:
  1378. return self.generateCandidates_Root_main_simulation_state_paused()
  1379. elif self.current_state[self.Root_main_simulation_state][0] == self.Root_main_simulation_state_continuous:
  1380. return self.generateCandidates_Root_main_simulation_state_continuous()
  1381. elif self.current_state[self.Root_main_simulation_state][0] == self.Root_main_simulation_state_realtime:
  1382. return self.generateCandidates_Root_main_simulation_state_realtime()
  1383. elif self.current_state[self.Root_main_simulation_state][0] == self.Root_main_simulation_state_big_step:
  1384. return self.generateCandidates_Root_main_simulation_state_big_step()
  1385. return False
  1386. def generateCandidates_Root_main_simulation_state(self):
  1387. if not self.combo_step.isArenaChanged(self.Root_main_simulation_state):
  1388. return self.generateCandidatesChildren_Root_main_simulation_state()
  1389. else:
  1390. return True
  1391. def generateCandidatesCurrent_Root_main_simulation_state_paused(self):
  1392. enabled_events = self.getEnabledEvents()
  1393. for e in enabled_events:
  1394. if (e.name == "simulate") and (e.port == "request"):
  1395. self.small_step.addCandidate(self.transition_Root_main_simulation_state_paused_1, e.parameters)
  1396. return True
  1397. enabled_events = self.getEnabledEvents()
  1398. for e in enabled_events:
  1399. if (e.name == "realtime") and (e.port == "request"):
  1400. self.small_step.addCandidate(self.transition_Root_main_simulation_state_paused_2, e.parameters)
  1401. return True
  1402. enabled_events = self.getEnabledEvents()
  1403. for e in enabled_events:
  1404. if (e.name == "big_step") and (e.port == "request"):
  1405. self.small_step.addCandidate(self.transition_Root_main_simulation_state_paused_3, e.parameters)
  1406. return True
  1407. return False
  1408. def generateCandidates_Root_main_simulation_state_paused(self):
  1409. if not self.combo_step.isArenaChanged(self.Root_main_simulation_state_paused):
  1410. return self.generateCandidatesCurrent_Root_main_simulation_state_paused()
  1411. else:
  1412. return True
  1413. def transition_Root_main_simulation_state_paused_1(self, parameters):
  1414. configuration = parameters[0]
  1415. self.exit_Root_main_simulation_state_paused()
  1416. self.parse_options(configuration)
  1417. self.combo_step.setArenaChanged(self.Root_main_simulation_state)
  1418. self.enter_Root_main_simulation_state_continuous()
  1419. def transition_Root_main_simulation_state_paused_2(self, parameters):
  1420. configuration = parameters[0]
  1421. self.exit_Root_main_simulation_state_paused()
  1422. self.parse_options(configuration)
  1423. self.combo_step.setArenaChanged(self.Root_main_simulation_state)
  1424. self.enter_Root_main_simulation_state_realtime()
  1425. def transition_Root_main_simulation_state_paused_3(self, parameters):
  1426. configuration = parameters[0]
  1427. self.exit_Root_main_simulation_state_paused()
  1428. self.parse_options(configuration)
  1429. self.combo_step.setArenaChanged(self.Root_main_simulation_state)
  1430. self.enter_Root_main_simulation_state_big_step()
  1431. def generateCandidatesCurrent_Root_main_simulation_state_continuous(self):
  1432. enabled_events = self.getEnabledEvents()
  1433. for e in enabled_events:
  1434. if (e.name == "pause") and (e.port == "request"):
  1435. self.small_step.addCandidate(self.transition_Root_main_simulation_state_continuous_1, e.parameters)
  1436. return True
  1437. enabled_events = self.getEnabledEvents()
  1438. for e in enabled_events:
  1439. if e.name == "termination_condition":
  1440. self.small_step.addCandidate(self.transition_Root_main_simulation_state_continuous_2, e.parameters)
  1441. return True
  1442. return False
  1443. def generateCandidates_Root_main_simulation_state_continuous(self):
  1444. if not self.combo_step.isArenaChanged(self.Root_main_simulation_state_continuous):
  1445. return self.generateCandidatesCurrent_Root_main_simulation_state_continuous()
  1446. else:
  1447. return True
  1448. def transition_Root_main_simulation_state_continuous_1(self, parameters):
  1449. self.exit_Root_main_simulation_state_continuous()
  1450. # Just override termination condition
  1451. self.termination_condition = lambda i, j, k : True
  1452. self.termination_time = None
  1453. self.combo_step.setArenaChanged(self.Root_main_simulation_state)
  1454. self.enter_Root_main_simulation_state_continuous()
  1455. def transition_Root_main_simulation_state_continuous_2(self, parameters):
  1456. self.exit_Root_main_simulation_state_continuous()
  1457. self.big_step.outputEvent(Event("terminate", "reply", [self.simulation_time]))
  1458. self.flush_file()
  1459. self.big_step.outputEvent(Event("all_states", "reply", [self.simulation_time, {m.getModelFullName(): (m.time_next, m.state) for m in self.model.component_set}, self.structural_changes]))
  1460. self.structural_changes = {}
  1461. self.combo_step.setArenaChanged(self.Root_main_simulation_state)
  1462. self.enter_Root_main_simulation_state_paused()
  1463. def generateCandidatesCurrent_Root_main_simulation_state_realtime(self):
  1464. enabled_events = self.getEnabledEvents()
  1465. for e in enabled_events:
  1466. if (e.name == "pause") and (e.port == "request"):
  1467. self.small_step.addCandidate(self.transition_Root_main_simulation_state_realtime_1, e.parameters)
  1468. return True
  1469. enabled_events = self.getEnabledEvents()
  1470. for e in enabled_events:
  1471. if e.name == "termination_condition":
  1472. self.small_step.addCandidate(self.transition_Root_main_simulation_state_realtime_2, e.parameters)
  1473. return True
  1474. return False
  1475. def generateCandidates_Root_main_simulation_state_realtime(self):
  1476. if not self.combo_step.isArenaChanged(self.Root_main_simulation_state_realtime):
  1477. return self.generateCandidatesCurrent_Root_main_simulation_state_realtime()
  1478. else:
  1479. return True
  1480. def transition_Root_main_simulation_state_realtime_1(self, parameters):
  1481. self.exit_Root_main_simulation_state_realtime()
  1482. # Just override termination condition
  1483. self.termination_condition = lambda i, j, k : True
  1484. self.termination_time = None
  1485. self.combo_step.setArenaChanged(self.Root_main_simulation_state)
  1486. self.enter_Root_main_simulation_state_realtime()
  1487. def transition_Root_main_simulation_state_realtime_2(self, parameters):
  1488. self.exit_Root_main_simulation_state_realtime()
  1489. self.big_step.outputEvent(Event("terminate", "reply", [self.simulation_time]))
  1490. self.flush_file()
  1491. self.combo_step.setArenaChanged(self.Root_main_simulation_state)
  1492. self.enter_Root_main_simulation_state_paused()
  1493. def generateCandidatesCurrent_Root_main_simulation_state_big_step(self):
  1494. enabled_events = self.getEnabledEvents()
  1495. for e in enabled_events:
  1496. if e.name == "big_step_done":
  1497. self.small_step.addCandidate(self.transition_Root_main_simulation_state_big_step_1, e.parameters)
  1498. return True
  1499. enabled_events = self.getEnabledEvents()
  1500. for e in enabled_events:
  1501. if e.name == "termination_condition":
  1502. self.small_step.addCandidate(self.transition_Root_main_simulation_state_big_step_2, e.parameters)
  1503. return True
  1504. return False
  1505. def generateCandidates_Root_main_simulation_state_big_step(self):
  1506. if not self.combo_step.isArenaChanged(self.Root_main_simulation_state_big_step):
  1507. return self.generateCandidatesCurrent_Root_main_simulation_state_big_step()
  1508. else:
  1509. return True
  1510. def transition_Root_main_simulation_state_big_step_1(self, parameters):
  1511. self.exit_Root_main_simulation_state_big_step()
  1512. self.combo_step.setArenaChanged(self.Root_main_simulation_state)
  1513. self.enter_Root_main_simulation_state_paused()
  1514. def transition_Root_main_simulation_state_big_step_2(self, parameters):
  1515. self.exit_Root_main_simulation_state_big_step()
  1516. self.big_step.outputEvent(Event("terminate", "reply", [self.simulation_time]))
  1517. self.flush_file()
  1518. self.combo_step.setArenaChanged(self.Root_main_simulation_state)
  1519. self.enter_Root_main_simulation_state_paused()
  1520. def generateCandidatesChildren_Root_main_breakpoint_manager(self):
  1521. if self.current_state[self.Root_main_breakpoint_manager][0] == self.Root_main_breakpoint_manager_breakpoint_manage:
  1522. return self.generateCandidates_Root_main_breakpoint_manager_breakpoint_manage()
  1523. return False
  1524. def generateCandidates_Root_main_breakpoint_manager(self):
  1525. if not self.combo_step.isArenaChanged(self.Root_main_breakpoint_manager):
  1526. return self.generateCandidatesChildren_Root_main_breakpoint_manager()
  1527. else:
  1528. return True
  1529. def generateCandidatesCurrent_Root_main_breakpoint_manager_breakpoint_manage(self):
  1530. enabled_events = self.getEnabledEvents()
  1531. for e in enabled_events:
  1532. if (e.name == "add_breakpoint") and (e.port == "request"):
  1533. self.small_step.addCandidate(self.transition_Root_main_breakpoint_manager_breakpoint_manage_1, e.parameters)
  1534. return True
  1535. enabled_events = self.getEnabledEvents()
  1536. for e in enabled_events:
  1537. if (e.name == "del_breakpoint") and (e.port == "request"):
  1538. self.small_step.addCandidate(self.transition_Root_main_breakpoint_manager_breakpoint_manage_2, e.parameters)
  1539. return True
  1540. enabled_events = self.getEnabledEvents()
  1541. for e in enabled_events:
  1542. if (e.name == "toggle_breakpoint") and (e.port == "request"):
  1543. self.small_step.addCandidate(self.transition_Root_main_breakpoint_manager_breakpoint_manage_3, e.parameters)
  1544. return True
  1545. return False
  1546. def generateCandidates_Root_main_breakpoint_manager_breakpoint_manage(self):
  1547. if not self.combo_step.isArenaChanged(self.Root_main_breakpoint_manager_breakpoint_manage):
  1548. return self.generateCandidatesCurrent_Root_main_breakpoint_manager_breakpoint_manage()
  1549. else:
  1550. return True
  1551. def transition_Root_main_breakpoint_manager_breakpoint_manage_1(self, parameters):
  1552. breakpoint_id = parameters[0]
  1553. function = parameters[1]
  1554. enabled = parameters[2]
  1555. disable_on_trigger = parameters[3]
  1556. self.exit_Root_main_breakpoint_manager_breakpoint_manage()
  1557. # TODO: report to the user if a breakpoint is invalid (trying to include in scope and reporting any exceptions).
  1558. self.breakpoints.append(Breakpoint(breakpoint_id, function, enabled, disable_on_trigger))
  1559. self.combo_step.setArenaChanged(self.Root_main_breakpoint_manager)
  1560. self.enter_Root_main_breakpoint_manager_breakpoint_manage()
  1561. def transition_Root_main_breakpoint_manager_breakpoint_manage_2(self, parameters):
  1562. del_breakpoint_id = parameters[0]
  1563. self.exit_Root_main_breakpoint_manager_breakpoint_manage()
  1564. self.breakpoints = [breakpoint for breakpoint in self.breakpoints if breakpoint.id != del_breakpoint_id]
  1565. self.combo_step.setArenaChanged(self.Root_main_breakpoint_manager)
  1566. self.enter_Root_main_breakpoint_manager_breakpoint_manage()
  1567. def transition_Root_main_breakpoint_manager_breakpoint_manage_3(self, parameters):
  1568. breakpoint_id = parameters[0]
  1569. enabled = parameters[1]
  1570. self.exit_Root_main_breakpoint_manager_breakpoint_manage()
  1571. for breakpoint in self.breakpoints:
  1572. if breakpoint.id == breakpoint_id:
  1573. breakpoint.enabled = enabled
  1574. break
  1575. self.combo_step.setArenaChanged(self.Root_main_breakpoint_manager)
  1576. self.enter_Root_main_breakpoint_manager_breakpoint_manage()
  1577. def generateCandidatesChildren_Root_main_listeners(self):
  1578. if self.current_state[self.Root_main_listeners][0] == self.Root_main_listeners_listening:
  1579. return self.generateCandidates_Root_main_listeners_listening()
  1580. return False
  1581. def generateCandidates_Root_main_listeners(self):
  1582. if not self.combo_step.isArenaChanged(self.Root_main_listeners):
  1583. return self.generateCandidatesChildren_Root_main_listeners()
  1584. else:
  1585. return True
  1586. def generateCandidatesCurrent_Root_main_listeners_listening(self):
  1587. enabled_events = self.getEnabledEvents()
  1588. for e in enabled_events:
  1589. if e.name == "set_listen_ports":
  1590. self.small_step.addCandidate(self.transition_Root_main_listeners_listening_1, e.parameters)
  1591. return True
  1592. return False
  1593. def generateCandidates_Root_main_listeners_listening(self):
  1594. if not self.combo_step.isArenaChanged(self.Root_main_listeners_listening):
  1595. return self.generateCandidatesCurrent_Root_main_listeners_listening()
  1596. else:
  1597. return True
  1598. def transition_Root_main_listeners_listening_1(self, parameters):
  1599. port = parameters[0]
  1600. function = parameters[1]
  1601. self.exit_Root_main_listeners_listening()
  1602. self.listeners_by_string[port] = function
  1603. self.combo_step.setArenaChanged(self.Root_main_listeners)
  1604. self.enter_Root_main_listeners_listening()
  1605. def generateCandidatesChildren_Root_main_reset(self):
  1606. if self.current_state[self.Root_main_reset][0] == self.Root_main_reset_reset:
  1607. return self.generateCandidates_Root_main_reset_reset()
  1608. return False
  1609. def generateCandidates_Root_main_reset(self):
  1610. if not self.combo_step.isArenaChanged(self.Root_main_reset):
  1611. return self.generateCandidatesChildren_Root_main_reset()
  1612. else:
  1613. return True
  1614. def generateCandidatesCurrent_Root_main_reset_reset(self):
  1615. enabled_events = self.getEnabledEvents()
  1616. for e in enabled_events:
  1617. if (e.name == "reset") and (e.port == "request"):
  1618. self.small_step.addCandidate(self.transition_Root_main_reset_reset_1, e.parameters)
  1619. return True
  1620. return False
  1621. def generateCandidates_Root_main_reset_reset(self):
  1622. if not self.combo_step.isArenaChanged(self.Root_main_reset_reset):
  1623. return self.generateCandidatesCurrent_Root_main_reset_reset()
  1624. else:
  1625. return True
  1626. def transition_Root_main_reset_reset_1(self, parameters):
  1627. self.exit_Root_main()
  1628. self.model = pickle.loads(self.save_model)
  1629. self.initialize_simulation()
  1630. self.combo_step.setArenaChanged(self.Root)
  1631. self.enter_Root_initializing()
  1632. # Generate transition candidates for current small step
  1633. def generateCandidates(self):
  1634. self.generateCandidates_Root()
  1635. class ObjectManager(ObjectManagerBase):
  1636. def __init__(self, controller):
  1637. ObjectManagerBase.__init__(self, controller)
  1638. def instantiate(self, class_name, construct_params):
  1639. if class_name == "SCCDSimulator":
  1640. instance = SCCDSimulator(self.controller, construct_params[0])
  1641. instance.associations = {}
  1642. return instance
  1643. class Controller(ThreadsControllerBase):
  1644. def __init__(self, model, keep_running = None):
  1645. if keep_running == None: keep_running = True
  1646. ThreadsControllerBase.__init__(self, ObjectManager(self), keep_running)
  1647. self.addInputPort("request")
  1648. self.addOutputPort("reply")
  1649. self.object_manager.createInstance("SCCDSimulator", [model])