|On this page…|
The plot in Run the Simulation indicates how many entities have departed from the server, but does not address the following question: Is any entity still in the server at the conclusion of the simulation? To answer the question, you can use the SimEvents® debugger, as described in this section. Using the debugger involves running the simulation in a special debugging mode that lets you suspend a simulation at each step or breakpoint and query simulation behavior. Using the debugger does not require you to change the model. The topics in this section are as follows:
To open a completed version of the example model for this tutorial, enter simeventsdocex('doc_dd1')simeventsdocex('doc_dd1') in the MATLAB® Command Window. Save the model in your working folder as dd1.
To start simulating the current system in debugging mode, enter this command at the MATLAB command prompt:
The output in the MATLAB Command Window indicates that the debugger is active. The output also includes hyperlinks to information sources.
*** SimEvents Debugger *** Functions | Help | Watch Video Tutorial %==============================================================================% Initializing Model dd1 sedebug>>
The sedebug>> notation is the debugger prompt, where you enter commands.
The simulation has initialized but does not proceed. In debugging mode, you indicate to the debugger when to proceed through the simulation and how far to proceed before returning control to you. The purpose of this example is to find out whether an entity is in the server when the simulation ends. To continue the simulation until it ends, enter this command at the sedebug>> prompt:
The Command Window displays a long series of messages that indicate what is happening during the simulation. The end of the output indicates that the debugger has suspended the simulation just before the end:
Hit built-in breakpoint for the end of simulation. Use 'cont' to end the simulation or any other function to inspect final states of the system. %==============================================================================% Terminating Model dd1
To understand the long series of messages, see Simulation Log in the Debugger.
The debugger has suspended the simulation just before the end and the sedebug>> prompt indicates that you can still enter debugging commands. In this way, you have an opportunity to inspect the final states of blocks or other aspects of the simulation. To get information about the Single Server block, enter this command:
The output shows the state of the Single Server block at the current time, T=10. The last two rows of the output represent a table that lists entities in the block. The table has one row because the server is currently storing one entity. The entity has a unique identifier, en11, and is currently in service. This output affirmatively answers the question of whether an entity is in the server when the simulation ends.
The simulation is still suspended just before the end. To proceed, enter this command:
The simulation ends, the debugging session ends, and the MATLAB command prompt returns.
For additional information about the SimEvents debugger, see Debug Simulation.
The dd1 model that you created in Build a Discrete-Event Model plots the number of entities that depart from the server. This section modifies the model to plot other quantities that can reveal aspects of the simulation. The topics are as follows:
To open a completed version of the example model for this tutorial, enter simeventsdocex('doc_dd1')simeventsdocex('doc_dd1') in the MATLAB Command Window. Before modifying the model, save it with a different file name.
The FIFO Queue block can report the queue length, that is, the number of entities it stores at a given time during the simulation. To configure the FIFO Queue block to report its queue length, do the following:
Double-click the FIFO Queue block to open its dialog box. Click the Statistics tab to view parameters related to the statistical reporting of the block.
Set the Number of entities in queue parameter to On and click OK. This causes the block to have a signal output port for the queue-length signal. The port label is #n.
The model already contains a Signal Scope block for plotting the entity count signal. To add another Signal Scope block for plotting the queue-length signal (enabled above), follow these steps:
In the main SimEvents library window, double-click the SimEvents Sinks icon to open the SimEvents Sinks library.
Drag the Signal Scope block from the library into the model window. The block automatically assumes a unique block name, Signal Scope1, to avoid a conflict with the existing Signal Scope block in the model.
Connect the #n signal output port of the FIFO Queue block to the in signal input port of the Signal Scope1 block by dragging the mouse pointer from one port to the other. The model now looks like the following figure.
By changing the intergeneration time (that is, the reciprocal of the entity arrival rate) in the Time-Based Entity Generator block, you can see when entities accumulate in the queue. Try this procedure:
Note: If you skipped the earlier model-building steps, you can open a completed version of the model for this section by entering simeventsdocex('doc_dd1_blockage')simeventsdocex('doc_dd1_blockage') in the MATLAB Command Window.
Double-click the Time-Based Entity Generator block to open its dialog box, set the Period parameter to 0.85, and click OK. This causes entities to arrive somewhat faster than the Single Server block can process them. As a result, the queue is not always empty.
Save and run the simulation. The plot whose title bar is labeled Signal Scope1 represents the queue length. The figure below explains some of the points on the plot. The vertical range on the plot has been modified to fit the data better.
Reopen the Time-Based Entity Generator block's dialog box and set Period to 0.3.
Run the simulation again. Now the entities arrive much faster than the server can process them. You can make these observations from the plot:
Every 0.3 s, the queue length increases because a new entity arrives.
Every 1 s, the queue length decreases because the server becomes empty and accepts an entity from the queue.
Every 3 s, the queue length increases and then decreases in the same time instant. The plot shows two markers at T = 0, 3, 6, and 9.
Reopen the Time-Based Entity Generator block's dialog box and set Period to 1.1.
Run the simulation again. Now the entities arrive more slowly than the server's service rate, so every entity that arrives at the queue is able to depart in the same time instant. The queue length is never greater than zero for a positive amount of time.
The queue length is an example of a statistic that quantifies a state at a particular instant. Other statistics, such as average waiting time and server utilization, summarize behavior between T=0 and the current time. To modify the model so that you can view the average waiting time of entities in the queue and server, as well as the proportion of time that the server spends storing an entity, use the following procedure:
Note: To skip the model-building steps and open a completed version of the model for this section, enter simeventsdocex('doc_dd1_wait_util')simeventsdocex('doc_dd1_wait_util') in the MATLAB Command Window. Then skip to step 8 to run the simulation.
Double-click the FIFO Queue block to open its dialog box. Click the Statistics tab, set the Average wait parameter to On, and click OK. This causes the block to have a signal output port for the signal representing the average duration that entities wait in the queue. The port label is w.
Double-click the Single Server block to open its dialog box. Click the Statistics tab, set both the Average wait and Utilization parameters to On, and click OK. This causes the block to have a signal output port labeled w for the signal representing the average duration that entities wait in the server, and a signal output port labeled util for the signal representing the proportion of time that the server spends storing an entity.
Copy the Signal Scope1 block and paste it into the model window.
Double-click the new copy to open its dialog box.
Set Plot type to Continuous and click OK. For summary statistics like average waiting time and utilization, a continuous-style plot is more appropriate than a stairstep plot. Note that the Continuous option refers to the appearance of the plot and does not change the signal itself to make it continuous-time.
Copy the Signal Scope2 block that you just modified and paste it into the model window twice. You now have five scope blocks.
Each copy assumes a unique name. If you want to make the model and plots easier to read, you can click the names underneath each scope block and rename the block to use a descriptive name like Queue Waiting Time, for example.
Connect the util signal output port and the two w signal output ports to the in signal input ports of the unconnected scope blocks by dragging the mouse pointer from port to port. The model now looks like the following figure. Save the model.
Run the simulation with different values of the Period parameter in the Time-Based Entity Generator block, as described in Simulate with Different Intergeneration Times. Look at the plots to see how they change if you set the intergeneration time to 0.3 or 1.1, for example.
The average waiting time in the server does not change after the first departure from the server because the service time is fixed for all departed entities. The average waiting time statistic does not include partial waiting times for entities that are in the server but have not yet departed.
The utilization of the server is nondecreasing if the intergeneration time is small (such as 0.3) because the server is constantly busy once it receives the first entity.
The utilization might decrease if the intergeneration time is larger than the service time (such as 1.5) because the server has idle periods between entities.
The average waiting time in the queue increases throughout the simulation if the intergeneration time is small (such as 0.3) because the queue gets longer and longer.
The average waiting time in the queue is zero if the intergeneration time is larger than the service time (such as 1.1) because every entity that arrives at the queue is able to depart immediately.
Other examples modify this one by varying the processing sequence for simultaneous events or by making the intergeneration times and/or service times random. The modified examples are: