Express your interests to contact@o2des.net

Step 2: M/M/n Queue Basic Model

queue1

What is M/M/n queue?

Customers arrive at a rate of λ, following a Poisson process. They are served at a rate μ, following an exponential distribution. There are n servers intotal.

What is "3 Elements & 5 Steps" ?

3–5

Model Building

1.Describe static property for the model

public class Statics : Scenario
{
/* All static properties shall be public, */
public int ServerCapacity { get; set; }
public double HourlyArrivalRate { get; set; }
public double HourlyServiceRate { get; set; }
}

  • “Scenario”: It is a class defined in library
  • “get””set”: The code block for the “get” accessor is executed when the property is read; the code block for the “set” accessor is executed when the property is assigned a new value.
静止

2. Describe dynamic property of the model

/* All dynamic properties shall have only public getter, */
/* where setter should remain as private. */
public int QueueLength { get; private set; } = 0;
public int NInService { get; private set; } = 0;
public HourCounter HourCounter_QueueLength { get; private set; } = new HourCounter();
public HourCounter HourCounter_NInService { get; private set; } = new HourCounter();

3.1 Define relevant events of the model-ArriveEvent

private abstract class InternalEvent : Event<MMnQueue, Statics> { } // event adapter

private class ArriveEvent : InternalEvent
{  public override void Invoke()
{    Log(“Arrive.”);
This.QueueLength++;
Execute(new StartServiceEvent());
Schedule(new ArriveEvent(), TimeSpan.FromHours(
Exponential.Sample(This.DefaultRS, 1 / This.Config.HourlyArrivalRate)));}
}

  • “Log”: Simulation log, used for file record or console display
  • “Execute”: Execute the event immediately
  • “Schedule”: Execute the event in the future
  • “Exponential”: Exponential.Sample (Random seed, expected value of random variable);

3.2 Define relevant events of the model-StartServiceEvent

private class StartServiceEvent : InternalEvent
{
public override void Invoke()
{
if (This.QueueLength > 0 && This.NInService < This.Config.ServerCapacity)
{
Log(“Start Service.”);
This.QueueLength–;
This.NInService++;
Schedule(new DepartEvent(), TimeSpan.FromHours(
Exponential.Sample(This.DefaultRS, 1 / This.Config.HourlyServiceRate)));
}
This.HourCounter_NInService.ObserveCount(This.NInService, ClockTime);
This.HourCounter_QueueLength.ObserveCount(This.QueueLength, ClockTime);
}
}

hug-1

3.3 Define relevant events of the model - DepartEvent

private class DepartEvent : InternalEvent
{
public override void Invoke()
{
Log(“Depart.”);
This.NInService–;
Execute(new StartServiceEvent());
}
}

4. Complete model configuration:Dynamic property initialization & Event initialization

public MMnQueue(Statics config, int seed, string tag = null) : base(config, seed, tag)
{
Name = “MMnQueue”;
InitEvents.Add(new ArriveEvent { This = this });
}

  • “This”: “This” is a property of the event; while “this” represents current module

5.1 Model warm-up

public override void WarmedUp(DateTime clockTime)
{
HourCounter_NInService.WarmedUp(clockTime);
HourCounter_QueueLength.WarmedUp(clockTime);
}

滑板

5.2 Console display

public override void WriteToConsole(DateTime? clockTime = null)
{
Console.WriteLine(clockTime);
Console.WriteLine(“Queue Length:\t{0}”, QueueLength);
Console.WriteLine(“# in Serveice:\t{0}”, NInService);
Console.WriteLine(“Avg. Q Length:\t{0:F2}”, HourCounter_QueueLength.AverageCount);
Console.WriteLine(“Server Util.:\t{0:F2}”, HourCounter_NInService.AverageCount / Config.ServerCapacity);
}

Model Validation

validation
result
  • Based on formula of M/M/n (n=2) to calculate theoretical value, LQ = 7.67, Service Utility = 0.9
  • Run 10 replications and calculate the average of “Avg. Q Length” and “Server Util”
  • The result of replications: LQ = 7.72, Service Utility = 0.9
  • The result of replications matches the theoretical value