Simulation Model in Simula-like Style
M/M/1/1 simulation model
Consider the same system as in the
block simulation example.
Entities arrive at a single server according to a Poisson process, the service time is exponentially distributed,
and the total system capacity is limited to 1.
The simulation model in this example will be created in a style similar to the Simula programming language.
M/M/1/1 Model in OpenSIMPLY
The Simula programming language does not provide built-in simulation blocks or similar modeling components.
It is a purely process-oriented discrete-event simulation language, where the process is the core concept.
A process must be described, created, and activated.
If necessary, it can be suspended and resumed later.
Statistics gathering must also be implemented manually.
Model Creation
To make this model comparable to the
block simulation example,
let's use the term Generator to simulate incoming entities and Server to simulate their servicing.
Process behavior is described using the TSimProcess class — similar to Simula's Process class.
Two classes derived from the TSimProcess class are defined: TSimGenerator and TSimServer.
The Generator's behavior is defined in the
Body method of TSimGenerator, and the Server's behavior in the
Body method of TSimServer.
Download ready-to-run models of queuing theory and call centers.
Model Parameters
The following variables and constants are used in the model:
- Capacity — the total number of entities to be simulated
- InterarrivalTime — the mean time between entities arrivals
- ServiceTime — the mean value of service time
- RandExp — a function that returns exponentially distributed random values
Complete Program Code with Input Data and 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 behavior.
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 behavior.
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 behavior.
var
SimGenerator: TSimGenerator;
begin
SimGenerator := TSimGenerator.Create; // Creating the generator instance.
Run(SimGenerator); // Launching the start process.
// Results
OutTextRealLn('Loss probability', BusyCount / Capacity);
SimGenerator.Free; // 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/1 model, verify its results against the exact formula.
Thus, the blocking (loss) probability can be obtained using the Erlang B formula.
The Simula-style model runs much faster than the block-based model — it is written entirely for this particular system.
However, the Simula-like approach is significantly more difficult for developing models of complex systems.
A reasonable compromise is to combine both styles: use the block approach for most parts of the model and apply Simula-like
code only in sections where execution time is critical.