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.
  • lambda is mean value between entities arrivals.
  • mu 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,lambda]); // Creation of TGenerator instance.

Srv:=TServer.Create([ExpTime,mu]); // Creation of TServer instance.

Gen.Next:=Srv; // Connection of block "Gen" to block "Srv".

Model wrapper

For compiling and receiving of executable file, the code of model behaviour has to be placed into the standard model wrapper. This wrapper is the same for practically 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,lambda]);     //  
  Srv:=TServer.Create([ExpTime,mu]);                     //  Model behavior.
  Gen.Next:=Srv;                                         //  
  
  Run(Gen);                            //  Starting of initial block.
  
                                       //  Outputting of results.
  with Gen do                      
    OutTextRealLn('Loss probability',BusyCount/Count);   
end;

begin
  Capacity:=1000;                      // Initial values of the model.
  lambda:=1;
  mu:=0.5;
  
  Simulate(TMyModel);                  // Starting of the model.
end.   
      


To verify the model the simulation results of M/M/1 system can be checked with analytics of traffic theory.
The loss 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.
OpenSIMPLY tutorial contains the practical examples with detailed description.
Discrete event simulation software OpenSIMPLY is absolutely free. Try it. Free download. Free use.