Browser width
is too narrow.

Rotate the screen
or increase
the width.
OpenSIMPLY Free open source simulation software
▲

M/M/1/1 Simulation Model in Simula-like Style

System Description

Consider the same system as in the block simulation example.

Entities arrive at the 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 loss system

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.
Simula source printout

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 service.

Process behavior is described using the TSimProcess class — similar to the Process class in Simula.

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.
 

Model Parameters

The following variables and constants are used in the model:
  • TotalEntities — the total number of entities to be simulated during the model run.
  • InterarrivalTime — the mean time between entity arrivals.
  • ServiceTime — the mean value of service time.
  • ExpTime — a pointer to 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 the block simulation example.

program SimulaStyleMM1;
{$apptype xxx }  // xxx "GUI" or "Console" 
{$S-}
uses
  SimBase,
                                            //  SimBlocks unit is not required.
  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                                         //  Model parameters.
  TotalEntities,
  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
  SimSrv: TSimServer;
  i: Integer;
begin
  SimSrv := TSimServer.Create;              //  Creating server instance.
  SimSrv.Busy := false;
  BusyCount := 0;
                                            //  No entities creation is needed.  
  for i := 1 to TotalEntities do
  begin
    if SimSrv.Busy then                     //  Check server status only.
      inc(BusyCount)                        //  Gather statistics.
    else
      Activate(SimSrv, After, self);        //  Activate server after generator.
  
    Hold(RandExp(InterarrivalTime));        //  Entity interarrival time simulation.
  end;
  
  SimSrv.Free;                              //  Destroying server instance.
end;

procedure TMyModel.Body;                    //  Model behavior.
var
  SimGen: TSimGenerator;
begin
  SimGen := TSimGenerator.Create;           //  Creating generator instance.
  
  Run(SimGen);                              //  Launching start process.
  
                                            //  Results
  
  OutTextRealLn('Blocking probability', BusyCount / TotalEntities);    
 
  SimGen.Free;                              //  Destroying generator instance.
end;

begin
  TotalEntities := 1000;                    // Initial values of model.
  InterarrivalTime := 1;
  ServiceTime := 0.5;

  Simulate(TMyModel);                       // Starting model.
end.

Model Validation

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.

Conclusion

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.