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

M/M/1 loss system The code of the model below demonstrates modeling using the Simula style of simulation. No blocks are used. Every elements of the model has to be described. The system M/M/1 has to have a generator and a server. The class "TMyGenerator" will repesent the incoming entities stream, the class "TMyServer" will be used for the entites serving (delay) simulation.

The parameters that will be used in the model

  • Capacity is the total number of entities for simulation.
  • lambda is the mean value of arrived entities stream.
  • mu is the mean value of service time.
The function RandExp is used to receive the exponentially distributed random values.

The complete program code containing the input data and the output of the 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             // The real entities creation is not needed  
  begin
    if not MyServer.Busy then             // The server status is checked only
    begin
      MyServer.ServiceTime:=RandExp(mu);  //  Service time assigning 
      Reactivate(MyServer,After,Self);    //  The server will be activated after ...
    end                                    
    else
      inc(BusyCount);		
    Hold(RandExp(lambda));   // ... the generator "sleeps" until "new entity" event
  end;
  
  MyServer.Destroy;
end;

procedure TMyModel.Body;               //  Model description.
var
  MyGenerator: TMyGenerator;
begin
  MyGenerator:=TMyGenerator.Create;
  
  Run(MyGenerator);                    //  Starting of initial block.
									   
  OutTextRealLn('Loss probability',BusyCount/Count);     //  Outputting of results.
 
  MyGenerator.Destroy;
end;

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

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.