Simple simulation example M/M/1 system as Simula-style simulation

M/M/1 loss system Simula source printout The code of the model below demonstrates modeling using the Simula style of simulation. No blocks are used. Every element of the model has to be described.

The model of M/M/1 system as for case of block simulation requires two elements: entities generator and and entities server. The class "TMyGenerator" will represent the arrival Poisson process, the class "TMyServer" will be used for the entities serving simulation (delay).

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 model, the code above should be placed in a standard wrapper of a model 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, Count: 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;
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 using 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 can be executed faster as a block simulation model because such model is made for the particular case. But the development of the model with Simula-like approach is more difficult for the complex systems. It could be the gold mean to combine in the model both styles of simulation using the advanced one for critical sections.


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.