Specify Intergeneration Times for Entities
The intergeneration time is the time interval between successive entities that the block generates. You can have a generation process that is:
Periodic
Sampled from a random distribution or time-based signal
From custom code
For example, if the block generates entities at T = 50, T = 53, T = 60, and T = 60.1, the corresponding intergeneration times are 3, 7, and 0.1. After each new entity departs, the block determines the intergeneration time that represents the interval until the block generates the next entity.
Determine Intergeneration Time
You configure the Entity Generator block by indicating criteria that it uses to determine intergeneration times for the entities it creates. You can generate entities:
From random distribution
Periodically
At arbitrary times
Use the dropdown list in the Time source parameter of the Entity Generation block to determine intergeneration times:
Dialog
Uses the Period parameter to periodically vary the intergeneration times.
Signal port
Uses a signal from an external block, such as the Sine wave block, to vary the intergeneration times.
MATLAB action
Enables an Intergeneration time action field, in which you enter MATLAB® code to customize the intergeneration times.
Periodically Vary the Intergeneration Times
In a new model, from the SimEvents® library, drag the Entity Generator, Entity Terminator, and Scope blocks.
In the Entity Generation tab of the Entity Generator, set the Time source parameter to
Dialog
.In the Statistics tab of the Entity Terminator block, select the Number of entities arrived check box.
Connect these blocks and simulate the model. The period is 1.
Vary the period to
8
and simulate the model again. Observe the change in the scope.
Use a Signal to Vary the Intergeneration Times
In a new model, from the SimEvents library, drag the Entity Generator and Entity Terminator blocks. From the Simulink® library add the Sine Wave, and Scope blocks.
In the Entity Generation tab of the Entity Generator, set the Time source parameter to
Signal port
.A new signal port appears on the Entity Generator block.
In the Statistics tab of the Entity Terminator block, select the Number of entities arrived check box.
Double-click the Sine Wave block. By default, the first value of the Sine Wave block is
0
. To add a constant value to the sine to produce the output of this block, change the Bias parameter to another value, for example,1.5
.Connect these blocks and simulate the model.
Upon generating each entity, the Entity Generator block reads the value of the input signal and uses that value as the time interval until the next entity generation.
Notice the capital E on the signal line from the Sine Wave block to the Entity Generator block. This icon indicates the transition from a time-based system to a discrete-event system.
Customize the Variation of the Intergeneration Times
In a new model, from the SimEvents library, drag the Entity Generator, Entity Terminator, and Scope blocks.
In the Entity Generation tab of the Entity Generator, set the Time source parameter to
MATLAB action
.A new Intergeneration time action field appears on the Entity Generator block.
To customize the intergeneration times for your model, in the Intergeneration time action field, enter MATLAB code, for example:
dt = rand();
Note
For intergeneration times, you must set the fixed name, dt. You cannot set any other variable name for this value.
In the Statistics tab of the Entity Terminator block, select the Number of entities arrived check box.
Connect these blocks and simulate the model.
To generate entities with exponential random arrival times,
in the Intergeneration time action field, enter MATLAB code
that uses the mean
function, for example:
mean = 1; dt = -mean*log(1-rand());
The code example below, when written as an event action, shows a way to generate entities at a list of arbitrary, predetermined intergeneration times, and also fix the number of entities that is generated at each instance.
In the following example, the interGenerationTimes
structure
is built in such a way as to indicate that three entities are generated at time t =
1, four entities are generated at time t = 5, and so on.
persistent idx; interGenerationTimes = [1 1 1 5 5 5 5 7 7 7 7 7 9 10]; if isempty(idx) idx = 1; dt = interGenerationTimes(idx); else if idx <= length(interGenerationTimes) % if dt = 0, we generate an entity at current time. dt = interGenerationTimes(idx) - interGenerationTimes(idx - 1); else dt = inf; end end idx = idx + 1;
See Also
Entity Generator | Entity Queue | Entity Server | Entity Terminator | Discrete-Event Chart | MATLAB Discrete-Event System | Entity Replicator
Related Examples
- Generate Entities When Events Occur
- Working with Entity Attributes and Entity Priorities
- Inspect Structures of Entities
- Generate Multiple Entities at Time Zero
- Count Simultaneous Departures from a Server
- Model Resource Allocation Using Composite Entity Creator Block
- Replicate Entities on Multiple Paths