Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Queue

Class that represents a resource and collects statistics within a simulation.

We refer to queues and resources interchangeably. Resources are just Queues with limited capacity. Seizing a resource is the same as entering a Queue, and releasing a resource is the same as leaving a Quue.

Queues can be seized and released by entities while the simulation runs using the Entity.enterQueue and Entity.leaveQueue methods.

When that happens, the simulation collects aggregate statistics about the number of entities in the queue and the amount of time they spent there.

For example, the script below causes entities to enter a waiting queue, seize one capacity unit of a server queue, leave the waiting queue, undergo a delay that represents the service, then leave the server:

class Customer extends Entity<BarberShop> {
    service = new Uniform(15 - 3, 15 + 3);
    async script() {
        const shop = this.simulation;
        await this.enterQueue(shop.qWait); // enter the line (unlimited capacity)
        await this.enterQueue(shop.qJoe); // seize Joe the barber (capacity == 1)
        this.leaveQueue(shop.qWait); // leave the line
        await this.delay(this.service.sample()); // get a haircut
        this.leaveQueue(shop.qJoe); // free Joe        
    }
}

Queue statistics can be obtained at the end of the simulation by inspecting the queue's grossPop and grossDwell Tally objects.

You can also generate complete reports on queue utilization using the Simulation.getStatsTable method.

In addition to the Entity.enterQueue and Entity.leaveQueue methods, SimScript has an Entity.seize method that provides a shorter way to instruct entities to enter one or more waiting queues (unlimited capacity), seize a resource (limited capacity), undergo a delay, and leave the waiting queues.

For example, the code below uses the Entity.seize method to perform the same tasks as the script listed above:

class Customer extends Entity<BarberShop> {
    service = new Uniform(15 - 3, 15 + 3);
    async script() {
        const shop = this.simulation;

        // seize method: enter the line, seize the barber, leave the line,
        // get a haircut, release the barber
        await this.seize(shop.qJoe, this.service.sample(), shop.qWait);
    }
}

Hierarchy

  • Queue

Index

Constructors

constructor

  • new Queue(name?: string, capacity?: number, options?: any): Queue
  • Initializes a new instance of a Queue object.

    Parameters

    • name: string = ''

      Queue name. This is the name that will appear in reports generated by the Simulation.getStatsTable method. If ommitted, the queue will not be included in any reports.

    • capacity: number = null

      Queue capacity. If an entity tries to enter a queue that does not have enough capacity, it enters a wait state until another entity leaves the queue and enough capacity becomes available. If ommitted, the queue has infinite capacity.

    • Optional options: any

      Object with parameters used to initialize the Queue.

    Returns Queue

Accessors

averageDwell

  • get averageDwell(): number
  • Gets the average dwell time for entities/units in this queue.

    Returns number

averageLength

  • get averageLength(): number
  • Gets the average queue length in entities/units.

    Returns number

capacity

  • get capacity(): number
  • set capacity(value: number): void
  • Gets or sets the Queue capacity.

    The queue's capacity limits the flow of entities through the simulation. When an entity tries to enter a queue that is at capacity, it is forced to wait until another entity exits the queue.

    This property is set to null by default, which means the queue has infinite capacity.

    Returns number

  • Gets or sets the Queue capacity.

    The queue's capacity limits the flow of entities through the simulation. When an entity tries to enter a queue that is at capacity, it is forced to wait until another entity exits the queue.

    This property is set to null by default, which means the queue has infinite capacity.

    Parameters

    • value: number

    Returns void

entities

  • Gets an array containing the entities currently in the Queue.

    Returns Entity<Simulation>[]

grossDwell

  • get grossDwell(): Tally
  • Gets a Tally object containing statistics about the queue dwell times (amount of simulated time during which capacity units were in use).

    Returns Tally

grossPop

  • Gets a Tally object containing statistics about the queue population (capacity units used).

    Returns Tally

items

  • Gets a Map where the keys are the entities in the queue and the values are {@link QueueItem} objects containing information about the entities.

    Returns Map<Entity<Simulation>, QueueItem>

lastChange

  • get lastChange(): number
  • Gets the last simulated time when an entity entered or left the queue.

    Returns number

maxDwell

  • get maxDwell(): number
  • Gets the maximum dwell time for entities/units in this queue.

    Returns number

maxLength

  • get maxLength(): number
  • Gets the maximum queue length in entities/units.

    Returns number

name

  • get name(): string
  • set name(value: string): void
  • Gets or sets the Queue name.

    The queue's name is used in output reports such as the ones created by the Simulation.getStatsTable method.

    Returns string

  • Gets or sets the Queue name.

    The queue's name is used in output reports such as the ones created by the Simulation.getStatsTable method.

    Parameters

    • value: string

    Returns void

netDwell

  • Gets a Tally object containing statistics about the queue net dwell times (amount of simulated time during which capacity units were in use).

    This Tally excludes periods when the Queue was empty.

    Returns Tally

netPop

  • Gets a Tally object containing statistics about the queue net population (capacity units used).

    This Tally excludes periods when the Queue was empty.

    Returns Tally

pop

  • get pop(): number
  • Gets the number of entities currently in the queue.

    This value is usually, but not always, the same as the number of queue capacity units in use.

    By default, entities entering queues use up one capacity unit. In this case, the pop and unitsInUse properties will return the same value. But if entities take arbitrary queue capacity units when they enter the queue, those values will be different.

    Returns number

totalCount

  • get totalCount(): number
  • Gets the total number of entities/units that were seized and released during the simulation.

    Returns number

totalIn

  • get totalIn(): number
  • Gets the total number of entities that have entered the queue since the simulation started.

    Returns number

unitsInUse

  • get unitsInUse(): number
  • Gets the total number of capacity units currently in use.

    The Entity.enterQueue method allows entities to seize arbitry capacity units when entering queues. If all entities seize one capacity unit when entering the queue, then the unitsInUse property returns the same value as the pop property.

    Returns number

utilization

  • get utilization(): number
  • Gets the queue utilization.

    This value is calculated based on the queue's capacity and grossPop tally.

    Returns number

Methods

_updateTallies

  • _updateTallies(): void
  • internal

    Returns void

add

canEnter

  • canEnter(units?: number): boolean
  • Checks whether the Queue has enough capacity to accept a new entry.

    Parameters

    • units: number = 1

      Number of units to check for.

    Returns boolean

    True Queue has at least units capacity units available, false otherwise.

remove

reset

  • reset(): void
  • Resets the Queue to its initial state, removing all entities and resetting all its Tally objects.

    Returns void

Generated using TypeDoc