05-Evaluation.tex 62 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614
  1. \chapter{Evaluation}
  2. \label{chapt:Evaluation}
  3. In this chapter, we first compare our solution to YAKINDU, studying its semantics and overall feature-set. Next, we demonstrate 2 example models, implemented in SCCD and YAKINDU, and discuss the chosen semantic options for those models. Finally, we discuss some generally applicable insights obtained through implementation of the example models.
  4. \section{Comparison study: YAKINDU}
  5. YAKINDU Statechart Tools \cite{yakindu} is a well-known open-source tool for statechart development. It features a graphical interface for editing and simulating statechart models, and can compile models, generate optimized code for Java, C, and C++. It also features an advanced model testing framework.
  6. In this section, we first study YAKINDU's semantics and attempt to describe them as a BSML. We then compare YAKINDU's features to SCCD.
  7. \subsection{YAKINDU's semantics}
  8. YAKINDU features some semantic variation points, although fewer than SCCD. We discuss each of the variation points and map them onto BSML.
  9. \begin{table}
  10. \centering
  11. \small
  12. \begin{tabularx}{\textwidth}{ | X | c | c | }
  13. % \hline
  14. % & \multicolumn{2}{c|}{YAKINDU} \\
  15. \hline
  16. & \textbf{Cycle-based} & \textbf{Event-driven} \\
  17. \hline
  18. Big-Step Maximality & \textsc{Take One} & \textsc{Take Many} \\
  19. & superstep: \textsc{Take Many} & \\
  20. \hline
  21. Combo-Step Maximality & - & \textsc{Combo Take One} \\
  22. & & superstep: \textsc{Combo Take Many} \\
  23. \hline
  24. Input Event Lifeline & \textsc{Present in Whole} & \textsc{Present in First Combo Step} \\
  25. \hline
  26. Internal Event Lifeline & \textsc{Present in Remainder} & \textsc{Combo-Queued} \\
  27. \hline
  28. Priority & \multicolumn{2}{c|}{ \textsc{Hierarchical} (\textsc{Source-Parent} or \textsc{Source-Child}), \textsc{Explicit}} \\
  29. \hline
  30. Order of Small Steps & \multicolumn{2}{c|}{ \textsc{Explicit}} \\
  31. \hline
  32. Memory Protocol & \multicolumn{2}{c|}{ \textsc{Small Step}} \\
  33. \hline
  34. Concurrency & \multicolumn{2}{c|}{ \textsc{Single}} \\
  35. \hline
  36. \end{tabularx}
  37. \caption{Semantics of YAKINDU}
  38. \label{tab:yakindu_as_bsml}
  39. \end{table}
  40. \subsubsection{Cycle-based and event-driven execution}
  41. At the very highest level, the modeler can choose between 2 execution algorithms: \emph{Cycle-based} and \emph{event-driven} execution. From the viewpoint of BSML, each algorithm represents a set of choices for several semantic options.
  42. With \textbf{cycle-based execution}, the statechart responds at regular intervals to a set of simultaneously enabled input events, by performing a \emph{run-to-completion step} (RTC step). During an RTC step, every region (YAKINDU's term for an Or-state) may fire a single transition. Internal events raised during transition execution are simply added to the set of enabled events of the current RTC step, for the remainder of unfired regions to possibly respond to. When no more transitions can be made, the RTC step is complete.
  43. These semantics clearly map onto BSML. An RTC step here is a big-step, if we choose the semantic options Big-Step Maximality: \textsc{Take One}, Input Event Lifeline: \textsc{Present in Whole} and Internal Event Lifeline: \textsc{Present in Remainder}.
  44. With \textbf{event-driven execution}, the statechart performs an RTC step immediately for every raised input event. As a result, during every RTC step, exactly one event is enabled. The semantics of the RTC step itself are similar as with cycle-based execution, as every region is allowed to fire a single transition. Internally raised events, however, are not added to the set of enabled events of the current RTC step, but are put in a FIFO-queue of internally raised events. When the RTC step is over, another RTC step is immediately executed with as input the next event in the queue (giving higher priority to internal events than input events). This is repeated until the queue is empty.
  45. These semantics do not map perfectly onto BSML. A ``close'' semantic configuration is when we treat RTC steps as combo-steps: Big-Step Maximalty: \textsc{Take Many}, Combo Step Maximality: \textsc{Combo Take One}, Input Event Lifeline: \textsc{Present in First Combo Step} and Internal Event Lifeline: \textsc{Present in Next Combo Step}. However, this configuration will accumulate all internally raised events of combo step $n$ into enabled events of combo step $(n+1)$ (combo steps possibly having multiple simultaneously enabled events), as opposed to YAKINDU's semantics of starting a ``combo'' step per enabled event.
  46. SCCD has an Internal Event Lifeline option called \textsc{Queue} which somewhat resembles YAKINDU's event-driven execution. It appends internally raised events to the global (external to the statechart) event queue, but this causes them to be potentially handled after certain input events (if those input events have the same timestamp as the internal events, and pre-existed in the queue). YAKINDU, on the other hand, gives priority to internally raised events, by maintaining a separate queue for them.
  47. Let's invent a new Internal Event Lifeline option for YAKINDU, called \textsc{Combo-Queued}, queueing internal events and handling them in FIFO order, one event per combo step. This option combined with the other options from our ``close'' configuration accurately describes YAKINDU's event-driven execution semantics.
  48. \subsubsection{Superstep semantics}\label{sec:superstep}
  49. Another semantic option, altering the behavior of RTC steps is the \emph{superstep} option (to be included in their next release, version 4.0). Enabling this option allows regions to fire as many transitions per RTC step as they can. We did not test the precise semantics of this option, but from the execution pseudocode in the documentation\footnote{https://www.itemis.com/en/yakindu/state-machine/documentation/user-guide/sclang\_definition\_section\#sclang\_superstep}, it seems that RTC steps use \emph{fairness}, giving other regions a chance to fire a transition before the same region is given a chance again.
  50. Mapping this option to BSML, for cycle-based execution, this changes Big-Step Maximality from \textsc{Take One} to \textsc{Take Many} (with fairness). Other semantic options remain the same.
  51. For event-driven execution, we still handle one event per combo step, but a single event may now cause more than one transition to fire in the same region, so \textsc{Combo Take One} becomes \textsc{Combo Take Many} (with fairness). Other semantic options remain the same.
  52. \subsubsection{Child/parent first}
  53. For every statechart in YAKINDU, a choice must be made between the \emph{parent-first} or \emph{child-first} execution. There is no need to explain these options, as they simply map onto BSML's \textsc{Hierarchical} Priority options: \textsc{Source-Parent} and \textsc{Source-Child}.
  54. \subsubsection{Explicit outgoing transition priority}
  55. In order to avoid non-determinism, the outgoing transitions of a state always have an explicit priority relative to each other. If a state has multiple outgoing transitions, this explicit priority is graphically displayed as a number on every transition. The outgoing transitions' relative priorities are part of the syntax, and can be edited for every state. This behavior trivially maps onto Priority: \textsc{Explicit.}
  56. \subsubsection{Explicit region order}
  57. In YAKINDU, regardless of the rest of the execution semantics, regions get a chance on-by-one to fire a transition. Just like the order of outgoing transitions, the order in which regions are allowed to fire transitions, is an explicit part of the syntax, i.e. left-to-right, top-to-bottom in the graphical layout of the statechart. In BSML, this would be considered the option Order of Small Steps: \textsc{Explicit}.
  58. The combination of hierarchical priority, explicit outgoing transition priority, and explicit region order yields a total ordering on all transitions in the statechart, yielding fully deterministic behavior.
  59. \subsubsection{No memory snapshots}
  60. YAKINDU does not feature memory snapshot semantics, like SCCD: Transitions always have direct read/write access to a statechart's variables.
  61. This behavior maps onto the \textsc{Small Step} options for (Enabledness / Assignment) Memory Protocol of BSML.
  62. \subsubsection{No concurrency}
  63. YAKINDU features no concurrency semantics.
  64. \subsubsection{Summary}
  65. YAKINDU offers only 3 semantic choices, with 2 options for each: cycle-based vs. event-driven execution, superstep semantics (off/on) and parent-first vs. child-first hierarchical priority.
  66. YAKINDU's semantics map well onto BSML, if we invent a new Internal Event Lifeline option \textsc{Combo-Queued}. Table \ref{tab:yakindu_as_bsml} shows the semantic options available in YAKINDU. By implementing the \textsc{Combo-Queued} option in SCCD, it would support all of YAKINDU's semantics.
  67. \subsection{Comparison to SCCD}
  68. Despite its narrower set of semantic options, YAKINDU offers many more features than SCCD currently does. We will give an extensive overview of YAKINDU features NOT (yet) implemented in SCCD. They may serve as inspiration for future development efforts.
  69. \subsubsection{Graphical statechart editor}
  70. Statecharts are a visual, topological language. The inclusion of a graphical editor is a requirement for any serious statechart development.
  71. YAKINDU includes such a graphical editor. For SCCD, the intention is to eventually include a graphical editor as well, preferably modeled as a statechart itself.
  72. Because of the burden of editing statecharts in XML format, SCCD does include a script (based on the NodeJs script state-machine-cat\footnote{https://github.com/sverweij/state-machine-cat}, which again is based on GraphViz\footnote{https://graphviz.org/}) that renders XML statechart files as SVG images. This has been a great help during development of SCCD, as many test files had to be maintained in XML format. Visualizing them quickly made their state hierarchy apparent.
  73. The quality of the rendered images varies. GraphViz, the rendering backend used, can automatically generate appropriate layouts for graph data (the SCCD XML statechart format contains no layout information), but does not natively work with hierarchical graphs (or higraphs, as Harel \cite{harel1987statecharts} called them), so a workaround is used. This workaround sometimes causes rendered statecharts to look weird. Figure \ref{fig:hit_or_miss} shows 2 examples of rendered statecharts.
  74. \begin{figure}
  75. \centering
  76. \begin{subfigure}[t]{0.5\textwidth}
  77. \centering
  78. \includegraphics[width=0.7\textwidth]{statechart_fig9_trafficlight}
  79. \caption{traffic light}
  80. \end{subfigure}%
  81. \begin{subfigure}[t]{0.5\textwidth}
  82. \centering
  83. \includegraphics[width=0.7\textwidth]{statechart_priority_hierarchical}
  84. \caption{test file for hierarchical priority semantics}
  85. \end{subfigure}
  86. \caption{Examples of SCCD statecharts automatically rendered from XML}\label{fig:hit_or_miss}
  87. Quality of the result can be a hit-or-miss.
  88. \end{figure}
  89. It should also be noted that a graphical editor such as YAKINDU's puts somewhat of a burden on the modeler to choose a useful statechart layout. Especially for large statecharts with many transitions, this can be a nontrivial task, as transition labels tend to overlap with each other and with other parts of the statechart. Perhaps a hybrid approach, where the modeler is only concerned with the topology of the statechart, and possibly with layout decisions at the highest level, and the editor assisting by making (small) layout decisions, would work best.
  90. \subsubsection{Interactive debugging}
  91. YAKINDU can simulate and debug statechart models in its graphical editor, highlighting current states and allowing the modeler to enable input events interactively.
  92. \subsubsection{Syntactical constructs}
  93. YAKINDU features some syntactical constructs that SCCD does not have. Some of these can be considered syntactic sugar, while others add features to the language:
  94. \begin{description}
  95. \item[Synchronizations] There are 2 types of synchronizations: The first type can be understood a transition with multiple source states, where the sources have to be orthogonal to each other. This type expresses a transition that can only be taken if several orthogonal parts of the statechart are in a specific configuration. The source states are exited, and a the target is entered in a regular fashion.
  96. The second type can be understood as a transition with multiple target states, where the targets have to be orthogonal to each other. This type expresses a transition that sets up a specific configuration for several orthogonal parts of the statechart. With this type, the source state is exited in a regular fashion, and the target states are entered.
  97. Figure \ref{fig:synchronizations} shows both types of synchronizations.
  98. Synchronizations are not syntactic sugar and not supported in SCCD. SCCD does feature the \texttt{in\_state} function (which is also supported in YAKINDU), where e.g. a transition's guard can check if another state (in any region) is part of the configuration. This can replace the first type of synchronization. There is no trivial replacement for the second type.
  99. This feature also exists in Statemate \cite{harel1996statemate} and Rhapsody \cite{harel2004rhapsody}, where it is called \emph{join} (type 1) and \emph{fork} (type 2).
  100. \begin{figure}
  101. \centering
  102. \includegraphics[width=\textwidth]{synchronizations}
  103. \caption{Synchronizations in YAKINDU.}\label{fig:synchronizations}
  104. Figure taken from {https://www.itemis.com/en/yakindu/state-machine/documentation/user-guide/sclang\_graphical\_elements}
  105. \end{figure}
  106. \item[Choice-pseudo states] Syntactic sugar: a transition, possibly with a trigger, to a choice-pseudo state splits into several transitions, also with triggers, and actions. The same effect can be achieved by creating separate transitions with the combined triggers and actions from the part before and after the choice pseudo-state. This construct is used a lot in practice, and helps decluttering the visual representation of the statechart.
  107. \item[Named entry- and exit-points] In YAKINDU, the modeler can specify multiple named ``initial'' states, called named entry points. A transition to a composite state can specify the name of the entry to be taken. Likewise, a transition from a composite state can specify the name of the exit-point that should be taken. Entry- and exit-points are pseudo-states, as they are never part of the configuration. This feature gives composite states an \emph{interface}, making them reusable into different statecharts or different parts of the same statechart. The same functionality can be achieved by setting the source or target of a transition directly to a composite states's inner state, but this breaks the composite state's encapsulation. Currently, YAKINDU does not support composable statecharts (this feature is planned for version 4.0). Reused states would probably be \emph{inlined} in the compiled model. For this reason, this feature can be considered syntactic sugar.
  108. Another statechart-like formalism that supports (or rather, forces) encapsulation of composite states through explicit entry- and exit-points is ROOMcharts, part of the ROOM modeling language \cite{selic1996real}.
  109. \item[External variables] As an alternative to input/output events and synchronous function calls (called operations in YAKINDU), a statechart in YAKINDU can interact with its environment by reading or writing external variables, i.e. variables that are readable or writable externally. This feature can be mimicked by writing getter and/or setter operations, but direct access to variables may have a smaller overhead.
  110. \item[Every-trigger] This is a timed trigger (like an after-trigger). An every-trigger becomes enabled at fixed intervals in time. This construct can be considered syntactic sugar, as it can be modeled with a self-transition with after-trigger as well.
  111. \end{description}
  112. \subsection{Unit-testing framework}
  113. YAKINDU has a very powerful unit-testing framework. YAKINDU has its own textual language for specifying tests. It features white-box testing (checking if certain states are active), and allows the modeler to write multiple scenarios for the same model, each scenario raising events, checking states and waiting at will.
  114. SCCD currently only has a black-box testing framework, where every test includes only a single scenario of timed input events and expected output events. This approach was sufficient for working with artificial statecharts, specifically modeled to show different behavior under different semantics. For serious statechart development however, a framework like YAKINDU's is highly desirable. SCCD tests are also written in an XML format, which is not very convenient (to read or to write).
  115. \subsubsection{Code generation}
  116. An important feature of YAKINDU that our version of SCCD currently does not have, is statechart compilation (code generation). YAKINDU has several code generators, currently supporting C, C++ and Java, and support for more languages is on its way.
  117. According to the documentation, YAKINDU's generated code does not take care of scheduling, timers, input event queueing, thread-safety or memory management. The generated code primarily exposes a function to execute, in BSML terms, a ``big-step''. This is very similar to the implementation of the statechart language part of SCCD. Scheduling and input event queueing are implemented in the Controller; timers and thread-safety are implemented in different classes of the ``realtime''-library. As opposed to YAKINDU's generated code, statechart execution does dynamically allocate memory, as the action language's stack frames are allocated on Python's heap. YAKINDU's action code simply uses the current thread's stack instead for temporary variables. We could do the same if we compiled our action code.
  118. Generated code is well optimized. From studying the generated C code of a simple model, it was observed that YAKINDU stores its set of current states as an array of the configurations of orthogonal regions. The configuration of each region is stored as the state ID (as integer) of the deepest child that is a current state. This is a more compact representation than the bitmap representation used by the SCCD runtime. Transitions are always selected based on the current set of states in the configuration, by switch-case statements over the configuration of each region. The code generator can be configured to inline many types of functions.
  119. YAKINDU's code generation approach may serve as inspiration for a future SCCD code generator. It would be an interesting endeavor to develop a code generator supporting the wide semantic variation of SCCD (or substantial subset thereof).
  120. \section{Example models}
  121. % SIMON: Deze sectie zou wat gedetailleerder mogen. Sowieso zou ik voor Yakindu/SCCD de architectuur van de oplossingen laten zien (verschillende componenten, libraries, execution platforms) en waar de "calls" zitten (function calls, externe events, etc.). Ook de interface van elke component zou beschreven moeten worden. Als er iets toegevoegd werd aan SCCD zou je daar een snippet van moeten laten zien.
  122. % SIMON: Het is omgekeerd: de SCCD modellen waren eerst.
  123. 2 ``example'' statechart models are included with the SCCD project: \textbf{Digital watch} and \textbf{chat client}. They were adapted from solutions to homework assignments for the ``Modeling of Software-Intensive Systems'' course\footnote{http://msdl.cs.mcgill.ca/people/hv/teaching/MoSIS/} at the University Of Antwerp. With each assignment, a set of requirements was given, and an interface to interact with a piece of software (also given) implementing/simulating the rest of the system.
  124. Both examples are similar, in that they were both intentionally designed to encourage maximal usage of statechart language constructs, such as timed transitions and history states.
  125. The examples were also implemented in YAKINDU, and the YAKINDU solutions would have the exact same statechart structure, apart from some usage of YAKINDU's syntactic sugar, such as choice-states. In YAKINDU, the same semantics were always used: event-driven execution and parent-first priority. In SCCD, the default semantics (which are similar to YAKINDU's event-driven semantics) would yield a correct model, but for each example, the semantics were manually set to more ``restrictive'' options, which will be motivated.
  126. \subsection{Digital Watch}
  127. The digital watch example\footnote{http://msdl.cs.mcgill.ca/people/hv/teaching/MoSIS/201314/assignments/Statecharts/} is a controller for a (hardware) digital watch with 4 physical buttons, a time display, a chronometer display, an alarm display, an editing mode for setting the time and alarm, and backlighting.
  128. \begin{figure}
  129. \centering
  130. \includegraphics[width=0.25\textwidth]{dwatch}
  131. \caption{Screenshot of digital watch demo application}\label{fig:dwatch}
  132. \end{figure}
  133. \subsubsection{Interface}
  134. The ``hardware'' and some other functionality is implemented as a GUI application in Python/TkInter (Figure \ref{fig:dwatch}). The statechart interacts with the Python code by calling synchronous operations on it, and the Python code may also send events to the statechart.
  135. The Python code / ``hardware'' also has some \textbf{state}, in principle the following ``variables'':
  136. \begin{itemize}
  137. \item The value of the current time, as hours, minutes and seconds. The current value is this variable is drawn to the display only when requested by the statechart.
  138. \item The value of the current alarm, as hours and minutes. Similar to the current time.
  139. \item The value of the chrono, as minutes, seconds and $1/100$ seconds. Similar to the current time.
  140. \item A flag, shown or not shown on the display, to indicate whether the alarm is active. The flag is only a display property and has no further effect.
  141. \item Whether the display background light is on or off.
  142. \item Whether selection mode is active, on what ``variable'' it is active (time or alarm) and the group of digits (hours, minutes, seconds) currently selected. In selection mode, the selected group of digits blinks, and this is the only situation where the Python code \emph{autonomously} updates the display.\footnote{Note that this could have also been implemented nicely in the statechart, by exposing operations to it for setting visibility of individual digit groups, making the display truly ``passive'', and moving all selection-state entirely to the statechart. A possible motivation for not doing so, could have been to make the assignment not too big.}
  143. \end{itemize}
  144. The Python code exposes a set of \textbf{operations} to the statechart. The statechart can call these synchronously from its action code, while making a transition:
  145. \begin{description}
  146. \item[refreshTimeDisplay()] Redraw the time with the current internal time value. The display does not need to be cleaned before calling this function. For instance, if the alarm is currently displayed, it will be deleted before drawing the time.
  147. \item[refreshChronoDisplay()] See refreshTimeDisplay()
  148. \item[refreshDateDisplay()] See refreshTimeDisplay()
  149. \item[refreshAlarmDisplay()] See refreshTimeDisplay()
  150. \item[increaseTimeByOne()] Increase the time by one second. Note how minutes, hours, days, month and year will be modified appropriately, if needed (for example, when increaseTimeByOne() is called at time 11:59:59, the new time will be 12:00:00).
  151. \item[resetChrono()] Resets the internal chrono to 00:00:00.
  152. \item[increaseChronoByOne()] Increase the chrono by 1/100 second.
  153. \item[startSelection()] Selects the leftmost digit group currently displayed on the screen.
  154. \item[increaseSelection()] Increases the currently selected digit group's value by one.
  155. \item[selectNext()] Select the next digit group, looping back to the leftmost digit group when the rightmost digit group is currently selected. If the time is currently displayed on the screen, select also the date digits. If the alarm is displayed on the screen, don't select the date digits. (to simplify the statechart).
  156. \item[stopSelection()] Exits editing mode.
  157. \item[setIndiglo()] Turn on the display background light.
  158. \item[unsetIndiglo()] Turn off the display background light.
  159. \item[setAlarm()] Toggles the alarm flag on the display on or off.
  160. \item[checkTime()] Checks if the alarm time set is exactly equal to the current clock time. If so, it will broadcast the ``alarmStart'' event to the statechart and return true. Otherwise, it returns false. Note that checkTime() does not care/check whether the alarm has been set "on".
  161. Since the current time and the alarm time only change when explicitly requested (by the statechart) through the operations just explained, and statecharts have an \emph{exact} notion of time through the use of simulated time (i.e. transitions do not take time to execute, and timed transition fire after precisely the amount of time specified), the statechart has exact control over the current time (and alarm time), as well as the timings of its calls to checkTime(), and will therefore, if properly designed, never ``miss'' an alarm.
  162. \end{description}
  163. The Python code may send the following \textbf{input events} to the statechart:
  164. \begin{description}
  165. \item[button press / release events] Events are named `topRightPressed', `topRightReleased', `topLeftPressed', `topLeftReleased', `bottomRightPressed', `bottomRightReleased', `bottomLeftPressed', `bottomLeftReleased', and generated when their respective buttons are clicked by the mouse in the GUI.
  166. \item[alarmStart] Generated when checkTime() operation is called (see later), and current time == alarm time.
  167. \end{description}
  168. \subsubsection{Requirements}
  169. The requirements for the solution are as follows:
  170. \begin{enumerate}
  171. % 1. check
  172. \item The time value should be updated every second, even when it is not displayed (as for example, when the chrono is running). However, time is not updated when it is being edited.
  173. % 2. check
  174. \item Pressing the top right button turns on the Indiglo light. The light stays on for as long as the button remains pressed. From the moment the button is released, the light stays on for 2 more seconds, after which it is turned off.
  175. % 3. check
  176. \item Pressing the top left button alternates between the chrono and the time display modes. The system starts in the time display mode. In this mode, the time (HH:MM:SS) and date (MM/DD/YY) are displayed.
  177. % 4. check
  178. \item When in chrono display mode, the elapsed time is displayed MM:SS:FF (with FF hundreths of a second). Initially, the chrono starts at 00:00:00. The bottom right button is used to start the chrono. The running chrono updates in 1/100 second increments. Subsequently pressing the bottom right button will pause/resume the chrono. Pressing the bottom left button resets the chrono to 00:00:00. The chrono will keep running (when in running mode) or keep its value (when in paused mode), even when the watch is in a different display mode (for example, when the time is displayed).
  179. Note: interactive simulation (in AToM3) of a model containing time increments of 1/100 second is possible, but it is difficult to manually insert other events. Hence, while you are simulating your model, it is advisable to use larger increments (such as 1/4 second) for simulation purposes.
  180. % 5. check
  181. \item When in time display mode, the watch will go into time editing mode when the bottom right button is held pressed for at least 1.5 seconds.
  182. % 6. check
  183. \item When in time display mode, the alarm can be displayed and toggled between on or off by pressing the bottom left button. If the bottom left button is held for 1.5 seconds or more, the watch goes into alarm editing mode. This is not an example of good User Interface design, as going to editing mode will also toggle on/off and that may not be desired. It is however how the 1981 Texas Instruments LCD Alarm Chronograph works. %The first time alarm editing mode is entered, the alarm time is set to 12:00:00.
  184. % 7. check
  185. \item The alarm is activated when the alarm time is equal to the time in display mode. When it is activated, the screen will blink for 4 seconds, then the alarm turns off. Blinking means switching to/from highlighted background (Indiglo) twice per second. The alarm can be turned-off before the elapsed 4 seconds by a user interrupt (i.e.: if any button is pressed). After the alarm is turned off, activity continues exactly where it was left-off. Note that after the alarm finishes (flashing ends), the alarm is un-set (so it will not go off the next day at the same time).
  186. % 8. check
  187. \item When in (either time or alarm) editing mode, briefly pressing the bottom left button will increase the current selection. Note that it is only possible to increase the current selection, there is no way to decrease or reset the current selection. If the bottom left button is held down, the current selection is incremented automatically every 0.3 seconds. Editing mode should be exited if no editing event occurs for 5 seconds. Holding the bottom right button down for 2 seconds will also exit the editing mode. Pressing the bottom right button for less than 2 seconds will move to the next selection (for example, from editing hours to editing minutes).
  188. \end{enumerate}
  189. \subsubsection{Solution}
  190. The solution statechart consists of 5 orthogonal regions at the highest level, named Time, Alarm, Indiglo, Display and Chrono. These regions model (mostly) independent stateful parts of the behavior:
  191. \begin{enumerate}
  192. \item The ``Time''-region that increases the time, every second, as long as we are not in ``time editing mode'', implementing requirement (1). The entering and exiting of time editing mode is done in another region of the statechart, and signaled to this region with the use of ``time\_edit'' and ``edit\_done'' internal events. It is also this region that calls the ``checkTime''-operation with each increase of the time, but only if we are in the alarm-on-state (in the ``Alarm'' region, see later). Checking if we are in a state from action code is done using the ``in\_state''-function.
  193. \begin{figure}
  194. \centering
  195. \includegraphics[]{sc_dwatch_time}
  196. \caption{Time region of digital watch}
  197. \label{fig:sc_dwatch_time}
  198. Internal events are {\color{myblue}blue}.
  199. \end{figure}
  200. \item The ``Alarm''-region keeps track of whether the alarm is on or off, and makes the alarm go off (blinking the light) if the ``alarmStart'' input event is received. We use enter- and exit-actions for the symmetric operations of (un)setting the watch's backlight. This way, we can be certain that e.g. the watch's backlight is not forgotten to be turned off, if the Blinking-state is exited. Similary, toggling the displays' alarm flag (operation ``setAlarm()'') is done by enter- and exit-actions of the On-state.
  201. We partially implement requirement (6), toggling the alarm with the bottom-left button while in time display mode. We also implement requirement (7), interrupting the alarm with any button when the alarm is blinking. This is done with 4 transitions (one for each button), but they are drawn as one transition for clarity.
  202. \begin{figure}
  203. \centering
  204. \includegraphics[]{sc_dwatch_alarm}
  205. \caption{Alarm region of digital watch}
  206. \end{figure}
  207. \item The ``Indiglo'' region implements requirement (2).
  208. \begin{figure}
  209. \centering
  210. \includegraphics[]{sc_dwatch_indiglo}
  211. \caption{Indiglo region of digital watch}
  212. \label{fig:sc_dwatch_indiglo}
  213. \end{figure}
  214. \item The ``Display'' region is the largest region, implementing requirements (3), (5), (6) and (8). It controls what is visible on the display (the time, the chrono or the alarm time) and also implements the editing mode, which can be entered from the time or alarm view.
  215. Note that this region responds to the internal events ``refresh\_chrono'' and ``refresh\_time'' by refreshing the chrono and time view, resp. The region also raises the internal events ``time\_edit'', ``alarm\_edit'' and ``edit\_done'' to signal the beginning and end of time / alarm edit mode.
  216. \begin{figure}
  217. \centering
  218. \includegraphics[width=\textwidth]{sc_dwatch_display}
  219. \caption{Display region of digital watch}
  220. Internal events are {\color{myblue}blue}.
  221. \end{figure}
  222. \item The ``Chrono'' region implements requirement (4) and contains the logical states of the chrono: Paused and Running. These states are wrapped in a composite state in order to support resetting the chrono from either of these states.
  223. This region raises the internal event ``refresh\_chrono'' when the chrono display should be updated.
  224. \begin{figure}
  225. \centering
  226. \includegraphics[width=\textwidth]{sc_dwatch_chrono}
  227. \caption{Chrono region of digital watch}
  228. Internal events are {\color{myblue}blue}.
  229. \end{figure}
  230. \end{enumerate}
  231. \subsubsection{Valid semantic choices}\label{sec:dwatch_semantics}
  232. The model has been observed to behave correctly under different semantics. Assuming we only handle 1 input event at a time, there are some observations about the intended behavior:
  233. \begin{itemize}
  234. \item A reaction to an input event raises at most 1 internal event.
  235. \item A reaction to an internal event raises no further internal events.
  236. \item A reaction to an input event fires at most 1 transition in the statechart (with one exception, to be explained).
  237. \item A reaction to an internal event fires at most 1 transition in the statechart, and in a different region than the reaction that raised the internal event. Every internal event ``flows'' from one region to another:
  238. \begin{itemize}
  239. \item refresh\_time: Time $\rightarrow$ Display
  240. \item refresh\_chrono: Chrono $\rightarrow$ Display
  241. \item time\_edit: Display $\rightarrow$ Time
  242. \item edit\_done: Display $\rightarrow$ Time
  243. \end{itemize}
  244. \end{itemize}
  245. The last observation allows us to choose \textsc{Take One} for Big-Step Maximality. \textsc{Take Many} adds no benefit, and, under both YAKINDU (Section \ref{sec:superstep}) and SCCD (Section \ref{sec:rounds}, Figure \ref{fig:rounds_example}) results in a more complex execution (featuring one more nested loop), making the behavior more difficult to predict for the modeler, and introducing the risk of never-ending big-steps.
  246. If \textsc{Take Many} is chosen anyway, we must choose \textsc{Present in First Small Step} for Input Event Lifeline, to ensure that every input event only causes 1 transition to be made. Otherwise, never-ending big-steps would occur: Several regions contain transitions of the type shown in Figure \ref{fig:sc_takemany_button}. E.g. the Display-region would oscilate endlessly between ChronoView and TimeView when the topleft button is pressed. Similarly, we would also have to choose \textsc{Present in Next Small Step} for Internal Event Lifelife, to ensure every internal event is also only responded to once. Otherwise, e.g. the self-transition with trigger ``refresh\_time'' of Display/TimeView would endlessly repeat.
  247. Choosing \textsc{Present in First Small Step} slightly alters the behavior of the model: When the Alarm-region is in the Blinking-state, a button press may cause the alarm to be interrupted, or cause a transition elsewhere, in another region. (This is the only situation where an input event can be responded to in more than 1 region.) The transition first responding to the input event ``consumes'' it. In order to satisfy the requirements, we must thus give the Alarm-region a higher (\textsc{Explicit}) priority than the other regions. This can be done in both YAKINDU and SCCD. The button press, consumed by the Alarm-region, will no longer cause any other reaction. The requirements are ambiguous here, not mandating or forbidding this ``alternative'' behavior.
  248. \begin{figure}
  249. \centering
  250. \includegraphics[]{sc_takemany_button}
  251. \caption{A statechart that would behave differently under \textsc{Take One} vs. \textsc{Take Many} semantics}
  252. \label{fig:sc_takemany_button}
  253. \end{figure}
  254. Under \textsc{Take One}-semantics, all event input/internal lifeline options are valid (except \textsc{Present in Same}). If Input Event Lifeline \textsc{Present in Whole} and Internal Event Lifeline \textsc{Present in Remainder} are chosen, input and internal events may be simultaneously enabled, but a region would never have to choose between an input and internal event, because in the model, internal events are always responded to in a (different) region that does not respond to the input event.
  255. % Because we know every button press-event is followed by a button release-event at a later point in time (i.e. in a later big-step), it is possible to avoid \textsc{Take Many}'s never-ending big-steps by introducing additional states. For instance, the Indiglo-region could also have been implemented as shown in Figure \ref{fig:sc_dwatch_alt_indiglo}, behaving correctly under \textsc{Take One}, but under \textsc{Take Many}, it would repeat the ``Pushed''-state's self-transition endlessly. The implementation originally demonstrated in Figure \ref{fig:sc_dwatch_indiglo} does not have this problem, due to the explicit ``Released''-state that it enters upon button release.
  256. % This approach still cannot ``fix'' the entire statechart, because there is one type of input event to which we whish to respond with a self-transition, yet has no ``mirror'' event: The after-transition in the Time-region (Figure \ref{fig:sc_dwatch_time}) is implemented in both SCCD and YAKINDU by transparently (to the modeler) requesting the scheduler to generate a future \emph{input event}. With \textsc{Present in Whole} semantics, this input event would allow the transition to repeat itself endlessly under \textsc{Take Many}.
  257. % \begin{figure}
  258. % \centering
  259. % \includegraphics[]{sc_dwatch_alt_indiglo}
  260. % \caption{Alternative implementation of Indiglo-region, with fewer states, behaving currectly under \textsc{Take One}, and incorrectly under \textsc{Take Many} semantics}
  261. % \label{fig:sc_dwatch_alt_indiglo}
  262. % \end{figure}
  263. % Choosing Input Event Lifeline: \textsc{Present in First Small Step} would ``fix'' \textsc{Take Many}, and would work with \textsc{Take One} as well. This option would change the behavior slightly, as it would allow only a single region to respond to each input event. There is only one situation where a single input may cause several regions to respond, and this is when the alarm is interrupted, by pressing any button. The same button press will be reacted to in another region, as every button press in the model \emph{always} has some effect. By choosing \textsc{Present in First Small Step}, only a single region will react, ``consuming'' the event. YAKINDU and SCCD let the modeler give regions an \textsc{Explicit} priority, in order to produce fully deterministic behavior. We must give the alarm region the highest priority, otherwise the alarm could not be interrupted, violating the requirements. The button press would have no other effect. Whether this is \emph{correct} behavior, is not stated in the requirements.
  264. % Regions communicate by use of internal events (and the \texttt{in\_state} function). The way the model is designed, internal events can only be raised as reaction to an input event, not as a reaction to another input event. This guarantees terminating big-steps, should we use \textsc{Take Many} and \textsc{Present in Next Small Step} for Internal Event Lifeline. If we use \textsc{Take One}, all causal options for Internal Event Lifeline are valid.
  265. The model does not require combo steps. Combo steps are only useful if the reactions have to be \emph{grouped}, and constraints need to be applied to each group. One case would be when input and internal event reactions are expected to have overlapping regions, but we still want to allow only 1 transition region per set of input/internal events (i.e. \textsc{Combo Take One}, \textsc{Present in First/Next Combo Step}). This is the default semantic configuration of SCCD, and also resembles the event-driven execution of YAKINDU, and is a valid semantic configuration for our model, but since it adds no value, while increasing execution complexity, there is no reason to use it.
  266. Figure \ref{fig:dwatch_semantics} shows a tree of valid combinations of the semantic options just discussed. \textsc{Take One}-semantics are definitely preferred for the reasons discussed above. Note that also YAKINDU's cycle-based and event-driven semantics are valid semantics, but that for cycle-based semantics, simultaneous input events could occur, which the model doesn't support (and also the requirements don't mention).
  267. \begin{figure}
  268. \centering
  269. \includegraphics[width=\textwidth]{dwatch_semantics}
  270. \caption{8 correct semantic configurations for digital watch}
  271. \label{fig:dwatch_semantics}
  272. \end{figure}
  273. The explicit priority of regions has already been discussed, and only requires us to set a high priority to the Alarm-region if we choose \textsc{Present in First Small Step} for input events.
  274. Any explicit priority for every state's outgoing transitions is a valid one. All transitions have event triggers. For every state, there can be multiple outgoing transitions with different input events as triggers, but simultaneous input events are not expected to occur, and if they would occur (e.g. 2 buttons simultaneously pressed), the requirements do not specify what needs to happen, so any deterministic choice is a good one. Every state never has more than 1 internal event-triggered outgoing transition, which is given the lowest priority, since our chosen semantics always prioritizes input events.
  275. For hierarchical priority, any choice is a correct one, since for every event, only a single transition per region can be selected.
  276. The statechart has no variables, so Memory Protocol options do not apply.
  277. % It is difficult to conclude a ``best'' semantical configuration for our model. We definitely prefer \textsc{Take One} for its simple execution. For input events, we can choose between \textsc{Present in Whole} and \textsc{Present in First Small Step}, depending on the desired behavior as described above. For internal events, the choice really doesn't matter here.
  278. \subsubsection{Concrete implementation}
  279. The SCCD implementation differs from the YAKINDU implementation, because, at the time, SCCD did not support synchronous functions called directly from the statechart. A workaround was applied, using output events instead of synchronous functions. This workaround had no further impact on the statechart's structure or set of correct semantics. If output events are handled in the order that they were raised, there is no real difference between them or synchronous functions, as long as functions don't return data.%\footnote{Strictly speaking, in BSML, the output events of a big-step are simultaneous and have no order, so we deviate here.}
  280. In SCCD, this example makes use of the event loop-integration library. All statechart simulation runs from TkInter's event loop. This way, the entire application runs from a single thread, making it easy to interact with TkInter (which is not thread-safe).
  281. \subsection{Chat Client}
  282. \begin{figure}
  283. \centering
  284. \includegraphics[width=0.5\textwidth]{chatclient}
  285. \caption{Screenshot of chat client demo application}\label{fig:chatclient}
  286. \end{figure}
  287. The chat client example\footnote{http://msdl.cs.mcgill.ca/people/hv/teaching/MoSIS/assignments/Statecharts} is a keyboard-commanded GUI chat application. The example consists of a client and a server program. The chat client is partially implemented as a statechart. The client-server protocol and the chat server are ad-hoc programmed in Python (Java for the YAKINDU version). The original version of SCCD includes a chat server implemented in statecharts as well, but it relies on multi-instance models, which our version does not yet support.
  288. % The protocol is as follows:
  289. % \begin{itemize}
  290. % \item Clients may connect to the server, and disconnect.
  291. % \item After having connected, a client may join a chatroom. Chatrooms are identified by an integer number. Every client can join at most 1 chatroom at the same time. A chatroom may have any number of clients in it.
  292. % \item After having joined a chatroom, a client may leave the chatroom.
  293. % \item Clients may send a (textual) message to a server they are connected to. The server will broadcast the message to all clients who are in the same chatroom as the client.
  294. % \item The requests for joining/leaving and sending a message are acknowledged by the server.
  295. % \item At any time, clients may send a \emph{ping}-request to a server they are connected to. The server acknowledges ping-requests with an \emph{alive}-response.
  296. % \end{itemize}
  297. \subsubsection{Interface}
  298. % The statechart model implements the chat client, which is a networked GUI-application.
  299. The statechart interfaces with 2 components: A network client, for interacting with a chat server, and a UI window, implementing the chat client's window. Both components are implemented in Python (Java for the YAKINDU version).
  300. The network client exposes the following \textbf{operations}:
  301. \begin{description}
  302. \item[get\_nr\_of\_servers(): int] Returns the number of (hardcoded) servers in the client
  303. \item[get\_server(index: int): str] Returns the address of the server with given index
  304. \end{description}
  305. The network client can receive the following \textbf{output events} from the statechart:
  306. \begin{description}
  307. \item[connect(address: str)] Request the client to connect to the server with given address.
  308. \item[disconnect] Request the client to disconnect from the server.
  309. \item[join(room: int)] Request the client to join the chatroom with given index.
  310. \item[leave] Request the client to leave the current room.
  311. \item[ping] Request the client to send a `ping' request to the currently connected server.
  312. \item[send\_message(msg: str)] Request the client to send a message to the server. The server will broadcast the message to other clients in the same chatroom.
  313. \end{description}
  314. The network client may also send the following \textbf{input events} to the statechart:
  315. \begin{description}
  316. \item[connected] Sent when the client is successfully connected to a server.
  317. \item[disconnected] Sent when the client is successfully disconnected from a server.
  318. \item[joined] Sent when the client successfully joins a room.
  319. \item[left] Sent when the client successfully leaves a room.
  320. \item[receive\_message: string] Sent when a client receives a message from the server. (another participant in the room sent a message)
  321. \item[alive] Sent when the client receives an "alive" message. (response to a "ping")
  322. \end{description}
  323. The UI window consists of a scrollable list of logs and received messages, and has an input box on the bottom. It exposes the following \textbf{operations}:
  324. \begin{description}
  325. \item[add\_message(msg: str, type: str)] Prints out a message to the scrollable list, with the specified type (as a string, either "info", "local", or "remote"))
  326. \item[append\_to\_buffer(char: str)] Adds a string to the input box and visualizes the change
  327. \item[remove\_last\_in\_buffer()] Removes the final character from the input box and visualizes the change
  328. \item[clear\_input()] Clears the input box and visualizes the change
  329. \item[input\_join()] Colors the input box in the 'join' mode (green)
  330. \item[input\_msg()] Colors the input box in the 'message' mode (white)
  331. \item[input\_command()] Colors the input box in the 'command' mode (grey)
  332. \item[get\_buffer(): str] Returns the current content of the input box
  333. \end{description}
  334. The UI window can also send one type of \textbf{input event} to the statechart:
  335. \begin{description}
  336. \item[input(char: str)] Sent when a keystroke occured. The parameter of the event contains the input character.
  337. \end{description}
  338. \subsubsection{Requirements}
  339. \begin{enumerate}
  340. \item The client is either disconnected or connected to a chatserver.
  341. \item The client has a (hardcoded) list of servers that it can connect to. A server is identified by its IP address (or hostname) and a port.
  342. \item If the client is disconnected, the user can not enter any input and must wait for a connection to be established.
  343. \item The client will autonomously connect to a server by sending a connection request. If the server does not respond within a certain amount of time, another server is chosen until one of the connections succeeds.
  344. \item As soon as the client is connected, the client will continuously ping the server with a certain interval. Should the server not respond after a certain timeout, the client will automatically go to disconnected mode and the user is again unable to enter any input.
  345. \item After transferring to disconnected mode, the client will automatically try to establish a connection to another server. After a connection is successfully made, the user can again enter input.
  346. \item All input that was made by the user before a disconnect should remain in memory and visible to the user.
  347. \item When the user has connected to a server, the user starts without having joined any room. The user can give the input 'j' (Join) to join a specific room. After pressing 'j', the input box is colored green and only numerical input is accepted. Other input is not accepted.
  348. \item After joining a room, the user starts to receive messages from the server that should be shown in the chat window. The user can either leave the room again by pressing 'l' (Leave), or can send a message by pressing 'm' (Message).
  349. \item After pressing 'm', the entry box colors white and the user can type a message. The message will be sent after the return key is pressed.
  350. \item Should a disconnect from the server occur while the user has already joined a room, the same room should automatically be joined after reconnection to the server.
  351. \item Make sure that backspace also works in every input mode.
  352. \item Input processing must happen in a way that resembles Finite State Automata.
  353. \item You should test the above requirements by building a testing harnass that will determine whether your Statechart satisfies the requirements. Do this by using sctunit, the testing framework provided by Yakindu.
  354. \end{enumerate}
  355. \subsubsection{Solution}
  356. First of all, the solution statechart has 3 variables:
  357. \begin{itemize}
  358. \item \texttt{curr\_server}: Integer, index of the server currently attempting to connect to, or connected to. Initially 0.
  359. \item \texttt{room\_number}: Integer, number of the chatroom attempting to join, joined, or last joined. Initially 0.
  360. \item \texttt{reconnecting}: Boolean, whether a previous connection to a server was lost. Initially false.
  361. \end{itemize}
  362. The solution consists of 3 orthogonal regions at the highest level:
  363. \begin{enumerate}
  364. \item The ``Receiving''-region has only a single sub-state with a self-transition, printing out any received message. No additional checks on server connectedness or chatroom joinedness are required, since we only expect to receive messages when connected and joined.
  365. \begin{figure}
  366. \centering
  367. \includegraphics[]{sc_chat_receiving}
  368. \caption{Receiving-region of chat client}
  369. \label{fig:sc_chat_receiving}
  370. \end{figure}
  371. \item The ``Pinging''-region starts pinging the server when the input event ``connected'' is received. When no response is received after 2 seconds, the region stops sending pings, and notifies other regions of this through the internal event ``timeout''.
  372. \begin{figure}
  373. \centering
  374. \includegraphics[]{sc_chat_pinging}
  375. \caption{Pinging-region of chat client}
  376. Internal events are {\color{myblue}blue}.
  377. \label{fig:sc_chat_pinging}
  378. \end{figure}
  379. \item Finally, the ``Main''-region models all user interactions and the main window's state. At the highest level, there are 2 sub-states:
  380. \begin{itemize}
  381. \item Connecting: Initial state, attempts to connect in a round-robin fashion to one of the servers hardcoded in the network client. The first connection that succeeds takes us to the Connected-state.
  382. \item Connected: Contains the client's behavior while connected to a server. When connection is lost (sensed through the ``timeout''-internal event coming from the Pinging-region), we go back to Connecting, while setting the variable \texttt{reconnecting} to True, causing the Connecting-state to connect to the same server as before.
  383. \end{itemize}
  384. The most complex feature, is automatically re-joining the chatroom after a restored connection. This is done by dividing the Connected-state into 2 (non-orthogonal) regions: LeavingOrLeft (should not re-join) and JoiningOrJoined (should re-join). At the same level, a history-state records which of those we were in.
  385. \begin{figure}
  386. \centering
  387. \includegraphics[width=102mm]{sc_chat2_main}
  388. \caption{Main-region of chat client}
  389. Internal events are {\color{myblue}blue}. Variables are {\color{mygreen}green}.
  390. \label{fig:sc_chat_main}
  391. \end{figure}
  392. When going to the Joined-state, we must always send a join-request to the server first. Therefore we always pass through the Joining-state. When joined, another history-state is keeps track of whether we were entering a message, or not.
  393. When entering a regions that has history, we always enter the history state. If no history for the region exists yet, both YAKINDU and SCCD enter the region's initial state, which is what we want.
  394. Note that the outgoing transitions of ``EnteringMessage'' are given explicit priorities. The self-transition appending entered characters to the input field buffer is a lower priority than the rest, because it has no guard checking the key that was pressed, and may otherwise ``steal'' events from the other outgoing transitions.
  395. \end{enumerate}
  396. \subsubsection{Valid semantic choices}
  397. % The same observations from apply to this model: We only expect one input event simultaneously, and every input event causes at most one transition per region to be executed, possibly raising one internal event (the only internal event here is ``timeout'', flowing from region Pinging $\rightarrow$ Main), causing at most one more transition to be executed, in a different region. The exact same tree of semantic options applies (Figure \ref{fig:dwatch_semantics}).
  398. For the same reasons as explained in the digital watch example (Section \ref{sec:dwatch_semantics}), choosing \textsc{Take One} for Big-Step Maximality is appropriate. For Input Event Lifeline, we cannot choose \textsc{Present in First Small Step}, because the input event ``connected'' needs to be responded to in both the Pinging- and Main-region, so the only option remaining is \textsc{Present in Whole}. For Internal Event Lifeline, any option would be correct (except \textsc{Present in Same}).
  399. Alternatively, SCCD's default semantics (\textsc{Take Many}, \textsc{Combo Take One}, \textsc{Present in First/Next Combo Step}) is also valid, but more complex to execute. No other working set of semantic choices can include \textsc{Take Many}.
  400. The statechart includes variables, so a choice should be made for Memory Protocol semantics. Any choice is a valid one, because values written to a variable are not read until the next big step. An exception is the transition GettingRoomNumber $\rightarrow$ JoiningOrJoined, which writes a value to the variable \texttt{room\_number}, and subsequently reads it (as the enter-action of Joining). However, SCCD considers this write-read sequence as part of a single transition, and therefore always reads the ``fresh'' value, ignoring memory protocol options. This feature was called ``locally observable writes'' in Section \ref{sec:locally_obs_writes}.
  401. \subsubsection{Concrete implementation}
  402. The YAKINDU solution makes extensive use of choice-pseudo states, which is syntactic sugar to group outgoing transitions with the same event trigger but with a different guard condition, such as for states ``GettingRoomNumber'' and ``EnteringMessage''. This makes the model more readable. SCCD currently does not have this feature, requiring the modeler to model them as separate transitions, which is also the way they were (manually) drawn in Figure \ref{fig:sc_chat_main}.
  403. In order to implement this model, SCCD had to be extended with the ability to call external functions directly from its action code, as certain interactions with e.g. the GUI (such as getting the text entered in the box at the bottom) had to be implemented as synchronous calls. Once this was done, the implementation was trivial, and identical to the YAKINDU-implementation.
  404. In SCCD, like with the digital watch, the event loop integration library is used to run the statechart from the TkInter thread, but the network client library \emph{has} to run separate threads for sending and receiving data, as these are blocking I/O operations on socket-objects in Python. In order to send or receive events from the statechart, thread-safe queues were used.
  405. \section{Meaningful semantics}
  406. Most semantic options of BSML can be arbitrarily combined, but not all combinations are useful. The paper on BSML \cite{sabzali2010deconstructing} lists very few dependencies between options (such as \textsc{Combo Take Many} $\Rightarrow$ \textsc{Syntactic} $\vee$ \textsc{Take Many}) but these dependencies are the bare minimum, technical restrictions for carrying out \emph{some} form of execution. We will now see if we can further delimit combinations of semantic options for statecharts.
  407. \subsection{Maximality, Event Lifeline}
  408. The semantic aspects Big-/Combo-Step Maximality and Input/Internal Event Lifeline are considered ``orthogonal'' in BSML, which is correct from the viewpoint of ``being able to execute them'', but for realistic models, the options chosen for these aspects depend heavily on each other.
  409. Together, these options control 2 things:
  410. \begin{enumerate}
  411. \item For how long transitions can be made as response to input or internal events.
  412. \item At what point the effects of input event-triggered transitions begin to influence the remainder of the execution of the big-step, by means of internal events and variable assignments.
  413. \end{enumerate}
  414. For the first property, an input/internal event lifeline spectrum exists from ``short'' to ``long'': For instance, \textsc{Present in Next Small Step} is a ``short'' option, while \textsc{Present in Remainder} is a ``long'' option. For the second property, an internal event lifeline spectrum exists from ``sooner'' to ``later'': For instance, \textsc{Present in Next Small Step} is a ``soon'' option, while \textsc{Queue} (only in SCCD) is a ``late'' option.
  415. \begin{figure}
  416. \centering
  417. \includegraphics[]{late_long}
  418. \caption{Properties of event lifeline options}
  419. \end{figure}
  420. Choosing a ``late'' an event lifeline option helps separate reactions to input events from reactions to internal events. The ``later'' an event lifeline option, the more need for \textsc{Take Many}. The ``longer'' the event lifeline option, the worse it behaves with \textsc{Take Many}, because of never-ending big-steps: The options \textsc{Present in Remainder} and \textsc{Present in Whole} are unlikely to work well with \textsc{Take Many} (e.g. the digital watch example, Section \ref{sec:dwatch_semantics}).
  421. Introducing combo-steps (using \textsc{Combo Take One} with a combo-step event lifeline option) helps to avoid never-ending big-steps with \textsc{Take Many}. Combo-steps are very useful to build a semantic configuration that is ``fool-proof'', such as YAKINDU's event-driven execution, and SCCD's default configuration, which execute input events and internal events in separate rounds. However, many complex models (such as both examples discussed in the previous section) function perfectly fine under \textsc{Take One} semantics, even though they were developed with combo-steps in mind. The simplicity of \textsc{Take One}, both for the modeler and execution runtime (performance-wise) is a good argument for always chosing this option, if possible.
  422. \subsection{Memory Protocol}
  423. Usually, the modeler would want to use the Memory Protocol option that matches the point in time where internally raised events become enabled. This way, the full effect of one transition, consisting of raised events and variable assignments, becomes visible at a single point in time.
  424. The default semantics of SCCD follow this principle, with the \textsc{Combo Step}-option being the default, following the default event lifeline option \textsc{Present in Next Combo Step}. With these semantics, the statechart appears to behave as if the transitions within a combo-step fire concurrently.
  425. When not using combo-step semantics or for any other reason, the modeler may also choose to disable Memory Protocol semantics by choosing \textsc{Small Step} (i.e. variable assignments become visible to the next transition). This is how YAKINDU behaves.
  426. \subsection{Priority}
  427. We consider priority truly orthogonal to other semantic options. In YAKINDU and SCCD, the priority of all transitions is a total ordering, explicitly created by the modeler. In models only responding to single-item sets of input events, usually there is no need for setting an explicit priority, because few transitions will be enabled at any point in time. Such models would still behave deterministically in the absense of priority rule(s). In the case of our example models (digital watch and chat client), we only sporadically had to set a priority. In our example models, there also were no hierarchical conflicts that needed resolution (e.g. ``parent first'').
  428. \subsection{Conclusion}
  429. We agree with \cite{sabzali2010deconstructing} that semantics should be chosen on a model-by-model basis. We advise to start out with a simple, restrictive set of semantics, e.g. \textsc{Take One}, as it is easy to understand, efficient to execute, and has been shown to work even for large and complex models. The default semantics of SCCD and YAKINDU (event-driven) are less restrictive and fairly intuitive, but have a higher runtime overhead due to the use of combo-steps. Combo-steps can also be used to ``simulate'' concurrency, by enabling Memory Protocol semantics. Explicitly assigning priority to regions or transitions to resolve ambiguity, only has to be done sporadically even in large models.
  430. % - Estimated number of combinations as presented in Day & Atlee: very large number!
  431. % - Number can be reduced by finding interactions between semantic choices:
  432. % general property: effect of one transition on another, one of:
  433. % 1) immediate (synchronous, sooner)
  434. % 2) queueing (asynchronous, later)
  435. % => IEL: range of options: "Same" (most immediate) -> "Queue" (latest)
  436. % => Memory protocol: typically want same as IEL
  437. % => Maximality: the more "immediate" the effect, the less need for "Take Many"
  438. % - SCCD's default semantics: BSM: "Take Many" + IEL: "Next Combo Step" + MP: "Combo step"
  439. % => rather on the "queueing" end of spectrum, permissive
  440. % => modeler should restrict semantics more towards immediate if possible