M/M/1/1 Simulation Model
This is a single-server system.
The server serves an
entity for a time determined by the service time distribution and its parameters.
When the server is idle and a new entity arrives, it immediately starts serving that entity and becomes busy.
Entity
An entity can represent various concepts in a model.
For example, it could be a forklift in a warehouse, a barbershop client, a car at a traffic light,
a data packet in a network, a phone call, or a passenger in an airport.
Theoretical Background
This system is denoted as
M/M/1/1 in Kendall's notation.
In this system:
- entities arrive according to a Poisson process (M/M/1/1),
- the service time is exponentially distributed (M/M/1/1),
- there is only one server (M/M/1/1),
- and the total system capacity is 1 (M/M/1/1).
The system capacity is the total number of entities being served or waiting.
If the server is busy when an entity arrives, the entity is rejected and considered lost.
Therefore, such a system is called a
loss system.
Watch the
educational video about the
M/M/1/1 loss system.
Blocks for Discrete-Event Simulation
In OpenSIMPLY, the simulation block is a ready-to-use component for building discrete-event models.
A model consists of blocks connected according to the behavior of the system being studied.
The behavior of a block is defined by a class in the programming language.
The block operates on an entity — an object that passes through the connected blocks.
Using the Simula-like approach, you can create models with better performance.
However, this approach has the following significant disadvantages:
- Model development takes more time.
- Model statistics must be manually implemented for each model individually.
- It is much more difficult to develop and debug a complex model.
Thus, the block simulation approach is much easier and more reliable for model development, and it provides powerful and flexible built-in statistics.
Model in OpenSIMPLY
To create a model of the
M/M/1/1 system, only two blocks are required:
the
Generator block, which creates entities, and the
Server block, which simulates their service.
In Delphi and Free Pascal, these blocks are represented by the
TGenerator and
TServer classes, respectively.
Model Creation
To describe the model's behavior, you need to create instances of the required block classes.
Initial Values
The block can have initial values that specify its functionality.
Create Constructor
When creating an instance of the block class, you must use the Create constructor.
The Create constructor has a mandatory InitialValues parameter, where the initial values of the block can be specified.
InitialValues is of type array of const and accepts a comma-separated list of items enclosed in square brackets.
For example:
[TotalEntities, ExpTime, InterarrivalTime]
The type of each item, the number of items, and whether they are mandatory or optional depend on the specific block.
CreateDefault Constructor
Alternatively, for some blocks, you can use the CreateDefault constructor, which does not require the InitialValues parameter.
In this case, the instance is created with default initial values for that block type.
Generator
For the
TGenerator class, you cannot use the
CreateDefault constructor because
The Generator has mandatory items in
InitialValues, and therefore you must use
Create only.
The first few (mandatory) items of its
InitialValues parameter are:
- Capacity – the maximum number of entities that the Generator can create.
- The function that determines the interarrival time of entities.
- The parameter(s) for that function.
Server
The
TServer class has mandatory items too, so you must use
Create only.
The first few (mandatory) items of
InitialValues of the
TServer class are:
- The function that determines the service time of entities.
- The parameter(s) for that function.
Model Parameters
The following variables and constants will be used for the initial values of the blocks for this example.
TotalEntities — the total number of entities to be simulated during the model run.
InterarrivalTime — the mean time between entity arrivals.
ServiceTime — the mean service time.
ExpTime — a pointer to a function that returns exponentially distributed random values.
For instances of the
TGenerator and
TServer classes, the variables
Gen and
Srv will be used, respectively.
Connect Blocks
Use the
Connect method to connect blocks. It requires only a single
Block parameter.
The code below defines the behavior of the
M/M/1/1 system as an OpenSIMPLY model.
Gen := TGenerator.Create( [TotalEntities, ExpTime, InterarrivalTime] ); // Creating Generator.
Srv := TServer.Create( [ExpTime, ServiceTime] ); // Creating Server.
Gen.Connect(Srv) // Connecting Generator to Server.
Model Wrapper
To compile the model, place the code above into the standard model wrapper, which is the same for all models.
program MySimulation;
{$apptype xxx } // xxx is either "GUI" or "Console"
{$S-}
uses
SimBase,
SimBlocks,
SimStdGUI;
type
TMyModel = class(TModel) // Model declaration.
procedure Body; override;
end;
var // Model parameters.
TotalEntities: Integer;
procedure TMyModel.Body; // Model behavior.
var
// Blocks declaration.
begin
// Model behavior.
end;
begin
// Assignment of initial values of the model.
TotalEntities := 1000;
Simulate(TMyModel); // Starting model.
end.
Complete Program Code with Input Data and Results
program BlocksStyleMM11;
{$apptype xxx } // xxx is either "GUI" or "Console"
uses
SimBase,
SimBlocks,
SimStdGUI;
type
TMyModel = class(TModel) // Model declaration.
procedure Body; override;
end;
var // Model parameters.
TotalEntities: Integer;
InterarrivalTime,
ServiceTime: Double;
procedure TMyModel.Body; // Model behavior.
var
Gen: TGenerator; // Blocks declaration.
Srv: TServer;
begin // Model behavior.
Gen := TGenerator.Create([TotalEntities, ExpTime, InterarrivalTime]);
Srv := TServer.Create([ExpTime, ServiceTime]);
Gen.Connect(Srv);
Run(Gen); // Launching start block.
// Results.
Gen.ShowStats; // Blocking (loss) probability
end;
begin
TotalEntities := 1000; // Initial values of model.
InterarrivalTime := 1;
ServiceTime := 0.5;
Simulate(TMyModel); // Starting model.
end.
To validate the M/M/1/1 model, verify its results against the exact formula.
Thus, the blocking (loss) probability can be obtained using the Erlang B formula.
Simula-like Simulation Style
You can also create a simulation model of an
M/M/1/1 system using a Simula-like simulation style.
It is based on the concept of a process, which is the cornerstone of the Simula language.
This style does not use blocks and does not provide automatic statistics gathering.
Despite these disadvantages, the simulation runtime is much faster, and you have unlimited flexibility in creating custom components.
Take a look at an example of a
Simula-like simulation style of the same system.