Skip to content

API — Queuing

pyworkforce.queuing

ErlangC

python
ErlangC(transactions, aht, asa, interval, shrinkage=0.0)

Erlang C (M/M/c) queue: Poisson arrivals, exponential handling times, infinite queue, no abandonment.

Parameters

  • transactions (float) — transactions arriving in the interval.
  • aht (float) — average handle time.
  • asa (float) — target average speed of answer.
  • interval (float) — interval length.
  • shrinkage (float, default 0.0) — unavailable fraction, in [0, 1).

Attributes

  • intensity (float) — offered load in Erlangs.

Methods

  • required_positions(service_level, max_occupancy=1.0)dict with raw_positions, positions, service_level, occupancy, waiting_probability.
  • waiting_probability(positions, scale_positions=False)float
  • service_level(positions, scale_positions=False)float
  • achieved_occupancy(positions, scale_positions=False)float
  • get_params()dict

Set scale_positions=True when positions already includes shrinkage.

See the Erlang C guide.

ErlangA

python
ErlangA(transactions, aht, asa, interval, patience, shrinkage=0.0)

Erlang A (M/M/c+M) queue with customer abandonment. All metrics are computed exactly from the birth-death stationary distribution.

Parameters — as ErlangC, plus:

  • patience (float) — mean time before a waiting customer abandons.

Methods

  • required_positions(service_level, max_occupancy=1.0, max_abandonment=1.0, asa=None)dict with raw_positions, positions, service_level, occupancy, abandonment_probability, waiting_probability, average_speed_of_answer.
  • waiting_probability(positions)float
  • abandonment_probability(positions)float
  • achieved_occupancy(positions)float
  • average_speed_of_answer(positions)float
  • average_queue_length(positions)float
  • service_level(positions, asa=None)float
  • get_params()dict

See the Erlang A guide.

MultiErlangC

python
MultiErlangC(param_grid, n_jobs=2, pre_dispatch='2 * n_jobs')

Evaluate ErlangC over a grid of parameters in parallel.

Parameters

  • param_grid (dict) — ErlangC constructor arguments, each mapped to a list of values.
  • n_jobs (int, default 2) — parallel workers (-1 = all CPUs).
  • pre_dispatch (str, default '2 * n_jobs') — joblib pre-dispatch.

Methods (each takes an arguments_grid dict and returns a list of results)

  • required_positions(arguments_grid)
  • service_level(arguments_grid)
  • waiting_probability(arguments_grid)
  • achieved_occupancy(arguments_grid)

Attributes (set after the matching method runs, aligned with results)

  • required_positions_params, service_level_params, waiting_probability_params, achieved_occupancy_params — lists of (erlang_params, method_params) tuples.

See the MultiErlangC guide.

MultiErlangA

python
MultiErlangA(param_grid, n_jobs=2, pre_dispatch='2 * n_jobs')

The abandonment-aware counterpart of MultiErlangC: evaluates ErlangA over a parameter grid in parallel. param_grid takes ErlangA constructor arguments (including patience).

Methods (each takes an arguments_grid dict and returns a list of results)

  • required_positions(arguments_grid)
  • service_level(arguments_grid)
  • waiting_probability(arguments_grid)
  • abandonment_probability(arguments_grid)
  • achieved_occupancy(arguments_grid)
  • average_speed_of_answer(arguments_grid)
  • average_queue_length(arguments_grid)

Each method stores the matching (erlang_params, method_params) tuples in a <method>_params attribute, aligned with the results.

See the scenarios tutorial.

ErlangB

python
ErlangB(transactions, aht, interval, shrinkage=0.0)

Erlang B (M/M/c/c) pure-loss queue: Poisson arrivals, exponential holding times, no waiting room — a call that finds all channels busy is blocked and lost. The blocking probability is computed via the numerically stable Erlang B recursion.

Parameters

  • transactions (float) — calls arriving in the interval.
  • aht (float) — average holding time (same unit as interval).
  • interval (float) — interval length.
  • shrinkage (float, default 0.0) — unavailable fraction, in [0, 1).

Attributes

  • intensity (float) — offered traffic in Erlangs.

Methods

  • required_positions(max_blocking, max_occupancy=1.0)dict with raw_positions, positions, blocking_probability, occupancy.
  • blocking_probability(positions, scale_positions=False)float
  • achieved_occupancy(positions, scale_positions=False)float
  • get_params()dict

Set scale_positions=True when positions already includes shrinkage.

See the Erlang B guide.

MultiErlangB

python
MultiErlangB(param_grid, n_jobs=2, pre_dispatch='2 * n_jobs')

Evaluate ErlangB over a grid of parameters in parallel. Interface mirrors MultiErlangC.

Parameters

  • param_grid (dict) — ErlangB constructor arguments, each mapped to a list of values.
  • n_jobs (int, default 2) — parallel workers (-1 = all CPUs).
  • pre_dispatch (str, default '2 * n_jobs') — joblib pre-dispatch.

Methods (each takes an arguments_grid dict and returns a list of results)

  • required_positions(arguments_grid)
  • blocking_probability(arguments_grid)
  • achieved_occupancy(arguments_grid)

Attributes (set after the matching method runs, aligned with results)

  • required_positions_params, blocking_probability_params, achieved_occupancy_params — lists of (erlang_params, method_params) tuples.

See the Erlang B guide.

results_to_dataframe

python
from pyworkforce.utils import results_to_dataframe

results_to_dataframe(results, params=None)

Combine a Multi* result list (and the matching *_params) into a tidy pandas.DataFrame, one row per scenario. Result keys that collide with an input parameter name are suffixed with _result so both the target and the achieved value are kept.

Released under the MIT License.