Simulation model in Simula-like style
Simulation model of the M/M/1 loss system
Consider the same M/M/1 loss system as for the
block simulation example, as follows:
Entities arrive at a single server as a Poisson process.
The service time value is exponentially distributed.
The simulation model in this example will be created in a style similar to the Simula programming language.
The model of the M/M/1 loss system in terms of OpenSIMPLY
The Simula programming language does not consider simulation blocks or similar modeling components.
It was a purely discrete-event simulation language in which a process is the cornerstone of the concept.
The process has to be described, created and activated. If necessary, the process can be suspended, and activated after suspension.
It is also necessary to implement the gathering of the required statistics.
Model creation
To relate this model to the model of the
block simulation example,
let's introduce the term Generator to simulate the flow of incoming entities and the term Server to simulate the servicing of entities.
To describe the process in the model, the TSimProcess class will be used.
This class is similar to Process class of Simula.
Let's create TSimGenerator and TSimServer classes that are derived from TSimProcess class.
The behavior of the Generator will be described in the Body method of the TSimGenerator class, and the behavior of the Server will be described in the Body method of the TSimServer class.
Download executable models of queuing theory and call centers.
Model parameters
- Capacity is the total number of entities for simulation.
- InterarrivalTime is mean value between entities arrivals.
- ServiceTime is mean value of service time.
- RandExp is a function returning exponentially distributed random values.
Complete program code containing input data and output of results.
To compile a program, the model should be placed in a standard wrapper similar to
block simulation example.
program SimulaStyleMM1;
{$apptype xxx } // xxx "GUI" or "Console"
{$S-}
uses
SimBase,
// Unit SimBlocks is not needed.
SimStdGUI;
type
TSimServer = class(TSimProcess) // Server declaration.
Busy: boolean;
procedure Body; override;
end;
TSimGenerator = class(TSimProcess) // Generator declaration.
procedure Body; override;
end;
TMyModel = class(TModel) // Model declaration.
procedure Body; override;
end;
var
Capacity,
BusyCount: Integer;
InterarrivalTime,
ServiceTime: Double;
procedure TSimServer.Body; // Server description.
begin
repeat
Busy := true; // Busy server indication.
Hold(RandExp(ServiceTime)); // Service simulation.
Busy := false; // Free server indication.
Passivate; // Server becomes idle.
until false;
end;
procedure TSimGenerator.Body; // Generator description.
var
SimServer: TSimServer;
i: Integer;
begin
SimServer := TSimServer.Create; // Creating the server instance.
SimServer.Busy := false;
BusyCount := 0;
// No entities creation is needed.
for i := 1 to Capacity do
begin
if SimServer.Busy then // Check server status only.
inc(BusyCount) // Gather statistics.
else
Activate(SimServer, After, self); // Activate the server after the generator.
Hold(RandExp(InterarrivalTime)); // Entity interarrival time simulation.
end;
SimServer.Destroy; // Destroying the server instance.
end;
procedure TMyModel.Body; // Model description.
var
SimGenerator: TSimGenerator;
begin
SimGenerator := TSimGenerator.Create; // Creating the generator instance.
Run(SimGenerator); // Launching the start process.
OutTextRealLn('Loss probability', BusyCount / Capacity); // Results
SimGenerator.Destroy; // Destroying the generator instance.
end;
begin
Capacity := 1000; // Initial values of a model.
InterarrivalTime := 1;
ServiceTime := 0.5;
Simulate(TMyModel); // Starting a model.
end.
To validate the M/M/1 loss model, the simulation results can be verified using the exact formula.
The value of loss (blocking) probability can be obtained with Erlang B formula.
Conclusion
The Simula-style model is executed much faster as a block simulation model because such a model is created for the particular case.
It should be also noticed, that the development of the model with Simula-like approach is also much difficult for the complex systems.
Perhaps the middle ground is to combine both modeling styles using an advanced Simula-style for model sections where runtime is critical.