Browse Source

added DEVS and a little PyDEVS to paper

sampieters 1 year ago
parent
commit
2a0866a69f

+ 18 - 1
examples/BouncingBalls/PyDEVS/target.py

@@ -1106,7 +1106,24 @@ class Ball(AtomicDEVS, ObjectManagerBase):
                 ev = Event("instance_started", None, [f"{input[0]}[{len(self.instances)-1}]"], input[2].instance)
                 self.to_send.append((input[0], input[1], ev))
             elif input[2].name == "delete_instance":
-                pass
+                for index in input[2].parameters[1]:
+                    i = self.instances[index]
+                    try:
+                        for assoc_name in i.associations:
+                            if assoc_name != 'parent':
+                                traversal_list = self.processAssociationReference(assoc_name)
+                                instances = self.getInstances(i["instance"], traversal_list)
+                                if len(instances) > 0:
+                                    raise RuntimeException("Error removing instance from association %s, still %i children left connected with association %s" % (association_name, len(instances), assoc_name))
+                        # TODO: These still do need to be implemented
+                        #association.removeInstance(i["instance"])
+                        #self.eventless.discard(i["instance"])
+                    except AssociationException as exception:
+                        raise RuntimeException("Error removing instance from association '" + association_name + "': " + str(exception))
+                    i.user_defined_destructor()
+                    i.stop()
+                self.instances = [self.instances[i] for i in range(len(self.instances)) if i not in input[2].parameters[1]]
+                #source.addEvent(Event("instance_deleted", parameters = [parameters[1]]))
             elif input[2].name == "associate_instance":
                 pass
             elif input[2].name == "disassociate_instance":

+ 9 - 11
paper/00-Abstract.tex

@@ -2,14 +2,12 @@
 \phantomsection 
 \addcontentsline{toc}{chapter}{Abstract}
 \chapter*{Abstract}
-This master's thesis explores the translation of Synchronous Concurrent Constraint Datalog (SCCD) models into the PyDEVS (Python-based Discrete Event System Specification) framework, investigating its implications and applications. SCCD, a formalism for modeling concurrent systems, offers powerful expressive capabilities for describing complex interactions. PyDEVS, on the other hand, provides a versatile platform for discrete event simulation.
-
-The primary objective of this research is to bridge the gap between these two simulation paradigms, facilitating the integration of SCCD models into the PyDEVS ecosystem. This translation enables the utilization of SCCD models within PyDEVS for simulation and analysis, thereby extending the reach of SCCD-based approaches to a broader audience of researchers and practitioners.
-
-The thesis first presents an in-depth analysis of SCCD and PyDEVS, highlighting their respective features, strengths, and weaknesses. Subsequently, it proposes a systematic methodology for translating SCCD models into PyDEVS specifications, addressing challenges such as semantic differences, modeling paradigms, and computational efficiency.
-
-To demonstrate the utility of this translation approach, the thesis showcases several case studies where SCCD models are successfully translated into PyDEVS and simulated using the PyDEVS framework. These case studies encompass diverse application domains, including concurrent systems, distributed algorithms, and communication protocols.
-
-Furthermore, the thesis discusses the practical implications and benefits of integrating SCCD into PyDEVS, such as enhanced scalability, interoperability with existing simulation tools, and the ability to leverage PyDEVS's rich ecosystem of libraries and tools for simulation analysis.
-
-Overall, this research contributes to advancing the field of discrete event simulation by facilitating the seamless integration of SCCD models into the PyDEVS framework, opening up new avenues for research and applications in diverse domains requiring concurrent system modeling and analysis.
+This master's thesis explores the translation of Statecharts and class diagrams (SCCD) models into the PyDEVS (Python-based Discrete Event System Specification) framework, investigating its implications and applications. 
+SCCD, a language that combines the Statecharts language with Class Diagrams. It allows users to model complex, timed, autonomous, reactive, dynamic-structure systems. PyDEVS, on the other hand, provides a versatile platform 
+for discrete event simulation. The primary objective of this research is to bridge the gap between these two simulation paradigms, facilitating the integration of SCCD models into the PyDEVS ecosystem. This translation 
+enables the utilization of SCCD models within PyDEVS for simulation and analysis, thereby extending the reach of SCCD-based approaches to a broader audience of researchers and practitioners. The thesis first presents an 
+in-depth analysis of SCCD and PyDEVS, highlighting their respective features, strengths, and weaknesses. Subsequently, it proposes a systematic methodology for translating SCCD models into PyDEVS specifications, addressing 
+challenges such as semantic differences, modeling paradigms, and computational efficiency. To demonstrate the utility of this translation approach, the thesis showcases several case studies where SCCD models are successfully 
+translated into PyDEVS and simulated using the PyDEVS framework. Furthermore, the thesis discusses the practical implications and benefits of integrating SCCD into PyDEVS, such as enhanced scalability, interoperability with 
+existing simulation tools, and the ability to leverage PyDEVS's rich ecosystem of libraries and tools for simulation analysis. Overall, this research contributes to advancing the field of discrete event simulation by 
+facilitating the seamless integration of SCCD models into the PyDEVS framework, opening up new avenues for research and applications in diverse domains requiring concurrent system modeling and analysis.

+ 4 - 1
paper/00-Acknowledgements.tex

@@ -2,4 +2,7 @@
 \phantomsection 
 \addcontentsline{toc}{chapter}{Acknowledgements}
 \chapter*{Acknowledgements}
-Write Acknowledgements here
+I would like to express my deepest gratitude to Professor Hans Vangheluwe for his invaluable guidance, unwavering support, and for entrusting me with the project that laid the foundation for this thesis. His insightful perspectives and encouragement have been instrumental in 
+shaping my academic journey.
+
+I am also indebted to Joeri Excelmans and Randy Paredis for their consistent assistance and unwavering commitment throughout the duration of this project. Their expertise, encouragement, and willingness to lend a helping hand have been truly invaluable.

+ 2 - 4
paper/01-Introduction.tex

@@ -12,12 +12,10 @@ Overall, this thesis aims to contribute to the advancement of discrete event sim
 
 \section{Definitions}
 \begin{enumerate}
-    \item \textbf{Synchronous Concurrent Constraint Datalog (SCCD):} A formalism for modeling concurrent systems, combining elements of constraint programming and database query languages to express constraints and concurrent actions in a synchronized manner.
+    \item \textbf{Statecharts and class diagrams (SCCD):} A language that combines the Statecharts language with Class Diagrams. It allows users to model complex, timed, autonomous, reactive, dynamic-structure systems.
     
     \item \textbf{PyDEVS:} Python-based Discrete Event System Specification, a framework for discrete event simulation that provides a platform for modeling and analyzing dynamic systems using the DEVS (Discrete Event System Specification) formalism.
-    
-    \item \textbf{Formalism:} A precise mathematical or computational framework used to represent and analyze systems, providing rules and syntax for expressing system behaviors.
-        
+            
     \item \textbf{Discrete Event Simulation:} A simulation technique used to model systems where events occur at distinct points in time, with changes in system state triggered by these events.
     
     \item \textbf{Translation:} The process of converting models or specifications from one formalism or representation to another while preserving essential characteristics and semantics.

+ 371 - 2
paper/02-Background.tex

@@ -5,5 +5,374 @@
 \subsection{Statechart}
 \subsection{SCXML}
 
-\section{PyDEVS}
-\subsection{DEVS Formalism}
+\section{DEVS Formalism}
+The Discrete Event System Specification (DEVS)
+formalism was first introduced by Zeigler (TODO) in 1976 to provide a rigourous common basis for discrete-event modelling and 
+simulation. For the class of formalisms denoted as discrete-event (TODO), system models are described at an abstraction 
+level where the time base is continuous (TODO), but during a bounded time-span, only a finite number of relevant events 
+occur. These events can cause the state of the system to change. In between events, the state of the system does not 
+change. This is unlike continuous models in which the state of the system may change continuously over time. As an 
+extension of Finite State Automata, the DEVS (Discrete Event Systems) formalism captures concepts from Discrete Event 
+simulation. As such it is a sound basis for meaningful model exchange in the Discrete Event realm. (TODO: citation)
+
+The DEVS formalism fits the general structure of deterministic, causal systems in classical systems theory. DEVS allows 
+for the description of system behaviour at two levels. At the lowest level, an atomic DEVS describes the autonomous 
+behaviour of a discrete-event system as a sequence of deterministic transitions between sequential states as well as 
+how it reacts to external input (events) and how it generates output (events). At the higher level, a coupled DEVS 
+describes a system as a network of coupled components. The components can be atomic DEVS models or coupled DEVS in their 
+own right. The connections denote how components influence each other. In particular, output events of one component 
+can become, via a network connection, input events of another component. It is shown in [Zei84a] how the DEVS formalism 
+is closed under coupling: for each coupled DEVS, a resultant atomic DEVS can be constructed. As such, any DEVS model, 
+be it atomic or coupled, can be replaced by an equivalent atomic DEVS. The construction procedure of a resultant atomic 
+DEVS is also the basis for the implementation of an abstract simulator or solver capable of simulating any DEVS model. 
+As a coupled DEVS may have coupled DEVS components, hierarchical modelling is supported. In the following, the different 
+aspects of the DEVS formalism are explained in more detail.
+
+\subsection{The atomic DEVS Formalism}
+The atomic DEVS formalism is a structure describing the different aspects of the discrete-event behaviour of a system:
+\begin{equation}
+    atomicDEVS \equiv \langle S, ta, \delta_{int}, X, \delta_{ext}, Y, \lambda \rangle
+\end{equation}
+The time base $T$ is continuous and is not mentioned explicitly
+\begin{equation}
+    T = \mathbb{R}
+\end{equation}
+The state set $S$ is the set of admissible sequential states: the DEVS dynamics consists of an ordered sequence of states
+from $S$. Typically, $S$ will be a structured set (a product set)
+\begin{equation}
+    S = \times_{i=1}^{n} S_i.
+\end{equation}
+This formalizes multiple (n) concurrent parts of a system. It is noted how a structured state set is often synthesized
+from the state sets of concurrent components in a coupled DEVS model. 
+
+The time the system remains in a sequential state before making a transition to the next sequential state is modelled by 
+the time advance function
+\begin{equation}
+    ta: S \rightarrow \mathbb{R}^+_{0, + \infty}.
+\end{equation}
+As time in the real world always advances, the image of $ta$ must be non-negative numbers. $ta = 0$ allows for the 
+representation of instantaneous transitions: no time elapses before transition to a new state. Obviously, this is an 
+abstraction of reality which may lead to simulation artifacts such as infinite instantaneous loops which do not correspond 
+to real physical behaviour. If the system is to stay in an end-state $s$ forever, this is modelled by means of $ta(s) = +\infty$.
+
+The internal transition function
+\begin{equation}
+    \delta_{int}: S \rightarrow S
+\end{equation}
+models the transition from one state to the next sequential state. $\delta_{int}$ describes the behaviour of a Finite State 
+Automaton; $ta$ adds the progression of time.
+
+It is possible to observe the system output. The output set $Y$ denotes the set of admissible outputs. Typically, $Y$ will be a 
+structured set (a product set)
+\begin{equation}
+    Y = \times_{i=1}^l Y_i.
+\end{equation}
+This formalizes multiple ($l$) output ports. Each port is identified by its unique index $i$. In a user-oriented modelling 
+language, the indices would be derived from unique port names. 
+
+The output function
+\begin{equation}
+    \lambda : S \rightarrow Y \cup \{ \phi \}
+\end{equation}
+maps the internal state onto the output set. Output events are only generated by a DEVS model at the time of an internal 
+transition. At that time, the state before the transition is used as input to $\lambda$. At all other times, the non-event 
+$\phi$ is output. To describe the total state of the system at each point in time, the sequential state $s \in S$ is not 
+sufficient. The elapsed time $e$ since the system made a transition to the current state $s$ needs also to be taken into 
+account to construct the total state set
+\begin{equation}
+    Q = \{ (s,e) | s \in S,, 0 \leq e \leq ta(s)\}
+\end{equation}
+The elapsed time $e$ takes on values ranging from 0 (transition just made) to $ta(s)$ (about to make transition to the next
+sequential state). Often, the time left $\sigma$ in a state is used:
+\begin{equation}
+    \sigma = ta(s) - e
+\end{equation}
+Up to now, only an autonomous system was described: the system receives no external inputs. Hence, the input set $X$ 
+denoting all admissible input values is defined. Typically, $X$ will be a structured set (a product set)
+\begin{equation}
+    X = \times_{i=1}^m X_i
+\end{equation}
+This formalizes multiple ($m$) input ports. Each port is identified by its unique index $i$. As with the output set, 
+port indices may denote names. 
+
+The set $\Omega$ contains all admissible input segments $\omega$
+\begin{equation}
+    \omega : T \rightarrow X \cup \{ \phi \}
+\end{equation}
+In discrete-event system models, an input segment generates an input event different from the non-event $\phi$ only at a finite 
+number of instants in a bounded time-interval. These external events, inputs $x$ from $X$, cause the system to interrupt its 
+autonomous behaviour and react in a way prescribed by the external transition function
+\begin{equation}
+    \delta_{ext}: Q \times X \rightarrow S
+\end{equation}
+The reaction of the system to an external event depends on the sequential state the system is in, the particular input and 
+the elapsed time. Thus, $\delta_{ext}$ allows for the description of a large class of behaviours typically found in 
+discrete-event models (including synchronization, preemption, suspension and re-activation). When an input event $x$ to an 
+atomic model is not listed in the $\delta_{ext}$ specification, the event is ignored.
+
+% TODO: Example of traffic light/ Starts with "In Figure 1" ...
+
+\subsection{The coupled DEVS Formalism} 
+The coupled DEVS formalism describes a discrete-event system in terms of a network of coupled components.
+\begin{equation}
+    coupledDEVS \equiv \langle X_{self}, Y_{self}, D, \{M_i\}, \{I_i\}, \{Z_{i,j}\}, select \rangle
+\end{equation}
+The component $self$ denotes the coupled model itself. $X_{self}$ is the (possibly structured) set of allowed external inputs 
+to the coupled model. $Y_{self}$ is the (possibly structured) set of allowed (external) outputs of the coupled model. $D$ is 
+a set of unique component references (names). The coupled model itself is referred to by means of $self$, a unique reference 
+not in $D$.
+
+The set of components is
+\begin{equation}
+    \{M_i | i \in D\}.
+\end{equation}
+Each of the components must be an atomic DEVS
+\begin{equation}
+    M_i = \langle S_i, ta_i, \delta_{int, i}, X_i, \delta_{ext, i}, Y_i, \lambda_i \rangle , \forall i \in D.
+\end{equation}
+The set of influences of a component, the components influenced by $i \in D \cup \{self\}$, is $I_i$. The set of all influences 
+describes the coupling network structure
+\begin{equation}
+    \{ I_i | i \in D \cup \{self\}\}.
+\end{equation}
+For modularity reasons, a component (including $self$) may not influence components outside its scope -the coupled model-, 
+rather only other components of the coupled model, or the coupled model $self$:
+\begin{equation}
+    \forall i \in D \cup \{self\}: I_i \subseteq D \cup \{self\}.
+\end{equation}
+This is further restricted by the requirement that none of the components (including $self$) may influence themselves directly 
+as this could cause an instantaneous dependency cycle (in case of a 0 time advance inside such a component) akin to an algebraic 
+loop in continuous models:
+\begin{equation}
+    \forall i \in D \cup \{self\}: i \not \in I_i.
+\end{equation}
+Note how one can always encode a self-loop ($i \in I_i$) in the internal transition function.
+
+To translate an output event of one component (such as a departure of a customer) to a corresponding input event (such as the 
+arrival of a customer) in influencees of that component, output-to-input translation functions $Z_{i,j}$ are defined:
+\begin{equation}
+    \{ Z_{i,j} | i \in D \cup \{self\}, j \in I_i\}, \\
+    Z_{self, j} : X_{self} \rightarrow X_j, \forall j \in D, \\
+    Z_{i, self} : Y_i \rightarrow Y_{self}, \forall i \in D, \\
+    Z_{i, j} : Y_i \rightarrow X_j, \forall i,j \in D.
+\end{equation}
+Together, $I_i$ and $Z_i,j$ completely specify the coupling (structure and behaviour).
+
+As a result of coupling of concurrent components, multiple state transitions may occur at the same simulation time. This is 
+an artifact of the discrete-event abstraction and may lead to behaviour not related to real-life phenomena. A logic-based 
+foundation to study the semantics of these artifacts was introduced by Radiya and Sargent (TODO). In sequential simulation 
+systems, such transition collisions are resolved by means of some form of selection of which of the components' transitions 
+should be handled first. This corresponds to the introduction of priorities in some simulation languages. The coupled DEVS 
+formalism explicitly represents a select function for tie-breaking between simultaneous events:
+\begin{equation}
+    select : 2^D \rightarrow D
+\end{equation}
+$select$ chooses a unique components from any non-empty subset E of D:
+\begin{equation}
+    select(E) \in E.
+\end{equation}
+The subset E corresponds to the set of all components having a state transition simultaneously.
+
+\subsection{Closure of DEVS under coupling}
+As mentioned before, it is possible to construct a resultant atomic DEVS model for each coupled DEVS. This closure under 
+coupling of atomic DEVS models makes any coupled DEVS equivalent to an atomic DEVS. By induction, any hierarchically coupled 
+DEVS can thus be flattened to an atomic DEVS. As a result, the requirement that each of the components of a coupled DEVS be 
+an atomic DEVS can be relaxed to be atomic or coupled as the latter can always be replaced by an equivalent atomic DEVS.
+
+The core of the closure procedure is the selection of the most imminent (i.e., soonest to occur) event from all the components' 
+scheduled events (TODO). In case of simultaneous events, the select function is used. In the sequel, the resultant construction 
+is described.
+
+From the coupled DEVS
+\begin{equation}
+    \langle X_{self}, Y_{self}, D, \{M_i\}, \{I_i\}, \{Z_{i,j}\}, select \rangle
+\end{equation}
+with all components $M_i$ atomic DEVS models
+\begin{equation}
+    M_i = \langle S_i, ta_i, \delta_{int, i}, X_i, \delta_{ext, i}, Y_i, \lambda_i \rangle, \forall i \in D
+\end{equation}
+the atomic DEVS
+\begin{equation}
+    \langle S, ta, \delta_{int}, X, \delta_{ext}, Y, \lambda \rangle
+\end{equation}
+is constructed.
+
+The resultant set of sequential states is the product of the total state sets of all the components
+\begin{equation}
+    S = \times_{i \in D} Q_i
+\end{equation}
+where
+\begin{equation}
+    Q_i = \{ (s_i, e_i) | s \in S_i, 0 \leq e_i \leq ta_i(s_i) \}, \forall i \in D.
+\end{equation}
+The time advance function $ta$
+\begin{equation}
+    ta : S \rightarrow \mathbb{R}^+_{0, + \infty}
+\end{equation}
+is constructed by selecting the most imminent event time, of all components. This means, finding the smallest time remaining 
+until internal transition, of all the components
+\begin{equation}
+    ta(s) = \min \{\sigma_i = ta_i(s_i) - e_i | i \in D \}.
+\end{equation}
+A number of imminent components may be scheduled for a simultaneous internal transition. These components are collected in a 
+set
+\begin{equation}
+    IMM(s) = \{i \in D | \sigma_i = ta(s)\}.
+\end{equation}
+From $IMM$, a set of elements of $D$, one component $i^*$ is chosen by means of the select tie-breaking function of the coupled 
+model
+\begin{equation}
+    select : 2^D \rightarrow D \\
+    IMM(s) \rightarrow i^*
+\end{equation}
+Output of the selected component is generated before it makes its internal transition. Note also how, as in a Moore machine, 
+input does not directly influence output. In DEVS models, only an internal transition produces output. An input can only 
+influence/generate output via an internal transition similar to the presence of memory in the form of integrating elements in 
+continuous models. Allowing an external transition to produce output could lead to infinite instantaneous loops. This is equivalent 
+to algebraic loops in continuous systems. The output of the component is translated into coupled model output by means of the 
+coupling information
+\begin{equation}
+    \lambda(s) = Z_{i^*, self} (\lambda_{i^*}(s_{i^*})), \text{if} self \in I_{i^*}.
+\end{equation}
+If the output of $i^*$ is not connected to the output of the coupled model, the non-event $\phi$ can be generated as output of 
+the coupled model. As $\phi$ literally stands for no event, the output can also be ignored without changing the meaning (but 
+increasing performance of simulator implementations).
+
+The internal transition function transforms the different parts of the total state as follows:
+\begin{equation}
+    \delta_{int}(s) = (..., (s'_j, e'_j),...), \text{where} \\
+    (s'_j, e'_j) = (\delta_{int, j} (s_j), 0), \text{for} j = i^*, \\
+                 = (\delta_{ext, j} (s_j, e_j + ta(s), Z_{i^*, j}))
+                 % TODO: Verder doen
+\end{equation}
+The selected imminent component $i^*$ makes an internal transition to sequential state $\delta_{int, i^*} (s_i^*)$. Its elpased 
+time is reset to 0. All the influencees of $i^*$ change their state due to an external transition prompted by an input which is 
+the output-to-input translated output of $i^*$, with an elapsed time adjusted for the time advance $ta(s)$. The influencees' 
+elapsed time is reset to 0. Note how $i^*$ is not allowed to be an influencee of $i^*$ in DEVS. The state of all other components 
+is not affected and their elapsed time is merely adjusted for the time advance $ta(s)$.
+
+The external transition function transforms the different parts of the total state as follows:
+\begin{equation}
+    \delta_{ext}(s,e,x) = (..., (s'_i, e'_i), ...)
+    % TODO
+\end{equation}
+An incoming external event is routed, with an adjustment for elapsed time, to each of the components connected to the coupled 
+model input (after the appropriate input-to-input translation). For all those components, the elapsed time is reset to 0. All 
+other components are not affected and only the elapsed time is adjusted.
+
+Some limitations of DEVS are that
+\begin{itemize}
+    \item a conflict due to simultaneous internal and external events is resolved by ignoring the internal event. It should be 
+    possible to explicitly specify behaviour in case of conflicts;
+    \item there is limited potential for parallel implementation;
+    \item the select function is an artificial legacy of the semantics of traditional sequential simulators based on an event 
+    list;
+    \item it is not possible to describe variable structure.
+\end{itemize}
+Some of these are compensated for in parallel DEVS (TODO).
+
+\subsection{Implementation of a DEVS Solver}
+The algorithm in Figure (TODO) is based on the closure under coupling construction and can be used as a specification of a 
+(possibly parallel) implementation of a DEVS solver or “abstract simulator” (TODO). In an atomic DEVS solver, the last event 
+time $t_L$ as well as the local state $s$ are kept. In a coordinator, only the last event time $t_L$ is kept. The 
+next-event-time $t_N$ is sent as output of either solver. It is possible to also keep $t_N$ in the solvers. This requires 
+consistent (recursive) initialization of the $t_N$s. If kept, the $t_N$ allows one to check whether the solvers are 
+appropriately synchronized. The operation of an abstract simulator involves handling four types of messages. The ($x, from, t$)
+message carries external input information. The ($y, from, t$) message carries external output information. The ($*, from, t$) 
+and ($done, from, t_N$) messages are used for scheduling (synchronizing) the abstract simulators. In these messages, $t$ is the 
+simulation time and $t_N$ is the next-event-time. The ($*, from, t$) message indicates an internal event * is due.When a 
+coordinator receives a ($*, from, t$) message, it selects an imminent component $i^*$ by means of the tie-breaking function 
+select specified for the coupled model and routes the message to $i^*$. Selection is necessary as there may be more than one 
+imminent component (with minimum next remaining time).
+
+When an atomic simulator receives a ($*, from, t$) message, it generates an output message ($y, from, t$) based on the old state 
+$s$. It then computes the new state by means of the internal transition function. Note how in DEVS, output messages are only 
+produced while executing internal events. When a simulator outputs a ($y, from, t$) message, it is sent to its parent coordinator. 
+The coordinator sends the output, after appropriate output-to-input translation, to each of the influencees of $i^*$ (if any). If 
+the coupled model itself is an influencee of $i^*$, the output, after appropriate output-to-output translation, is sent to the the 
+coupled model's parent coordinator.
+
+% TODO: Figure 3 
+
+When a coordinator receives an ($x, from, t$) message from its parent coordinator, it routes the message, after appropriate 
+input-to-input translation, to each of the affected components.
+
+When an atomic simulator receives an ($x, from, t$) message, it executes the external transition function of its associated atomic 
+model.
+
+After processing an ($x, from, t$) or ($y, from, t$) message, a simulator sends a ($done, from, t_N$) message to its parent 
+coordinator to prepare a new schedule. When a coordinator has received ($done, from, t_N$) messages from all its components, 
+it sets its next-event-time $t_N$ to the minimum $t_N$ of all its components and sends a ($done, from, t_N$) message to its parent 
+coordinator. This process is recursively applied until the top-level coordinator or root coordinator receives a ($done, from, t_N$) 
+message.
+
+
+As the simulation procedure is synchronous, it does not support asynchronously arriving (real-time) external input. Rather, the 
+environment or Experimental Frame should also be modelled as a DEVS component.
+
+To run a simulation experiment, the initial conditions $t_L$ and $s$ must first be set in all simulators of the hierarchy. If $t_N$ 
+s kept in the simulators, it must be recursively set too. Once the initial conditions are set, the main loop described in Figure 
+(TODO) is executed.
+
+
+\section{The pythonDEVS (pyDEVS) simulator}
+In this chapter we first present an implementation of the classical formalism. An early prototype of a DEVS Modeling and Simulation 
+Package is then introduced. The chapter then moves on to discuss a real-time execution framework. The motivation behind real-time 
+DEVS execution is discussed as well as the implications of 0-time semantics.
+
+\subsection{Design and implementation}
+This version of the DEVS Modeling and Simulation Package has been implemented using Python, an interpreted, very high-level, 
+object-oriented programming language. The package consists of two files, the first of which (DEVS.py) provides a class architecture 
+that allows hierarchical DEVS models to be easily defined. The simulation engine (SE) itself is implemented in the second file 
+(Simulator.py). Based on the DEVS simulator described in (TODO), it uses the same message- passing mechanism. A detailed description 
+of both the model architecture and the SE follows.
+
+\subsubsection{Model Architecture}
+The model architecture implemented in DEVS.py is a canvas from which hierarchical DEVS mod- els can be easily described. It consists 
+of a number of classes arranged to capture the essence of hierarchical DEVS. A model is described in a dedicated file by deriving 
+coupled and/or atomic- DEVS descriptive classes from this architecture. These atomic models are then arranged hierarchically through 
+composition. Methods and attributes form the standard interface that allows an SE, such as the one described in the next sub-section, 
+to interact with the instantiated DEVS model. Our main concern with the architecture are twofold: remain as consistent as possible 
+with the original hierarchical DEVS definition, and maintain a flexible approach to DEVS so as to encourage model reusability 
+through parameterization.
+
+The class architecture is represented in Figure (TODO): BaseDEVS is the root class which provides basic functionalities common to both 
+atomic and coupled models.
+
+Two classes are inherited from BaseDEVS to deal with the specifics of atomic and coupled DEVS formalisms (Figure (TODO)). These three 
+classes are all abstract in that they cannot be directly instantiated. Rather, a model is described by deriving descriptive classes 
+from either the AtomicDEVS or the CoupledDEVS class. This provides them with a suitable constructor and overrides the default 
+interface methods. Note that the constructors at every level of the class hierarchy have an active role. Hence, a descriptive class' 
+constructor should always start by calling the parent class' constructor.
+
+The constructor of the AtomicDEVS class merely initializes the myID attribute and provides a default initial value for the DEVS' 
+total state, through the state and elapsed attributes. The remaining class definitions consist of default method declarations for 
+the interface functions $\delta_{ext}$ (extTransition), $\delta_{int}$ (intTransition), $ta$ (timeAdvance) and $\lambda$ (outputFnc). 
+These methods expect no parameter, and it is up to the modeler to be consistent with the corresponding functions' domain when overriding 
+the methods. Except for outputFnc (which uses the poke method as described below), all the methods shall return a value compatible with 
+the corresponding function range.
+
+Since default values are provided for both attributes and methods, the minimal atomic-DEVS descriptive class is empty:
+
+% TODO: code
+
+This atomic-DEVS is passive. It remains in its default state forever. A more interesting example is a generator, which sends a message 
+(the integer 1 in this case) through its unique output port at a constant time interval:
+
+% TOOD: code
+
+As mentioned above, the outputFnc returns no value; instead it relies on the poke method to send message (second parameter) through the 
+OUT output port (first parameter). The companion method, peek, returns the message on the input port that is given as a unique parameter, 
+and is used exclusively in the extTransition function. Both poke and peek methods are defined in the AtomicDEVS class, and should not be 
+overridden.
+
+The CoupledDEVS class only has one method to override, the tie-breaking select function. This takes a list of sub-models which are in 
+conflict. The select function should return the sub-model instance from this list who's transition is to fire next. All a CoupledDEVS 
+sub-models should be included by passing their instance variables to the addSubModel function.
+
+Coupling of ports is performed through the connectPorts method. Its first parameter is the source port and the second parameter is the 
+destination port. A coupling is rejected and an error message issued if the coupling is invalid.
+
+The source and destination ports are instances of the class Port. This class defines channels where events may pass between DEVS models. 
+These channels are defined in the Port's inLine and outLine attributes.
+

+ 22 - 15
paper/MasterThesis.fdb_latexmk

@@ -1,13 +1,13 @@
 # Fdb version 3
-["bibtex MasterThesis"] 0 "MasterThesis.aux" "MasterThesis.bbl" "MasterThesis" 1713729005
+["bibtex MasterThesis"] 0 "MasterThesis.aux" "MasterThesis.bbl" "MasterThesis" 1714375830
   "/usr/local/texlive/2019/texmf-dist/bibtex/bst/base/plain.bst" 1292289607 20613 bd3fbfa9f64872b81ac57a0dd2ed855f ""
-  "MasterThesis.aux" 1713729005 4855 4de148b7aed8145232674f45d259f977 "pdflatex"
+  "MasterThesis.aux" 0 -1 0 "pdflatex"
   "references.bib" 1312367667 789 20803d158fccdc749b2e64f161e2607a ""
   (generated)
   "MasterThesis.bbl"
   "MasterThesis.blg"
-["pdflatex"] 1713729005 "/Users/sampieters/Desktop/VSCodeProjects/SCCD2DEVS/paper/MasterThesis.tex" "/Users/sampieters/Desktop/VSCodeProjects/SCCD2DEVS/paper/MasterThesis.pdf" "MasterThesis" 1713729005
-  "/Users/sampieters/Desktop/VSCodeProjects/SCCD2DEVS/paper/MasterThesis.aux" 1713729005 8 a94a2480d3289e625eea47cd1b285758 ""
+["pdflatex"] 1714375829 "/Users/sampieters/Desktop/VSCodeProjects/SCCD2DEVS/paper/MasterThesis.tex" "/Users/sampieters/Desktop/VSCodeProjects/SCCD2DEVS/paper/MasterThesis.pdf" "MasterThesis" 1714375830
+  "/Users/sampieters/Desktop/VSCodeProjects/SCCD2DEVS/paper/MasterThesis.aux" 1714375829 8 a94a2480d3289e625eea47cd1b285758 ""
   "/Users/sampieters/Desktop/VSCodeProjects/SCCD2DEVS/paper/MasterThesis.tex" 1708595575 2030 b07d38d40f55a12ddbb2150cd1cb0161 ""
   "/usr/local/texlive/2019/texmf-dist/fonts/map/fontname/texfonts.map" 1511824771 3332 103109f5612ad95229751940c61aada0 ""
   "/usr/local/texlive/2019/texmf-dist/fonts/tfm/public/cm/cmbx12.tfm" 1136768653 1324 c910af8c371558dc20f2d7822f66fe64 ""
@@ -27,8 +27,14 @@
   "/usr/local/texlive/2019/texmf-dist/fonts/tfm/public/cm/cmsy8.tfm" 1136768653 1120 8b7d695260f3cff42e636090a8002094 ""
   "/usr/local/texlive/2019/texmf-dist/fonts/tfm/public/cm/cmti12.tfm" 1136768653 1484 ed72f8f5cf654cda15ecc8e32bfcbee5 ""
   "/usr/local/texlive/2019/texmf-dist/fonts/type1/public/amsfonts/cm/cmbx12.pfb" 1248133631 32080 340ef9bf63678554ee606688e7b5339d ""
+  "/usr/local/texlive/2019/texmf-dist/fonts/type1/public/amsfonts/cm/cmmi12.pfb" 1248133631 36741 fa121aac0049305630cf160b86157ee4 ""
+  "/usr/local/texlive/2019/texmf-dist/fonts/type1/public/amsfonts/cm/cmmi8.pfb" 1248133631 35469 70d41d2b9ea31d5d813066df7c99281c ""
   "/usr/local/texlive/2019/texmf-dist/fonts/type1/public/amsfonts/cm/cmr12.pfb" 1248133631 32722 d7379af29a190c3f453aba36302ff5a9 ""
+  "/usr/local/texlive/2019/texmf-dist/fonts/type1/public/amsfonts/cm/cmr8.pfb" 1248133631 32726 0a1aea6fcd6468ee2cf64d891f5c43c8 ""
   "/usr/local/texlive/2019/texmf-dist/fonts/type1/public/amsfonts/cm/cmssbx10.pfb" 1248133631 28902 2f5c04fd2884d1878057baa5aad22765 ""
+  "/usr/local/texlive/2019/texmf-dist/fonts/type1/public/amsfonts/cm/cmsy10.pfb" 1248133631 32569 5e5ddc8df908dea60932f3c484a54c0d ""
+  "/usr/local/texlive/2019/texmf-dist/fonts/type1/public/amsfonts/cm/cmsy6.pfb" 1248133631 32587 1788b0c1c5b39540c96f5e42ccd6dae8 ""
+  "/usr/local/texlive/2019/texmf-dist/fonts/type1/public/amsfonts/cm/cmsy8.pfb" 1248133631 32626 4f5c1b83753b1dd3a97d1b399a005b4b ""
   "/usr/local/texlive/2019/texmf-dist/fonts/type1/public/amsfonts/cm/cmti12.pfb" 1248133631 36118 fad905eba93cff5bce1e185fe980a177 ""
   "/usr/local/texlive/2019/texmf-dist/tex/context/base/mkii/supp-pdf.mkii" 1461363279 71627 94eb9990bed73c364d7f53f960cc8c5b ""
   "/usr/local/texlive/2019/texmf-dist/tex/generic/babel-english/english.ldf" 1496785618 7008 9ff5fdcc865b01beca2b0fe4a46231d4 ""
@@ -41,6 +47,7 @@
   "/usr/local/texlive/2019/texmf-dist/tex/generic/oberdiek/hobsub-generic.sty" 1536701967 185392 b99a6d53180e04300c35e18725f31231 ""
   "/usr/local/texlive/2019/texmf-dist/tex/generic/oberdiek/hobsub-hyperref.sty" 1465595255 70864 bcd5b216757bd619ae692a151d90085d ""
   "/usr/local/texlive/2019/texmf-dist/tex/latex/base/ifthen.sty" 1523050425 5161 c004ea5a189d4bdcf42e86754ad75a58 ""
+  "/usr/local/texlive/2019/texmf-dist/tex/latex/base/omscmr.fd" 1523050425 2472 aa08940f0a4dc6c24ae9f943b04ae0b9 ""
   "/usr/local/texlive/2019/texmf-dist/tex/latex/base/report.cls" 1544567569 22992 ac205d2578ad3f18cf73b50579632d1c ""
   "/usr/local/texlive/2019/texmf-dist/tex/latex/base/size12.clo" 1544567569 8305 6a682ae291edd56e2d7accbf95eca451 ""
   "/usr/local/texlive/2019/texmf-dist/tex/latex/colortbl/colortbl.sty" 1544741426 10678 47854138cd4fdca1d7b24b0290c999d4 ""
@@ -85,19 +92,19 @@
   "/usr/local/texlive/2019/texmf-var/fonts/map/pdftex/updmap/pdftex.map" 1557342064 3277517 23507ed665b4dd9046f0f2a94bbef2be ""
   "/usr/local/texlive/2019/texmf-var/web2c/pdftex/pdflatex.fmt" 1581889033 4259636 d37c56afa7e03d15fcc5f2788a45c45a ""
   "/usr/local/texlive/2019/texmf.cnf" 1557341546 577 d150fef99ac436ad1156e86b0892f6ef ""
-  "00-Abstract.tex" 1713726104 2183 e62abdc8148e9412b0d51c935d7090f5 ""
-  "00-Acknowledgements.tex" 1312367667 134 74cc9bb4494a6282239f34e7cb65ad6e ""
+  "00-Abstract.tex" 1714059270 2073 13ccc55c5cd51514a665533fb52a9e1c ""
+  "00-Acknowledgements.tex" 1714059530 667 8e107c839354f000e37d04dc25ae918a ""
   "00-NedSamenvatting.tex" 1312367667 167 8399376b625bface729d36e4e2250554 ""
-  "01-Introduction.tex" 1713727615 4289 4bc548d9608641e333273b420d9921f6 ""
-  "02-Background.tex" 1713729004 150 709a53f80754773ff4095400f93f58e7 ""
+  "01-Introduction.tex" 1714128909 4068 1b7abf65cd933cb114e95a696e069d8b ""
+  "02-Background.tex" 1714375829 24623 51c848e8c64d3a8d3bc89c5b8987c5a8 ""
   "03-Methodology.tex" 1708865037 5239 30d99e6e522d5663924569fc8bdf8d22 ""
   "04-Implementation.tex" 1708595418 112 55cb6455e2f9f0104ec4d8e6d0f49273 ""
   "05-Examples.tex" 1708595429 100 9e94dd9a3549d797588d04c14167759b ""
   "99-Conclusions.tex" 1312367667 96 14738e95e1c9f65e878257a213a68c0e ""
   "AA-Testcode.tex" 1312367667 88 92b0f084449dc6404f28e8aa563e51d2 ""
-  "MasterThesis.aux" 1713729005 4855 4de148b7aed8145232674f45d259f977 "pdflatex"
+  "MasterThesis.aux" 0 -1 0 "pdflatex"
   "MasterThesis.bbl" 1708594014 231 de400b7dcca806f26018f05e817af9f6 "bibtex MasterThesis"
-  "MasterThesis.out" 1713729005 1532 9eebd7c8c0f6f6b817073a47954a9c27 "pdflatex"
+  "MasterThesis.out" 0 -1 0 "pdflatex"
   "MasterThesis.tex" 1708595575 2030 b07d38d40f55a12ddbb2150cd1cb0161 ""
   "algorithm2e.sty" 1312367667 90314 30002475f17985f6891a4234c2b3fb79 ""
   "appendix.sty" 1312367667 8966 36f3fb990db085b747e9212d3dddd969 ""
@@ -110,12 +117,12 @@
   "picinpar.sty" 1312367667 24409 c0cc078f3063909ee9f34b5dc9ae71ef ""
   "titlesec.sty" 1312367667 47627 5593f18067f6da9a34ba2dc08abaee8e ""
   (generated)
-  "MasterThesis.lof"
-  "MasterThesis.lot"
-  "MasterThesis.aux"
   "MasterThesis.out"
   "MasterThesis.toc"
   "MasterThesis.pdf"
-  "MasterThesis.log"
-  "/Users/sampieters/Desktop/VSCodeProjects/SCCD2DEVS/paper/MasterThesis.log"
+  "MasterThesis.aux"
+  "MasterThesis.lof"
   "/Users/sampieters/Desktop/VSCodeProjects/SCCD2DEVS/paper/MasterThesis.pdf"
+  "/Users/sampieters/Desktop/VSCodeProjects/SCCD2DEVS/paper/MasterThesis.log"
+  "MasterThesis.log"
+  "MasterThesis.lot"

BIN
paper/MasterThesis.pdf


BIN
paper/MasterThesis.synctex.gz


BIN
paper/images/DEVSSimulationProcedure.png


+ 17 - 5
sccd/runtime/DEVS_statecharts_core.py

@@ -56,7 +56,7 @@ class Association(object):
         if self.allowedToAdd():
             new_id = self.next_id
             self.next_id += 1
-            self.instances[new_id] = new_id
+            self.instances[new_id] = instance
             self.instances_to_ids[instance] = new_id
             self.size += 1
             return new_id
@@ -65,7 +65,8 @@ class Association(object):
 
     def removeInstance(self, instance):
         if self.allowedToRemove():
-            index = self.instances_to_ids[instance]
+            #index = self.instances_to_ids[instance]
+            index = instance
             del self.instances[index]
             del self.instances_to_ids[instance]
             self.size -= 1
@@ -848,7 +849,12 @@ class ObjectManagerBase(object):
             source_index = 0
 
         association_name = parameters[1]
-        
+
+        index = 0
+        for inst in self.instances:
+            index += len(inst.associations[association_name].instances)
+
+
         traversal_list = self.processAssociationReference(association_name)
         instances = self.getInstances(source, traversal_list)
         
@@ -861,7 +867,7 @@ class ObjectManagerBase(object):
             new_instance = association_name + f"[{len(instances)}]"
 
             try:
-                index = association.addInstance(new_instance)
+                new_index = association.addInstance(index)
             except AssociationException as exception:
                 raise RuntimeException("Error adding instance to association '" + association_name + "': " + str(exception))
             
@@ -887,6 +893,9 @@ class ObjectManagerBase(object):
             
             instances = self.getInstances(source, traversal_list)
             association = source.associations[traversal_list[0][0]]
+
+            for assoc in association.instances:
+                association.removeInstance(assoc)
             
             #for i in instances:
             #    try:
@@ -910,7 +919,10 @@ class ObjectManagerBase(object):
             index = self.processAssociationReference(source.association_name)
             index = index[0][1]
 
-            self.to_send.append((source.association_name, association.to_class, Event("delete_instance", None, [parameters[1]], index)))
+
+            params = list(association.instances.values())
+
+            self.to_send.append((source.association_name, association.to_class, Event("delete_instance", None, [parameters[1], params], index)))