Build a Discrete-Event Model

This example describes how to build a new model representing a discrete-event system. The system is a simple queuing system in which "customers" — entities — arrive at a fixed deterministic rate, wait in a queue, and advance to a server that operates at a fixed deterministic rate. This type of system is known as a D/D/1 queuing system in queuing notation. The notation indicates a deterministic arrival rate, a deterministic service rate, and a single server.

The example system shows how to perform basic model-building tasks, such as:

  • Adding blocks to models

  • Configuring blocks using their parameter dialog boxes

Open a Model and Library

The first steps in building a model are to set up your environment, open a new model window, and open the libraries containing blocks.

Open a New Model Window

On the Home tab, select New > Simulink Model. An empty model window opens.

To name the model and save it as a file, select File > Save from the model window's menu. Save the model in your working folder as dd1.

Open the SimEvents Library

In the MATLAB® Command Window, enter


The main SimEvents® library window appears. This window contains an icon for each SimEvents library. To open a library and view the blocks it contains, double-click the icon that represents that library.

Open Simulink Libraries

In the Simulink® editor, click the Library Browser button. The Simulink Library Browser opens, using a tree structure to display the available libraries and blocks. To view the blocks in a library listed in the left pane, select the library name, and the list of blocks appears in the right pane. The Library Browser provides access not only to Simulink blocks but also to SimEvents blocks.

Move Blocks into the Model Window

To move blocks from libraries into the model window, follow these steps:

  1. In the SimEvents library window, drag the Entity Generator block from the library into the model window.

  2. Drag the Entity Queue block into the model window.

  3. Drag the Entity Server block into the model window.

  4. Drag the Entity Terminator block into the model window.

  5. From the Simulink Sinks library, drag the Scope block into the model window.

As a result, the model window contains blocks that represent the key processes in the simulation: blocks that generate entities, store entities in a queue, serve entities, and create a plot showing relevant data.

Model window containing all the blocks for the example

Configure Blocks

Each block in a model, in this case, dd1, has a dialog box that enables you to specify block parameters. Default parameter values might or might not be appropriate, depending on what you are modeling.

View Parameter Values

Two important parameters in the D/D/1 queuing system are the arrival rate and service rate. The reciprocals of these rates are the duration between successive entities and the duration of service for each entity. To examine these durations:

  1. Double-click the Entity Generator block to open its dialog box. Observe and that the Period parameter is set to 1. This means that the block generates a new entity every second.

  2. Double-click the Entity Server block to open its dialog box. Observe that the Service time parameter is set to 1.0. This means that the server spends one second processing each entity that arrives at the block.

  3. Click Cancel in both dialog boxes to dismiss them without changing any parameters.

The Period and Service time parameters have the same value, which means that the server completes an entity's service at exactly the same time that a new entity is being created.

Change Parameter Values

Configure blocks to create a plot that shows when each entity departs from the server, and to make the queue have an infinite capacity.

  1. Double-click the Entity Server block to open its dialog box.

  2. Click the Statistics tab to view parameters related to the statistical reporting of the block.

  3. Select Number of entities departed, d.

    Then click OK. The Entity Server block acquires a signal output port labeled d. During the simulation, the block will produce an output signal at this d port; the signal's value is the running count of entities that have completed their service and departed from the server. You can connect a Scope block to this entity line and display the statistics (running count of entities).

  4. Double-click the Entity Queue block to open its dialog box.

  5. Set the Capacity parameter to Inf and click OK.

    The model window now contains blocks that represents key processes.

Connect Blocks

Connect the blocks as shown and save the dd1 model you have created.

SimEvents connects the source block to the destination block. If necessary, the software also routes the connecting line around intervening blocks or lines.

Run the Simulation

To start the simulation, select Simulation > Run from the model window's menu.

Results of the Simulation

When the simulation runs, the Simulink Scope block opens a window containing a plot. The horizontal axis represents the times at which entities depart from the server, while the vertical axis represents the total number of entities that have departed from the server.

After an entity departs from the Entity Server block, the block updates its output signal at the d port.

See Also

| | | | | | | | | | | | | | | |

Related Examples

More About

Was this topic helpful?