QueueSim
QueueSim is a Python package for discrete event stochastic simulation of queueing networks. For Kendall models the performance indicators can also be computed using Erlang and Allen Cunneen approximation formulas.
Install / Use
/learn @A-Herzog/QueueSimREADME
QueueSim
QueueSim is a Python package for discrete event stochastic simulation of queueing networks. For Kendall models the performance indicators can also be computed using Erlang and Allen Cunneen approximation formulas.
Installation
A PyPI package is not yet available. Just download and extract the zip package offered here.
The zip package also includes some example files (as plain Python files and as Jupyter notebooks) describing the base functions.
- If you are using a Python environment which can show Jupyter notebooks, open and run any from the
example_*.ipynbfiles in this directory. - If you are using plain Python, open and run any from the
example_*.pyfiles in this directory. - If you want to use a virtual environment just run
init_venv_1.bat(Windows) orinit_venv_1.sh(Linux) to create the environment and then runinit_venv_2.bat(Windows) orinit_venv_2.sh(Linux) from within the virtual environment to install all required modules.
Requirements
- Python 3.9 or higher is needed to execute QueueSim.
scipyis used to generate pseudo-random numbers of some probability distributionsnumpyis used byqueuesim.statisticsand in several example files.pandasandscipyare used inqueuesim.analytic.- The visualizations in the example Jupyter notebooks use
matplotlibandseaborn. - The graphical network builder (see
queuesim.graph.build_graph) usesnetworkx.
As long a you are not using the function for calculating analytic results, not using the Jupyter notebooks and not using the graph builder you will not need pandas, mathplotlib, seaborn and networkx.
You can install all required module by running pip install -r requirements.txt (or use a virtual environment, see installation notes above).
Main features of QueueSim
- Building queueing networks on source code base (not only Kendall models)
- Option to use any lambda expressions for inter-arrival and service times (lambda expression generators for the most common distributions are included)
- Batch arrival and service is possible
- Option to model impatience of the clients
- Branching clients by conditions or by chance
- Different service disciplines are available (FIFO, LIFO or user-defined priority formulas)
- Automatic statistic recording
- Erlang and Allen Cunneen classes for comparison of simulation and analytic results
- Helper classes for parallel multi-process simulation
- Can be compiled using Cython (
pyxclasses with type annotations for speed-up are included)
Usage examples
- Simulating simple models
- Random number distributions
- Impatience
- Networks
- Batch arrival and batch service
- Multiple client types with different service times or different priorities
- FIFO/LIFO/Random
- Post-processing times
- Queueing systems with control
- Statistics results
- Parallelization
- Calculating analytical results
Example files
There is a number of py files and Jupyter notebooks that illustrate various functions of QueueSim:
Analytical calculations
- Erlang B formula for M/M/c/c models
- Plain Python:
example_analytic_erlang_b.py - Jupyter notebook:
example_analytic_erlang_b.ipynb
- Plain Python:
- Erlang C formula for M/M/c models
- Plain Python:
example_analytic_erlang_c.py - Jupyter notebook:
example_analytic_erlang_c.ipynb
- Plain Python:
- Extended Erlang C formula (with impatient clients) for M/M/c/K+M models
- Plain Python:
example_analytic_erlang_c_ext.py - Jupyter notebook:
example_analytic_erlang_c_ext.ipynb
- Plain Python:
- Allen Cunneen approximation formula for GI/G/c models
- Plain Python:
example_analytic_ac_approx.py - Jupyter notebook:
example_analytic_ac_approx.ipynb
- Plain Python:
Simulation
Very simple simulation models not using QueueSim
- Minimal simulator for a M/M/1 model not using QueueSim, just a few lines of code
- Plain Python:
example_sim_minimal_MM1.py - Jupyter notebook:
example_sim_minimal_MM1.ipynb
- Plain Python:
- Minimal simulator for G/G/c models not using QueueSim, just a few lines of code
- Plain Python:
example_sim_minimal_GGc.py - Jupyter notebook:
example_sim_minimal_GGc.ipynb
- Plain Python:
Simulation models
- Simulation results of a M/M/c model compared to the analytical Erlang C results
- Plain Python:
example_sim_mmc_simple.py - Jupyter notebook:
example_sim_mmc_simple.ipynb
- Plain Python:
- Recording the course of number of clients in the system in a M/M/c model
- Plain Python:
example_sim_mmc_course.py - Jupyter notebook:
example_sim_mmc_course.ipynb
- Plain Python:
- Parameter study of a M/M/c model
- Plain Python:
example_sim_mmc_series.py - Jupyter notebook:
example_sim_mmc_series.ipynb
- Plain Python:
Complex simulation models
- Simulation of a call center model (a M/M/c/K+M model with forwarding and retry)
- Plain Python:
example_sim_call_center.py - Jupyter notebook:
example_sim_call_center.ipynb
- Plain Python:
- Parameter study of a call center model
- Plain Python:
example_sim_call_center_series.py - Jupyter notebook:
example_sim_call_center_series.ipynb
- Plain Python:
- Simulation of a queueing network with transition probabilities defined via matrices
- Plain Python:
example_sim_network.py - Jupyter notebook:
example_sim_network.ipynb
- Plain Python:
- Distribution random number generator tests
- Plain Python:
example_sim_random_numbers.py - Jupyter notebook:
example_sim_random_numbers.ipynb
- Plain Python:
- System design - comparison of different queueing disciplines
- Plain Python:
exmaple_sim_shortest_queue.py - Jupyter notebook:
exmaple_sim_shortest_queue.ipynb
- Plain Python:
Queueing disciplines
- FIFO, LIFO or random selection of the next client
- Plain Python:
example_sim_mmc_priorities1.py - Jupyter notebook:
example_sim_mmc_priorities1.ipynb
- Plain Python:
- Two client types with different priorities
- Plain Python:
example_sim_mmc_priorities2.py - Jupyter notebook:
example_sim_mmc_priorities2.ipynb
- Plain Python:
Optimization
- Simple iterative optimization example
- Plain Python:
example_optimize_simple1.py - Jupyter notebook:
example_optimize_simple1.ipynb
- Plain Python:
- Simple optimization example using BOBYQA
- Plain Python:
example_optimize_simple2.py - Jupyter notebook:
example_optimize_simple2.ipynb
- Plain Python:
- More complex iterative optimization example
- Plain Python:
example_optimize_complex1.py - Jupyter notebook:
example_optimize_complex1.ipynb
- Plain Python:
- More complex optimization example using BOBYQA
- Plain Python:
example_optimize_complex2.py - Jupyter notebook:
example_optimize_complex2.ipynb
- Plain Python:
Overview of the main classes
The Simulator
class queuesim.Simulator
The Simulator class contains the code for event management and for running simulations. There is only one relevant method in this class: run()
import queuesim
simulator = queuesim.Simulator()
# Define stations here, link stations to each other and to the simulator
simulator.run()
# Process statistic results here
Stations
QueueSim offers 7 station types from which many types of queueing networks can be built: Source, Process, Delay, Decide, DecideCondition, DecideClientType and Dispose. While most stations have input and output connections, the Source station has only an output and the Dispose station only an input. All station types are defined in module queuesim.stations.
Source
Each model starts with one or more Source stations. At these stations clients enter the system.
import queuesim
import queuesim.stations
simulator = queuesim.Simulator()
count = 100_000 # Number of arrivals to be simulated
get_i = ... # string (to be evaluated) or lambda expression to generate inter-arrival times
source = queuesim.stations.Source(simulator, count, get_i)
next_station_in_queueing_network = ...
source.set_next(next_station_in_queueing_network)
(For helper functions to generate pseudo random number generators for the inter-arrival times see description of module queuesim.random_dist below.) Additionally there is an optional parameter getIB= in the constructor of the Source object by which variable arrival batch sizes can be defined.
Process
The Process station is the main component of every queueing model. Here is the queue and the
