02-Background.tex 44 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661
  1. \chapter{Background}
  2. \label{chapt:Background}
  3. \section{Statecharts and Class Diagrams (SCCD)}
  4. \subsection{The Statechart Formalism}
  5. Statecharts, originally introduced by D. Harel (\ref{TODO}), are finite state machines extended with hierarchy and
  6. orthogonality (parallelism), allowing a complex system to be expressed in a more compact and elegant way.
  7. In order to understand the basics of statecharts, it is useful to first look at higraphs. Higraphs, while normally used
  8. for formal mathematical specification, are also used as a basis for statecharts.
  9. Statecharts can be represented as visual objects. While this thesis does not use a visual notation for the statecharts,
  10. it is usefull to understand the basics of statecharts. To understand the basics of statecharts, it is useful to first
  11. look at higraphs. Higraphs, while normally used for formal mathematical specification, are also used as a basis for
  12. statecharts.
  13. \subsubsection{Higraph}
  14. A higraph combines notions from several topovisual formalisms.
  15. Topovisual formalisms are a class of graphical representations to model and visualize the topological structure of systems.
  16. They primarily focus on depicting the spatial relationships and connectivity between various components or entities within
  17. a system. The shapes of the visual objects is not that important in these formalisms.
  18. One of these topovisual formalisms is the formalism of graphs, and the second is the notion of Euler circles, which later
  19. evolved into Venn diagrams.
  20. A graph, in its most basic form, is simply a set of points, or nodes, connected by edges or arcs. Its role is to represent
  21. a (single) set of elements S and some binary relation R on them. The precise meaning of the relation R is part of the
  22. application and has little to do with the mathematical properties of the graph itself. Certain restrictions on the relation
  23. R yield special classes of graphs that are of particular interest, such as ones that are connected, directed, acyclic,
  24. planar, or bipartite.
  25. A somewhat less widely used extension of graphs is the formalism of hypergraphs. A hypergraph is a graph in which the
  26. relation being specified is not necessarily binary. Formally, an edge no longer connects a pair of nodes, but rather a
  27. subset thereof.
  28. \\
  29. \\
  30. TODO: Euler circles or Venn diagram
  31. \\
  32. \\
  33. These previous formalisms can be used to create the Highgraph construct. Venn diagrams are used to account for set
  34. inclusion and exclusion. Each set is called a blob and is denoted using a rectangle with rounded edges. The nesting of
  35. curves denotes set inclusion.
  36. \subsubsection{Statecharts}
  37. Statecharts are a higraph-based extension of standard state-transition diagrams, where the blobs represent states and
  38. arrows represent transitions. However, there are different kind of blobs and thus different kind of states. The
  39. different kind of states can be seen in Figure \ref{TODO}. The first blob, Figure \ref{TODO}, is called a BASIC-blob
  40. which is a state such that it has no sub-OR-blobs, sub-AND-blobs nor any sub-BASIC-blobs. OR-blobs are blobs that have
  41. one or more sub-OR-blobs. AND-blobs, Figure \ref{TODO}, have orthogonal components. Orthogonal components of a blob are
  42. normally drawn with a dashed line and denote concurrent operations. An example combining all these different kind of
  43. blobs can be seen in Figure \ref{TODO}. These blobs only introduce hierarchy in statecharts, the order to specify system
  44. dynamics in the diagrams are not yet specified. This is what transitions are used for. A transition is simply an arrow
  45. which indicates the system can change its current state from the source state of the transition to the destination state
  46. of the transition. Transitions are labeled as follows:
  47. \begin{equation}
  48. e [c]/a
  49. \end{equation}
  50. This syntax denotes that the transition fires when event e occurs and condition c is true. The $/a$ usually means one of
  51. two different things, depending on the variant of statechart. In some definitions, $/a$ denotes that upon firing the
  52. transition, the a event is broadcast throughout the entire statechart, which may trigger more transitions. In the UML
  53. definition, $/a$ usually denotes a series of actions (such as computer code) to execute, upon firing the transition. The
  54. UML suggests the potential use of a function $GEN(e)$ , which can be one the many steps in a. This function is used to
  55. broadcast the event e. Most statechart variants combine these two aspects.
  56. There are different kinds of transitions. First, there is the initial transition. It is the default transitions that
  57. fires upon entering any type of blob or the root. They force the diagram to be deterministic by denoting which is the
  58. current state upon entering an OR-blob. They are usually drawn as a small filled-in circle with the connected transition
  59. pointing towards a blob and may only be labeled with an action (no trigger event $e$).
  60. \subsection{State Chart XML (SCXML)}
  61. State Chart XML (SCXML) is a general-purpose event-based state machine language that combines concepts from CCXML and Harel
  62. State Tables.
  63. \subsubsection{Core constructs}
  64. \paragraph{$<$scxml$>$}
  65. The top-level wrapper element, which carries version information. It can consist of the following attributes:
  66. \subsection{Statecharts and Class Diagrams (SCCD)}
  67. In this section the SCCD (a Statecharts and Class Diagrams hybrid) formalism and its SCCDXML representation, an extension
  68. of SCXML, is explained. SCCD facilitates the specification of complex timed, reactive, interactive discrete-event systems
  69. (e.g., complex user interfaces).
  70. \subsubsection{The SCCD language}
  71. The SCCD languages extends the SCXML, explained in subsection (TODO), by adding new features to its concrete syntax.
  72. \paragraph{Top-level Elements}
  73. The top-level element is a diagram. It has an input/output interface to communicate with its environment, it can optionally
  74. import library classes, and it holds a number of class definitions. One of these classes is the default, and is instantiated
  75. when the application is launched.
  76. % TODO: Listing
  77. Listing (TODO) shows the top-level diagram of an application. It imports a library class that is used to draw the graphical
  78. elements on the screen, one input port called "input" which receives events when the user interacts with the UI (for example,
  79. pressing a key), and four classes, explained in the following subsections.
  80. \paragraph{Classes}
  81. Classes are the main addition of the SCCD language. They model both structure and behaviour—structure in the form of
  82. attributes and relations with other classes, behaviour in the form of methods, which access and change the values of
  83. attributes of the class, and an SCXML model, which constitutes the "modal" part of the system, modelling the control flow
  84. of the class's behaviour. At runtime, a class can be instantiated, which creates an object. Objects are initialized according
  85. to the class's constructor, and can be deleted, invoking the class's destructor. The relationships modelled between classes
  86. are instantiated at runtime in the form of links. They serve as communication channels, over which objects can send and receive
  87. events.
  88. % TODO: Listing
  89. Listing 2 shows the definition of the "Ball" class. It defines a number of relations (discussed in the next paragraph), a
  90. constructor and destructor, a method that moves the ball to a new position, and an SCXML model that consists of four states.
  91. It can optionally also define private input ports and output ports. In this case, the ball defines a private input port, that
  92. allows the environment to send events that are only meant for a particular ball. For example, when the user left-clicks on a
  93. ball to select it, that event should only be sent to that specific instance.
  94. \paragraph{Relationships}
  95. Classes can have relationships with other classes. There are two types of relationships: associations and inheritance.
  96. An association is defined between a source class and a target class, and has a name. It allows instances of the source class
  97. to send events to instances of the target class by referencing the association name. An association has a multiplicity,
  98. defined as a minimal cardinality $c_{min} \in \mathbb{N}$ and a maximal cardinality $c_{max} \in \mathbb{N}_{>0} \cup \{inf\}$.
  99. They control how many instances of the target class have to be minimally associated to each instance of the source class, and
  100. how many instances of the target class can be maximally associated to each instance of the source class, respectively. Each
  101. time an association is created, it results in a link between the source and target object. This link gets a unique identifier,
  102. allowing the source object to reference the target, for example to send events.
  103. An inheritance relation results in the source of the relation to inherit all attributes and methods from the target of the
  104. relation. Specialisation of modal behaviour (i.e., (parts of) the SCXML model of the superclass) is currently not supported.
  105. % TODO: Listing
  106. Listing (TODO) shows the relationships of the "Window" class. It has an association to its parent, the main application.
  107. Exactly one instance of that link has to exist between each "Window" instance and the main application. It is additionally
  108. associated to a number of buttons and balls, and inherits from the library class "UIWidget", allowing it to be drawn on screen.
  109. \paragraph{Events}
  110. Events in SCCD are strings. They are accompanied by a number of parameter values: the sender is obliged to send the correct
  111. number of values, and the receiver declares the parameters when catching the event. Each parameter has a name, that can be used
  112. as a local variable in the action associated with the transition that catches the event.
  113. With the addition of a public input/output interface using ports, as well as classes and associations, comes the need for
  114. scoping events. In traditional SCXML models, an event is sensed by the Statecharts model that generated it. SCCD adds the ability
  115. to transmit events to class instances and to output ports. In particular, the raise tag was extended with a scope attribute, that
  116. can take on the following values:
  117. \begin{itemize}
  118. \item \textbf{local:} The event will only be visible for the sending instance.
  119. \item \textbf{broad:} The event is broadcast to all instances.
  120. \item \textbf{output:} The event is sent to an output port and is only valid in combination with the output attribute, which
  121. specifies the name of the output port.
  122. \item \textbf{narrow:} The event is narrow-cast to specific instances only, and is only valid in combination with the target
  123. attribute, which specifies the instance to send the event to. For example, an instance of the "Window" class can narrow-cast
  124. an event by sending the event to a specific instance of the "Ball" class, identified by a unique link identifier.
  125. \item \textbf{cd:} The event is processed by the object manager. See the next section for more details.
  126. \end{itemize}
  127. % TODO: Listing
  128. Listing (TODO) presents a transition modelled on the "Button" class. It reacts to the user left-clicking the button (represented
  129. by an event sent on the button input port). The button reacts by notifying its parent that it was clicked.
  130. \subsubsection{The Object Manager}
  131. At runtime, a central entity called the object manager is responsible for creating, deleting, and starting class instances, as
  132. well as managing links (instances of associations) between class instances. It also checks whether no cardinalities are violated:
  133. when the user creates an association, it checks that the maximal cardinality is not violated, and when the user deletes an
  134. association, it check whether the minimal cardinality is not violated. As mentioned previously, instances can send events to the
  135. object manager using the "cd" scope. The object manager can thus be seen as an ever-present, globally accessible object instance,
  136. although it is implicitly defined in the runtime, instead of as a SCCD class.
  137. When the application is started, the object manager creates an instance of the default class and starts its associated Statecharts
  138. model. From then on, instances can send several events to the object manager to control the set of currently executing objects.
  139. The object manager accepts four events. We list them below, including the parameters that have to be sent as part of the event:
  140. \begin{itemize}
  141. \item \textbf{create\_instance(association name, class name, args*):}
  142. \item \textbf{delete\_instance(link\_ref):}
  143. \item \textbf{start\_instance(link\_ref):}
  144. \item \textbf{associate\_instance(source\_ref, association\_name, target\_ref):}
  145. \end{itemize}
  146. % TODO: Verder aanvullen
  147. \subsubsection{The SCCD compiler}
  148. The semantics of an SCCD model are loosely based on the agent model, where each instance of a class can be seen as an agent that
  149. communicates with other agents through its input/output interface, and its autonomous behaviour controlled by its Statecharts
  150. model. The compiler generates appropriate code that continuously executes the system by allowing each agent to execute a step,
  151. which optionally generates output that can be sensed by the other agents.
  152. The compiler supports two programming languages, Javascript and Python, and options for the statecharts semantics. Supporting
  153. multiple languages is a major advantage, as one can imagine developing an application in SCCD and generating code for multiple
  154. languages from the same model. The generated code would exhibit identical behaviour for each implementation language, such as a
  155. web-based application (implemented in HTML/Javascript) and a desktop application (implemented in, for example, Python).
  156. SCCD has one semantic definition. There are, however, many platforms on which the code generated from an SCCD model can be run.
  157. The runtime platform provides essential functions used by the runtime kernel, such as the queueing of events and the scheduling
  158. of (timed) events. Three runtime platforms are supported. A platform holds a list (or queue) of events, and they differ in the
  159. way they handle events generated during execution. The kernel attempts to run the SCCD model in real-time, meaning that the delay
  160. on timed transitions is intepreted as an amount of seconds. Raising of events and untimed transitions are executed as fast as
  161. possible. Figure (TODO) presents an overview of the three platforms, and how they handle events.
  162. The most basic platform, available in most programming languages, is based on threads. Currently, the platform runs one thread,
  163. which manipulates a global event queue, made thread-safe by locks. Input from the environment is handled by obtaining this lock,
  164. which the kernel releases after every step of the execution algorithm. This allows external input to be interleaved with
  165. internally raised events. Running an application on this platform can interfere with other scheduling mechanisms, such as a UI
  166. module, however.
  167. To overcome this interference problem, the event loop platform reuses the event queue managed by an existing UI platform, such
  168. as Tkinter. The UI platform provides functions for managing time-outs (for timed events), as well as pushing and popping items
  169. from the queue. This results in a seamless integration of both Statecharts events and external UI events, such as user clicks:
  170. the UI platform is now responsible for the correct interleaving.
  171. The game loop platform facilitates integration with game engines (such as the open-source Unity engine), where objects are
  172. updated only at predefined points in time. In the "update" function, the kernel is responsible for checking the current time
  173. (as some time has passed since the last call to the "up-date" function), and process all the events generated by objects. This
  174. means that events generated in between two of these points are not processed immediately, but queued and their processing delayed
  175. until the next processing time.
  176. \subsubsection{Semantics}
  177. The Statecharts language has been around for a long time. In that time, its basic structures have almost not changed. In its
  178. original definition [(TODO)], Harel left many of the semantic choices undefined. Since then, many semantics have been defined,
  179. such as the one used in Statemate [(TODO)]. More recently, Esmaeilsabzali et al. [(TODO)] have performed a study of big-step
  180. modelling languages, such as Statecharts, and defined a set of semantic variation points, with which the different Statecharts
  181. execution semantics can be classified. Central to their discussion is the notion of a "big step". The execution of a Statecharts
  182. model is a sequence of big steps. A big step is a unit of interaction between a model and its environment. A big step takes input
  183. from the environment (at the beginning of the big step), and produces output to the environment (after the big step has taken
  184. place). Input cannot change during the big step. A big step consists of 0 or more small steps. A small step is an unordered set
  185. of 1 or more transition executions, but in our case, a small step always consists of exactly one transition execution. Small steps
  186. are grouped in so-called combo steps. A combo step is a maximal sequence of small steps, such that it only contains transitions
  187. that are orthogonal to each other.
  188. The SCCD compiler allows to choose which semantics to use based on a number of semantic variation points. This gives modellers
  189. more control to fine-tune the application to their needs. The semantic variation points are:
  190. \begin{itemize}
  191. \item \textbf{Big Step Maximality} specifies when a big step ends: either after one combo step executed (Take One), or when
  192. no more combo steps can be executed (Take Many).
  193. \item \textbf{Internal Event Lifeline} specifies when an internally raised event becomes available: either in the next small
  194. step (immediately), in the next combo step (which only makes sense in combination with the Take Many option), or the event is
  195. queued and treated as an external event (making it available in the next big step).
  196. \item \textbf{Input Event Lifeline} specifies when an input event is available during a big step: either throughout the first
  197. small step, the first combo step, or throughout the whole big step.
  198. \item \textbf{Priority} specifies what to do when two transitions are enabled at the same time, where the source state of one
  199. of the transitions is the ancestor of the source state of the other transition. Either the transition of the ancestor gets
  200. priority (Source-Parent), or the transition of the (indirect) child gets priority (Source-Child).
  201. \end{itemize}
  202. \section{DEVS Formalism}
  203. The Discrete Event System Specification (DEVS)
  204. formalism was first introduced by Zeigler (TODO) in 1976 to provide a rigourous common basis for discrete-event modelling and
  205. simulation. For the class of formalisms denoted as discrete-event (TODO), system models are described at an abstraction
  206. level where the time base is continuous (TODO), but during a bounded time-span, only a finite number of relevant events
  207. occur. These events can cause the state of the system to change. In between events, the state of the system does not
  208. change. This is unlike continuous models in which the state of the system may change continuously over time. As an
  209. extension of Finite State Automata, the DEVS (Discrete Event Systems) formalism captures concepts from Discrete Event
  210. simulation. As such it is a sound basis for meaningful model exchange in the Discrete Event realm. (TODO: citation)
  211. The DEVS formalism fits the general structure of deterministic, causal systems in classical systems theory. DEVS allows
  212. for the description of system behaviour at two levels. At the lowest level, an atomic DEVS describes the autonomous
  213. behaviour of a discrete-event system as a sequence of deterministic transitions between sequential states as well as
  214. how it reacts to external input (events) and how it generates output (events). At the higher level, a coupled DEVS
  215. describes a system as a network of coupled components. The components can be atomic DEVS models or coupled DEVS in their
  216. own right. The connections denote how components influence each other. In particular, output events of one component
  217. can become, via a network connection, input events of another component. It is shown in [Zei84a] how the DEVS formalism
  218. is closed under coupling: for each coupled DEVS, a resultant atomic DEVS can be constructed. As such, any DEVS model,
  219. be it atomic or coupled, can be replaced by an equivalent atomic DEVS. The construction procedure of a resultant atomic
  220. DEVS is also the basis for the implementation of an abstract simulator or solver capable of simulating any DEVS model.
  221. As a coupled DEVS may have coupled DEVS components, hierarchical modelling is supported. In the following, the different
  222. aspects of the DEVS formalism are explained in more detail.
  223. \subsection{The atomic DEVS Formalism}
  224. The atomic DEVS formalism is a structure describing the different aspects of the discrete-event behaviour of a system:
  225. \begin{equation}
  226. atomicDEVS \equiv \langle S, ta, \delta_{int}, X, \delta_{ext}, Y, \lambda \rangle
  227. \end{equation}
  228. The time base $T$ is continuous and is not mentioned explicitly
  229. \begin{equation}
  230. T = \mathbb{R}
  231. \end{equation}
  232. The state set $S$ is the set of admissible sequential states: the DEVS dynamics consists of an ordered sequence of states
  233. from $S$. Typically, $S$ will be a structured set (a product set)
  234. \begin{equation}
  235. S = \times_{i=1}^{n} S_i.
  236. \end{equation}
  237. This formalizes multiple (n) concurrent parts of a system. It is noted how a structured state set is often synthesized
  238. from the state sets of concurrent components in a coupled DEVS model.
  239. The time the system remains in a sequential state before making a transition to the next sequential state is modelled by
  240. the time advance function
  241. \begin{equation}
  242. ta: S \rightarrow \mathbb{R}^+_{0, + \infty}.
  243. \end{equation}
  244. As time in the real world always advances, the image of $ta$ must be non-negative numbers. $ta = 0$ allows for the
  245. representation of instantaneous transitions: no time elapses before transition to a new state. Obviously, this is an
  246. abstraction of reality which may lead to simulation artifacts such as infinite instantaneous loops which do not correspond
  247. 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$.
  248. The internal transition function
  249. \begin{equation}
  250. \delta_{int}: S \rightarrow S
  251. \end{equation}
  252. models the transition from one state to the next sequential state. $\delta_{int}$ describes the behaviour of a Finite State
  253. Automaton; $ta$ adds the progression of time.
  254. It is possible to observe the system output. The output set $Y$ denotes the set of admissible outputs. Typically, $Y$ will be a
  255. structured set (a product set)
  256. \begin{equation}
  257. Y = \times_{i=1}^l Y_i.
  258. \end{equation}
  259. This formalizes multiple ($l$) output ports. Each port is identified by its unique index $i$. In a user-oriented modelling
  260. language, the indices would be derived from unique port names.
  261. The output function
  262. \begin{equation}
  263. \lambda : S \rightarrow Y \cup \{ \phi \}
  264. \end{equation}
  265. maps the internal state onto the output set. Output events are only generated by a DEVS model at the time of an internal
  266. transition. At that time, the state before the transition is used as input to $\lambda$. At all other times, the non-event
  267. $\phi$ is output. To describe the total state of the system at each point in time, the sequential state $s \in S$ is not
  268. sufficient. The elapsed time $e$ since the system made a transition to the current state $s$ needs also to be taken into
  269. account to construct the total state set
  270. \begin{equation}
  271. Q = \{ (s,e) | s \in S,, 0 \leq e \leq ta(s)\}
  272. \end{equation}
  273. The elapsed time $e$ takes on values ranging from 0 (transition just made) to $ta(s)$ (about to make transition to the next
  274. sequential state). Often, the time left $\sigma$ in a state is used:
  275. \begin{equation}
  276. \sigma = ta(s) - e
  277. \end{equation}
  278. Up to now, only an autonomous system was described: the system receives no external inputs. Hence, the input set $X$
  279. denoting all admissible input values is defined. Typically, $X$ will be a structured set (a product set)
  280. \begin{equation}
  281. X = \times_{i=1}^m X_i
  282. \end{equation}
  283. This formalizes multiple ($m$) input ports. Each port is identified by its unique index $i$. As with the output set,
  284. port indices may denote names.
  285. The set $\Omega$ contains all admissible input segments $\omega$
  286. \begin{equation}
  287. \omega : T \rightarrow X \cup \{ \phi \}
  288. \end{equation}
  289. In discrete-event system models, an input segment generates an input event different from the non-event $\phi$ only at a finite
  290. number of instants in a bounded time-interval. These external events, inputs $x$ from $X$, cause the system to interrupt its
  291. autonomous behaviour and react in a way prescribed by the external transition function
  292. \begin{equation}
  293. \delta_{ext}: Q \times X \rightarrow S
  294. \end{equation}
  295. The reaction of the system to an external event depends on the sequential state the system is in, the particular input and
  296. the elapsed time. Thus, $\delta_{ext}$ allows for the description of a large class of behaviours typically found in
  297. discrete-event models (including synchronization, preemption, suspension and re-activation). When an input event $x$ to an
  298. atomic model is not listed in the $\delta_{ext}$ specification, the event is ignored.
  299. % TODO: Example of traffic light/ Starts with "In Figure 1" ...
  300. \subsection{The coupled DEVS Formalism}
  301. The coupled DEVS formalism describes a discrete-event system in terms of a network of coupled components.
  302. \begin{equation}
  303. coupledDEVS \equiv \langle X_{self}, Y_{self}, D, \{M_i\}, \{I_i\}, \{Z_{i,j}\}, select \rangle
  304. \end{equation}
  305. The component $self$ denotes the coupled model itself. $X_{self}$ is the (possibly structured) set of allowed external inputs
  306. to the coupled model. $Y_{self}$ is the (possibly structured) set of allowed (external) outputs of the coupled model. $D$ is
  307. a set of unique component references (names). The coupled model itself is referred to by means of $self$, a unique reference
  308. not in $D$.
  309. The set of components is
  310. \begin{equation}
  311. \{M_i | i \in D\}.
  312. \end{equation}
  313. Each of the components must be an atomic DEVS
  314. \begin{equation}
  315. M_i = \langle S_i, ta_i, \delta_{int, i}, X_i, \delta_{ext, i}, Y_i, \lambda_i \rangle , \forall i \in D.
  316. \end{equation}
  317. The set of influences of a component, the components influenced by $i \in D \cup \{self\}$, is $I_i$. The set of all influences
  318. describes the coupling network structure
  319. \begin{equation}
  320. \{ I_i | i \in D \cup \{self\}\}.
  321. \end{equation}
  322. For modularity reasons, a component (including $self$) may not influence components outside its scope -the coupled model-,
  323. rather only other components of the coupled model, or the coupled model $self$:
  324. \begin{equation}
  325. \forall i \in D \cup \{self\}: I_i \subseteq D \cup \{self\}.
  326. \end{equation}
  327. This is further restricted by the requirement that none of the components (including $self$) may influence themselves directly
  328. as this could cause an instantaneous dependency cycle (in case of a 0 time advance inside such a component) akin to an algebraic
  329. loop in continuous models:
  330. \begin{equation}
  331. \forall i \in D \cup \{self\}: i \not \in I_i.
  332. \end{equation}
  333. Note how one can always encode a self-loop ($i \in I_i$) in the internal transition function.
  334. To translate an output event of one component (such as a departure of a customer) to a corresponding input event (such as the
  335. arrival of a customer) in influencees of that component, output-to-input translation functions $Z_{i,j}$ are defined:
  336. \begin{equation}
  337. \{ Z_{i,j} | i \in D \cup \{self\}, j \in I_i\}, \\
  338. Z_{self, j} : X_{self} \rightarrow X_j, \forall j \in D, \\
  339. Z_{i, self} : Y_i \rightarrow Y_{self}, \forall i \in D, \\
  340. Z_{i, j} : Y_i \rightarrow X_j, \forall i,j \in D.
  341. \end{equation}
  342. Together, $I_i$ and $Z_i,j$ completely specify the coupling (structure and behaviour).
  343. As a result of coupling of concurrent components, multiple state transitions may occur at the same simulation time. This is
  344. an artifact of the discrete-event abstraction and may lead to behaviour not related to real-life phenomena. A logic-based
  345. foundation to study the semantics of these artifacts was introduced by Radiya and Sargent (TODO). In sequential simulation
  346. systems, such transition collisions are resolved by means of some form of selection of which of the components' transitions
  347. should be handled first. This corresponds to the introduction of priorities in some simulation languages. The coupled DEVS
  348. formalism explicitly represents a select function for tie-breaking between simultaneous events:
  349. \begin{equation}
  350. select : 2^D \rightarrow D
  351. \end{equation}
  352. $select$ chooses a unique components from any non-empty subset E of D:
  353. \begin{equation}
  354. select(E) \in E.
  355. \end{equation}
  356. The subset E corresponds to the set of all components having a state transition simultaneously.
  357. \subsection{Closure of DEVS under coupling}
  358. As mentioned before, it is possible to construct a resultant atomic DEVS model for each coupled DEVS. This closure under
  359. coupling of atomic DEVS models makes any coupled DEVS equivalent to an atomic DEVS. By induction, any hierarchically coupled
  360. DEVS can thus be flattened to an atomic DEVS. As a result, the requirement that each of the components of a coupled DEVS be
  361. an atomic DEVS can be relaxed to be atomic or coupled as the latter can always be replaced by an equivalent atomic DEVS.
  362. The core of the closure procedure is the selection of the most imminent (i.e., soonest to occur) event from all the components'
  363. scheduled events (TODO). In case of simultaneous events, the select function is used. In the sequel, the resultant construction
  364. is described.
  365. From the coupled DEVS
  366. \begin{equation}
  367. \langle X_{self}, Y_{self}, D, \{M_i\}, \{I_i\}, \{Z_{i,j}\}, select \rangle
  368. \end{equation}
  369. with all components $M_i$ atomic DEVS models
  370. \begin{equation}
  371. M_i = \langle S_i, ta_i, \delta_{int, i}, X_i, \delta_{ext, i}, Y_i, \lambda_i \rangle, \forall i \in D
  372. \end{equation}
  373. the atomic DEVS
  374. \begin{equation}
  375. \langle S, ta, \delta_{int}, X, \delta_{ext}, Y, \lambda \rangle
  376. \end{equation}
  377. is constructed.
  378. The resultant set of sequential states is the product of the total state sets of all the components
  379. \begin{equation}
  380. S = \times_{i \in D} Q_i
  381. \end{equation}
  382. where
  383. \begin{equation}
  384. Q_i = \{ (s_i, e_i) | s \in S_i, 0 \leq e_i \leq ta_i(s_i) \}, \forall i \in D.
  385. \end{equation}
  386. The time advance function $ta$
  387. \begin{equation}
  388. ta : S \rightarrow \mathbb{R}^+_{0, + \infty}
  389. \end{equation}
  390. is constructed by selecting the most imminent event time, of all components. This means, finding the smallest time remaining
  391. until internal transition, of all the components
  392. \begin{equation}
  393. ta(s) = \min \{\sigma_i = ta_i(s_i) - e_i | i \in D \}.
  394. \end{equation}
  395. A number of imminent components may be scheduled for a simultaneous internal transition. These components are collected in a
  396. set
  397. \begin{equation}
  398. IMM(s) = \{i \in D | \sigma_i = ta(s)\}.
  399. \end{equation}
  400. From $IMM$, a set of elements of $D$, one component $i^*$ is chosen by means of the select tie-breaking function of the coupled
  401. model
  402. \begin{equation}
  403. select : 2^D \rightarrow D \\
  404. IMM(s) \rightarrow i^*
  405. \end{equation}
  406. Output of the selected component is generated before it makes its internal transition. Note also how, as in a Moore machine,
  407. input does not directly influence output. In DEVS models, only an internal transition produces output. An input can only
  408. influence/generate output via an internal transition similar to the presence of memory in the form of integrating elements in
  409. continuous models. Allowing an external transition to produce output could lead to infinite instantaneous loops. This is equivalent
  410. to algebraic loops in continuous systems. The output of the component is translated into coupled model output by means of the
  411. coupling information
  412. \begin{equation}
  413. \lambda(s) = Z_{i^*, self} (\lambda_{i^*}(s_{i^*})), \text{if} self \in I_{i^*}.
  414. \end{equation}
  415. 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
  416. the coupled model. As $\phi$ literally stands for no event, the output can also be ignored without changing the meaning (but
  417. increasing performance of simulator implementations).
  418. The internal transition function transforms the different parts of the total state as follows:
  419. \begin{equation}
  420. \delta_{int}(s) = (..., (s'_j, e'_j),...), \text{where} \\
  421. (s'_j, e'_j) = (\delta_{int, j} (s_j), 0), \text{for} j = i^*, \\
  422. = (\delta_{ext, j} (s_j, e_j + ta(s), Z_{i^*, j}))
  423. % TODO: Verder doen
  424. \end{equation}
  425. The selected imminent component $i^*$ makes an internal transition to sequential state $\delta_{int, i^*} (s_i^*)$. Its elpased
  426. time is reset to 0. All the influencees of $i^*$ change their state due to an external transition prompted by an input which is
  427. the output-to-input translated output of $i^*$, with an elapsed time adjusted for the time advance $ta(s)$. The influencees'
  428. 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
  429. is not affected and their elapsed time is merely adjusted for the time advance $ta(s)$.
  430. The external transition function transforms the different parts of the total state as follows:
  431. \begin{equation}
  432. \delta_{ext}(s,e,x) = (..., (s'_i, e'_i), ...)
  433. % TODO
  434. \end{equation}
  435. An incoming external event is routed, with an adjustment for elapsed time, to each of the components connected to the coupled
  436. model input (after the appropriate input-to-input translation). For all those components, the elapsed time is reset to 0. All
  437. other components are not affected and only the elapsed time is adjusted.
  438. Some limitations of DEVS are that
  439. \begin{itemize}
  440. \item a conflict due to simultaneous internal and external events is resolved by ignoring the internal event. It should be
  441. possible to explicitly specify behaviour in case of conflicts;
  442. \item there is limited potential for parallel implementation;
  443. \item the select function is an artificial legacy of the semantics of traditional sequential simulators based on an event
  444. list;
  445. \item it is not possible to describe variable structure.
  446. \end{itemize}
  447. Some of these are compensated for in parallel DEVS (TODO).
  448. \subsection{Implementation of a DEVS Solver}
  449. The algorithm in Figure (TODO) is based on the closure under coupling construction and can be used as a specification of a
  450. (possibly parallel) implementation of a DEVS solver or “abstract simulator” (TODO). In an atomic DEVS solver, the last event
  451. 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
  452. 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
  453. consistent (recursive) initialization of the $t_N$s. If kept, the $t_N$ allows one to check whether the solvers are
  454. appropriately synchronized. The operation of an abstract simulator involves handling four types of messages. The ($x, from, t$)
  455. message carries external input information. The ($y, from, t$) message carries external output information. The ($*, from, t$)
  456. and ($done, from, t_N$) messages are used for scheduling (synchronizing) the abstract simulators. In these messages, $t$ is the
  457. simulation time and $t_N$ is the next-event-time. The ($*, from, t$) message indicates an internal event * is due.When a
  458. coordinator receives a ($*, from, t$) message, it selects an imminent component $i^*$ by means of the tie-breaking function
  459. select specified for the coupled model and routes the message to $i^*$. Selection is necessary as there may be more than one
  460. imminent component (with minimum next remaining time).
  461. When an atomic simulator receives a ($*, from, t$) message, it generates an output message ($y, from, t$) based on the old state
  462. $s$. It then computes the new state by means of the internal transition function. Note how in DEVS, output messages are only
  463. produced while executing internal events. When a simulator outputs a ($y, from, t$) message, it is sent to its parent coordinator.
  464. The coordinator sends the output, after appropriate output-to-input translation, to each of the influencees of $i^*$ (if any). If
  465. the coupled model itself is an influencee of $i^*$, the output, after appropriate output-to-output translation, is sent to the the
  466. coupled model's parent coordinator.
  467. % TODO: Figure 3
  468. When a coordinator receives an ($x, from, t$) message from its parent coordinator, it routes the message, after appropriate
  469. input-to-input translation, to each of the affected components.
  470. When an atomic simulator receives an ($x, from, t$) message, it executes the external transition function of its associated atomic
  471. model.
  472. After processing an ($x, from, t$) or ($y, from, t$) message, a simulator sends a ($done, from, t_N$) message to its parent
  473. coordinator to prepare a new schedule. When a coordinator has received ($done, from, t_N$) messages from all its components,
  474. 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
  475. coordinator. This process is recursively applied until the top-level coordinator or root coordinator receives a ($done, from, t_N$)
  476. message.
  477. As the simulation procedure is synchronous, it does not support asynchronously arriving (real-time) external input. Rather, the
  478. environment or Experimental Frame should also be modelled as a DEVS component.
  479. 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$
  480. s kept in the simulators, it must be recursively set too. Once the initial conditions are set, the main loop described in Figure
  481. (TODO) is executed.
  482. \section{The pythonDEVS (pyDEVS) simulator}
  483. In this chapter we first present an implementation of the classical formalism. An early prototype of a DEVS Modeling and Simulation
  484. Package is then introduced. The chapter then moves on to discuss a real-time execution framework. The motivation behind real-time
  485. DEVS execution is discussed as well as the implications of 0-time semantics.
  486. \subsection{Design and implementation}
  487. This version of the DEVS Modeling and Simulation Package has been implemented using Python, an interpreted, very high-level,
  488. object-oriented programming language. The package consists of two files, the first of which (DEVS.py) provides a class architecture
  489. that allows hierarchical DEVS models to be easily defined. The simulation engine (SE) itself is implemented in the second file
  490. (Simulator.py). Based on the DEVS simulator described in (TODO), it uses the same message- passing mechanism. A detailed description
  491. of both the model architecture and the SE follows.
  492. \subsubsection{Model Architecture}
  493. The model architecture implemented in DEVS.py is a canvas from which hierarchical DEVS models can be easily described. It consists
  494. of a number of classes arranged to capture the essence of hierarchical DEVS. A model is described in a dedicated file by deriving
  495. coupled and/or atomic- DEVS descriptive classes from this architecture. These atomic models are then arranged hierarchically through
  496. composition. Methods and attributes form the standard interface that allows an SE, such as the one described in the next sub-section,
  497. to interact with the instantiated DEVS model. Our main concern with the architecture are twofold: remain as consistent as possible
  498. with the original hierarchical DEVS definition, and maintain a flexible approach to DEVS so as to encourage model reusability
  499. through parameterization.
  500. The class architecture is represented in Figure (TODO): BaseDEVS is the root class which provides basic functionalities common to both
  501. atomic and coupled models.
  502. Two classes are inherited from BaseDEVS to deal with the specifics of atomic and coupled DEVS formalisms (Figure (TODO)). These three
  503. classes are all abstract in that they cannot be directly instantiated. Rather, a model is described by deriving descriptive classes
  504. from either the AtomicDEVS or the CoupledDEVS class. This provides them with a suitable constructor and overrides the default
  505. interface methods. Note that the constructors at every level of the class hierarchy have an active role. Hence, a descriptive class'
  506. constructor should always start by calling the parent class' constructor.
  507. The constructor of the AtomicDEVS class merely initializes the myID attribute and provides a default initial value for the DEVS'
  508. total state, through the state and elapsed attributes. The remaining class definitions consist of default method declarations for
  509. the interface functions $\delta_{ext}$ (extTransition), $\delta_{int}$ (intTransition), $ta$ (timeAdvance) and $\lambda$ (outputFnc).
  510. These methods expect no parameter, and it is up to the modeler to be consistent with the corresponding functions' domain when overriding
  511. the methods. Except for outputFnc (which uses the poke method as described below), all the methods shall return a value compatible with
  512. the corresponding function range.
  513. Since default values are provided for both attributes and methods, the minimal atomic-DEVS descriptive class is empty:
  514. % TODO: code
  515. This atomic-DEVS is passive. It remains in its default state forever. A more interesting example is a generator, which sends a message
  516. (the integer 1 in this case) through its unique output port at a constant time interval:
  517. % TOOD: code
  518. As mentioned above, the outputFnc returns no value; instead it relies on the poke method to send message (second parameter) through the
  519. OUT output port (first parameter). The companion method, peek, returns the message on the input port that is given as a unique parameter,
  520. and is used exclusively in the extTransition function. Both poke and peek methods are defined in the AtomicDEVS class, and should not be
  521. overridden.
  522. The CoupledDEVS class only has one method to override, the tie-breaking select function. This takes a list of sub-models which are in
  523. conflict. The select function should return the sub-model instance from this list who's transition is to fire next. All a CoupledDEVS
  524. sub-models should be included by passing their instance variables to the addSubModel function.
  525. Coupling of ports is performed through the connectPorts method. Its first parameter is the source port and the second parameter is the
  526. destination port. A coupling is rejected and an error message issued if the coupling is invalid.
  527. The source and destination ports are instances of the class Port. This class defines channels where events may pass between DEVS models.
  528. These channels are defined in the Port's inLine and outLine attributes.
  529. Consider the example of the situation illustrated in Figure (TODO). There exists a descriptive class SomeDEVS for a DEVS (either atomic
  530. or coupled) with an input and output port locally known as IN and OUT. We want to connect the input port to the output port of the
  531. SimpleGenerator atomic- DEVS described above: both DEVS must of course be children of the same coupled-DEVS for the coupling to be
  532. performed. The coupled-DEVS descriptive class is defined below.
  533. % TODO: code
  534. Note that the parameter to the constructor is used to parameterize the SimpleGenerator atomic- DEVS. As for atomic-DEVS, the constructor
  535. first calls the parent class' constructor. Note also that the coupled-DEVS itself has an output port. The first coupling is an internal
  536. coupling, while the second is an external output coupling. This is a complete definition for a coupled-DEVS descriptive class. The
  537. default select function is used.
  538. Once all the descriptive classes in the hierarchical DEVS model have been defined, the whole model can be build by instantiating the
  539. root DEVS. This is possible since the hierarchical representation of the model is built by composition rather than aggregation.
  540. As a final warning, note that recursive definitions are illegal, since they are incompatible with a tree structure. As a trivial example,
  541. a coupled-DEVS' descriptive class SomeCoupledDEVS cannot call in its constructor the addSubModel method with an instance of
  542. SomeCoupledDEVS. This is mentionned since such recursive constructs will not be detected.
  543. \subsubsection{Simulation Engine}