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

M/M/1 loss system Simula source printout The code of the model below demonstrates simulation modeling using the Simula-like style.

No blocks are used. Every element of the model has to be described.

The model of M/M/1 system as for the block simulation requires two elements: 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.

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.


To compile a program, the model should be placed in a standard wrapper similar to block simulation example.

Complete program code containing input data and output of results.

program SimulaStyleMM1;
{$apptype xxx }  // xxx "GUI" or "Console" 

uses
  SimBase,
                                       //  Unit SimBlocks is not needed.
  SimStdGUI;
  
type
  TMyServer = class(TCoProcess)        //  Server declaration.  
    Busy: boolean;
    ServiceTime: 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;
  lambda, mu: Double;

procedure TMyServer.Body;              //  Server description.
begin
  repeat
    Busy:=true;                        
    Hold(ServiceTime);                 //  Simulate serving.  
    Busy:=false;
    Passivate;	                       //  Becomes idle.
  until false;
end;

procedure TMyGenerator.Body;           //  Generator description.
var
  MyServer: TMyServer;
  Count: integer;
begin
  MyServer:=TMyServer.Create;
  MyServer.Busy:=false;
  BusyCount:=0;
  
  for Count:=1 to Capacity do                         //  No entities creation is needed.  
  begin
    if not MyServer.Busy then                         //  Server status should be checked only.
    begin
      MyServer.ServiceTime:=RandExp(ServiceTime);     //  Service time assigning.  
      Reactivate(MyServer,After,Self);                //  Rise Server after Generator suspension.
    end                                    
    else
      inc(BusyCount);	
  
    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 of initial process.
										  
  OutTextRealLn('Loss probability',BusyCount/Count);  //  Outputting of 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 simulation results of Simula-style model M/M/1 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.


The OpenSIMPLY tutorial will help you quickly get started. The tutorial contains practical examples with detailed descriptions.

The project documentation is available in different formats and compatible with any IDE.

Discrete event simulation software OpenSIMPLY is free and open source. Free download. Free use. Try it.