Suppose that you are modeling a queue that can physically hold 100 entities and you want to determine what proportion of the time the queue length exceeds 10. You can model the long queue as a pair of shorter queues connected in series. The shorter queues have length 90 and 10.
Although the division of the long queue into two shorter queues has no basis in physical reality, it enables you to gather statistics related to one of the shorter queues. In particular, you can view the queue length (n) of the queue having length 90. If the signal is positive over a nonzero time interval, then the length-90 queue contains an entity that cannot advance to the length-10 queue. This means that the length-10 queue is full. As a result, the physical length-100 queue contains more than 10 items. Determining the proportion of time the physical queue length exceeds 10 is equivalent to determining the proportion of time the queue length signal of the logical length-90 queue exceeds 0.
You can vary the service time of a server using one of the following methods:
Constant source, where you vary the constant
Use the Service time source parameter of the Entity Server block to apply these methods. You can select from:
Enter the constant value in the Service time value parameter.
Connect a time source to the resulting signal port.
Enter the name of the attribute that contains data to be interpreted as service.
In the Service time action section, enter MATLAB® code to vary the service time. Assign the variable dt, which the model uses as service time.
This example is a simple queuing system in which entities arrive
at a fixed deterministic rate. They then wait in a queue and advance
to a server that services the entities at random intervals. It illustrates
use of the
Service time from random distribution design pattern.
In a new model, drag the blocks shown in the example
and relabel and connect them as shown. For convenience, start with
Service time from random distribution design
To generate entities every .5 seconds, in the Entity Generator block:
In the Entity Generation tab,
change the Period to
In the Statistics tab, select Number of entities departed, d.
In the Entity Queue block, select Number of entities in block, n.
In the Entity Server block:
Verify that the server is configured for random service
time. If not, copy the Server block from the
from random distribution design pattern.
In the Statistics tab, select Number of entities in block, n.
In the Entity Terminator block, in the Statistics tab, select Number of entities arrived, a.
Save and run the model. In particular, observe the pattern of the entities leaving the Entity Generator block and the entities at random service times.
To determine whether a queue is storing any entities, use this technique:
Enable the n output signal from the queue block. In the block dialog box, on the Statistics tab, select the Number of entities in block, n check box.
From the Sinks library in the Simulink® library set, insert a Scope block into the model. Connect the n output port of the queue block to the input port of the Scope block.
The scope shows if the queue is empty.