Browser width is too narrow.

Rotate the screen or increase the width.
▲

The M/M/1 loss model in the style of Simula-like simulation

Shown here is a simple simulation example in a simulation style similar to Simula programing language.

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, activated, if necessary, suspended and reactivated again. The model time should also be taken into account and controlled.

Simula source printout

The model

Consider the M/M/1 loss system as for the block simulation example. This system consists of a single server. Entities are arrived as a Poisson process. The service time value is exponentially distributed.

Describe the simulation model in a Simula-like terms. In this case no blocks are used. Every model component should be described. Moreover, not the same components are required as in the block simulation model, but only an entity generator and an entity server. The TMyGenerator class will represent the flow of arrived entities. The TMyServer class will be used for entity servicing simulation.

Download executable models of queuing theory and call centers.
M/M/1 loss system

Model parameters

The parameter list is the same as for block simulation example.

  • 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 
  TMyServer = class(TCoProcess)           //  Server declaration.
    Busy: boolean;
    procedure Body; override;
  end;

  TMyGenerator = class(TCoProcess)        //  Generator declaration.
    procedure Body; override;
  end;
  
  TMyModel = class(TModel)                //  Model declaration.
    procedure Body; override;
  end;

var
  Capacity,
  BusyCount: Integer;
  InterarrivalTime,
  ServiceTime: Double;

procedure TMyServer.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 TMyGenerator.Body;              //  Generator description.
var
  MyServer: TMyServer;
  i: Integer;
begin
  MyServer := TMyServer.Create;           //  Creating the server instance.
  MyServer.Busy := false;
  BusyCount := 0;
                                          //  No entities creation is needed.  
  for i := 1 to Capacity do
  begin
    if MyServer.Busy then                 //  Check server status only.
      inc(BusyCount)                      //  Gather statistics.
    else
      Reactivate(MyServer, After, self);  //  Rise the server after generator.
  
    Hold(RandExp(InterarrivalTime));      //  Entity interarrival time simulation.
  end;
  
  MyServer.Destroy;                       //  Destroying the server instance.
end;

procedure TMyModel.Body;                  //  Model description.
var
  MyGenerator: TMyGenerator;
begin
  MyGenerator := TMyGenerator.Create;     //  Creating the generator instance.
  
  Run(MyGenerator);                       //  Launching the start process.
  
                                          //  Results

  OutTextRealLn('Loss probability', BusyCount / Capacity);
 
  MyGenerator.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 model of M/M/1 loss system, simulation results can be verified with traffic theory analytics. 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.