.Modelica_StateGraph2.UsersGuide.Tutorial.SafeStateGraphs.SingleAssignmentRule

Information

In all state machine formalisms problems are present when assignments to the same variables are performed in branches that are executed in parallel. Typically, actions are formulated within a step. Such actions are, e.g., distinguished as entry, normal, exit and abort actions. For example, a valve might be opened by an entry action of a step and might be closed by an exit action of the same step. This widly used standard approach becomes critical, when the same variable is assigned in graphs that are executed in parallel, because it is then not clear which value the variable will have, and different tools might give different results.

In StateGraphs, it is not possible to assign the same variable in graphs that are executed in parallel, due to Modelicas "single assignment rule" that requires that every variable is defined by exactly one equation. This feature of a StateGraph2 is very useful, since it allows a Modelica translator to guarantee that a given StateGraph2 has always deterministic behaviour without conflicts. In other state diagram methodologies this is much more cumbersome. For example, if two steps are executed in parallel and both step actions modify the same variable, the result is either non-deterministic or non-obvious rules have to be defined which action takes priority. In a StateGraph2, such a situation is detected by the translator resulting in an error, since there are two equations to compute one variable.

In the Figure below an artifical example is shown how to handle such problems in a StateGraph2 model, e.g., with a MultiSwitch action block "openValve". The purpose is to set:

  openValve.y = true,  if Step fill1 is entered
  openValve.y = false, if Step fill2 is entered

and the question is which value openValve.y will have, if both steps fill1 and fill2 are executed in parallel. In the StateGraph2 model below, everything is well defined: There are two input connections to the openValve block. If both become true at the same time instant, the connection with the "lowest" index (i.e., the upper signal in the Figure) has highest priority (as defined and implemented in the MultiSwitch block). Therefore, openValve.y gets the value true, once the Parallel component is entered.


Generated at 2024-12-17T19:26:02Z by OpenModelicaOpenModelica 1.24.3 using GenerateDoc.mos