Rotate the screen

The model of M/M/1 loss system with Simula-like simulation style

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

Simula source printout
Here write a Simula-like simulation model. In this case no blocks are used. Every component of the model has to be described manually. Two elements are required: entity generator and entity server. The class "TMyGenerator" will represent the flow of arrived entities. The class "TMyServer" will be used for the simulation of entities serving.

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

Model parameters

The parameter list is the same as in 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" 

uses
  SimBase,
                                    //  Unit SimBlocks is not needed.
  SimStdGUI;
  
type
  TMyServer = class(TCoProcess)     //  Server declaration.
    Busy: boolean;                  
    HoldTime: Double;               
    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;                //  Occupation of server.
    Hold(HoldTime);            //  Simulation of service time.
    Busy:=false;               //  Freeing of server.
    Passivate;                 //  Server becomes idle.
  until false;                 
end;

procedure TMyGenerator.Body;   //  Generator description.
var
  MyServer: TMyServer;
  Count: integer;
begin
  MyServer:=TMyServer.Create;  // Creation of server. 
  MyServer.Busy:=false;
  BusyCount:=0;
 
  for Count:=1 to Capacity do
  begin                                         //  No entities creation is needed.  
    if not MyServer.Busy then                   //  Server status should be checked only.
    begin                                       
      MyServer.HoldTime:=RandExp(ServiceTime);  //  Assigning of service time. 
      Reactivate(MyServer,After,Self);          //  Rise server after generator suspension.
    end  
    else
      inc(BusyCount);                 //  Gather statistics.
  
    Hold(RandExp(InterArrivalTime));  //  Generator is suspended until "new entity" event.
  end;
  
  MyServer.Destroy;                   //  Destroying Server at the end of simulation.
end;

procedure TMyModel.Body;              //  Model description.
var
  MyGenerator: TMyGenerator;
begin
  MyGenerator:=TMyGenerator.Create;   //  Generator creation
  
  Run(MyGenerator);                   //  Starting an initial process.

  OutTextRealLn('Loss probability',BusyCount/Count);  //  Outputting results.
 
  MyGenerator.Destroy;                //  Destroying Generator at the end of simulation.
end;

begin
  Capacity:=1000;                     // Initial values of the 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 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.
Simulation results of Simula-style model M/M/1 loss system