This example shows how to save and restore the simulation state of a SimEvents® model by using Save final operating point check box and use it as an initial state for future simulations. For more information about using Save final operating point, see Save and Restore Simulation Operating Point.
The Save final operating point check box is used to save the state of a simple queuing system with an Entity Generator block, an Entity Queue block, an Entity Server block, and an Entity Terminator block. The signal output port n displaying the number of entities departed the Entity Queue block is connected to a Scope block. For more information about performing basic tasks to create this model, see Create a Discrete-Event Model. The only difference in the model is the placement of the scope.
Open the Entity Server Block Parameters dialog box. Set the Service time value to 2.
The queue length increases throughout the simulation because service time is larger than the entity intergeneration time.
From the Simulink® Toolstrip, select Modeling tab and
Model Settings. In the Configuration Parameters
dialog box, in the Data Import/Export pane, select the
Final states check box with the variable name
xFinal
and select the Save final operating
point check box.
Simulate the model and open the Scope block. Observe that the
final queue length is 6
.
The queue length increases, with spikes at times 2
,
4
, 6
, 8
, and
10
because the Service time value of
the Entity Server block is 2
. The entity in
the Entity Server block departs, and the entity that arrives at
the Entity Queue block immediately advances to the Entity
Server block.
In the Configuration Parameters dialog box, select the Initial
state check box and specify the variable name as
xFinal
.
xFinal
is used as an initial state for the next
simulation.
Increase the simulation time to 20
.
Set the simulation time larger than 10
to observe
simulation with the saved initial simulation state.
Simulate the model. Open the Scope block. Observe that the
simulation starts from the queue length 6
, which is the final
state of the previous simulation.
Entity Generator | Entity Queue | Entity Server | Entity Terminator