Skip to Main Content Skip to Search
Product Documentation

Regulating the Simulation Length

Overview

When you gather statistics from a simulation, ending the simulation at the right time is more important than if you are only observing behavior qualitatively. Typical criteria for ending a discrete-event simulation include the following:

Setting a Fixed Stop Time

To run a simulation interactively with a fixed stop time, do the following:

  1. Open the Configuration Parameters dialog box by choosing Simulation > Configuration Parameters in the menu of the model window.

  2. In the dialog box, set Stop time to the desired stop time.

  3. Run the simulation by choosing Simulation > Start.

To fix the stop time when running a simulation programmatically, use syntax like

sim('model',timespan)

where model is the name of the model and timespan is the desired stop time.

Stopping Upon Processing a Fixed Number of Entities

By counting entities, you can stop the simulation when the simulation processes a fixed number of entities. The basic procedure for stopping a simulation based on the total number of entity departures from a block is:

  1. Find the parameter of the block that enables the departure counter as a signal output. Most blocks call the parameter Number of entities departed. Exceptions are in the following table.

    BlockParameter
    Entity Departure CounterWrite count to signal port #d
    Entity SinkNumber of entities arrived

  2. Set the check box. This setting causes the block to have a signal output port corresponding to the entity count.

  3. Connect the new signal output port to an Atomic Subsystem block.

  4. Double-click the subsystem block to open the subsystem it represents.

  5. Delete the Outport block labeled Out.

  6. Connect the Inport block labeled In to a Compare To Constant block.

  7. In the Compare To Constant block,

    • Set Operator to >=.

    • Set Constant value to the desired number of entity departures.

    • Set Output data type mode to boolean.

  8. Connect the Compare To Constant block to a Stop Simulation block. The result should look like the following, except that your SimEvents block might be a block other than Entity Departure Counter.

    Top-Level Model

    Subsystem Contents

See the considerations discussed in Tips for Using State-Based Stopping Conditions below. They are relevant if you are stopping the simulation based on an entity count, where "desired state" means the entity-count threshold.

Stopping Upon Reaching a Particular State

Suppose you want the simulation to end when it achieves a particular state, such as an overflow or a machine failure. The state might be the only criterion for ending the simulation, or the state might be one of multiple criteria, each of which is sufficient reason to end the simulation. An example that uses multiple criteria is a military simulation that ends when all identified targets are destroyed or all resources (ammunition, aircraft, etc.) are depleted, whichever occurs first.

Once you have identified a state that is relevant for ending the simulation, you typically create a Boolean signal that queries the state and connect the signal to a Stop Simulation block. Typical ways to create a Boolean signal that queries a state include the following:

Tips for Using State-Based Stopping Conditions

When using a state rather than a time to determine when the simulation ends, keep in mind the following considerations:

  


Free SimEvents Evaluation Kit

Learn how you can use SimEvents discrete-event simulation capabilities through these technical resources.

Get free kit

Trials Available

Try the latest version of discrete-event simulation products.

Get trial software
 © 1984-2012- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS