Kaynağa Gözat

ported hybrid simulator to new sccd compiler

Cláudio Gomes 9 yıl önce
ebeveyn
işleme
3d90bbf91c

+ 1 - 0
.gitignore

@@ -199,3 +199,4 @@ sympy-plots-for-*.tex/
 fsa_cbd_composition/cbdsimulator/plot.html
 fsa_cbd_composition/cbdsimulator/log.txt
 fsa_cbd_composition/fsasimulator/log.txt
+fsa_cbd_composition/fsa_cbd_simulator/log.txt

Dosya farkı çok büyük olduğundan ihmal edildi
+ 1852 - 484
fsa_cbd_composition/figures/hybrid_fsa_sccd_hierarchical.graphml


+ 3 - 0
fsa_cbd_composition/fsa_cbd_simulator/.pydevproject

@@ -5,4 +5,7 @@
 <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>

+ 17 - 0
fsa_cbd_composition/fsa_cbd_simulator/fsa_cbd_simulator weaved_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="/fsa_cbd_simulator/weaved_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:fsa_cbd_simulator/weaved_runner.py}"/>
+<stringAttribute key="org.eclipse.ui.externaltools.ATTR_OTHER_WORKING_DIRECTORY" value="${workspace_loc:fsa_cbd_simulator}"/>
+<stringAttribute key="org.eclipse.ui.externaltools.ATTR_TOOL_ARGUMENTS" value=""/>
+<stringAttribute key="org.eclipse.ui.externaltools.ATTR_WORKING_DIRECTORY" value="${workspace_loc:fsa_cbd_simulator}"/>
+<stringAttribute key="org.python.pydev.debug.ATTR_INTERPRETER" value="__default"/>
+<stringAttribute key="org.python.pydev.debug.ATTR_PROJECT" value="fsa_cbd_simulator"/>
+<intAttribute key="org.python.pydev.debug.ATTR_RESOURCE_TYPE" value="1"/>
+<stringAttribute key="process_factory_id" value="org.python.pydev.debug.processfactory.PyProcessFactory"/>
+</launchConfiguration>

+ 6 - 0
fsa_cbd_composition/fsa_cbd_simulator/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\fsa_cbd_simulator\weaved_cbd_fsa_simulator_hierarchical.sccd" -o "C:\Users\clagms\Source Control\Git_MLE\fsa_cbd_composition\fsa_cbd_simulator\weaved_cbd_fsa_simulator.py"
+endlocal
+pause

Dosya farkı çok büyük olduğundan ihmal edildi
+ 642 - 1024
fsa_cbd_composition/fsa_cbd_simulator/weaved_cbd_fsa_simulator.py


+ 492 - 0
fsa_cbd_composition/fsa_cbd_simulator/weaved_cbd_fsa_simulator.py.xml

@@ -0,0 +1,492 @@
+<?xml version="1.0" ?>
+<diagram name="Weaved_CBD_FSA_Simulator_Manual" author="Sadaf Mustafiz and Bruno Barroca and Claudio Gomes">
+	<description>
+		Automatically woven CBD and FSA simulators with the FSA being the dominant.
+	</description>
+	<top>
+		from sccd.runtime.libs.ui import *
+		from sccd.runtime.libs.utils import *
+		import copy
+		from CBD_Controller import CBDController
+		import Options
+		from fsa_cbd_weaved_classes import CBDState
+		from weaved_cbd_fsa_lib import FSACBDLib
+	</top>
+	<class name="Weaved_CBD_FSA_Simulator" default="True">
+		<attribute name="weaved_global_state"/>
+		<attribute name="fsa_elapsed"/>
+		<attribute name="cbd_options"/>
+		<attribute name="weaved_lib"/>
+		<attribute name="woven_child_initialized"/>
+		<attribute name="cbd_clock"/>
+		<attribute name="fsa_currentEvent"/>
+		<attribute name="weaved_delta"/>
+		<attribute name="weaved_model"/>
+		<attribute name="cbd_controller"/>
+		<attribute name="fsa_timestep"/>
+		<attribute name="cbd_currentCompIdx"/>
+		<attribute name="fsa_eventList"/>
+		<attribute name="cbd_depGraph"/>
+		<attribute name="fsa_selectedTransition"/>
+		<attribute name="cbd_strongComponentList"/>
+		<attribute name="weaved_previous_global_state"/>
+		<attribute name="cbd_delta"/>
+		<attribute name="weaved_triggered_when_transition"/>
+		<attribute name="cbd_iteration"/>
+		<attribute name="fsa_logicalTime"/>
+		<attribute name="fsa_currentState"/>
+		<method name="Weaved_CBD_FSA_Simulator">
+			<parameter name="cbd_options"/>
+			<parameter name="amodel"/>
+			<parameter name="fsa_events"/>
+			<body>
+			<![CDATA[
+				self.weaved_lib = FSACBDLib()
+				self.cbd_options = cbd_options
+				self.cbd_delta = self.cbd_options.getDeltaT()
+				self.weaved_model = amodel
+				self.fsa_eventList = fsa_events
+				self.fsa_timestep = 1.0
+			]]>
+			</body>
+		</method>
+		<method name="fsa_processEvent">
+			<parameter name="event"/>
+			<body>
+			<![CDATA[
+				if (event != None):
+					self.fsa_eventList.popEvent(event)
+					event.processed = True
+			]]>
+			</body>
+		</method>
+		<method name="updateCBDState">
+			<body>
+			<![CDATA[
+				self.weaved_lib.updateCBDState(self.weaved_global_state, self.fsa_currentState.cbd)
+			]]>
+			</body>
+		</method>
+		<method name="cbd_maxIterationsReached">
+			<body>
+			<![CDATA[
+				return self.cbd_iteration >= self.cbd_options.getMaxIterations()
+			]]>
+			</body>
+		</method>
+		<method name="fsa_getInputEventAt">
+			<parameter name="time"/>
+			<body>
+			<![CDATA[
+				return self.fsa_eventList.getInputAt(time)
+			]]>
+			</body>
+		</method>
+		<method name="cbd_computeBlock">
+			<body>
+			<![CDATA[
+				if self.cbd_currentComponentIsCycle():
+					self.cbd_controller.computeNextAlgebraicLoop(self.cbd_strongComponentList[self.cbd_currentCompIdx], self.cbd_iteration)
+				else:
+					self.cbd_controller.computeNextBlock(self.cbd_strongComponentList[self.cbd_currentCompIdx], self.cbd_iteration)
+			]]>
+			</body>
+		</method>
+		<method name="updateGlobalState">
+			<body>
+			<![CDATA[
+				self.weaved_previous_global_state = copy.deepcopy(self.weaved_global_state)
+				self.weaved_lib.updateGlobalState(self.weaved_global_state, self.fsa_currentState.cbd, self.cbd_clock)
+			]]>
+			</body>
+		</method>
+		<method name="cbd_currentComponentIsCycle">
+			<body>
+			<![CDATA[
+				return self.cbd_controller.componentIsCycle(self.cbd_strongComponentList[self.cbd_currentCompIdx], self.cbd_depGraph)
+			]]>
+			</body>
+		</method>
+		<method name="cbd_hasNextStrongComponent">
+			<body>
+			<![CDATA[
+				return (self.cbd_currentCompIdx) < len(self.cbd_strongComponentList)
+			]]>
+			</body>
+		</method>
+		<method name="getTriggeredWhenTransition">
+			<body>
+			<![CDATA[
+				return self.weaved_lib.getTriggeredWhenTransition(self.weaved_model, self.fsa_currentState, self.weaved_global_state, self.weaved_previous_global_state)
+			]]>
+			</body>
+		</method>
+		<scxml  initial="FSA" final="HybridTerminated">
+			<state id="ChildPaused">
+				<transition target="../NoStateEventDetected" cond="self.weaved_triggered_when_transition == None">
+					<script>
+						<![CDATA[
+							print('From ChildPaused to NoStateEventDetected... ')
+						]]>
+					</script>
+				</transition>
+				<transition target="../StateEventDetected" cond="self.weaved_triggered_when_transition != None">
+					<script>
+						<![CDATA[
+							print('From ChildPaused to StateEventDetected... ')
+						]]>
+					</script>
+				</transition>
+			</state>
+			<state id="ParentMicroStepProcessed">
+				<transition target="../ParentPaused">
+					<script>
+						<![CDATA[
+							print('From ParentMicroStepProcessed to ParentPaused and resetting the child... ')
+							self.woven_child_initialized = False
+						]]>
+					</script>
+				</transition>
+			</state>
+			<state id="ChildNotInitialized">
+				<transition target="../CBD/Started">
+					<script>
+						<![CDATA[
+							print('From ChildNotInitialized to CBD/Started... ')
+							self.cbd_delta = self.weaved_delta
+							self.updateCBDState()
+							self.woven_child_initialized = True
+						]]>
+					</script>
+				</transition>
+			</state>
+			<state id="ChildDetected">
+				<transition target="../ChildInitialized" cond="self.woven_child_initialized">
+					<script>
+						<![CDATA[
+							print('From ChildDetected to ChildInitialized... ')
+						]]>
+					</script>
+				</transition>
+				<transition target="../ChildNotInitialized" cond="not self.woven_child_initialized">
+					<script>
+						<![CDATA[
+							print('From ChildDetected to ChildNotInitialized... ')
+						]]>
+					</script>
+				</transition>
+			</state>
+			<state id="ChildProcessed">
+				<transition target="../FSA/MicroStepProcessed">
+					<script>
+						<![CDATA[
+							print('From ChildProcessed to FSA/MicroStepProcessed... ')
+						]]>
+					</script>
+				</transition>
+			</state>
+			<state id="ChildInitialized">
+				<transition target="../CBD/MacroStepProcessed">
+					<script>
+						<![CDATA[
+							print('From ChildInitialized to CBD/MacroStepProcessed... ')
+							self.cbd_clock = self.cbd_clock + self.cbd_delta
+							self.cbd_iteration = self.cbd_iteration + 1
+							self.cbd_controller.advanceTimeStep()
+							print('CBD clock: ' + str(self.cbd_clock))
+							print('CBD iteration: ' + str(self.cbd_iteration))
+						]]>
+					</script>
+				</transition>
+			</state>
+			<state id="HybridTerminated">
+			</state>
+			<state id="FSA" initial="Started">
+				<state id="MacroStepPrepared">
+					<transition target="../../ParentPaused">
+						<script>
+							<![CDATA[
+								print('From FSA/MacroStepPrepared to ParentPaused... ')
+							]]>
+						</script>
+					</transition>
+					<transition target="../MicroStepProcessed" cond="False">
+						<script>
+							<![CDATA[
+								print('From FSA/MacroStepPrepared to MicroStepProcessed... ')
+							]]>
+						</script>
+					</transition>
+				</state>
+				<state id="MicroStepPrepared">
+					<transition target="../../ParentMicroStepProcessed">
+						<script>
+							<![CDATA[
+								print('From FSA/MicroStepPrepared to ParentMicroStepProcessed and attempting to take transition... ')
+								print('Transition to be taken: ' + str(self.fsa_selectedTransition))
+								self.fsa_currentState = self.fsa_selectedTransition.target
+								self.fsa_elapsed = 0
+								self.fsa_processEvent(self.fsa_currentEvent)
+								self.weaved_lib.dumpDiscreteEvent(self.weaved_model, self.fsa_logicalTime, self.fsa_currentState, self.fsa_selectedTransition)
+								self.weaved_lib.dumpGlobalState(self.weaved_model, self.weaved_global_state, self.fsa_logicalTime, self.fsa_currentState)
+								print('New state: ' + str(self.fsa_currentState))
+								print('Reading events:')
+								self.fsa_currentEvent = self.fsa_getInputEventAt(self.fsa_logicalTime)
+								self.fsa_selectedTransition = self.weaved_model.getTransitionFrom(self.fsa_currentState, self.fsa_currentEvent, self.fsa_elapsed)
+								print(self.fsa_currentEvent)
+								print(self.fsa_selectedTransition)
+							]]>
+						</script>
+					</transition>
+					<transition target="../MicroStepProcessed" cond="False">
+						<script>
+							<![CDATA[
+								print('From FSA/MicroStepPrepared to MicroStepProcessed and attempting to take transition... ')
+								print('Transition to be taken: ' + str(self.fsa_selectedTransition))
+								self.fsa_currentState = self.fsa_selectedTransition.target
+								self.fsa_elapsed = 0
+								self.fsa_processEvent(self.fsa_currentEvent)
+								self.weaved_lib.dumpDiscreteEvent(self.weaved_model, self.fsa_logicalTime, self.fsa_currentState, self.fsa_selectedTransition)
+								self.weaved_lib.dumpGlobalState(self.weaved_model, self.weaved_global_state, self.fsa_logicalTime, self.fsa_currentState)
+								print('New state: ' + str(self.fsa_currentState))
+								print('Reading events:')
+								self.fsa_currentEvent = self.fsa_getInputEventAt(self.fsa_logicalTime)
+								self.fsa_selectedTransition = self.weaved_model.getTransitionFrom(self.fsa_currentState, self.fsa_currentEvent, self.fsa_elapsed)
+								print(self.fsa_currentEvent)
+								print(self.fsa_selectedTransition)
+							]]>
+						</script>
+					</transition>
+				</state>
+				<state id="Initialized">
+					<transition target="../CheckTermination">
+						<script>
+							<![CDATA[
+								print('From FSA/Initialized to FSA/CheckTermination... ')
+							]]>
+						</script>
+					</transition>
+				</state>
+				<state id="MicroStepProcessed">
+					<transition target="../MicroStepPrepared" cond="self.fsa_selectedTransition != None">
+						<script>
+							<![CDATA[
+								print('From FSA/MicroStepProcessed to MicroStepPrepared... ')
+							]]>
+						</script>
+					</transition>
+					<transition target="../CheckTermination" cond="self.fsa_selectedTransition == None">
+						<script>
+							<![CDATA[
+								print('From FSA/MicroStepProcessed to FSA/CheckTermination and advancing time... ')
+								self.fsa_logicalTime = self.fsa_logicalTime + self.fsa_timestep
+								self.fsa_elapsed = self.fsa_elapsed + self.fsa_timestep
+								print(self.fsa_logicalTime)
+								print(self.fsa_elapsed)
+							]]>
+						</script>
+					</transition>
+				</state>
+				<state id="Started">
+					<transition target="../../ParentStarted">
+						<script>
+							<![CDATA[
+								print('From FSA/Started to ParentStarted... ')
+								self.weaved_delta = min(self.fsa_timestep, self.cbd_delta)
+								self.fsa_logicalTime = 0.0
+								self.fsa_elapsed = 0
+								self.fsa_timestep = self.weaved_delta
+								self.fsa_currentState = self.weaved_model.initialState
+							]]>
+						</script>
+					</transition>
+				</state>
+				<state id="CheckTermination" initial="MacroStepProcessed">
+					<state id="MacroStepProcessed">
+						<transition target="../../MacroStepPrepared" cond="not self.fsa_currentState.final">
+							<script>
+								<![CDATA[
+									print('From FSA/CheckTermination/MacroStepProcessed to FSA/MacroStepPrepared and reading events... ')
+									self.fsa_currentEvent = self.fsa_getInputEventAt(self.fsa_logicalTime)
+									self.fsa_selectedTransition = self.weaved_model.getTransitionFrom(self.fsa_currentState, self.fsa_currentEvent, self.fsa_elapsed)
+									print(self.fsa_currentEvent)
+									print(self.fsa_selectedTransition)
+								]]>
+							</script>
+						</transition>
+						<transition target="../../Terminated" cond="self.fsa_currentState.final">
+							<script>
+								<![CDATA[
+									print('From FSA/CheckTermination/MacroStepProcessed to Terminated... ')
+								]]>
+							</script>
+						</transition>
+					</state>
+				</state>
+				<state id="Terminated">
+					<transition target="../../HybridTerminated">
+						<script>
+							<![CDATA[
+								print('From FSA/Terminated to HybridTerminated... ')
+							]]>
+						</script>
+					</transition>
+				</state>
+			</state>
+			<state id="NoStateEventDetected">
+				<transition target="../ChildProcessed">
+					<script>
+						<![CDATA[
+							print('From NoStateEventDetected to ChildProcessed... ')
+						]]>
+					</script>
+				</transition>
+			</state>
+			<state id="StateEventDetected">
+				<transition target="../ChildProcessed">
+					<script>
+						<![CDATA[
+							print('From StateEventDetected to ChildProcessed... ')
+							if self.fsa_selectedTransition == None:
+								self.fsa_selectedTransition = self.weaved_triggered_when_transition
+						]]>
+					</script>
+				</transition>
+			</state>
+			<state id="ParentPaused">
+				<transition target="../ChildDetected" cond="isinstance(self.fsa_currentState, CBDState)">
+					<script>
+						<![CDATA[
+							print('From ParentPaused to ChildDetected... ')
+							self.cbd_model = self.fsa_currentState.cbd
+						]]>
+					</script>
+				</transition>
+				<transition target="../ChildProcessed" cond="not isinstance(self.fsa_currentState, CBDState)">
+					<script>
+						<![CDATA[
+							print('From ParentPaused to ChildProcessed without any child to process... ')
+						]]>
+					</script>
+				</transition>
+			</state>
+			<state id="ParentStarted">
+				<transition target="../FSA/Initialized">
+					<script>
+						<![CDATA[
+							print('From ParentStarted to FSA/Initialized... ')
+							self.weaved_global_state = dict()
+							self.weaved_previous_global_state = dict()
+							self.woven_child_initialized = False
+						]]>
+					</script>
+				</transition>
+			</state>
+			<state id="CBD" initial="Started">
+				<state id="Initialized">
+					<transition target="../MacroStepProcessed">
+						<script>
+							<![CDATA[
+								print('From CBD/Initialized to MacroStepProcessed... ')
+							]]>
+						</script>
+					</transition>
+				</state>
+				<state id="Started">
+					<transition target="../Initialized">
+						<script>
+							<![CDATA[
+								print('From CBD/Started to Initialized... ')
+								print('Performing initialization...')
+								self.cbd_iteration = 0
+								self.cbd_clock = 0
+								self.cbd_controller = CBDController(self.cbd_model, self.cbd_delta)
+								self.cbd_controller.initSimulation()
+								print('Performing initialization... DONE')
+							]]>
+						</script>
+					</transition>
+				</state>
+				<state id="MicroStepProcessed">
+					<transition target="../MicroStepPrepared" cond="self.cbd_hasNextStrongComponent()">
+						<script>
+							<![CDATA[
+								print('From CBD/MicroStepProcessed to MicroStepPrepared')
+							]]>
+						</script>
+					</transition>
+					<transition target="../MacroStepProcessed" cond="not self.cbd_hasNextStrongComponent() and False">
+						<script>
+							<![CDATA[
+								print('From CBD/MicroStepProcessed to MacroStepProcessed and advancing time... ')
+								self.cbd_clock = self.cbd_clock + self.cbd_delta
+								self.cbd_iteration = self.cbd_iteration + 1
+								self.cbd_controller.advanceTimeStep()
+								print('CBD clock: ' + str(self.cbd_clock))
+								print('CBD iteration: ' + str(self.cbd_iteration))
+							]]>
+						</script>
+					</transition>
+					<transition target="../../ChildPaused" cond="not self.cbd_hasNextStrongComponent()">
+						<script>
+							<![CDATA[
+								print('From CBD/MicroStepProcessed to ChildPaused and detecting triggered transitions... ')
+								self.updateGlobalState()
+								self.weaved_lib.dumpGlobalState(self.weaved_model, self.weaved_global_state, self.fsa_logicalTime, self.fsa_currentState)
+								self.weaved_triggered_when_transition = self.getTriggeredWhenTransition()
+							]]>
+						</script>
+					</transition>
+				</state>
+				<state id="MacroStepPrepared">
+					<transition target="../MicroStepProcessed">
+						<script>
+							<![CDATA[
+								print('From CBD/MacroStepPrepared to MicroStepProcessed... ')
+							]]>
+						</script>
+					</transition>
+				</state>
+				<state id="MacroStepProcessed">
+					<transition target="../Terminated" cond="self.cbd_maxIterationsReached()">
+						<script>
+							<![CDATA[
+								print('From CBD/MacroStepProcessed to Terminated... ')
+							]]>
+						</script>
+					</transition>
+					<transition target="../MacroStepPrepared" cond="not self.cbd_maxIterationsReached()">
+						<script>
+							<![CDATA[
+								print('From CBD/MacroStepProcessed to MacroStepPrepared... ')
+								self.cbd_currentCompIdx = 0
+								self.cbd_depGraph = self.cbd_controller.createDepGraph(self.cbd_iteration)
+								self.cbd_strongComponentList = self.cbd_controller.createStrongComponents(self.cbd_depGraph, self.cbd_iteration)
+							]]>
+						</script>
+					</transition>
+				</state>
+				<state id="Terminated">
+					<transition target="../../HybridTerminated">
+						<script>
+							<![CDATA[
+								print('From CBD/Terminated to HybridTerminated... ')
+							]]>
+						</script>
+					</transition>
+				</state>
+				<state id="MicroStepPrepared">
+					<transition target="../MicroStepProcessed">
+						<script>
+							<![CDATA[
+								print('From CBD/MicroStepPrepared to MicroStepProcessed...')
+								self.cbd_computeBlock()
+								self.cbd_currentCompIdx = self.cbd_currentCompIdx + 1
+							]]>
+						</script>
+					</transition>
+				</state>
+			</state>
+		</scxml>
+	</class>
+</diagram>

+ 382 - 0
fsa_cbd_composition/fsa_cbd_simulator/weaved_cbd_fsa_simulator_hierarchical.sccd

@@ -0,0 +1,382 @@
+Diagram(name = 'Weaved_CBD_FSA_Simulator_Manual',
+        author = 'Sadaf Mustafiz and Bruno Barroca and Claudio Gomes',
+        description = 'Automatically woven CBD and FSA simulators with the FSA being the dominant.'):
+    Top {
+		import copy
+        from CBD_Controller import CBDController
+		import Options
+		from fsa_cbd_weaved_classes import CBDState
+		from weaved_cbd_fsa_lib import FSACBDLib
+    }
+
+    Class(name = 'Weaved_CBD_FSA_Simulator', default = True):
+        Attribute(name = 'fsa_timestep')
+		Attribute(name = 'fsa_elapsed')
+		Attribute(name = 'fsa_currentState')
+		Attribute(name = 'fsa_logicalTime')
+		Attribute(name = 'fsa_currentEvent')
+		Attribute(name = 'fsa_selectedTransition')
+		Attribute(name = 'fsa_eventList')
+		
+		Attribute(name='cbd_iteration')
+        Attribute(name='cbd_strongComponentList')
+        Attribute(name='cbd_currentCompIdx')
+        Attribute(name='cbd_clock')
+        Attribute(name='cbd_options')
+        Attribute(name='cbd_delta')
+        Attribute(name='cbd_controller')
+		Attribute(name='cbd_depGraph')
+		
+		Attribute(name='weaved_delta')
+        Attribute(name='woven_child_initialized')
+		Attribute(name='weaved_model')
+        Attribute(name='weaved_global_state')
+        Attribute(name='weaved_previous_global_state')
+        Attribute(name='weaved_triggered_when_transition')
+        Attribute(name='weaved_lib')
+        
+		Method fsa_processEvent(event) {
+			if (event != None):
+				self.fsa_eventList->popEvent(event)
+				event.processed = True
+			end
+		}
+		
+		Method fsa_getInputEventAt(time) {
+			return self.fsa_eventList->getInputAt(time)
+		}
+		
+		Method cbd_computeBlock(){
+			if self->cbd_currentComponentIsCycle():
+				self.cbd_controller->computeNextAlgebraicLoop(self.cbd_strongComponentList[self.cbd_currentCompIdx], self.cbd_iteration)
+			else:
+				self.cbd_controller->computeNextBlock(self.cbd_strongComponentList[self.cbd_currentCompIdx], self.cbd_iteration)
+			end
+		}
+		
+		Method cbd_maxIterationsReached() {
+			return self.cbd_iteration >= self.cbd_options->getMaxIterations()
+        }
+		
+		Method cbd_hasNextStrongComponent() {
+			return (self.cbd_currentCompIdx) < len(self.cbd_strongComponentList)
+        }
+		
+		Method cbd_currentComponentIsCycle() {
+            return self.cbd_controller->componentIsCycle(self.cbd_strongComponentList[self.cbd_currentCompIdx], self.cbd_depGraph)
+        }
+		
+		Method updateGlobalState() {
+			self.weaved_previous_global_state = copy->deepcopy(self.weaved_global_state)
+            self.weaved_lib->updateGlobalState(self.weaved_global_state, self.fsa_currentState.cbd, self.cbd_clock)
+        }
+		
+		Method updateCBDState() {
+            self.weaved_lib->updateCBDState(self.weaved_global_state, self.fsa_currentState.cbd)
+        }
+		
+		Method getTriggeredWhenTransition() {
+            return self.weaved_lib->getTriggeredWhenTransition(self.weaved_model, self.fsa_currentState, self.weaved_global_state, self.weaved_previous_global_state)
+        }
+		
+        Constructor(cbd_options, amodel, fsa_events) {
+            self.weaved_lib = FSACBDLib()
+			
+			self.cbd_options = cbd_options
+			self.cbd_delta = self.cbd_options->getDeltaT()
+			
+			self.weaved_model = amodel
+			self.fsa_eventList = fsa_events
+			self.fsa_timestep = 1.0
+        }
+		
+        StateMachine:
+            initial = 'FSA'
+			final = 'HybridTerminated'
+			State('ParentStarted'):
+				Transition(target='../FSA/Initialized'):
+					Actions {
+						print('From ParentStarted to FSA/Initialized... ')
+						self.weaved_global_state = dict()
+						self.weaved_previous_global_state = dict()
+						self.woven_child_initialized = False
+					}
+			State('FSA'):
+				initial = 'Started'
+				State('Started'):
+					Transition(target='../../ParentStarted'):
+						Actions {
+							print('From FSA/Started to ParentStarted... ')
+							self.weaved_delta = min(self.fsa_timestep, self.cbd_delta)
+							self.fsa_logicalTime = 0.0
+							self.fsa_elapsed = 0
+							self.fsa_timestep = self.weaved_delta
+							self.fsa_currentState = self.weaved_model.initialState
+						}
+				State('Initialized'):
+					Transition(target='../CheckTermination'):
+						Actions {
+							print('From FSA/Initialized to FSA/CheckTermination... ')
+						}
+				State('CheckTermination'):
+					initial = 'MacroStepProcessed'
+					State('MacroStepProcessed'):
+						Transition(target='../../MacroStepPrepared'):
+							guard = { not self.fsa_currentState.final }
+							Actions {
+								print('From FSA/CheckTermination/MacroStepProcessed to FSA/MacroStepPrepared and reading events... ')
+								self.fsa_currentEvent = self->fsa_getInputEventAt(self.fsa_logicalTime)
+								self.fsa_selectedTransition = self.weaved_model->getTransitionFrom(self.fsa_currentState, self.fsa_currentEvent, self.fsa_elapsed)
+								print(self.fsa_currentEvent)
+								print(self.fsa_selectedTransition)
+							}
+						Transition(target='../../Terminated'):
+							guard = { self.fsa_currentState.final }
+							Actions {
+								print('From FSA/CheckTermination/MacroStepProcessed to Terminated... ')
+							}
+				State('MacroStepPrepared'):
+					Transition(target='../MicroStepProcessed'):
+						guard = { False }
+						Actions {
+							print('From FSA/MacroStepPrepared to MicroStepProcessed... ')
+						}
+					Transition(target='../../ParentPaused'):
+						Actions {
+							print('From FSA/MacroStepPrepared to ParentPaused... ')
+						}
+				State('MicroStepProcessed'):
+					Transition(target='../CheckTermination'):
+						guard = { self.fsa_selectedTransition == None}
+						Actions {
+							print('From FSA/MicroStepProcessed to FSA/CheckTermination and advancing time... ')
+							self.fsa_logicalTime = self.fsa_logicalTime + self.fsa_timestep
+							self.fsa_elapsed = self.fsa_elapsed + self.fsa_timestep
+							print(self.fsa_logicalTime)
+							print(self.fsa_elapsed)
+						}
+					Transition(target='../MicroStepPrepared'):
+						guard = { self.fsa_selectedTransition != None }
+						Actions {
+							print('From FSA/MicroStepProcessed to MicroStepPrepared... ')
+						}
+				State('MicroStepPrepared'):
+					Transition(target='../MicroStepProcessed'):
+						guard = { False }
+						Actions {
+							print('From FSA/MicroStepPrepared to MicroStepProcessed and attempting to take transition... ')
+							print('Transition to be taken: ' + str(self.fsa_selectedTransition))
+							self.fsa_currentState = self.fsa_selectedTransition.target
+							self.fsa_elapsed = 0
+							self->fsa_processEvent(self.fsa_currentEvent)
+							self.weaved_lib->dumpDiscreteEvent(self.weaved_model, self.fsa_logicalTime, self.fsa_currentState , self.fsa_selectedTransition)
+							self.weaved_lib->dumpGlobalState(self.weaved_model, self.weaved_global_state , self.fsa_logicalTime, self.fsa_currentState)
+							print('New state: ' + str(self.fsa_currentState))
+							
+							print('Reading events:')
+							self.fsa_currentEvent = self->fsa_getInputEventAt(self.fsa_logicalTime)
+							self.fsa_selectedTransition = self.weaved_model->getTransitionFrom(self.fsa_currentState, self.fsa_currentEvent, self.fsa_elapsed)
+							print(self.fsa_currentEvent)
+							print(self.fsa_selectedTransition)
+						}
+					Transition(target='../../ParentMicroStepProcessed'):
+						Actions {
+							print('From FSA/MicroStepPrepared to ParentMicroStepProcessed and attempting to take transition... ')
+							print('Transition to be taken: ' + str(self.fsa_selectedTransition))
+							self.fsa_currentState = self.fsa_selectedTransition.target
+							self.fsa_elapsed = 0
+							self->fsa_processEvent(self.fsa_currentEvent)
+							self.weaved_lib->dumpDiscreteEvent(self.weaved_model, self.fsa_logicalTime, self.fsa_currentState , self.fsa_selectedTransition)
+							self.weaved_lib->dumpGlobalState(self.weaved_model, self.weaved_global_state , self.fsa_logicalTime, self.fsa_currentState)
+							print('New state: ' + str(self.fsa_currentState))
+							
+							print('Reading events:')
+							self.fsa_currentEvent = self->fsa_getInputEventAt(self.fsa_logicalTime)
+							self.fsa_selectedTransition = self.weaved_model->getTransitionFrom(self.fsa_currentState, self.fsa_currentEvent, self.fsa_elapsed)
+							print(self.fsa_currentEvent)
+							print(self.fsa_selectedTransition)
+						}
+				State('Terminated'):
+					Transition(target='../../HybridTerminated'):
+						Actions {
+							print('From FSA/Terminated to HybridTerminated... ')
+						}
+			State('ParentMicroStepProcessed'):
+				Transition(target='../ParentPaused'):
+					Actions {
+						print('From ParentMicroStepProcessed to ParentPaused and resetting the child... ')
+						self.woven_child_initialized = False
+					}
+			State('HybridTerminated')
+			State('ChildNotInitialized'):
+				Transition(target='../CBD/Started'):
+					Actions {
+						print('From ChildNotInitialized to CBD/Started... ')
+						self.cbd_delta = self.weaved_delta
+						self->updateCBDState()
+						self.woven_child_initialized = True
+					}
+			State('ChildInitialized'):
+				Transition(target='../CBD/MacroStepProcessed'):
+					Actions {
+						print('From ChildInitialized to CBD/MacroStepProcessed... ')
+						self.cbd_clock = self.cbd_clock + self.cbd_delta
+						self.cbd_iteration = self.cbd_iteration + 1
+						self.cbd_controller->advanceTimeStep()
+						print("CBD clock: " + str(self.cbd_clock))
+						print("CBD iteration: " + str(self.cbd_iteration))	
+					}
+			State('ChildPaused'):
+				Transition(target='../StateEventDetected'):
+					guard = { self.weaved_triggered_when_transition != None }
+					Actions {
+						print('From ChildPaused to StateEventDetected... ')
+					}
+				Transition(target='../NoStateEventDetected'):
+					guard = { self.weaved_triggered_when_transition == None }
+					Actions {
+						print('From ChildPaused to NoStateEventDetected... ')
+					}
+			State('NoStateEventDetected'):
+				Transition(target='../ChildProcessed'):
+					Actions {
+						print('From NoStateEventDetected to ChildProcessed... ')
+					}
+			State('StateEventDetected'):
+				Transition(target='../ChildProcessed'):
+					Actions {
+						print('From StateEventDetected to ChildProcessed... ')
+						if self.fsa_selectedTransition == None:
+							self.fsa_selectedTransition = self.weaved_triggered_when_transition
+						end
+					}
+			State('ChildProcessed'):
+				Transition(target='../FSA/MicroStepProcessed'):
+					Actions {
+						print('From ChildProcessed to FSA/MicroStepProcessed... ')
+					}
+			State('ParentPaused'):
+				Transition(target='../ChildProcessed'):
+					guard = { not isinstance(self.fsa_currentState, CBDState) }
+					Actions {
+						print('From ParentPaused to ChildProcessed without any child to process... ')
+					}
+				Transition(target='../ChildDetected'):
+					guard = { isinstance(self.fsa_currentState, CBDState) }
+					Actions {
+						print('From ParentPaused to ChildDetected... ')
+						self.cbd_model = self.fsa_currentState.cbd
+					}
+			State('ChildDetected'):
+				Transition(target='../ChildNotInitialized'):
+					guard = { not self.woven_child_initialized }
+					Actions {
+						print('From ChildDetected to ChildNotInitialized... ')
+					}
+				Transition(target='../ChildInitialized'):
+					guard = { self.woven_child_initialized }
+					Actions {
+						print('From ChildDetected to ChildInitialized... ')
+					}
+			State('CBD'):
+				initial = 'Started'
+				State('Started'):
+					Transition(target='../Initialized'):
+						Actions {
+							print('From CBD/Started to Initialized... ')
+							print('Performing initialization...')
+							self.cbd_iteration = 0
+							self.cbd_clock = 0
+							self.cbd_controller = CBDController(self.cbd_model,self.cbd_delta)
+							self.cbd_controller->initSimulation()
+							print('Performing initialization... DONE')
+						}
+				State('Initialized'):
+					Transition(target='../MacroStepProcessed'):
+						Actions {
+							print('From CBD/Initialized to MacroStepProcessed... ')
+						}
+				State('MacroStepProcessed'):
+					Transition(target='../MacroStepPrepared'):
+						guard = { not self->cbd_maxIterationsReached() }
+						Actions {
+							print('From CBD/MacroStepProcessed to MacroStepPrepared... ')
+							self.cbd_currentCompIdx = 0
+							self.cbd_depGraph = self.cbd_controller->createDepGraph(self.cbd_iteration)
+							self.cbd_strongComponentList = self.cbd_controller->createStrongComponents(self.cbd_depGraph, self.cbd_iteration)
+						}
+					Transition(target='../Terminated'):
+						guard = { self->cbd_maxIterationsReached() }
+						Actions {
+							print('From CBD/MacroStepProcessed to Terminated... ')
+						}
+				State('MacroStepPrepared'):
+					Transition(target='../MicroStepProcessed'):
+						Actions {
+							print('From CBD/MacroStepPrepared to MicroStepProcessed... ')
+						}
+				State('MicroStepProcessed'):
+					Transition(target='../MacroStepProcessed'):
+						guard = { not self->cbd_hasNextStrongComponent() and False }
+						Actions {
+							print('From CBD/MicroStepProcessed to MacroStepProcessed and advancing time... ')
+							self.cbd_clock = self.cbd_clock + self.cbd_delta
+							self.cbd_iteration = self.cbd_iteration + 1
+							self.cbd_controller->advanceTimeStep()
+							print("CBD clock: " + str(self.cbd_clock))
+							print("CBD iteration: " + str(self.cbd_iteration))
+						}
+					Transition(target='../../ChildPaused'):
+						guard = { not self->cbd_hasNextStrongComponent() }
+						Actions {
+							print('From CBD/MicroStepProcessed to ChildPaused and detecting triggered transitions... ')
+							self->updateGlobalState()
+							self.weaved_lib->dumpGlobalState(self.weaved_model, self.weaved_global_state , self.fsa_logicalTime, self.fsa_currentState)
+							self.weaved_triggered_when_transition = self->getTriggeredWhenTransition()
+						}
+					Transition(target='../MicroStepPrepared'):
+						guard = { self->cbd_hasNextStrongComponent() }
+						Actions {
+							print('From CBD/MicroStepProcessed to MicroStepPrepared')
+						}
+				State('MicroStepPrepared'):
+					Transition(target='../MicroStepProcessed'):
+						Actions {
+							print('From CBD/MicroStepPrepared to MicroStepProcessed...')
+							self->cbd_computeBlock()
+							self.cbd_currentCompIdx = self.cbd_currentCompIdx + 1
+						}
+				State('Terminated'):
+					Transition(target='../../HybridTerminated'):
+						Actions {
+							print('From CBD/Terminated to HybridTerminated... ')
+						}
+				
+			
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+

+ 0 - 1
fsa_cbd_composition/fsa_cbd_simulator/weaved_runner.py

@@ -56,7 +56,6 @@ if __name__ == '__main__':
     #events = Events([RunTimeEvent('enough',25.0)])
     controller = Controller(options, fsamodel, events, keep_running=False)
     controller.start()
-    controller.join()
     
     '''
     cbdModel = fsamodel.states[2].cbd;

+ 1 - 1
fsa_cbd_composition/fsasimulator/generateSCCD.bat

@@ -1,6 +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\fsasimulator.sccd" -o "C:\Users\clagms\Source Control\Git_MLE\fsa_cbd_composition\fsasimulator\fsasimulator.py"
+python "C:\Users\clagms\Source Control\Git_SCCD\textualnotations\sccdtnc.py" "C:\Users\clagms\Source Control\Git_MLE\fsa_cbd_composition\fsasimulator\fsasimulator_hierarchical.sccd" -o "C:\Users\clagms\Source Control\Git_MLE\fsa_cbd_composition\fsasimulator\fsasimulator.py"
 endlocal
 pause