A State Invariant is one of the UML elements. It is a runtime constraint applied to a lifeline in a Sequence diagram to specify conditions that are always true when a State is a current State. It is used to validate States. You may also specify State Invariants in the States directly. State Invariants on lifelines resolves variables in the same order as it does in message arguments.
When Cameo Simulation Toolkit runs a State Invariant in a model, it also evaluates its constraints. If the constraints are not satisfied, the evaluation will fail or return false and Cameo Simulation Toolkit will stop simulation (if "ConstraintAsBreakpoint" is set to true) at that invalid constraint or point. However, you can still continue the simulation to the next point. You can define constraints using any of the supported languages in Cameo Simulation Toolkit. State Invariants are used mostly in Interactions, but you can also use them in a State Machine diagram.
A State Invariant containing constraints being evaluated during execution.
Cameo Simulation Toolkit supports duration constraints between State invariants. The following figure shows the duration constraint, e.g., from playing to playing takes 5,000 ms of the total simulation time.
Duration constraints between State invariants are supported.
Time constraints of State invariants will be checked if right States are activated at the right time. When States change, Cameo Simulation Toolkit will check if active States contain required States, and time is exactly as specified in the constraints. If failed, an error message of the time constraints will be printed in the Console pane with the value, time unit, and State invariant name with hyperlinks accordingly, as shown in the figure below.