Skip to main content

A Python library for Discrete Event and Stochastic Simulation

Project description

DESTLib

DESTLib is a Python library for Discrete Event Simulation (DES) and Discrete Stochastic Simulation (DST). It provides flexible tools to model, simulate, and analyze queueing systems and other event-driven processes, supporting both single-server and multi-server scenarios, as well as priority levels.

Features

  • DES (Discrete Event Simulation):

    • Simulate queueing systems with customizable arrival and service time distributions.
    • Support for multiple servers and priority levels.
    • Built-in statistics and plotting for simulation results.
    • Save and load simulation metadata and results.
  • DST (Discrete Stochastic Simulation):

    • Generic simulation engine for stochastic processes.
    • Customizable behaviors, argument ranges, and weighted random choices.
  • Time Unit Utilities:

    • Convert between different time units (seconds, minutes, hours, etc.).

Installation

pip install destlib

Usage

Basic DES Example

from destlib import DES, uniform, TimeUnit

sim = (
    DES()
    .set_sample_size(30)
    .set_time_between_distro(uniform, a=1, b=7)
    .set_service_time_distro(uniform, a=1, b=7)
    .set_seed(7122004)
    .set_system_name("TollBooth")
    .set_entity_name("Car")
    .set_time_unit(TimeUnit.Min)
)

sim.set_num_servers(2)
sim.run()
sim.plot(v_lines=True)
print(sim.df.head())

Running Multiple Simulations

from destlib import run_simulations

for i, sim in enumerate(run_simulations(sim, 3)):
    sim.set_num_servers(i + 1)
    sim.run()
    sim.plot()

Priority Levels Example

from matplotlib.pylab import poisson
from destlib import DES, uniform, TimeUnit

patients = (
    DES()
    .set_sample_size(30)
    .set_time_between_distro(poisson, lam=8.0)
    .set_service_time_distro(uniform, a=1, b=30)
    .set_num_servers(3)
    .set_levels(
        levels=["Critical", "Severe", "Moderate"],
        levels_prob=[0.2, 0.4, 0.4],
    )
    .set_seed(7122004)
    .set_system_name("Hospital")
    .set_entity_name("Patient")
    .set_time_unit(TimeUnit.Min)
)

patients.run()
patients.plot()

print(patients.df.groupby("level")["wait_time"].mean())

patients.save_to("csv", True, True)

Outputs

Generated Data:

data

Some Statistics:

{
  "mean_time_between": 8.333,
  "mean_service_time": 13.633,
  "mean_idle_time": 12.333,
  "mean_waiting_time for each Patient": 0.933,
  "mean_waiting_time for levels": {
    "Critical": 0.143,
    "Moderate": 1.0,
    "Severe": 1.444
  }
}

System Flow:

plot

Modules

  • destlib.des: DES simulation engine (DES)
  • destlib.dst: DST simulation engine (DST)
  • destlib.time_units: Time unit utilities (TimeUnit)

License

MIT License


For more details, see the code and docstrings in each module.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

destlib-1.1.2.tar.gz (12.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

destlib-1.1.2-py3-none-any.whl (12.0 kB view details)

Uploaded Python 3

File details

Details for the file destlib-1.1.2.tar.gz.

File metadata

  • Download URL: destlib-1.1.2.tar.gz
  • Upload date:
  • Size: 12.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.10

File hashes

Hashes for destlib-1.1.2.tar.gz
Algorithm Hash digest
SHA256 b70cfad7b8f9a5c31033e752daf6e2d53a4bb3f4fc3f4bbaf10af809e9f7af8a
MD5 0ef856de1d4fee8d8d8b5ed749ee81ea
BLAKE2b-256 3cafff2b15773dfbfb6eb4d4612cbd8ca51cc682b7b466b3f68c092b8b8b4418

See more details on using hashes here.

File details

Details for the file destlib-1.1.2-py3-none-any.whl.

File metadata

  • Download URL: destlib-1.1.2-py3-none-any.whl
  • Upload date:
  • Size: 12.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.10

File hashes

Hashes for destlib-1.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 c613600b7d7e413376fb8001d28ab2eff3d6c8b2a8bc2e5b73099700bbf3516d
MD5 331249187d178bd0dd0998ba763ccff9
BLAKE2b-256 ee43656f49c28a2cdd74f6d2de020c4a19fe36f527a658accef7b4f39d2a6cc9

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page