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

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

This model requires two blocks only: block for entities generation and block for entities serving (delay block). The classes "TGenerator" and "TServer" are used for these purposes.

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 the block parameter for 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 TGenerator instance.

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

Gen.Next:=Srv;                                                  // Connecting the "Gen" block to the "Srv" block.
	  

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.                   
begin
                                       //  Model behavior.
end;

begin
  Simulate(TMyModel);                  // Starting of the 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                                    //  Global variables of the model.
  Capacity: integer;
  lambda, mu: Double;
                                       
procedure TMyModel.Body;               //  Model description.                   
var                                    
  Gen: TGenerator;                     //  Model variables.
  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.
  
                                       //  Outputting of results.
  with Gen do                      
    OutTextRealLn('Loss (blocking) probability',Losses/Generated);   
end;

begin
  Capacity:=1000;                      // Initial values of the model.
  InterArrivalTime:=1;                 //
  ServiceTime:=0.5;                    //
  
  Simulate(TMyModel);                  // Starting of the 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.

Simula-like simulation style

See also advanced Simula-like style simulation example of the same system M/M/1 with losses. Compare the code.


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.