Simple simulation example M/M/1 system in terms of OpenSIMPLY

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

This model requires only two blocks: the block for entity generation and the block for entity serving. The classes "TGenerator" and "TServer" are used for this purpose.

Watch also the learning video about M/M/1 system.

Model parameters

  • Capacity is the total number of entities for simulation.
  • InterArrivalTime is mean value between entities arrivals.
  • ServiceTime is mean value of service time.
  • ExpTime is a block function returning exponentially distributed random values.

The variables "Gen" and "Srv" will be used for assignment of class instances for TGenerator and TServer accordingly.

Model behavior

The lines below fully describe the model behaviour for M/M/1 system in terms of OpenSIMPLY:


Gen:=TGenerator.Create([Capacity,ExpTime,InterArrivalTime]);    //  Creating a Generator.

Srv:=TServer.Create([ExpTime,ServiceTime]);                     //  Creating a Server.

Gen.Next:=Srv;                                                  //  Connecting Generator to Server.
	  

Model wrapper

To compile a model, the code above should be placed in a standard wrapper of a model. This wrapper is the same for any model.

program MySimulation;
{$apptype xxx }  // xxx is either "GUI" or "Console" 

uses
  SimBase,
  SimBlocks,
  SimStdGUI;
  
type
  TMyModel = class(TModel)             //  Model declaration.  
    procedure Body; override;
  end;	
                                       
procedure TMyModel.Body;               //  Model description.  

                                       //  Blocks declaration.                 
begin
                                       //  Model behavior.
end;

begin                                  //  Initial values of the model.
									   
  Simulate(TMyModel);                  //  Starting a model.
end.   
      

Complete program code containing input data and output of results.

program BlocksStyleMM1;
{$apptype xxx }  // xxx is either "GUI" or "Console" 

uses
  SimBase,
  SimBlocks,
  SimStdGUI;
  
type
  TMyModel = class(TModel)             //  Model declaration.  
    procedure Body; override;
  end;	

var                                   
  Capacity,
  NumberOfServers: integer;            //  Model parameters. 
  InterArrivalTime,                      
  ServiceTime: Double;                 
                                       
procedure TMyModel.Body;               //  Model description.                   
var                                    
  Gen: TGenerator;                     //  Blocks declaration. 
  Srv: TServer;                        
begin

  Gen:=TGenerator.Create([Capacity,ExpTime,InterArrivalTime]);  //  
  Srv:=TServer.Create([ExpTime,ServiceTime]);                   //  Model behavior.
  Gen.Next:=Srv;                                                //  
  
  Run(Gen);                            //  Starting of initial block.
  
  Gen.ShowStats;                       //  Outputting of results.
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, the simulation results should be verified with traffic theory analytics.
So, the value of loss (blocking) probability can be obtained with Erlang_B formula.

Simula-like simulation style

See also advanced Simula-like style simulation example of the same system.


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.