Prev Next

Example: History Pseudostate

State History is a convenient concept associated with Regions of Composite States, whereby a Region keeps track of the configuration a State was in when it was last exited. This allows easy return to that State configuration, if necessary, the next time the Region becomes active (for example, after returning from handling an interrupt), or if there is a local Transition that returns to its history.

Enterprise Architect supports two types of History Pseudostate:

  • Deep History - representing the full State configuration of the most recent visit to the containing Region; the effect is the same as if the Transition terminating on the deepHistory Pseudostate had, instead, terminated on the innermost State of the preserved State configuration, including execution of all entry Behaviors encountered along the way
  • Shallow History - representing a return to only the top-most substate of the most recent State configuration, which is entered using the default entry rule

In this example, the Classes DeepTurbineManager and ShallowTurbineManager are exactly the same except that the contained StateMachine for the first has a deepHistory Pseudostate and for the second has a shallowHistory Pseudostate.

Both StateMachines have three Composite States: Turbine_01, Turbine_02 andTurbine_03, each of which has Off and On States and a History Pseudostate in its Region.

In order to better observe the difference between Deep History and Shallow History, we execute the two StateMachines in one simulation.

The StateMachine in DeepTurbineManager is illustrated in this diagram:

The StateMachine in ShallowTurbineManager is illustrated in this diagram:

Tip: If you right-click on the History node on the diagram and select the 'Advanced | Deep History' option, you can toggle the type of History Pseudostate between shallow and deep.

First Time Activation of States

After simulation starts, Turbine_01 and its substate Off are activated.

Trigger Sequence: [MODE, SPEED]

Then the active State configuration includes:

  • Turbine_01
  • Turbine_01.On
  • Turbine_01.On.High

This applies to both deepManager and shallowManager.

Trigger Sequence: [NEXT]

This trace sequence can be observed from the Simulation window (Simulate > Dynamic Simulation > Simulator > Open Simulation Window):

        01    shallowManager[ShallowTurbineManager].StateMachine_Turbine_01_On_High EXIT

        02    shallowManager[ShallowTurbineManager].StateMachine_Turbine_01_On EXIT

        03    shallowManager[ShallowTurbineManager].StateMachine_Turbine_01 EXIT

        04    shallowManager[ShallowTurbineManager].Turbine_01__TO__History2_105720_61730 Effect

        05    shallowManager[ShallowTurbineManager].StateMachine_Turbine_02 ENTRY

        06    shallowManager[ShallowTurbineManager].StateMachine_Turbine_02 DO

        07    shallowManager[ShallowTurbineManager].History2_105720__TO__Off_61731 Effect

        08    shallowManager[ShallowTurbineManager].StateMachine_Turbine_02_Off ENTRY

        09    shallowManager[ShallowTurbineManager].StateMachine_Turbine_02_Off DO

Note: Since deepManager has exactly the same trace as shallowManager, the trace for deepManager is filtered out from this sequence.

We can learn that:

  • Exiting a Composite State commences with the innermost State in the active State configuration (see lines 01 - 03 in the trace sequence)
  • The Default History Transition is only taken if execution leads to the History node (see line 04) and the State has never been active before (see line 07)

Then the active State configuration includes:

  • Turbine_02
  • Turbine_02.Off

This applies to both deepManager and shallowManager.

Trigger Sequence: [NEXT, MODE]

This trace sequence can be observed from the Simulation window:

          Trigger [NEXT]

        01    shallowManager[ShallowTurbineManager].StateMachine_Turbine_02_Off EXIT

        02    shallowManager[ShallowTurbineManager].StateMachine_Turbine_02 EXIT

        03    shallowManager[ShallowTurbineManager].Turbine_02__TO__History3_105713_61725 Effect

        04    shallowManager[ShallowTurbineManager].StateMachine_Turbine_03 ENTRY

        05    shallowManager[ShallowTurbineManager].StateMachine_Turbine_03 DO

        06    shallowManager[ShallowTurbineManager].Initial_105706__TO__Off_61718 Effect

        07    shallowManager[ShallowTurbineManager].StateMachine_Turbine_03_Off ENTRY

        08    shallowManager[ShallowTurbineManager].StateMachine_Turbine_03_Off DO

        Trigger [MODE]

           Message omitted...

Note: Since deepManager has exactly the same trace as shallowManager, the trace for deepManager is filtered out from this sequence.

We can learn that:

  • Since there is no default History Transition defined for History3, the standard default entry of the State is performed; an Initial node is found in the Region contained by Turbine_03, so the Transition originating from Initial is enabled (see line 06)

Then the active state configuration includes:

  • Turbine_03
  • Turbine_03.On
  • Turbine_03.On.Low

This applies to both deepManager and shallowManager.

History Entry of States

As a reference, we show the Deep History snapshot of each Turbine after its first activation:

Turbine_01

  • Turbine_01.On
  • Turbine_01.On.High

Turbine_02

  • Turbine_02.Off

Turbine_03

  • Turbine_03.On
  • Turbine_03.On.Low

When we further Trigger NEXT, Turbine_01 will be activated again.

This trace sequence can be observed from the Simulation window:

For shallowManager:

          Trigger [NEXT]

       01    shallowManager[ShallowTurbineManager].StateMachine_Turbine_03_On_Low EXIT

        02    shallowManager[ShallowTurbineManager].StateMachine_Turbine_03_On EXIT

        03    shallowManager[ShallowTurbineManager].StateMachine_Turbine_03 EXIT

        04    shallowManager[ShallowTurbineManager].Turbine_03__TO__History1_105711_61732 Effect

        05    shallowManager[ShallowTurbineManager].StateMachine_Turbine_01 ENTRY

        06    shallowManager[ShallowTurbineManager].StateMachine_Turbine_01 DO

        07    shallowManager[ShallowTurbineManager].StateMachine_Turbine_01_On ENTRY

        08    shallowManager[ShallowTurbineManager].StateMachine_Turbine_01_On DO

        09    shallowManager[ShallowTurbineManager].Initial_105721__TO__Low_61729 Effect

        10    shallowManager[ShallowTurbineManager].StateMachine_Turbine_01_On_Low ENTRY

        11    shallowManager[ShallowTurbineManager].StateMachine_Turbine_01_On_Low DO

We can learn that:

  • The shallowHistory node restores Turbine_01 as far as Turbine_01.On
  • Then the Region contained by Composite State Turbine_01.On will be activated by the Initial node, which activated at Low

For deepManager:

          Trigger [NEXT]

        01    deepManager[DeepTurbineManager].StateMachine_Turbine_03_On_Low EXIT

        02    deepManager[DeepTurbineManager].StateMachine_Turbine_03_On EXIT

        03    deepManager[DeepTurbineManager].StateMachine_Turbine_03 EXIT

        04    deepManager[DeepTurbineManager].Turbine_03__TO__History1_105679_61708 Effect

        05    deepManager[DeepTurbineManager].StateMachine_Turbine_01 ENTRY

        06    deepManager[DeepTurbineManager].StateMachine_Turbine_01 DO

        07    deepManager[DeepTurbineManager].StateMachine_Turbine_01_On ENTRY

        08    deepManager[DeepTurbineManager].StateMachine_Turbine_01_On_High ENTRY

We can learn that:

  • The deepHistory node restores Turbine_01 as far as Turbine_01.On.High

Trigger [NEXT] to exit Turbine_01 and activate Turbine_02

Both shallowManager and deepManager activate Turbine_02.Off, which is the History snapshot when they exited.

Trigger [NEXT] to exit Turbine_02 and activate Turbine_03

Both shallowManager and deepManager activate Turbine_03.On.Low. However, the sequences of shallowManager and deepManager are different.

For shallowManager, the shallowHistory can only restore as far as Turbine_03.On. Since an Initial node is defined in Turbine_03.On, the Transition originating from Initial will be enabled and Turbine_03.On.Low is reached.

        01    shallowManager[ShallowTurbineManager].StateMachine_Turbine_02_Off EXIT

        02    shallowManager[ShallowTurbineManager].StateMachine_Turbine_02 EXIT

        03    shallowManager[ShallowTurbineManager].Turbine_02__TO__History3_105713_61725 Effect

        04    shallowManager[ShallowTurbineManager].StateMachine_Turbine_03 ENTRY

        05    shallowManager[ShallowTurbineManager].StateMachine_Turbine_03 DO

        06    shallowManager[ShallowTurbineManager].StateMachine_Turbine_03_On ENTRY

        07    shallowManager[ShallowTurbineManager].StateMachine_Turbine_03_On DO

        08    shallowManager[ShallowTurbineManager].Initial_105727__TO__Low_61728 Effect

        09    shallowManager[ShallowTurbineManager].StateMachine_Turbine_03_On_Low ENTRY

        10    shallowManager[ShallowTurbineManager].StateMachine_Turbine_03_On_Low DO

For deepManager, the deephistory can restore as far as Turbine_03.On.Low directly.

        01    deepManager[DeepTurbineManager].StateMachine_Turbine_02_Off EXIT

        02    deepManager[DeepTurbineManager].StateMachine_Turbine_02 EXIT

        03    deepManager[DeepTurbineManager].Turbine_02__TO__History3_105680_61701 Effect

        04    deepManager[DeepTurbineManager].StateMachine_Turbine_03 ENTRY

        05    deepManager[DeepTurbineManager].StateMachine_Turbine_03 DO

        06    deepManager[DeepTurbineManager].StateMachine_Turbine_03_On ENTRY

        07    deepManager[DeepTurbineManager].StateMachine_Turbine_03_On_Low ENTRY