Skip to main content

A Discrete Event Simulation (DES) framework for modeling systems where state changes occur at discrete points in time.

Project description

DeSim (Discrete Event Simulator)

A Discrete Event Simulation (DES) framework for modeling systems where state changes occur at discrete points in time.

Description

to be added

Features

  • 📦 OOP: Object-oriented paradigm was taken in mind in order to allow flexibility while modeling dynamic systems.
  • ⏱️ Discrete time: Time updates are based on occurrences of events, and not on delta times.
  • ⏩ Queue-based: Events are retrieved from a priority queue that sorts them based on their time of occurrence.
  • 🍃 Lightweight: DeSim has no external dependencies.

Quick Example

from desim import DiscreteEvent, DiscreteEventQueue, run_to_end

#
# ...
#

class CustomerArrivalEvent(DiscreteEvent):
    def __init__(self, t):
        super().__init__(t)

    def _run(self, env):
        store, stats = env

        if store.is_open():
            store.customer_enters()
            print(f"{store.customers=}")

            next_arrival = CustomerArrivalEvent(self._after(stats.random_arrival_time()))
            customer_done = CustomerDoneEvent(self._after(stats.random_shopping_time()))
            return [next_arrival, customer_done]

        else:
            print("Oops, too late")
            return []

#
# ...
#

store = Store()
stats = Stats(mean_arrival_time=1, mean_shopping_time=5)

queue = DiscreteEventQueue()
queue.add_events(
    [
        OpenStoreEvent(0),
        ChangeArrivalTimeEvent(20, 0.5),  # rush-hour
        ChangeArrivalTimeEvent(45, 1.5),  # end of rush-hour
        CloseStoreEvent(60),
    ]
)

t = []
customers = []

def callback(_, __):
    t.append(queue.t)
    customers.append(store.customers)

run_to_end(queue, (store, stats), callback)

Installation

You can install DeSim using either PyPI or clone it from GitHub.

From PyPI (recommended):

pip install desim-python

From GitHub:

git clone https://github.com/larias95/desim-python.git
cd desim-python
pip install .

Examples

After installation you can run examples from the examples/ folder. E.g: python store_example.py.

You may need to install some dependencies before running the examples by using pip install -r requirements.txt from examples/ folder.

Links

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

desim_python-0.0.2.tar.gz (4.0 kB view details)

Uploaded Source

Built Distribution

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

desim_python-0.0.2-py3-none-any.whl (4.6 kB view details)

Uploaded Python 3

File details

Details for the file desim_python-0.0.2.tar.gz.

File metadata

  • Download URL: desim_python-0.0.2.tar.gz
  • Upload date:
  • Size: 4.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.3

File hashes

Hashes for desim_python-0.0.2.tar.gz
Algorithm Hash digest
SHA256 b17a20f6c069951b424e3015c4f32fdae6bc835ce7a6ac9772a6abdea2f79bc2
MD5 d1fd6e01c08fc256aba85e8c9ab009a8
BLAKE2b-256 12d47c0f0b5cf5ef7c81cb33c5ba7965d5f806a75b0dfc3c939c022f81111f03

See more details on using hashes here.

File details

Details for the file desim_python-0.0.2-py3-none-any.whl.

File metadata

  • Download URL: desim_python-0.0.2-py3-none-any.whl
  • Upload date:
  • Size: 4.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.3

File hashes

Hashes for desim_python-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 e76f6128a8db5a22b95ff7354d8720292cbed1de767d4977858ab3067b837bed
MD5 6e086a6d8c9801e3283756f92dc0ca59
BLAKE2b-256 cd9035d16618f3eaeaa95f331e7eb65cf48df188618ca0eefca7db57d394de7f

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