https://github.com/larias95/desim-python

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

https://github.com/larias95/desim-python

Science Score: 26.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
    Found .zenodo.json file
  • DOI references
  • Academic publication links
  • Academic email domains
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (11.0%) to scientific vocabulary
Last synced: 9 months ago · JSON representation

Repository

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

Basic Info
  • Host: GitHub
  • Owner: larias95
  • License: mit
  • Language: Python
  • Default Branch: main
  • Homepage:
  • Size: 10.7 KB
Statistics
  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • Open Issues: 0
  • Releases: 0
Created about 1 year ago · Last pushed about 1 year ago
Metadata Files
Readme License

readme.md

DeSim (Discrete Event Simulator)

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

Description

DeSim is a flexible Discrete Event Simulation (DES) library built for modeling systems where state changes occur at specific points in time. At its core is a queue of events that governs how the simulation evolves, processing scheduled actions in chronological order to reflect changes in system state. This method allows DeSim to simulate dynamic environments with precision and efficiency, focusing computation only when activity occurs, and so, mirroring the complexity of real-world systems without imposing rigid structures.

Using DeSim involves defining system behavior through object-oriented design. At the core of the library is a DiscreteEvent base class, which users extend to model specific types of events. Each derived event class encapsulates the logic needed to evolve the system, such as modifying state variables, scheduling future events, or interacting with other components. This design encourages clean separation of concerns and makes simulations more maintainable and reusable. By modeling system dynamics as a series of interacting event classes, DeSim allows users to build rich, modular simulations that are both intuitive and scalable.

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 while True: update(deltatime) approaches.
  • ⏩ 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

Suppose we want to model a store and the flow of customers that arrive over time. We can model this by implementing events like: the store opened, a customer arrived, a customer is ready to pay and leave the store, the store closed, etc. So, the execution of one customer arrival could lead to the next one, and also to generate an event for when that customer is done. We just need to override the _run(self, env) method from the DiscreteEvent base class to model all of those interactions.

```python from desim import DiscreteEvent, DiscreteEventQueue, runtoend

...

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(meanarrivaltime=1, meanshoppingtime=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)

runtoend(queue, (store, stats), callback) ```

Installation

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

From PyPI (recommended):

sh pip install desim-python

From GitHub:

sh 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

Owner

  • Login: larias95
  • Kind: user

GitHub Events

Total
  • Push event: 7
  • Create event: 2
Last Year
  • Push event: 7
  • Create event: 2

Dependencies

examples/requirements.txt pypi
  • matplotlib ==3.6.3
  • numpy ==1.26.4
pyproject.toml pypi
setup.py pypi