This example shows how to change the selected output port of an Output Switch block to route entities along different paths. The software selects the path on a per-entity basis, not on a predetermined time schedule.
When the software generates an entity, the entity advances to the Single Server block. Meanwhile, the Entity Departure Function-Call Generator Event block issues a function call that executes the Function-Call Subsystem block.
The Function-Call Subsystem block contains
a single Repeating Sequence Stair block, whose Sample
time parameter is set to
When the Function-Call Subsystem block executes, it outputs the next number from a repeating sequence. In this model, the output signal value is 3, 2 or 1, based on the sequence of values specified in the Repeating Sequence Stair block.
When service in the Single Server block is complete, the entity advances to the Output Switch block. The output signal of the Function-Call Subsystem block determines which output port the entity uses when it departs the Output Switch block. When the simulation is complete, this repeating port selection is shown by the output of the Signal Scope block.
When the Output Switch block uses an input signal p, the block might attempt to use the p signal before its first sample time hit. If the initial value of the p signal is out of range (for example, zero) or is not your desired initial port selection for the switch, then you should specify the initial port selection in the Output Switch block's dialog box. Use this procedure:
Select Specify initial port selection.
Set Initial port selection to the desired initial port selection. The value must be an integer between 1 and Number of entity output ports. The Output Switch block uses Initial port selection instead of the p signal's value until the signal has its first sample time hit.
Tip A common scenario in which you should specify the initial port selection is when the p signal is an event-based signal in a feedback loop. The first entity is likely to arrive at the switch before the p signal has its first sample time hit. See Queue Selection Using a Switch for an example of this scenario.
When the Output Switch block uses an input signal p, the block must successfully coordinate its entity-handling operations with the operations of whichever block produces the p signal. For example, if p is an event-based signal that can change at the same time when an entity arrives, the simulation behavior depends on whether the block reacts to the signal update before or after the arrival.
Coordination that is inappropriate for the model can cause the block to use a value of p from a previous time. You can prevent a systemic latency problem by using the Store entity before switching option.
If you select Store entity before switching in the Output Switch block, then the block becomes capable of storing one entity at a time. Furthermore, the block decouples its arrival and departure processing to give other blocks along the entity's path an opportunity to complete their processing. Completing their processing is important if, for example, it affects the p signal of the Output Switch block.
If an entity arrives and the storage location is empty, then the block does the following:
Stores the arriving entity and schedules a storage completion event on the event calendar.
Yields control to blocks in the model that perform operations that are either not scheduled on the event calendar, or prioritized ahead of the storage completion event on the event calendar. For example, this might give other blocks a chance to update the signal that connects to the p port.
Executes the storage completion event.
Determines which entity output port is the selected port.
If the selected port is not blocked, the stored entity departs immediately.
If the selected port is blocked, the stored entity departs when one of these occurs:
Storage for a Time Interval. A stored entity can stay in the block for a nonzero period of time if the selected port is blocked. The design of your model should account for the effect of this phenomenon on statistics or other simulation behaviors. For an example scenario, see the discussion of average wait in Example Without Storage.
Even if the stored entity departs at the same time that it arrives, step 2 is important for preventing latency.
Example Using Storage. The model in Queue Selection Using a Switch uses the Store entity before switching option in the Output Switch block. Suppose the queues have sufficient storage capacity so that the Output Switch block never stores an entity for a nonzero period of time. When an entity arrives at the Output Switch block, it does the following:
Stores the entity and schedules a storage completion event on the event calendar.
Yields control to other blocks so that the Time-Based Entity Generator and the subsystem can update their output signals in turn.
Executes the storage completion event.
Possibly detects a change in the p signal as a result of the subsystem computation, and reacts accordingly by selecting the appropriate entity output port.
Outputs the entity using the up-to-date value of the p signal.
If you do not select Store entity before switching in the Output Switch block, then the block processes an arrival and departure as an atomic operation. The block assumes that the p signal is already up to date at the given time.
For common problems and troubleshooting tips, see Unexpected Use of Old Value of Signal.
Example Without Storage. The model below (open modelmodel) does not use the Store entity before switching option in the Output Switch block. Storage in the switch is unnecessary here because the application processes service completion events after the Repeating Sequence Stair block has already updated its output signal at the given time.
Tip It is not always easy to determine whether storage is unnecessary in a given model. If you are not sure, you should select Store entity before switching.
Furthermore, storage in the switch is probably undesirable in this model. Storing entities in the Output Switch block for a nonzero period of time would affect the computation of average wait, which is the N-Server block's w output signal. If the goal is to compute the average waiting time of entities that have not yet reached the Single Server blocks, then the model would need to account for entities stored in the switch for a nonzero period of time.