Simon Van Mierlo 9 лет назад
Родитель
Сommit
f91b117c3e
23 измененных файлов с 3353 добавлено и 690 удалено
  1. 0 198
      debugging_fsa_cbd_composition/.keepme
  2. 612 461
      debugging_fsa_cbd_composition/cbdsimulator/cbdsim_debugging.py.svg
  3. 16 16
      debugging_fsa_cbd_composition/cbdsimulator/cbdsim_debugging.py.xml
  4. 3 3
      debugging_fsa_cbd_composition/cbdsimulator/plot.html
  5. 0 0
      debugging_fsa_cbd_composition/cbdsimulator/run_debug.py
  6. 0 0
      debugging_fsa_cbd_composition/cbdsimulator/run_sim.py
  7. 12 12
      debugging_fsa_cbd_composition/cbdsimulator/target.py
  8. 17 0
      debugging_fsa_cbd_composition/fsasimulator/.project
  9. 12 0
      debugging_fsa_cbd_composition/fsasimulator/.pydevproject
  10. 82 0
      debugging_fsa_cbd_composition/fsasimulator/DEPRECATED_fsasimulator.sccd
  11. 106 0
      debugging_fsa_cbd_composition/fsasimulator/DEPRECATED_fsasimulator_hierarchical.sccd
  12. 102 0
      debugging_fsa_cbd_composition/fsasimulator/DEPRECATED_fsasimulator_normal.sccd
  13. 6 0
      debugging_fsa_cbd_composition/fsasimulator/DEPRECATED_generateSCCD.bat
  14. 222 0
      debugging_fsa_cbd_composition/fsasimulator/fsaclasses.py
  15. 17 0
      debugging_fsa_cbd_composition/fsasimulator/fsasimulator runner.py.launch
  16. 241 0
      debugging_fsa_cbd_composition/fsasimulator/fsasimulator.py
  17. 330 0
      debugging_fsa_cbd_composition/fsasimulator/fsasimulator_debugging.py
  18. 487 0
      debugging_fsa_cbd_composition/fsasimulator/fsasimulator_debugging.py.xml
  19. 147 0
      debugging_fsa_cbd_composition/fsasimulator/fsasimulator_hierarchical.xml
  20. 6 0
      debugging_fsa_cbd_composition/fsasimulator/generateSCCD.bat
  21. 128 0
      debugging_fsa_cbd_composition/fsasimulator/run_debug.py
  22. 35 0
      debugging_fsa_cbd_composition/fsasimulator/run_sim.py
  23. 772 0
      debugging_fsa_cbd_composition/fsasimulator/target.py

+ 0 - 198
debugging_fsa_cbd_composition/.keepme

@@ -1,198 +0,0 @@
-# ---> Python
-# Byte-compiled / optimized / DLL files
-__pycache__/
-*.py[cod]
-*$py.class
-
-# C extensions
-*.so
-
-# Distribution / packaging
-.Python
-env/
-build/
-develop-eggs/
-dist/
-downloads/
-eggs/
-.eggs/
-lib/
-lib64/
-parts/
-sdist/
-var/
-*.egg-info/
-.installed.cfg
-*.egg
-
-# PyInstaller
-#  Usually these files are written by a python script from a template
-#  before PyInstaller builds the exe, so as to inject date/other infos into it.
-*.manifest
-*.spec
-
-# Installer logs
-pip-log.txt
-pip-delete-this-directory.txt
-
-# Unit test / coverage reports
-htmlcov/
-.tox/
-.coverage
-.coverage.*
-.cache
-nosetests.xml
-coverage.xml
-*,cover
-
-# Translations
-*.mo
-*.pot
-
-# Django stuff:
-*.log
-
-# Sphinx documentation
-docs/_build/
-
-# PyBuilder
-target/
-
-# ---> TeX
-## Core latex/pdflatex auxiliary files:
-*.aux
-*.lof
-*.log
-*.lot
-*.fls
-*.out
-*.toc
-
-## Intermediate documents:
-*.dvi
-*-converted-to.*
-# these rules might exclude image files for figures etc.
-# *.ps
-# *.eps
-# *.pdf
-
-## Bibliography auxiliary files (bibtex/biblatex/biber):
-*.bbl
-*.bcf
-*.blg
-*-blx.aux
-*-blx.bib
-*.brf
-*.run.xml
-
-## Build tool auxiliary files:
-*.fdb_latexmk
-*.synctex
-*.synctex.gz
-*.synctex.gz(busy)
-*.pdfsync
-
-## Auxiliary and intermediate files from other packages:
-
-
-# algorithms
-*.alg
-*.loa
-
-# achemso
-acs-*.bib
-
-# amsthm
-*.thm
-
-# beamer
-*.nav
-*.snm
-*.vrb
-
-#(e)ledmac/(e)ledpar
-*.end
-*.[1-9]
-*.[1-9][0-9]
-*.[1-9][0-9][0-9]
-*.[1-9]R
-*.[1-9][0-9]R
-*.[1-9][0-9][0-9]R
-*.eledsec[1-9]
-*.eledsec[1-9]R
-*.eledsec[1-9][0-9]
-*.eledsec[1-9][0-9]R
-*.eledsec[1-9][0-9][0-9]
-*.eledsec[1-9][0-9][0-9]R
-
-# glossaries
-*.acn
-*.acr
-*.glg
-*.glo
-*.gls
-
-# gnuplottex
-*-gnuplottex-*
-
-# hyperref
-*.brf
-
-# knitr
-*-concordance.tex
-*.tikz
-*-tikzDictionary
-
-# listings
-*.lol
-
-# makeidx
-*.idx
-*.ilg
-*.ind
-*.ist
-
-# minitoc
-*.maf
-*.mtc
-*.mtc[0-9]
-*.mtc[1-9][0-9]
-
-# minted
-_minted*
-*.pyg
-
-# morewrites
-*.mw
-
-# mylatexformat
-*.fmt
-
-# nomencl
-*.nlo
-
-# sagetex
-*.sagetex.sage
-*.sagetex.py
-*.sagetex.scmd
-
-# sympy
-*.sout
-*.sympy
-sympy-plots-for-*.tex/
-
-# TikZ & PGF
-*.dpth
-*.md5
-*.auxlock
-
-# todonotes
-*.tdo
-
-# xindy
-*.xdy
-
-# WinEdt
-*.bak
-*.sav
-

Разница между файлами не показана из-за своего большого размера
+ 612 - 461
debugging_fsa_cbd_composition/cbdsimulator/cbdsim_debugging.py.svg


+ 16 - 16
debugging_fsa_cbd_composition/cbdsimulator/cbdsim_debugging.py.xml

@@ -1,7 +1,7 @@
 <?xml version="1.0" ?>
 <diagram name="CBDSimulator" author="Sadaf Mustafiz and Claudio Gomes and Simon Van Mierlo">
     <description>
-        SCCD HUTN model of a CBD simulator
+        A debuggeable CBD simulator.
     </description>
     
     <inport name="user_input" />
@@ -42,6 +42,20 @@
             ]]>
             </body>
         </method>
+        <method name="currentComponentIsCycle">
+            <body>
+            <![CDATA[
+                return self.cbdController.componentIsCycle(self.strongComponentList[self.currentCompIdx], self.depGraph)
+            ]]>
+            </body>
+        </method>
+        <method name="hasNextStrongComponent">
+            <body>
+            <![CDATA[
+                return (self.currentCompIdx + 1) < len(self.strongComponentList)
+            ]]>
+            </body>
+        </method>
         <method name="initialize">
             <body>
             <![CDATA[
@@ -79,20 +93,6 @@
             ]]>
             </body>
         </method>
-        <method name="currentComponentIsCycle">
-            <body>
-            <![CDATA[
-                return self.cbdController.componentIsCycle(self.strongComponentList[self.currentCompIdx], self.depGraph)
-            ]]>
-            </body>
-        </method>
-        <method name="hasNextStrongComponent">
-            <body>
-            <![CDATA[
-                return (self.currentCompIdx + 1) < len(self.strongComponentList)
-            ]]>
-            </body>
-        </method>
         <method name="finalize">
             <body>
             <![CDATA[
@@ -203,7 +203,7 @@
             ]]>
             </body>
         </method>
-        <scxml initial="Main" internal_event_lifeline="next_combo_step">
+        <scxml initial="Main" final="SimulationComplete" internal_event_lifeline="next_combo_step">
             <parallel id="Main">
                 <state id="SimulationState" initial="Paused">
                     <state id="Paused">

Разница между файлами не показана из-за своего большого размера
+ 3 - 3
debugging_fsa_cbd_composition/cbdsimulator/plot.html


debugging_fsa_cbd_composition/cbdsimulator/runner.py → debugging_fsa_cbd_composition/cbdsimulator/run_debug.py


debugging_fsa_cbd_composition/cbdsimulator/run_cbd_sim.py → debugging_fsa_cbd_composition/cbdsimulator/run_sim.py


+ 12 - 12
debugging_fsa_cbd_composition/cbdsimulator/target.py

@@ -1,12 +1,12 @@
 """
 Generated by Statechart compiler by Glenn De Jonghe, Joeri Exelmans, Simon Van Mierlo, and Yentl Van Tendeloo (for the inspiration)
 
-Date:   Wed Oct 12 12:49:32 2016
+Date:   Wed Oct 12 16:59:32 2016
 
 Model author: Sadaf Mustafiz and Claudio Gomes and Simon Van Mierlo
 Model name:   CBDSimulator
 Model description:
-SCCD HUTN model of a CBD simulator
+A debuggeable CBD simulator.
 """
 
 from sccd.runtime.statecharts_core import *
@@ -60,6 +60,16 @@ class CBDSimulator(RuntimeClassBase):
         pass
     
     
+    # user defined method
+    def currentComponentIsCycle(self):
+        return self.cbdController.componentIsCycle(self.strongComponentList[self.currentCompIdx], self.depGraph)
+    
+    
+    # user defined method
+    def hasNextStrongComponent(self):
+        return (self.currentCompIdx + 1) < len(self.strongComponentList)
+    
+    
     # user defined method
     def initialize(self):
         self.iteration = 0
@@ -89,16 +99,6 @@ class CBDSimulator(RuntimeClassBase):
         self.time_next = self.clock + self.delta
     
     
-    # user defined method
-    def currentComponentIsCycle(self):
-        return self.cbdController.componentIsCycle(self.strongComponentList[self.currentCompIdx], self.depGraph)
-    
-    
-    # user defined method
-    def hasNextStrongComponent(self):
-        return (self.currentCompIdx + 1) < len(self.strongComponentList)
-    
-    
     # user defined method
     def finalize(self):
         from bokeh.plotting import figure, output_file, show    

+ 17 - 0
debugging_fsa_cbd_composition/fsasimulator/.project

@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+	<name>fsasimulator</name>
+	<comment></comment>
+	<projects>
+	</projects>
+	<buildSpec>
+		<buildCommand>
+			<name>org.python.pydev.PyDevBuilder</name>
+			<arguments>
+			</arguments>
+		</buildCommand>
+	</buildSpec>
+	<natures>
+		<nature>org.python.pydev.pythonNature</nature>
+	</natures>
+</projectDescription>

+ 12 - 0
debugging_fsa_cbd_composition/fsasimulator/.pydevproject

@@ -0,0 +1,12 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<?eclipse-pydev version="1.0"?><pydev_project>
+<pydev_property name="org.python.pydev.PYTHON_PROJECT_VERSION">python 2.7</pydev_property>
+<pydev_property name="org.python.pydev.PYTHON_PROJECT_INTERPRETER">Default</pydev_property>
+<pydev_pathproperty name="org.python.pydev.PROJECT_SOURCE_PATH">
+<path>/${PROJECT_DIR_NAME}</path>
+</pydev_pathproperty>
+
+<pydev_pathproperty name="org.python.pydev.PROJECT_EXTERNAL_SOURCE_PATH">
+<path>C:\Users\clagms\Source Control\Git_SCCD\src\build\lib</path>
+</pydev_pathproperty>
+</pydev_project>

+ 82 - 0
debugging_fsa_cbd_composition/fsasimulator/DEPRECATED_fsasimulator.sccd

@@ -0,0 +1,82 @@
+Diagram(name = 'FSASimulator',
+		author = 'Sadaf Mustafiz and Bruno Barroca and Claudio Gomes',
+		description = 'An FSA simulator written in SCCD. It supports after and events.'):
+	Top {
+		import fsaclasses
+	}
+
+	Class(name = 'FSASimulator', default = True):
+		Attribute(name = 'timestep')
+		Attribute(name = 'elapsed')
+		Attribute(name = 'currentState')
+		Attribute(name = 'logicalTime')
+		Attribute(name = 'currentEvent')
+		Attribute(name = 'selectedTransition')
+		Attribute(name = 'eventList')
+		Attribute(name = 'model')
+
+		Constructor(amodel, events) {
+			self.model = amodel
+			self.eventList = events
+		}
+		
+		Method getInputEventAt(time) {
+			return self.eventList->getInputAt(time)
+		}
+		
+		Method processEvent(event) {
+			if (event != None):
+				self.eventList->popEvent(event)
+				event.processed = True
+			end
+		}
+
+		StateMachine:
+			initial = 'Start'
+			final = 'End'
+			State('Start'):
+				Transition(target='../Check'):
+					Actions {
+						self.logicalTime = 0
+						self.elapsed = 0
+						self.timestep = 1.0
+						self.currentState = self.model.initialState
+					}
+			State('Check'):
+				Transition(target='../Processing'):
+					guard = { self.currentState.final == False }
+					Actions {
+						print('going to process... ')
+					}
+				Transition(target='../End'):
+					guard = { self.currentState.final == True }
+					Actions {
+						print('going to end... ')
+					}
+				OnEnter {
+					self.currentEvent = self->getInputEventAt(self.logicalTime)
+					self.selectedTransition = self.model->getTransitionFrom(self.currentState, self.currentEvent, self.elapsed)
+				}
+			State('Processing'):
+				Transition(target='../Check'):
+					guard = {self.selectedTransition != None}
+					Actions {
+						self.currentState = self.selectedTransition.target
+						self.elapsed = 0
+						self->processEvent(self.currentEvent)
+						
+						print("changing to state: ")
+						print(self.currentState->getName())
+						print(self.logicalTime)
+						print(self.elapsed)
+					}
+				Transition(target='../Check'):
+					guard = {self.selectedTransition == None}
+					Actions {
+						self.logicalTime = self.logicalTime + self.timestep
+						self.elapsed = self.elapsed + self.timestep
+						print(self.logicalTime)
+						print(self.elapsed)
+					}
+
+			State('End')

+ 106 - 0
debugging_fsa_cbd_composition/fsasimulator/DEPRECATED_fsasimulator_hierarchical.sccd

@@ -0,0 +1,106 @@
+Diagram(name = 'FSASimulator',
+		author = 'Sadaf Mustafiz and Bruno Barroca and Claudio Gomes',
+		description = 'An FSA simulator written in SCCD. It supports after and events.'):
+	Top {
+		import fsaclasses
+	}
+
+	Class(name = 'FSASimulator', default = True):
+		Attribute(name = 'timestep')
+		Attribute(name = 'elapsed')
+		Attribute(name = 'currentState')
+		Attribute(name = 'logicalTime')
+		Attribute(name = 'currentEvent')
+		Attribute(name = 'selectedTransition')
+		Attribute(name = 'eventList')
+		Attribute(name = 'model')
+		Attribute(name = 'super_step_completed')
+
+		Constructor(amodel, events) {
+			self.model = amodel
+			self.eventList = events
+		}
+		
+		Method getInputEventAt(time) {
+			return self.eventList->getInputAt(time)
+		}
+		
+		Method processEvent(event) {
+			if (event != None):
+				self.eventList->popEvent(event)
+				event.processed = True
+			end
+		}
+
+		StateMachine:
+			initial = 'Started'
+			final = 'End'
+			State('Started'):
+				Transition(target='../Initialized'):
+					Actions {
+						print('Going to Initialized... ')
+						self.logicalTime = 0
+						self.elapsed = 0
+						self.timestep = 1.0
+						self.currentState = self.model.initialState
+					}
+			State('Initialized'):
+				Transition(target='../CheckTermination'):
+					Actions {
+						print('Going to MacroStepProcessed... ')
+					}
+			State('CheckTermination'):
+				initial = 'MacroStepProcessed'
+				State('MacroStepProcessed'):
+					Transition(target='../../DoSimulation'):
+						guard = { not self.currentState.final }
+						Actions {
+							print('Going to DoSimulation and reading events... ')
+							self.currentEvent = self->getInputEventAt(self.logicalTime)
+							self.selectedTransition = self.model->getTransitionFrom(self.currentState, self.currentEvent, self.elapsed)
+							print(self.currentEvent)
+							print(self.selectedTransition)
+						}
+					Transition(target='../../End'):
+						guard = { self.currentState.final }
+						Actions {
+							print('Going to End... ')
+						}
+			State('DoSimulation'):
+				initial = 'MacroStepPrepared'
+				State('MacroStepPrepared'):
+					Transition(target='../MicroStepProcessed'):
+						Actions {
+							print('Going to MicroStepProcessed... ')
+						}
+				State('MicroStepProcessed'):
+					Transition(target='../../CheckTermination'):
+						guard = { self.selectedTransition == None }
+						Actions {
+							print('Going to CheckTermination and advancing time... ')
+							self.logicalTime = self.logicalTime + self.timestep
+							self.elapsed = self.elapsed + self.timestep
+							print(self.logicalTime)
+							print(self.elapsed)
+						}
+					Transition(target='../MicroStepPrepared'):
+						guard = { self.selectedTransition != None }
+						Actions {
+							print('Going to MicroStepPrepared... ')
+						}
+				State('MicroStepPrepared'):
+					Transition(target='../MicroStepProcessed'):
+						Actions {
+							print('Going to MicroStepProcessed, taking transition and reading events... ')
+							print('Transition to be taken: ' + str(self.selectedTransition))
+							self.currentState = self.selectedTransition.target
+							self.elapsed = 0
+							self->processEvent(self.currentEvent)
+							print('New state: ' + str(self.currentState))
+							
+							self.currentEvent = self->getInputEventAt(self.logicalTime)
+							self.selectedTransition = self.model->getTransitionFrom(self.currentState, self.currentEvent, self.elapsed)
+							print(self.currentEvent)
+							print(self.selectedTransition)
+						}
+			State('End')

+ 102 - 0
debugging_fsa_cbd_composition/fsasimulator/DEPRECATED_fsasimulator_normal.sccd

@@ -0,0 +1,102 @@
+Diagram(name = 'FSASimulator',
+		author = 'Sadaf Mustafiz and Bruno Barroca and Claudio Gomes',
+		description = 'An FSA simulator written in SCCD. It supports after and events.'):
+	Top {
+		import fsaclasses
+	}
+
+	Class(name = 'FSASimulator', default = True):
+		Attribute(name = 'timestep')
+		Attribute(name = 'elapsed')
+		Attribute(name = 'currentState')
+		Attribute(name = 'logicalTime')
+		Attribute(name = 'currentEvent')
+		Attribute(name = 'selectedTransition')
+		Attribute(name = 'eventList')
+		Attribute(name = 'model')
+		Attribute(name = 'super_step_completed')
+
+		Constructor(amodel, events) {
+			self.model = amodel
+			self.eventList = events
+		}
+		
+		Method getInputEventAt(time) {
+			return self.eventList->getInputAt(time)
+		}
+		
+		Method processEvent(event) {
+			if (event != None):
+				self.eventList->popEvent(event)
+				event.processed = True
+			end
+		}
+
+		StateMachine:
+			initial = 'Started'
+			final = 'End'
+			State('Started'):
+				Transition(target='../Initialized'):
+					Actions {
+						print('Going to Initialized... ')
+						self.logicalTime = 0
+						self.elapsed = 0
+						self.timestep = 1.0
+						self.currentState = self.model.initialState
+					}
+			State('Initialized'):
+				Transition(target='../MacroStepProcessed'):
+					Actions {
+						print('Going to MacroStepProcessed... ')
+					}
+			State('MacroStepProcessed'):
+				Transition(target='../MacroStepPrepared'):
+					guard = { not self.currentState.final }
+					Actions {
+						print('Going to MacroStepPrepared and reading events... ')
+						self.currentEvent = self->getInputEventAt(self.logicalTime)
+						self.selectedTransition = self.model->getTransitionFrom(self.currentState, self.currentEvent, self.elapsed)
+						print(self.currentEvent)
+						print(self.selectedTransition)
+					}
+				Transition(target='../End'):
+					guard = { self.currentState.final }
+					Actions {
+						print('Going to End... ')
+					}
+			State('MacroStepPrepared'):
+				Transition(target='../MicroStepProcessed'):
+					Actions {
+						print('Going to MicroStepProcessed... ')
+					}
+			State('MicroStepProcessed'):
+				Transition(target='../MacroStepProcessed'):
+					guard = { self.selectedTransition == None }
+					Actions {
+						print('Going to MacroStepProcessed and advancing time... ')
+						self.logicalTime = self.logicalTime + self.timestep
+						self.elapsed = self.elapsed + self.timestep
+						print(self.logicalTime)
+						print(self.elapsed)
+					}
+				Transition(target='../MicroStepPrepared'):
+					guard = { self.selectedTransition != None }
+					Actions {
+						print('Going to MicroStepPrepared... ')
+					}
+			State('MicroStepPrepared'):
+				Transition(target='../MicroStepProcessed'):
+					Actions {
+						print('Going to MicroStepProcessed, taking transition and reading events... ')
+						print('Transition to be taken: ' + str(self.selectedTransition))
+						self.currentState = self.selectedTransition.target
+						self.elapsed = 0
+						self->processEvent(self.currentEvent)
+						print('New state: ' + str(self.currentState))
+						
+						self.currentEvent = self->getInputEventAt(self.logicalTime)
+						self.selectedTransition = self.model->getTransitionFrom(self.currentState, self.currentEvent, self.elapsed)
+						print(self.currentEvent)
+						print(self.selectedTransition)
+					}
+			State('End')

+ 6 - 0
debugging_fsa_cbd_composition/fsasimulator/DEPRECATED_generateSCCD.bat

@@ -0,0 +1,6 @@
+@ECHO OFF
+setlocal
+set PYTHONPATH=C:\Users\clagms\Source Control\Git_SCCD\src\build\lib;C:\Users\clagms\Source Control\SVN_MvK
+python "C:\Users\clagms\Source Control\Git_SCCD\textualnotations\sccdtnc.py" "C:\Users\clagms\Source Control\Git_MLE\fsa_cbd_composition\fsasimulator\DEPRECATED_fsasimulator_hierarchical.sccd" -o "C:\Users\clagms\Source Control\Git_MLE\fsa_cbd_composition\fsasimulator\fsasimulator.py"
+endlocal
+pause

+ 222 - 0
debugging_fsa_cbd_composition/fsasimulator/fsaclasses.py

@@ -0,0 +1,222 @@
+import numpy
+from operator import attrgetter
+
+############### runtime classes
+
+class RunTimeEvent:
+    def __init__(self, name, time):
+        self.name = name
+        self.time = time
+        self.processed = False
+
+class Events:
+    def __init__(self, events):
+        self.events = sorted(events, key=attrgetter('time'))
+    
+    '''
+    Returns the most recent event with the timestamp smaller than time.
+    '''
+    def getInputAt(self,time):
+        event = None
+        if self.events != []:
+            # Claudio: this approach is assuming that the queue is sorted according the time of the events.
+            for e in self.events:
+                if e.time < time or numpy.isclose(e.time, time, 1e-05, 1e-08):
+                    event = e
+                else:
+                    # stop at the first event that satisfies e.time > time
+                    break
+        return event
+    
+    '''
+        Removes event all other older events from the queue.
+    '''
+    def popEvent(self, event):
+        if event == None:
+            return
+        
+        assert event in self.events
+        # Claudio: this approach is assuming that the queue is sorted according the time of the events.
+        # first collect list of events to be removed.
+        # then remove them.
+        eventsToBeRemoved = []
+        for e in self.events:
+            eventsToBeRemoved.append(e)
+            if e == event:
+                break
+        assert len(eventsToBeRemoved)>0
+        for e in eventsToBeRemoved:
+            self.events.remove(e)
+        
+
+############### static classes - invariants
+
+class Expression:
+    def __init__(self):
+        pass
+
+class FSAModel:
+    def __init__(self,states,transitions):
+        self.transitions = transitions
+        self.states = states
+        self.initialState = None
+        
+    def getTransitionFrom(self, state, event, elapsed):
+        assert state != None
+        assert elapsed >= 0.0
+        
+        # Priotiry goes to event.
+        selectedTransition = None
+        
+        if event!=None:
+            selectedTransition = self.getTriggeredTransition(state, event)
+        
+        # Then to after 
+        if (selectedTransition == None):
+            selectedTransition = self.getTransitionAfter(state, elapsed)
+        
+        # And finally to default transitions
+        if (selectedTransition == None):
+            selectedTransition = self.getDefaultTransition(state)
+        
+        return selectedTransition
+    
+    def getDefaultTransition(self, state):
+        assert state != None
+        for t in self.transitions:
+                if t.source == state and t.trigger == None:
+                    return t
+        
+        return None
+    
+    
+    def getTriggeredTransition(self, state, event):
+        assert event != None
+        for t in self.transitions:
+                if t.source == state and isinstance(t.trigger,Event) and t.trigger.name == event.name:
+                        return t
+        
+        return None
+    
+    def getTransitionAfter(self, state, elapsed):
+        for t in self.transitions:
+            if t.source == state and isinstance(t.trigger,After):
+                if ExpressionVisitor(t.trigger.after).visit() <= elapsed:
+                    return t
+        return None 
+
+class ExpressionVisitor:
+    def __init__(self, expression):
+        self.expression = expression
+        
+    def visit(self):
+        if(isinstance(self.expression,AtomValue)):
+            return self.expression.value
+        if(isinstance(self.expression,Operation)):
+            left = ExpressionVisitor(self.expression.left).visit()
+            right = ExpressionVisitor(self.expression.right).visit()
+            if(self.expression.op == '+'):
+                return left + right
+            if(self.expression.op == '-'):
+                return left - right
+            if(self.expression.op == '*'):
+                return left * right
+            if(self.expression.op == '/'):
+                return left / right
+            if(self.expression.op == 'and'):
+                return left and right
+            if(self.expression.op == 'or'):
+                return left or right
+        if(isinstance(self.expression,Not)):
+            return not ExpressionVisitor(self.expression.expression).visit()
+
+class State:
+    def __init__(self, name, final = False):
+        self.name = name
+        self.final = final
+        
+    def getName(self):
+        return self.name
+    
+    def __str__(self):
+        return self.name
+    
+    
+class Operation(Expression):
+    def __init__(self, left, right, op):
+        self.op = op
+        self.left = left
+        self.right = right
+        
+class Transition:
+    def __init__(self,name, source,target):
+        self.name = name
+        self.source = source
+        self.target = target
+        self.trigger = None
+        self.guard = None
+    
+    def __str__(self):
+        return str(self.source) + "--" + self.name + ": " +  str(self.trigger) + "-->" + str(self.target)
+    
+class Trigger:
+    def __init__(self):
+        pass
+
+class Event(Trigger):
+    def __init__(self,name):
+        self.name = name
+        
+    def __str__(self):
+        return self.name
+    
+class After(Trigger):
+    def __init__(self, expression):
+        self.after = expression
+    
+    def __str__(self):
+        return "after("+ str(self.after) + ")"
+    
+class Guard:
+    def __init__(self, expression):
+        self.expression = expression
+
+class And(Operation):
+    def __init__(self, lexpression, rexpression):
+        self.left = lexpression
+        self.right = rexpression
+        self.op = "and"
+
+class Or(Operation):
+    def __init__(self, lexpression, rexpression):
+        self.left = lexpression
+        self.right = rexpression
+        self.op = "or"
+
+class Not(Expression):
+    def __init__(self, expression):
+        self.expression = expression
+
+class Variable(Expression):
+    def __init__(self, varname):
+        self.name = varname
+
+class AtomValue(Expression):
+    def __init__(self, value):
+        self.value = value
+        
+    def __str__(self):
+        return str(self.value)
+    
+
+class Integer(AtomValue):
+    def __init__(self, value):
+        self.value = value
+    
+class Float(AtomValue):
+    def __init__(self, value):
+        self.value = value
+
+class String(AtomValue):
+    def __init__(self, value):
+        self.value = value

+ 17 - 0
debugging_fsa_cbd_composition/fsasimulator/fsasimulator runner.py.launch

@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<launchConfiguration type="org.python.pydev.debug.regularLaunchConfigurationType">
+<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_PATHS">
+<listEntry value="/fsasimulator/runner.py"/>
+</listAttribute>
+<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_TYPES">
+<listEntry value="1"/>
+</listAttribute>
+<stringAttribute key="org.eclipse.ui.externaltools.ATTR_LOCATION" value="${workspace_loc:fsasimulator/runner.py}"/>
+<stringAttribute key="org.eclipse.ui.externaltools.ATTR_OTHER_WORKING_DIRECTORY" value="${workspace_loc:fsasimulator}"/>
+<stringAttribute key="org.eclipse.ui.externaltools.ATTR_TOOL_ARGUMENTS" value=""/>
+<stringAttribute key="org.eclipse.ui.externaltools.ATTR_WORKING_DIRECTORY" value="${workspace_loc:fsasimulator}"/>
+<stringAttribute key="org.python.pydev.debug.ATTR_INTERPRETER" value="__default"/>
+<stringAttribute key="org.python.pydev.debug.ATTR_PROJECT" value="fsasimulator"/>
+<intAttribute key="org.python.pydev.debug.ATTR_RESOURCE_TYPE" value="1"/>
+<stringAttribute key="process_factory_id" value="org.python.pydev.debug.processfactory.PyProcessFactory"/>
+</launchConfiguration>

+ 241 - 0
debugging_fsa_cbd_composition/fsasimulator/fsasimulator.py

@@ -0,0 +1,241 @@
+"""
+Generated by Statechart compiler by Glenn De Jonghe, Joeri Exelmans, Simon Van Mierlo, and Yentl Van Tendeloo (for the inspiration)
+
+Date:   Tue Oct 11 13:15:37 2016
+
+Model author: Sadaf Mustafiz and Bruno Barroca and Claudio Gomes
+Model name:   FSASimulator
+Model description:
+An FSA simulator written in SCCD. It supports after and events.
+"""
+
+from sccd.runtime.statecharts_core import *
+from sccd.runtime.libs.ui import *
+from sccd.runtime.libs.utils import *
+import fsaclasses
+
+# package "FSASimulator"
+
+class FSASimulator(RuntimeClassBase):
+    def __init__(self, controller, amodel, events):
+        RuntimeClassBase.__init__(self, controller)
+        
+        self.semantics.big_step_maximality = StatechartSemantics.TakeMany
+        self.semantics.internal_event_lifeline = StatechartSemantics.Queue
+        self.semantics.input_event_lifeline = StatechartSemantics.FirstComboStep
+        self.semantics.priority = StatechartSemantics.SourceParent
+        self.semantics.concurrency = StatechartSemantics.Single
+        
+        # build Statechart structure
+        self.build_statechart_structure()
+        
+        # user defined attributes
+        self.elapsed = None
+        self.super_step_completed = None
+        self.model = None
+        self.logicalTime = None
+        self.timestep = None
+        self.currentEvent = None
+        self.selectedTransition = None
+        self.eventList = None
+        self.currentState = None
+        
+        # call user defined constructor
+        FSASimulator.user_defined_constructor(self, amodel, events)
+    
+    def user_defined_constructor(self, amodel, events):
+        self.model = amodel
+        self.eventList = events
+    
+    def user_defined_destructor(self):
+        pass
+    
+    
+    # user defined method
+    def processEvent(self, event):
+        if (event != None):
+        	self.eventList.popEvent(event)
+        	event.processed = True
+    
+    
+    # user defined method
+    def getInputEventAt(self, time):
+        return self.eventList.getInputAt(time)
+    
+    
+    # builds Statechart structure
+    def build_statechart_structure(self):
+        
+        # state <root>
+        self.states[""] = State(0, self)
+        
+        # state /CheckTermination
+        self.states["/CheckTermination"] = State(1, self)
+        
+        # state /CheckTermination/MacroStepProcessed
+        self.states["/CheckTermination/MacroStepProcessed"] = State(2, self)
+        
+        # state /DoSimulation
+        self.states["/DoSimulation"] = State(3, self)
+        
+        # state /DoSimulation/MicroStepPrepared
+        self.states["/DoSimulation/MicroStepPrepared"] = State(4, self)
+        
+        # state /DoSimulation/MicroStepProcessed
+        self.states["/DoSimulation/MicroStepProcessed"] = State(5, self)
+        
+        # state /DoSimulation/MacroStepPrepared
+        self.states["/DoSimulation/MacroStepPrepared"] = State(6, self)
+        
+        # state /Initialized
+        self.states["/Initialized"] = State(7, self)
+        
+        # state /Started
+        self.states["/Started"] = State(8, self)
+        
+        # state /End
+        self.states["/End"] = State(9, self)
+        
+        # add children
+        self.states[""].addChild(self.states["/CheckTermination"])
+        self.states[""].addChild(self.states["/DoSimulation"])
+        self.states[""].addChild(self.states["/Initialized"])
+        self.states[""].addChild(self.states["/Started"])
+        self.states[""].addChild(self.states["/End"])
+        self.states["/CheckTermination"].addChild(self.states["/CheckTermination/MacroStepProcessed"])
+        self.states["/DoSimulation"].addChild(self.states["/DoSimulation/MicroStepPrepared"])
+        self.states["/DoSimulation"].addChild(self.states["/DoSimulation/MicroStepProcessed"])
+        self.states["/DoSimulation"].addChild(self.states["/DoSimulation/MacroStepPrepared"])
+        self.states[""].fixTree()
+        self.states[""].default_state = self.states["/Started"]
+        self.states["/CheckTermination"].default_state = self.states["/CheckTermination/MacroStepProcessed"]
+        self.states["/DoSimulation"].default_state = self.states["/DoSimulation/MacroStepPrepared"]
+        
+        # transition /CheckTermination/MacroStepProcessed
+        _CheckTermination_MacroStepProcessed_0 = Transition(self, self.states["/CheckTermination/MacroStepProcessed"], [self.states["/End"]])
+        _CheckTermination_MacroStepProcessed_0.setAction(self._CheckTermination_MacroStepProcessed_0_exec)
+        _CheckTermination_MacroStepProcessed_0.setTrigger(None)
+        _CheckTermination_MacroStepProcessed_0.setGuard(self._CheckTermination_MacroStepProcessed_0_guard)
+        self.states["/CheckTermination/MacroStepProcessed"].addTransition(_CheckTermination_MacroStepProcessed_0)
+        _CheckTermination_MacroStepProcessed_1 = Transition(self, self.states["/CheckTermination/MacroStepProcessed"], [self.states["/DoSimulation"]])
+        _CheckTermination_MacroStepProcessed_1.setAction(self._CheckTermination_MacroStepProcessed_1_exec)
+        _CheckTermination_MacroStepProcessed_1.setTrigger(None)
+        _CheckTermination_MacroStepProcessed_1.setGuard(self._CheckTermination_MacroStepProcessed_1_guard)
+        self.states["/CheckTermination/MacroStepProcessed"].addTransition(_CheckTermination_MacroStepProcessed_1)
+        
+        # transition /DoSimulation/MicroStepPrepared
+        _DoSimulation_MicroStepPrepared_0 = Transition(self, self.states["/DoSimulation/MicroStepPrepared"], [self.states["/DoSimulation/MicroStepProcessed"]])
+        _DoSimulation_MicroStepPrepared_0.setAction(self._DoSimulation_MicroStepPrepared_0_exec)
+        _DoSimulation_MicroStepPrepared_0.setTrigger(None)
+        self.states["/DoSimulation/MicroStepPrepared"].addTransition(_DoSimulation_MicroStepPrepared_0)
+        
+        # transition /DoSimulation/MicroStepProcessed
+        _DoSimulation_MicroStepProcessed_0 = Transition(self, self.states["/DoSimulation/MicroStepProcessed"], [self.states["/DoSimulation/MicroStepPrepared"]])
+        _DoSimulation_MicroStepProcessed_0.setAction(self._DoSimulation_MicroStepProcessed_0_exec)
+        _DoSimulation_MicroStepProcessed_0.setTrigger(None)
+        _DoSimulation_MicroStepProcessed_0.setGuard(self._DoSimulation_MicroStepProcessed_0_guard)
+        self.states["/DoSimulation/MicroStepProcessed"].addTransition(_DoSimulation_MicroStepProcessed_0)
+        _DoSimulation_MicroStepProcessed_1 = Transition(self, self.states["/DoSimulation/MicroStepProcessed"], [self.states["/CheckTermination"]])
+        _DoSimulation_MicroStepProcessed_1.setAction(self._DoSimulation_MicroStepProcessed_1_exec)
+        _DoSimulation_MicroStepProcessed_1.setTrigger(None)
+        _DoSimulation_MicroStepProcessed_1.setGuard(self._DoSimulation_MicroStepProcessed_1_guard)
+        self.states["/DoSimulation/MicroStepProcessed"].addTransition(_DoSimulation_MicroStepProcessed_1)
+        
+        # transition /DoSimulation/MacroStepPrepared
+        _DoSimulation_MacroStepPrepared_0 = Transition(self, self.states["/DoSimulation/MacroStepPrepared"], [self.states["/DoSimulation/MicroStepProcessed"]])
+        _DoSimulation_MacroStepPrepared_0.setAction(self._DoSimulation_MacroStepPrepared_0_exec)
+        _DoSimulation_MacroStepPrepared_0.setTrigger(None)
+        self.states["/DoSimulation/MacroStepPrepared"].addTransition(_DoSimulation_MacroStepPrepared_0)
+        
+        # transition /Initialized
+        _Initialized_0 = Transition(self, self.states["/Initialized"], [self.states["/CheckTermination"]])
+        _Initialized_0.setAction(self._Initialized_0_exec)
+        _Initialized_0.setTrigger(None)
+        self.states["/Initialized"].addTransition(_Initialized_0)
+        
+        # transition /Started
+        _Started_0 = Transition(self, self.states["/Started"], [self.states["/Initialized"]])
+        _Started_0.setAction(self._Started_0_exec)
+        _Started_0.setTrigger(None)
+        self.states["/Started"].addTransition(_Started_0)
+    
+    def _CheckTermination_MacroStepProcessed_0_exec(self, parameters):
+        print('Going to End... ')
+    
+    def _CheckTermination_MacroStepProcessed_0_guard(self, parameters):
+        return self.currentState.final
+    
+    def _CheckTermination_MacroStepProcessed_1_exec(self, parameters):
+        print('Going to DoSimulation and reading events... ')
+        self.currentEvent = self.getInputEventAt(self.logicalTime)
+        self.selectedTransition = self.model.getTransitionFrom(self.currentState, self.currentEvent, self.elapsed)
+        print(self.currentEvent)
+        print(self.selectedTransition)
+    
+    def _CheckTermination_MacroStepProcessed_1_guard(self, parameters):
+        return not self.currentState.final
+    
+    def _DoSimulation_MicroStepPrepared_0_exec(self, parameters):
+        print('Going to MicroStepProcessed, taking transition and reading events... ')
+        print('Transition to be taken: ' + str(self.selectedTransition))
+        self.currentState = self.selectedTransition.target
+        self.elapsed = 0
+        self.processEvent(self.currentEvent)
+        print('New state: ' + str(self.currentState))
+        self.currentEvent = self.getInputEventAt(self.logicalTime)
+        self.selectedTransition = self.model.getTransitionFrom(self.currentState, self.currentEvent, self.elapsed)
+        print(self.currentEvent)
+        print(self.selectedTransition)
+    
+    def _DoSimulation_MicroStepProcessed_0_exec(self, parameters):
+        print('Going to MicroStepPrepared... ')
+    
+    def _DoSimulation_MicroStepProcessed_0_guard(self, parameters):
+        return self.selectedTransition != None
+    
+    def _DoSimulation_MicroStepProcessed_1_exec(self, parameters):
+        print('Going to CheckTermination and advancing time... ')
+        self.logicalTime = self.logicalTime + self.timestep
+        self.elapsed = self.elapsed + self.timestep
+        print(self.logicalTime)
+        print(self.elapsed)
+    
+    def _DoSimulation_MicroStepProcessed_1_guard(self, parameters):
+        return self.selectedTransition == None
+    
+    def _DoSimulation_MacroStepPrepared_0_exec(self, parameters):
+        print('Going to MicroStepProcessed... ')
+    
+    def _Initialized_0_exec(self, parameters):
+        print('Going to MacroStepProcessed... ')
+    
+    def _Started_0_exec(self, parameters):
+        print('Going to Initialized... ')
+        self.logicalTime = 0
+        self.elapsed = 0
+        self.timestep = 1.0
+        self.currentState = self.model.initialState
+    
+    def initializeStatechart(self):
+        # enter default state
+        self.default_targets = self.states["/Started"].getEffectiveTargetStates()
+        RuntimeClassBase.initializeStatechart(self)
+
+class ObjectManager(ObjectManagerBase):
+    def __init__(self, controller):
+        ObjectManagerBase.__init__(self, controller)
+    
+    def instantiate(self, class_name, construct_params):
+        if class_name == "FSASimulator":
+            instance = FSASimulator(self.controller, construct_params[0], construct_params[1])
+            instance.associations = {}
+        else:
+            raise Exception("Cannot instantiate class " + class_name)
+        return instance
+
+class Controller(ThreadsControllerBase):
+    def __init__(self, amodel, events, keep_running = None, behind_schedule_callback = None):
+        if keep_running == None: keep_running = True
+        if behind_schedule_callback == None: behind_schedule_callback = None
+        ThreadsControllerBase.__init__(self, ObjectManager(self), keep_running, behind_schedule_callback)
+        self.object_manager.createInstance("FSASimulator", [amodel, events])

+ 330 - 0
debugging_fsa_cbd_composition/fsasimulator/fsasimulator_debugging.py

@@ -0,0 +1,330 @@
+"""
+Generated by Statechart compiler by Glenn De Jonghe, Joeri Exelmans, Simon Van Mierlo, and Yentl Van Tendeloo (for the inspiration)
+
+Date:   Wed Oct 12 13:55:43 2016
+
+Model author: Sadaf Mustafiz and Bruno Barroca and Claudio Gomes and Simon Van Mierlo
+Model name:   FSASimulator
+Model description:
+A debuggeable FSA simulator. It supports after and events.
+"""
+
+from sccd.runtime.statecharts_core import *
+from sccd.runtime.libs.ui import *
+from sccd.runtime.libs.utils import *
+import fsaclasses
+import sccd.runtime.accurate_time as accurate_time
+
+class Breakpoint:
+    def __init__(self, name, function, enabled, disable_on_trigger):
+        self.name = name
+        self.function = function
+        self.enabled = enabled
+        self.disable_on_trigger = disable_on_trigger
+
+# package "FSASimulator"
+
+class FSASimulator(RuntimeClassBase):
+    def __init__(self, controller, amodel, events):
+        RuntimeClassBase.__init__(self, controller)
+        
+        self.semantics.big_step_maximality = StatechartSemantics.TakeMany
+        self.semantics.internal_event_lifeline = StatechartSemantics.Queue
+        self.semantics.input_event_lifeline = StatechartSemantics.FirstComboStep
+        self.semantics.priority = StatechartSemantics.SourceParent
+        self.semantics.concurrency = StatechartSemantics.Single
+        
+        # build Statechart structure
+        self.build_statechart_structure()
+        
+        # user defined attributes
+        self.elapsed = None
+        self.super_step_completed = None
+        self.model = None
+        self.logicalTime = None
+        self.timestep = None
+        self.currentEvent = None
+        self.selectedTransition = None
+        self.eventList = None
+        self.currentState = None
+        
+        # call user defined constructor
+        FSASimulator.user_defined_constructor(self, amodel, events)
+    
+    def user_defined_constructor(self, amodel, events):
+        self.model = amodel
+        self.eventList = events
+    
+    def user_defined_destructor(self):
+        pass
+    
+    
+    # user defined method
+    def processEvent(self, event):
+        if (event != None):
+            self.eventList.popEvent(event)
+            event.processed = True
+    
+    
+    # user defined method
+    def getInputEventAt(self, time):
+        return self.eventList.getInputAt(time)
+    
+    
+    # user defined method
+    def initialize(self):
+        self.logicalTime = 0
+        self.elapsed = 0
+        self.timestep = 1.0
+        self.currentState = self.model.initialState
+    
+    
+    # user defined method
+    def initializeDebugger(self):
+        self.breakpoints = []
+        self.triggered_bp = None
+    
+    
+    # user defined method
+    def endCondition(self):
+        return self.currentState.final
+    
+    
+    # user defined method
+    def advanceTime(self):
+        self.logicalTime = self.logicalTime + self.timestep
+        self.elapsed = self.elapsed + self.timestep
+    
+    
+    # user defined method
+    def addBreakpoint(self, name, function, enabled = None, disable_on_trigger = None):
+        if enabled == None: enabled = true
+        if disable_on_trigger == None: disable_on_trigger = true
+        if len([bp for bp in self.breakpoints if bp.name == name]) > 0:
+            return -1
+        self.breakpoints.append(Breakpoint(name, function, enabled, disable_on_trigger))
+        return 0
+    
+    
+    # user defined method
+    def delBreakpoint(self, name):
+        if len([bp for bp in self.breakpoints if bp.name == name]) == 0:
+            return -1
+        self.breakpoints = [bp for bp in self.breakpoints if bp.name != name]
+        return 0
+    
+    
+    # user defined method
+    def toggleBreakpoint(self, name):
+        if len([bp for bp in self.breakpoints if bp.name == name]) == 0:
+            return -1
+        for bp in self.breakpoints:
+            if bp.name == name:
+                bp.enabled = enabled
+                break
+        return 0
+    
+    
+    # user defined method
+    def breakpointTriggers(self, is_realtime_simulation):
+        self.triggered_bp = None
+        for bp in self.breakpoints:
+            if not bp.enabled:
+                continue
+            # include the function in the scope...
+            exec(bp.function)
+            # ... and execute it, note that the breakpoint thus has to start with "def breakpoint("
+            # note that we pass self.time_next instead of self.simulated_time in the case of as-fast-as-possible simulation (or stepping)
+            # this is to make sure that the simulation is stopped BEFORE the specified time is reached, and not AFTER (because we don't necessarily implement 'step back')
+            # in case of realtime simulation, we do pass the current simulated time, since we can stop at (more or less) exactly the right time
+            if breakpoint({'clock': (self.clock if is_realtime_simulation else self.time_next) / 1000.0, 'state': self.state}):
+                # triggered!
+                self.triggered_bp = bp.name
+                if bp.disable_on_trigger:
+                    bp.enabled = False
+                return True
+            else:
+                # not triggered, so continue
+                continue
+        return False
+    
+    
+    # user defined method
+    def godEvent(self, state_var, new_val):
+        pass
+    
+    
+    # builds Statechart structure
+    def build_statechart_structure(self):
+        
+        # state <root>
+        self.states[""] = State(0, self)
+        
+        # state /CheckTermination
+        self.states["/CheckTermination"] = State(1, self)
+        
+        # state /CheckTermination/MacroStepProcessed
+        self.states["/CheckTermination/MacroStepProcessed"] = State(2, self)
+        
+        # state /DoSimulation
+        self.states["/DoSimulation"] = State(3, self)
+        
+        # state /DoSimulation/MicroStepPrepared
+        self.states["/DoSimulation/MicroStepPrepared"] = State(4, self)
+        
+        # state /DoSimulation/MicroStepProcessed
+        self.states["/DoSimulation/MicroStepProcessed"] = State(5, self)
+        
+        # state /DoSimulation/MacroStepPrepared
+        self.states["/DoSimulation/MacroStepPrepared"] = State(6, self)
+        
+        # state /Initialized
+        self.states["/Initialized"] = State(7, self)
+        
+        # state /Started
+        self.states["/Started"] = State(8, self)
+        
+        # state /SimulationComplete
+        self.states["/SimulationComplete"] = State(9, self)
+        
+        # add children
+        self.states[""].addChild(self.states["/CheckTermination"])
+        self.states[""].addChild(self.states["/DoSimulation"])
+        self.states[""].addChild(self.states["/Initialized"])
+        self.states[""].addChild(self.states["/Started"])
+        self.states[""].addChild(self.states["/SimulationComplete"])
+        self.states["/CheckTermination"].addChild(self.states["/CheckTermination/MacroStepProcessed"])
+        self.states["/DoSimulation"].addChild(self.states["/DoSimulation/MicroStepPrepared"])
+        self.states["/DoSimulation"].addChild(self.states["/DoSimulation/MicroStepProcessed"])
+        self.states["/DoSimulation"].addChild(self.states["/DoSimulation/MacroStepPrepared"])
+        self.states[""].fixTree()
+        self.states[""].default_state = self.states["/Started"]
+        self.states["/CheckTermination"].default_state = self.states["/CheckTermination/MacroStepProcessed"]
+        self.states["/DoSimulation"].default_state = self.states["/DoSimulation/MacroStepPrepared"]
+        
+        # transition /CheckTermination/MacroStepProcessed
+        _CheckTermination_MacroStepProcessed_0 = Transition(self, self.states["/CheckTermination/MacroStepProcessed"], [self.states["/SimulationComplete"]])
+        _CheckTermination_MacroStepProcessed_0.setAction(self._CheckTermination_MacroStepProcessed_0_exec)
+        _CheckTermination_MacroStepProcessed_0.setTrigger(None)
+        _CheckTermination_MacroStepProcessed_0.setGuard(self._CheckTermination_MacroStepProcessed_0_guard)
+        self.states["/CheckTermination/MacroStepProcessed"].addTransition(_CheckTermination_MacroStepProcessed_0)
+        _CheckTermination_MacroStepProcessed_1 = Transition(self, self.states["/CheckTermination/MacroStepProcessed"], [self.states["/DoSimulation"]])
+        _CheckTermination_MacroStepProcessed_1.setAction(self._CheckTermination_MacroStepProcessed_1_exec)
+        _CheckTermination_MacroStepProcessed_1.setTrigger(None)
+        _CheckTermination_MacroStepProcessed_1.setGuard(self._CheckTermination_MacroStepProcessed_1_guard)
+        self.states["/CheckTermination/MacroStepProcessed"].addTransition(_CheckTermination_MacroStepProcessed_1)
+        
+        # transition /DoSimulation/MicroStepPrepared
+        _DoSimulation_MicroStepPrepared_0 = Transition(self, self.states["/DoSimulation/MicroStepPrepared"], [self.states["/DoSimulation/MicroStepProcessed"]])
+        _DoSimulation_MicroStepPrepared_0.setAction(self._DoSimulation_MicroStepPrepared_0_exec)
+        _DoSimulation_MicroStepPrepared_0.setTrigger(None)
+        self.states["/DoSimulation/MicroStepPrepared"].addTransition(_DoSimulation_MicroStepPrepared_0)
+        
+        # transition /DoSimulation/MicroStepProcessed
+        _DoSimulation_MicroStepProcessed_0 = Transition(self, self.states["/DoSimulation/MicroStepProcessed"], [self.states["/DoSimulation/MicroStepPrepared"]])
+        _DoSimulation_MicroStepProcessed_0.setAction(self._DoSimulation_MicroStepProcessed_0_exec)
+        _DoSimulation_MicroStepProcessed_0.setTrigger(None)
+        _DoSimulation_MicroStepProcessed_0.setGuard(self._DoSimulation_MicroStepProcessed_0_guard)
+        self.states["/DoSimulation/MicroStepProcessed"].addTransition(_DoSimulation_MicroStepProcessed_0)
+        _DoSimulation_MicroStepProcessed_1 = Transition(self, self.states["/DoSimulation/MicroStepProcessed"], [self.states["/CheckTermination"]])
+        _DoSimulation_MicroStepProcessed_1.setAction(self._DoSimulation_MicroStepProcessed_1_exec)
+        _DoSimulation_MicroStepProcessed_1.setTrigger(None)
+        _DoSimulation_MicroStepProcessed_1.setGuard(self._DoSimulation_MicroStepProcessed_1_guard)
+        self.states["/DoSimulation/MicroStepProcessed"].addTransition(_DoSimulation_MicroStepProcessed_1)
+        
+        # transition /DoSimulation/MacroStepPrepared
+        _DoSimulation_MacroStepPrepared_0 = Transition(self, self.states["/DoSimulation/MacroStepPrepared"], [self.states["/DoSimulation/MicroStepProcessed"]])
+        _DoSimulation_MacroStepPrepared_0.setAction(self._DoSimulation_MacroStepPrepared_0_exec)
+        _DoSimulation_MacroStepPrepared_0.setTrigger(None)
+        self.states["/DoSimulation/MacroStepPrepared"].addTransition(_DoSimulation_MacroStepPrepared_0)
+        
+        # transition /Initialized
+        _Initialized_0 = Transition(self, self.states["/Initialized"], [self.states["/CheckTermination"]])
+        _Initialized_0.setAction(self._Initialized_0_exec)
+        _Initialized_0.setTrigger(None)
+        self.states["/Initialized"].addTransition(_Initialized_0)
+        
+        # transition /Started
+        _Started_0 = Transition(self, self.states["/Started"], [self.states["/Initialized"]])
+        _Started_0.setAction(self._Started_0_exec)
+        _Started_0.setTrigger(None)
+        self.states["/Started"].addTransition(_Started_0)
+    
+    def _CheckTermination_MacroStepProcessed_0_exec(self, parameters):
+        print('Going to End... ')
+    
+    def _CheckTermination_MacroStepProcessed_0_guard(self, parameters):
+        return self.endCondition()
+    
+    def _CheckTermination_MacroStepProcessed_1_exec(self, parameters):
+        print('Going to DoSimulation and reading events... ')
+        self.currentEvent = self.getInputEventAt(self.logicalTime)
+        self.selectedTransition = self.model.getTransitionFrom(self.currentState, self.currentEvent, self.elapsed)
+        print(self.currentEvent)
+        print(self.selectedTransition)
+    
+    def _CheckTermination_MacroStepProcessed_1_guard(self, parameters):
+        return not self.endCondition()
+    
+    def _DoSimulation_MicroStepPrepared_0_exec(self, parameters):
+        print('Going to MicroStepProcessed, taking transition and reading events... ')
+        print('Transition to be taken: ' + str(self.selectedTransition))
+        self.currentState = self.selectedTransition.target
+        self.elapsed = 0
+        self.processEvent(self.currentEvent)
+        print('New state: ' + str(self.currentState))
+        self.currentEvent = self.getInputEventAt(self.logicalTime)
+        self.selectedTransition = self.model.getTransitionFrom(self.currentState, self.currentEvent, self.elapsed)
+        print(self.currentEvent)
+        print(self.selectedTransition)
+    
+    def _DoSimulation_MicroStepProcessed_0_exec(self, parameters):
+        print('Going to MicroStepPrepared... ')
+    
+    def _DoSimulation_MicroStepProcessed_0_guard(self, parameters):
+        return self.selectedTransition != None
+    
+    def _DoSimulation_MicroStepProcessed_1_exec(self, parameters):
+        print('Going to CheckTermination and advancing time... ')
+        self.advanceTime()
+        print(self.logicalTime)
+        print(self.elapsed)
+    
+    def _DoSimulation_MicroStepProcessed_1_guard(self, parameters):
+        return self.selectedTransition == None
+    
+    def _DoSimulation_MacroStepPrepared_0_exec(self, parameters):
+        print('Going to MicroStepProcessed... ')
+    
+    def _Initialized_0_exec(self, parameters):
+        print('Going to MacroStepProcessed... ')
+    
+    def _Started_0_exec(self, parameters):
+        print('Going to Initialized... ')
+        self.initialize()
+    
+    def initializeStatechart(self):
+        # enter default state
+        self.default_targets = self.states["/Started"].getEffectiveTargetStates()
+        RuntimeClassBase.initializeStatechart(self)
+
+class ObjectManager(ObjectManagerBase):
+    def __init__(self, controller):
+        ObjectManagerBase.__init__(self, controller)
+    
+    def instantiate(self, class_name, construct_params):
+        if class_name == "FSASimulator":
+            instance = FSASimulator(self.controller, construct_params[0], construct_params[1])
+            instance.associations = {}
+        else:
+            raise Exception("Cannot instantiate class " + class_name)
+        return instance
+
+class Controller(ThreadsControllerBase):
+    def __init__(self, amodel, events, keep_running = None, behind_schedule_callback = None):
+        if keep_running == None: keep_running = True
+        if behind_schedule_callback == None: behind_schedule_callback = None
+        ThreadsControllerBase.__init__(self, ObjectManager(self), keep_running, behind_schedule_callback)
+        self.addInputPort("user_input")
+        self.addInputPort("user_output")
+        self.object_manager.createInstance("FSASimulator", [amodel, events])

+ 487 - 0
debugging_fsa_cbd_composition/fsasimulator/fsasimulator_debugging.py.xml

@@ -0,0 +1,487 @@
+<?xml version="1.0" ?>
+<diagram name="FSASimulator" author="Sadaf Mustafiz and Bruno Barroca and Claudio Gomes and Simon Van Mierlo">
+    <description>
+        A debuggeable FSA simulator. It supports after and events.
+    </description>
+    
+    <inport name="user_input" />
+    <inport name="user_output" />
+    
+    <top>
+        from sccd.runtime.libs.ui import *
+        from sccd.runtime.libs.utils import *
+        import fsaclasses
+        import sccd.runtime.accurate_time as accurate_time
+        
+        class Breakpoint:
+            def __init__(self, name, function, enabled, disable_on_trigger):
+                self.name = name
+                self.function = function
+                self.enabled = enabled
+                self.disable_on_trigger = disable_on_trigger
+    </top>
+    
+    <class name="FSASimulator" default="True">
+        <attribute name="elapsed"/>
+        <attribute name="super_step_completed"/>
+        <attribute name="model"/>
+        <attribute name="clock"/>
+        <attribute name="timestep"/>
+        <attribute name="currentEvent"/>
+        <attribute name="selectedTransition"/>
+        <attribute name="eventList"/>
+        <attribute name="currentState"/>
+        <method name="FSASimulator">
+            <parameter name="amodel"/>
+            <parameter name="events"/>
+            <body>
+            <![CDATA[
+                self.model = amodel
+                self.eventList = events
+            ]]>
+            </body>
+        </method>
+        <method name="processEvent">
+            <parameter name="event"/>
+            <body>
+            <![CDATA[
+                if (event != None):
+                    self.eventList.popEvent(event)
+                    event.processed = True
+            ]]>
+            </body>
+        </method>
+        <method name="getInputEventAt">
+            <parameter name="time"/>
+            <body>
+            <![CDATA[
+                return self.eventList.getInputAt(time)
+            ]]>
+            </body>
+        </method>
+        <method name="initialize">
+            <body>        
+            <![CDATA[        
+                self.clock = 0
+                self.elapsed = 0
+                self.timestep = 1.0 * 1000.0
+                self.time_next = self.timestep
+                self.currentState = self.model.initialState
+            ]]>
+            </body>
+        </method>
+        <method name="initializeDebugger">
+            <body>
+            <![CDATA[
+                self.breakpoints = []
+                self.triggered_bp = None
+            ]]>
+            </body>
+        </method>
+        <method name="endCondition">
+            <body>
+            <![CDATA[
+                return self.currentState and self.currentState.final
+            ]]>
+            </body>
+        </method>
+        <method name="advanceTime">
+            <body>
+            <![CDATA[
+                self.clock = self.time_next
+                self.elapsed = self.elapsed + self.timestep
+                self.time_next = self.clock + self.timestep
+            ]]>
+            </body>
+        </method>
+        <method name="finalize">
+            <body>
+            <![CDATA[
+                print 'Simulation finalized.'
+            ]]>
+            </body>
+        </method>
+        <method name="waitTime">
+            <body>
+            <![CDATA[
+                # First, we convert from wall-clock time to simulated time.
+                # This means the elapsed time in wall-clock time needs to be scaled according to the realtime scale (for example, if the realtime scale is 2, an elapsed time of 1 second in wall-clock time is equal to an elapsed time of 2 seconds in simulated time).
+                simulated_diff = (accurate_time.time() - self.realtime_start_time) * self.realtime_scale
+                # time_next and simulated_diff are both in simulated time: so now scale back to wall-clock time by dividing.
+                # This function returns an amount of miliseconds.
+                return ((self.time_next - simulated_diff) / self.realtime_scale)
+            ]]>
+            </body>
+        </method>
+        <method name="addBreakpoint">
+            <parameter name="name" />
+            <parameter name="function" />
+            <parameter name="enabled" default="true" />
+            <parameter name="disable_on_trigger" default="true" />
+            <body>
+            <![CDATA[
+                if len([bp for bp in self.breakpoints if bp.name == name]) > 0:
+                    return -1
+                self.breakpoints.append(Breakpoint(name, function, enabled, disable_on_trigger))
+                return 0
+            ]]>
+            </body>
+        </method>
+        <method name="delBreakpoint">
+            <parameter name="name" />
+            <body>
+            <![CDATA[
+                if len([bp for bp in self.breakpoints if bp.name == name]) == 0:
+                    return -1
+                self.breakpoints = [bp for bp in self.breakpoints if bp.name != name]
+                return 0
+            ]]>
+            </body>
+        </method>
+        <method name="toggleBreakpoint">
+            <parameter name="name" />
+            <body>
+            <![CDATA[
+                if len([bp for bp in self.breakpoints if bp.name == name]) == 0:
+                    return -1
+                for bp in self.breakpoints:
+                    if bp.name == name:
+                        bp.enabled = enabled
+                        break
+                return 0
+            ]]>
+            </body>
+        </method>
+        <method name="breakpointTriggers">
+            <parameter name="is_realtime_simulation" />
+            <body>
+            <![CDATA[
+                self.triggered_bp = None
+                for bp in self.breakpoints:
+                    if not bp.enabled:
+                        continue
+                    # include the function in the scope...
+                    exec(bp.function)
+                    # ... and execute it, note that the breakpoint thus has to start with "def breakpoint("
+                    # note that we pass self.time_next instead of self.simulated_time in the case of as-fast-as-possible simulation (or stepping)
+                    # this is to make sure that the simulation is stopped BEFORE the specified time is reached, and not AFTER (because we don't necessarily implement 'step back')
+                    # in case of realtime simulation, we do pass the current simulated time, since we can stop at (more or less) exactly the right time
+                    if breakpoint({'clock': (self.clock if is_realtime_simulation else self.time_next) / 1000.0, 'state': self.currentState, 'event': self.currentEvent}):
+                        # triggered!
+                        self.triggered_bp = bp.name
+                        if bp.disable_on_trigger:
+                            bp.enabled = False
+                        return True
+                    else:
+                        # not triggered, so continue
+                        continue
+                return False
+            ]]>
+            </body>
+        </method>
+        <method name="godEvent">
+            <parameter name="new_state" />
+            <body>
+            <![CDATA[
+                filtered_states = [s for s in self.model.states if s.name == new_state]
+                if not len(filtered_states) == 1:
+                    return -1
+                self.currentState = filtered_states[0]
+                return 0
+            ]]>
+            </body>
+        </method>
+        <scxml initial="Main" final="SimulationComplete" internal_event_lifeline="next_combo_step">
+            <parallel id="Main">
+                <state id="SimulationState" initial="Paused">
+                    <state id="Paused">
+                        <transition target="../Running/Continuous" event="continuous" port="user_input" />
+                        <transition target="../Running/Realtime" event="realtime" port="user_input">
+                            <parameter name="realtime_scale" default="1.0" />
+                            <script>
+                                self.realtime_scale = float(realtime_scale)
+                            </script>
+                        </transition>
+                        <transition target="../Running/BigStep" event="big_step" port="user_input" />
+                        <transition target="../Running/SmallStep" event="small_step" port="user_input" />
+                        <!-- If a god event enables the end condition, the simulation should stop. -->
+                        <transition target="../PreStopped" cond="self.endCondition()" />
+                    </state>
+                    <state id="PrePaused">
+                        <!-- Here, we make sure the current step has finished, before we raise the 'paused' event. Otherwise, UserOutput will output the old state, not the latest one. -->
+                        <transition target="../Paused" after="self.sccd_yield() * 2">
+                            <raise event="paused" />
+                        </transition>
+                    </state>
+                    <state id="PreBreakpointTriggered">
+                        <!-- Here, we make sure the current step has finished, before we raise the 'paused' event. Otherwise, UserOutput will output the old state, not the latest one. -->
+                        <transition target="../Paused" after="self.sccd_yield() * 2">
+                            <raise event="breakpoint_triggered" />
+                        </transition>
+                    </state>
+                    <state id="Running" initial="Continuous">
+                        <transition target="../PreStopped" cond="self.endCondition()" />
+                        <transition target="../PrePaused" event="pause" port="user_input" />
+                        <transition target="../PreBreakpointTriggered" cond="self.breakpointTriggers(INSTATE('./Realtime'))" />
+                        <state id="Continuous" />
+                        <state id="BigStep">
+                            <!-- We go to a special 'BigStepDone' state because in the 'user_output' state, we need to check whether we are currently executing a big step.  -->
+                            <transition target="../BigStepDone" event="big_step_done" />
+                        </state>
+                        <state id="BigStepDone">
+                            <!-- We go back to the 'Paused' state once the big step has finished. -->
+                            <transition target="../../Paused" after="self.sccd_yield()" />
+                        </state>
+                        <state id="SmallStep">
+                            <!-- We go to a special 'SmallStepDone' state because in the 'user_output' state, we need to check whether we are currently executing a small step.  -->
+                            <transition target="../SmallStepDone" event="small_step_done" />
+                        </state>
+                        <state id="SmallStepDone">
+                            <!-- We go back to the 'Paused' state once the small step has finished. -->
+                            <transition target="../../Paused" after="self.sccd_yield()" />
+                        </state>
+                        <state id="Realtime">
+                            <onentry>
+                                <script>
+                                    # If the simulation was paused, we need to reset the start time of the simulation.
+                                    # The start time of the simulation is equal to the point in wall-clock time where simulated time is 0.
+                                    # If the simulation was paused, we have to recompute this point in time: it is the difference of the wall-clock time and the simulated time.
+                                    # If the scale was changed after the pause, this point of course moves backwards (for scales smaller than 1) or forwards (for scales larger than 1)
+                                    self.realtime_start_time = accurate_time.time() - (self.clock / self.realtime_scale)
+                                </script>
+                            </onentry>
+                        </state>
+                    </state>
+                    <state id="PreStopped">
+                        <transition target="../Stopped" after="self.sccd_yield() * 2">
+                            <raise event="termination_condition" />
+                        </transition>
+                    </state>
+                    <state id="Stopped" />
+                </state>
+                <state id="SimulationFlow" initial="Started">
+                    <state id="Started">
+                        <transition target="../Initialized">
+                            <script>
+                                <![CDATA[
+                                    print('Going to Initialized... ')
+                                    self.initialize()
+                                ]]>
+                            </script>
+                        </transition>
+                    </state>
+                    <state id="Initialized">
+                        <transition target="../InitializeDebugger">
+                            <script>
+                                <![CDATA[
+                                    print('Going to MacroStepProcessed... ')
+                                ]]>
+                            </script>
+                        </transition>
+                    </state>
+                    <state id="InitializeDebugger">
+                        <onentry>
+                            <script>
+                            <![CDATA[
+                                self.initializeDebugger()
+                            ]]>
+                            </script>
+                        </onentry>
+                        <transition target="../CheckTermination" />
+                    </state>
+                    <state id="CheckTermination" initial="MacroStepProcessed">
+                        <state id="MacroStepProcessed">
+                            <transition target="../../Stopped" cond="INSTATE('/Main/SimulationState/Stopped')" after="self.sccd_yield()">
+                                <script>
+                                    <![CDATA[
+                                        print('Going to End... ')
+                                    ]]>
+                                </script>
+                            </transition>
+                            <transition target="../../Waiting" cond="INSTATE('/Main/SimulationState/Running/Realtime')" />
+                            <transition target="../../DoSimulation" cond="INSTATE('/Main/SimulationState/Running/Continuous') or INSTATE('/Main/SimulationState/Running/BigStep') or INSTATE('/Main/SimulationState/Running/SmallStep')" />
+                        </state>
+                    </state>
+                    <state id="Waiting">
+                        <!-- We schedule to go back to the check_termination state after the smallest possible delay (to accomodate for pauses). -->
+                        <transition target="../CheckTermination" after="self.sccd_yield()">                            
+                            <!-- We set the simulation time to the correct value. -->
+                            <script>
+                                diff = accurate_time.time() - self.realtime_start_time
+                                self.clock = diff * self.realtime_scale
+                            </script>
+                        </transition>
+                        <!-- We execute a step when the wait time is smaller than the smallest possible delay. -->
+                        <transition target="../DoSimulation" cond="self.waitTime() / 1000.0 &lt;= self.sccd_yield()" />
+                    </state>
+                    <state id="DoSimulation" initial="MacroStepPrepared">
+                        <state id="MacroStepPrepared">
+                            <onentry>
+                                <script>
+                                    <![CDATA[
+                                        print('Entered MacroStepPrepared and reading events... ')
+                                        self.currentEvent = self.getInputEventAt(self.clock / 1000.0)
+                                        self.selectedTransition = self.model.getTransitionFrom(self.currentState, self.currentEvent, self.elapsed)
+                                        print self.clock / 1000.0
+                                        print(self.currentEvent)
+                                        print(self.selectedTransition)
+                                    ]]>
+                                </script>
+                            </onentry>
+                            <transition target="../MicroStepProcessed">
+                                <script>
+                                    <![CDATA[
+                                        print('Going to MicroStepProcessed... ')
+                                    ]]>
+                                </script>
+                                <raise event="small_step_done" />
+                            </transition>
+                        </state>
+                        <state id="MicroStepProcessed">
+                            <transition target="../MicroStepPrepared" cond="self.selectedTransition != None">
+                                <script>
+                                    <![CDATA[
+                                        print('Going to MicroStepPrepared... ')
+                                    ]]>
+                                </script>
+                            </transition>
+                            <transition target="../../CheckTermination" cond="self.selectedTransition == None" after="self.sccd_yield()">
+                                <script>
+                                    <![CDATA[
+                                        print('Going to CheckTermination and advancing time... ')
+                                        self.advanceTime()
+                                        print(self.clock / 1000.0)
+                                        print(self.elapsed / 1000.0)
+                                    ]]>
+                                </script>
+                                <raise event="big_step_done" />
+                            </transition>
+                        </state>
+                        <state id="MicroStepPrepared">
+                            <transition target="../MicroStepProcessed">
+                                <script>
+                                    <![CDATA[
+                                        print('Going to MicroStepProcessed, taking transition and reading events... ')
+                                        print('Transition to be taken: ' + str(self.selectedTransition))
+                                        self.currentState = self.selectedTransition.target
+                                        self.elapsed = 0
+                                        self.processEvent(self.currentEvent)
+                                        print('New state: ' + str(self.currentState))
+                                        self.currentEvent = self.getInputEventAt(self.clock / 1000.0)
+                                        self.selectedTransition = self.model.getTransitionFrom(self.currentState, self.currentEvent, self.elapsed)
+                                        print(self.currentEvent)
+                                        print(self.selectedTransition)
+                                    ]]>
+                                </script>
+                            </transition>
+                        </state>
+                    </state>
+                    <state id="Stopped" />
+                </state>
+                <state id="BreakpointManager" initial="Listening">
+                    <state id="Listening">
+                        <transition target="." event="add_breakpoint" port="user_input">
+                            <parameter name="name"/>
+                            <parameter name="function"/>
+                            <parameter name="enabled"/>
+                            <parameter name="disable_on_trigger"/>
+                            <script>
+                                result = self.addBreakpoint(name, function, bool(enabled), bool(disable_on_trigger))
+                            </script>
+                            <raise event="add_breakpoint_result" port="user_output">
+                                <parameter expr="result" />
+                            </raise>
+                        </transition>
+                        <transition target="." event="del_breakpoint" port="user_input">
+                            <parameter name="name"/>
+                            <script>
+                                result = self.delBreakpoint(name)
+                            </script>
+                            <raise event="del_breakpoint_result" port="user_output">
+                                <parameter expr="result" />
+                            </raise>
+                        </transition>
+                        <transition target="." event="toggle_breakpoint" port="user_input">
+                            <parameter name="name"/>
+                            <script>
+                                result = self.toggleBreakpoint(name)
+                            </script>
+                            <raise event="toggle_breakpoint_result" port="user_output">
+                                <parameter expr="result" />
+                            </raise>
+                        </transition>
+                        <transition target="." event="list_breakpoints" port="user_input">
+                            <raise event="list_breakpoints_result" port="user_output">
+                                <parameter expr="[bp.name for bp in self.breakpoints]" />
+                            </raise>
+                        </transition>
+                    </state>
+                </state>
+                <state id="GodEventManager" initial="Listening">
+                    <state id="Listening">
+                        <transition target="." event="god_event" port="user_input" cond="INSTATE('/Main/SimulationState/Paused')">
+                            <parameter name="new_state" />
+                            <script>
+                                result = self.godEvent(new_state)
+                            </script>
+                            <raise event="god_event_result" port="user_output">
+                                <parameter expr="result" />
+                            </raise>
+                            <raise event="current_state" port="user_output">
+                                <parameter expr="self.clock / 1000.0" />
+                                <parameter expr="self.currentState" />
+                            </raise>
+                        </transition>
+                    </state>
+                </state>
+                <state id="UserOutput" initial="Waiting">
+                    <state id="Waiting">
+                        <transition target="." event="termination_condition">
+                            <raise event="terminated" port="user_output"/>
+                            <raise event="current_state" port="user_output">
+                                <parameter expr="self.clock / 1000.0" />
+                                <parameter expr="self.currentState" />
+                            </raise>
+                        </transition>
+                        <transition target="." event="paused">
+                            <raise event="paused" port="user_output" />
+                            <raise event="current_state" port="user_output">
+                                <parameter expr="self.clock / 1000.0" />
+                                <parameter expr="self.currentState" />
+                            </raise>
+                        </transition>
+                        <transition target="." event="big_step_done" cond="INSTATE('/Main/SimulationState/Running/Realtime') or INSTATE('/Main/SimulationState/Running/BigStep') or INSTATE('/Main/SimulationState/Running/BigStepDone')">
+                            <raise event="big_step_done" port="user_output" />
+                            <raise event="current_state" port="user_output">
+                                <parameter expr="self.clock / 1000.0" />
+                                <parameter expr="self.currentState" />
+                            </raise>
+                        </transition>
+                        <transition target="." event="small_step_done" cond="INSTATE('/Main/SimulationState/Running/SmallStep') or INSTATE('/Main/SimulationState/Running/SmallStepDone')">
+                            <raise event="small_step_done" port="user_output" />
+                            <raise event="current_state" port="user_output">
+                                <parameter expr="self.clock / 1000.0" />
+                                <parameter expr="self.currentState" />
+                            </raise>
+                        </transition>
+                        <transition target="." event="breakpoint_triggered">
+                            <raise event="breakpoint_triggered" port="user_output">
+                                <parameter expr="self.triggered_bp" />
+                            </raise>
+                            <raise event="current_state" port="user_output">
+                                <parameter expr="self.clock / 1000.0" />
+                                <parameter expr="self.currentState" />
+                            </raise>
+                        </transition>
+                    </state>
+                </state>
+                <transition target="../SimulationComplete" cond="INSTATE('./SimulationState/Stopped') and INSTATE('./SimulationFlow/Stopped')">
+                    <script>
+                        self.finalize()
+                    </script>
+                </transition>
+            </parallel>
+            <state id="SimulationComplete" />
+        </scxml>
+    </class>
+</diagram>

+ 147 - 0
debugging_fsa_cbd_composition/fsasimulator/fsasimulator_hierarchical.xml

@@ -0,0 +1,147 @@
+<?xml version="1.0" ?>
+<diagram name="FSASimulator" author="Sadaf Mustafiz and Bruno Barroca and Claudio Gomes">
+	<description>
+		An FSA simulator written in SCCD. It supports after and events.
+	</description>
+	<top>
+		from sccd.runtime.libs.ui import *
+		from sccd.runtime.libs.utils import *
+		import fsaclasses
+	</top>
+	<class name="FSASimulator" default="True">
+		<attribute name="elapsed"/>
+		<attribute name="super_step_completed"/>
+		<attribute name="model"/>
+		<attribute name="logicalTime"/>
+		<attribute name="timestep"/>
+		<attribute name="currentEvent"/>
+		<attribute name="selectedTransition"/>
+		<attribute name="eventList"/>
+		<attribute name="currentState"/>
+		<method name="FSASimulator">
+			<parameter name="amodel"/>
+			<parameter name="events"/>
+			<body>
+			<![CDATA[
+				self.model = amodel
+				self.eventList = events
+			]]>
+			</body>
+		</method>
+		<method name="processEvent">
+			<parameter name="event"/>
+			<body>
+			<![CDATA[
+				if (event != None):
+					self.eventList.popEvent(event)
+					event.processed = True
+			]]>
+			</body>
+		</method>
+		<method name="getInputEventAt">
+			<parameter name="time"/>
+			<body>
+			<![CDATA[
+				return self.eventList.getInputAt(time)
+			]]>
+			</body>
+		</method>
+		<scxml  initial="Started" final="End">
+			<state id="CheckTermination" initial="MacroStepProcessed">
+				<state id="MacroStepProcessed">
+					<transition target="../../End" cond="self.currentState.final">
+						<script>
+							<![CDATA[
+								print('Going to End... ')
+							]]>
+						</script>
+					</transition>
+					<transition target="../../DoSimulation" cond="not self.currentState.final">
+						<script>
+							<![CDATA[
+								print('Going to DoSimulation and reading events... ')
+								self.currentEvent = self.getInputEventAt(self.logicalTime)
+								self.selectedTransition = self.model.getTransitionFrom(self.currentState, self.currentEvent, self.elapsed)
+								print(self.currentEvent)
+								print(self.selectedTransition)
+							]]>
+						</script>
+					</transition>
+				</state>
+			</state>
+			<state id="DoSimulation" initial="MacroStepPrepared">
+				<state id="MicroStepPrepared">
+					<transition target="../MicroStepProcessed">
+						<script>
+							<![CDATA[
+								print('Going to MicroStepProcessed, taking transition and reading events... ')
+								print('Transition to be taken: ' + str(self.selectedTransition))
+								self.currentState = self.selectedTransition.target
+								self.elapsed = 0
+								self.processEvent(self.currentEvent)
+								print('New state: ' + str(self.currentState))
+								self.currentEvent = self.getInputEventAt(self.logicalTime)
+								self.selectedTransition = self.model.getTransitionFrom(self.currentState, self.currentEvent, self.elapsed)
+								print(self.currentEvent)
+								print(self.selectedTransition)
+							]]>
+						</script>
+					</transition>
+				</state>
+				<state id="MicroStepProcessed">
+					<transition target="../MicroStepPrepared" cond="self.selectedTransition != None">
+						<script>
+							<![CDATA[
+								print('Going to MicroStepPrepared... ')
+							]]>
+						</script>
+					</transition>
+					<transition target="../../CheckTermination" cond="self.selectedTransition == None">
+						<script>
+							<![CDATA[
+								print('Going to CheckTermination and advancing time... ')
+								self.logicalTime = self.logicalTime + self.timestep
+								self.elapsed = self.elapsed + self.timestep
+								print(self.logicalTime)
+								print(self.elapsed)
+							]]>
+						</script>
+					</transition>
+				</state>
+				<state id="MacroStepPrepared">
+					<transition target="../MicroStepProcessed">
+						<script>
+							<![CDATA[
+								print('Going to MicroStepProcessed... ')
+							]]>
+						</script>
+					</transition>
+				</state>
+			</state>
+			<state id="Initialized">
+				<transition target="../CheckTermination">
+					<script>
+						<![CDATA[
+							print('Going to MacroStepProcessed... ')
+						]]>
+					</script>
+				</transition>
+			</state>
+			<state id="Started">
+				<transition target="../Initialized">
+					<script>
+						<![CDATA[
+							print('Going to Initialized... ')
+							self.logicalTime = 0
+							self.elapsed = 0
+							self.timestep = 1.0
+							self.currentState = self.model.initialState
+						]]>
+					</script>
+				</transition>
+			</state>
+			<state id="End">
+			</state>
+		</scxml>
+	</class>
+</diagram>

+ 6 - 0
debugging_fsa_cbd_composition/fsasimulator/generateSCCD.bat

@@ -0,0 +1,6 @@
+@ECHO OFF
+setlocal
+set PYTHONPATH=C:\Users\clagms\Source Control\Git_SCCD\src\build\lib
+python -m sccd.compiler.sccdc -p threads -l python -o fsasimulator.py fsasimulator_hierarchical.xml
+endlocal
+pause

+ 128 - 0
debugging_fsa_cbd_composition/fsasimulator/run_debug.py

@@ -0,0 +1,128 @@
+import target
+from sccd.runtime.statecharts_core import Event
+import threading
+import fsaclasses
+
+def buildModel():
+    statea = fsaclasses.State("a")
+    stateb = fsaclasses.State("b")
+    statet = fsaclasses.State("t")
+    statec = fsaclasses.State("c", final=True)
+    
+    transitionab = fsaclasses.Transition("a2b",statea,stateb)
+    transitionab.trigger = fsaclasses.Event("a")
+    
+    transitionbt = fsaclasses.Transition("b2t",stateb,statet)
+    transitionbt.trigger = fsaclasses.After(fsaclasses.Float(2.0))
+    
+    transitiontc = fsaclasses.Transition("t2c",statet,statec)
+
+    fsamodel = fsaclasses.FSAModel(
+                        [statea,stateb,statec],
+                        [transitionab,transitionbt, transitiontc]
+                        )
+    fsamodel.initialState = statea
+    return fsamodel
+
+if __name__ == '__main__':
+    fsamodel = buildModel()
+    events = fsaclasses.Events([fsaclasses.RunTimeEvent('a', 3.0)])
+    controller = target.Controller(fsamodel, events)
+    
+    def set_defaults(inp, defaultlist):
+        for i, v in enumerate(defaultlist):
+            if len(inp) == i + 1:
+                inp.append(v)
+                
+    def get_bool(val):
+        if val.lower() in ["true", "yes", "1"]:
+            return True
+        else:
+            return False
+
+    def raw_inputter():
+        while 1:
+            inp = raw_input().split(" ")
+            action = inp[0]
+            if action == "continuous":
+                params = []
+            elif action == "realtime":
+                set_defaults(inp, [1.0])
+                params = [inp[1]]
+            elif action == "big_step":
+                params = []
+            elif action == "small_step":
+                params = []
+            elif action == "pause":
+                params = []
+            elif action == "add_breakpoint":
+                if len(inp) < 5:
+                    print("Adding a breakpoint requires 4 parameters!")
+                    continue
+                # Merge together the final part again
+                params = [inp[1], " ".join(inp[2:-2]).replace("\\n", "\n").replace("\\t", "\t"), get_bool(inp[-2]), get_bool(inp[-1])]
+                print("Generated parameters: " + str(params))
+            elif action == "del_breakpoint":
+                if len(inp) < 2:
+                    print("Breakpoint removal requires 1 parameter!")
+                    continue
+                params = [inp[1]]
+            elif action == "toggle_breakpoint":
+                params = [inp[1]]
+            elif action == "list_breakpoints":
+                params = []
+            elif action == "god_event":
+                if len(inp) != 2:
+                    print("God events require 1 parameter!")
+                    continue
+                params = [inp[1]]
+            elif action == "help":
+                print("Supported operations:")
+                print("  continuous")
+                print("   --> Simulate until termination time is reached")
+                print("  pause")
+                print("   --> Pause the simulation")
+                print("  realtime [realtime_scale]")
+                print("   --> Simulate in realtime")
+                print("       realtime_scale can speed up or slow down the pace")
+                print("  big_step")
+                print("   --> Simulate a big step")
+                print("  small_step")
+                print("   --> Simulate a small step")
+                print("  add_breakpoint name function enabled disable_on_trigger")
+                print("   --> Add a breakpoint that will pause simulation when function returns True")
+                print("       the function should contain a definition of the 'breakpoint' function")
+                print("       and must take 1 parameter")
+                print("       enabled indicates whether or not the breakpoint should be checked")
+                print("       disable_on_trigger determines if the breakpoint should auto-disable")
+                print("       after being triggered")
+                print("  del_breakpoint name")
+                print("   --> Remove a breakpoint")
+                print("  toggle_breakpoint name")
+                print("   --> Toggle the designated breakpoint")
+                print("  list_breakpoints")
+                print("   --> List all breakpoints")
+                print("  god_event new_state")
+                print("   --> Updates the current state")
+                print("")
+                print("Defaults: ")
+                print("  realtime_scale   --> 1.0")
+                continue
+            else:
+                print("Command not understood: " + str(inp))
+                continue
+            controller.addInput(Event(action, "user_input", params))
+            
+    input_thread = threading.Thread(target=raw_inputter)
+    input_thread.daemon = True
+    input_thread.start()
+
+    output_listener = controller.addOutputListener(["user_output"])
+    def outputter():
+        while 1:
+            print output_listener.fetch(-1)
+    output_thread = threading.Thread(target=outputter)
+    output_thread.daemon = True
+    output_thread.start()
+
+    controller.start()

+ 35 - 0
debugging_fsa_cbd_composition/fsasimulator/run_sim.py

@@ -0,0 +1,35 @@
+'''
+Created on 10-sep.-2014
+
+@author: Bruno
+'''
+from fsaclasses import State, Transition, After, AtomValue, Float, FSAModel,Event,RunTimeEvent,Events
+import fsasimulator
+
+def buildModel():
+    statea = State("a")
+    stateb = State("b")
+    statet = State("t")
+    statec = State("c", final=True)
+    
+    transitionab = Transition("a2b",statea,stateb)
+    transitionab.trigger = Event("a")
+    
+    transitionbt = Transition("b2t",stateb,statet)
+    transitionbt.trigger = After(Float(2.0))
+    
+    transitiontc = Transition("t2c",statet,statec)
+
+    fsamodel = FSAModel(
+                        [statea,stateb,statec],
+                        [transitionab,transitionbt, transitiontc]
+                        )
+    fsamodel.initialState = statea
+    return fsamodel
+
+if __name__ == '__main__':
+    
+    fsamodel = buildModel()
+    events = Events([RunTimeEvent('a',3.0)])
+    controller = fsasimulator.Controller(fsamodel, events, [])
+    controller.start()

+ 772 - 0
debugging_fsa_cbd_composition/fsasimulator/target.py

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