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.
  • lambda is mean value between entities arrivals.
  • mu is mean value of service time.
The function RandExp will be used for receiving of exponentially distributed random values.


For compiling and receiving of executable file, the code of model behaviour has to be placed into the standard model 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,
                                       // The unit SimBlocks is not needed.
  SimStdGUI;
  
type
  TMyServer = class(TCoProcess)        //  Customer server declaration.  
    Busy: boolean;
    ServiceTime: Double;
    procedure Body; override;
  end;

  TMyGenerator = class(TCoProcess)     //  Customer 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;              //  Description of TMyServer.
begin
  repeat
    Busy:=true;                        
    Hold(ServiceTime);                 // Simulate serving  
    Busy:=false;
    Passivate;	                       // Becomes idle
  until false;
end;

procedure TMyGenerator.Body;           //  Description of TMyGenerator.
var
  MyServer: TMyServer;
begin
  MyServer:=TMyServer.Create;
  MyServer.Busy:=false;
  BusyCount:=0;
  
  for Count:=1 to Capacity do             // Entities creation is not needed  
  begin
    if not MyServer.Busy then             // Server status has to be checked only
    begin
      MyServer.ServiceTime:=RandExp(mu);  //  Service time assigning 
      Reactivate(MyServer,After,Self);    //  Server will be activated after Generator will be suspended
    end                                    
    else
      inc(BusyCount);		
    Hold(RandExp(lambda));                // 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;       //  Just Generator creation
  
  Run(MyGenerator);                       //  Starting of initial process.
  
                                           //  Outputting of results.
										  
  OutTextRealLn('Loss probability',BusyCount/Count); 
 
  MyGenerator.Destroy;                    // Destroying Generator at the end of simulation
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.

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 the advanced approach is more difficult for the complicated systems. It could be the gold mean to combine in the model both styles of simulation using the advanced one for critical sections.
OpenSIMPLY tutorial contains the practical examples with detailed description.
Discrete event simulation software OpenSIMPLY is absolutely free. Try it. Free download. Free use.