{"id":19289914,"url":"https://github.com/galenseilis/DESRu","last_synced_at":"2025-04-22T05:32:10.445Z","repository":{"id":257806453,"uuid":"866272502","full_name":"galenseilis/DESRu","owner":"galenseilis","description":"DESRu is a Rust crate which contains the bare minimum components to write discrete event simulations.","archived":false,"fork":false,"pushed_at":"2024-11-06T05:05:34.000Z","size":39,"stargazers_count":1,"open_issues_count":2,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-11-07T15:54:26.750Z","etag":null,"topics":["des","discrete-event-simulation","rust","rust-crate","rust-lang","rust-library","simulation","simulation-engine","simulation-environment","simulation-framework","simulations"],"latest_commit_sha":null,"homepage":"https://crates.io/crates/desru","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/galenseilis.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-10-02T00:20:27.000Z","updated_at":"2024-11-06T05:05:37.000Z","dependencies_parsed_at":null,"dependency_job_id":"6dcb2c61-3cbc-4000-b4fa-c181aea42ab9","html_url":"https://github.com/galenseilis/DESRu","commit_stats":null,"previous_names":["galenseilis/desru"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/galenseilis%2FDESRu","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/galenseilis%2FDESRu/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/galenseilis%2FDESRu/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/galenseilis%2FDESRu/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/galenseilis","download_url":"https://codeload.github.com/galenseilis/DESRu/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":223888667,"owners_count":17220138,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["des","discrete-event-simulation","rust","rust-crate","rust-lang","rust-library","simulation","simulation-engine","simulation-environment","simulation-framework","simulations"],"created_at":"2024-11-09T22:17:24.872Z","updated_at":"2024-11-09T22:17:37.497Z","avatar_url":"https://github.com/galenseilis.png","language":"Rust","readme":"# Overview\n\nDESRu (pronounced \"dez-ruh\") is a discrete event simulation package for Rust.\n\nThis Rust crate provides a flexible framework for simulating Discrete Event Systems (DES). It allows users to schedule, manage, and execute events over time, making it suitable for simulating systems such as queueing networks, resource allocation systems, and other event-driven models.\n\n# Key Features\n\n- **Event Scheduling**: Schedule events to occur at specific times or after delays.\n- **Event Logging**: Keep a log of all executed events and their outcomes for post-simulation analysis.\n- **Flexible Execution**: Run simulations for a specific duration or until a custom stopping condition is met.\n- **Contextual Information**: Attach metadata to events for richer simulation context and behavior customization.\n\n# Getting Started\n\n## Installation\n\n```bash\n$ cargo add desru\n```\n\n## Examples of Usage\n\n### Scheduling an Event\n\n```rust\nuse desru::{Event, EventScheduler};\n\nfn main() {\n    let mut scheduler = EventScheduler::new();\n    let event = Event::new(\n        0.0, \n        Some(Box::new(|scheduler| Some(\"Executed\".to_string()))), \n        None\n    );\n    \n    scheduler.schedule(event);\n    scheduler.run_until_max_time(10.0);\n}\n```\n\n### Clock\n\nInspired by the simple clock example in the SimPy documentation.\n\n\n```rust\nuse desru::{Event, EventScheduler};\n\nfn clock(scheduler: \u0026mut EventScheduler, name: String, tick: f64) {\n    // Function to handle the clock's actions and schedule the next tick\n    fn action(scheduler: \u0026mut EventScheduler, name: String, tick: f64) {\n        // Print the name of the clock and the current simulation time\n        println!(\"{}: {}\", name, scheduler.current_time);\n\n        // Schedule the next tick of the clock\n        let next_time = scheduler.current_time + tick;\n        let event = Event::new(\n            next_time,\n            Some(Box::new(move |scheduler: \u0026mut EventScheduler| {\n                action(scheduler, name.clone(), tick);\n                None\n            })),\n            None,\n        );\n        scheduler.schedule(event);\n    }\n\n    // Schedule the first event for the clock at time 0\n    scheduler.schedule(Event::new(\n        0.0,\n        Some(Box::new(move |scheduler: \u0026mut EventScheduler| {\n            action(scheduler, name.clone(), tick);\n            None\n        })),\n        None,\n    ));\n}\n\nfn main() {\n    // Initialize the event scheduler\n    let mut scheduler = EventScheduler::new();\n\n    // Schedule initial clock processes\n    clock(\u0026mut scheduler, \"fast\".to_string(), 0.5);\n    clock(\u0026mut scheduler, \"slow\".to_string(), 1.0);\n\n    // Run the scheduler until the maximum simulation time\n    scheduler.run_until_max_time(2.0);\n}\n```\n\n\n### Simple Car Process\n\nThis example replicates the classic SimPy Car simulation, where a car alternates between parking and driving.\n\n```rust\nuse desru::{Event, EventScheduler};\n\nconst PARK_DURATION: f64 = 5.0;\nconst DRIVE_DURATION: f64 = 2.0;\n\nfn car(scheduler: \u0026mut EventScheduler) {\n    park(scheduler);\n}\n\nfn park(scheduler: \u0026mut EventScheduler) {\n    println!(\"Start parking at {}\", scheduler.current_time);\n    scheduler.schedule(Event::new(\n        scheduler.current_time + PARK_DURATION,\n        Some(Box::new(move |scheduler: \u0026mut EventScheduler| {\n            drive(scheduler);\n            None\n        })),\n        None,\n    ));\n}\n\nfn drive(scheduler: \u0026mut EventScheduler) {\n    println!(\"Start driving at {}\", scheduler.current_time);\n    scheduler.schedule(Event::new(\n        scheduler.current_time + DRIVE_DURATION,\n        Some(Box::new(move |scheduler: \u0026mut EventScheduler| {\n            park(scheduler);\n            None\n        })),\n        None,\n    ));\n}\n\nfn main() {\n    let mut scheduler = EventScheduler::new();\n    car(\u0026mut scheduler);\n    scheduler.run_until_max_time(15.0);\n}\n```\n\n### Object-Oriented Car Process\n\nThis example uses a more object-oriented approach to simulate a car alternating between charging and driving.\n\n```rust\nuse desru::{Event, EventScheduler};\n\nconst CHARGE_DURATION: f64 = 5.0;\nconst TRIP_DURATION: f64 = 2.0;\n\nstruct Car\u003c'a\u003e {\n    scheduler: \u0026'a mut EventScheduler,\n}\n\nimpl\u003c'a\u003e Car\u003c'a\u003e {\n    fn new(scheduler: \u0026'a mut EventScheduler) -\u003e Self {\n        let mut car = Car { scheduler };\n        car.charge();\n        car\n    }\n\n    fn charge(\u0026mut self) {\n        println!(\"Start charging at {}\", self.scheduler.current_time);\n        self.scheduler.schedule(Event::new(\n            self.scheduler.current_time + CHARGE_DURATION,\n            Some(Box::new(move |scheduler: \u0026mut EventScheduler| {\n                let mut car_instance = Car { scheduler };\n                car_instance.drive();\n                None\n            })),\n            None,\n        ));\n    }\n\n    fn drive(\u0026mut self) {\n        println!(\"Start driving at {}\", self.scheduler.current_time);\n        self.scheduler.schedule(Event::new(\n            self.scheduler.current_time + TRIP_DURATION,\n            Some(Box::new(move |scheduler: \u0026mut EventScheduler| {\n                let mut car_instance = Car { scheduler };\n                car_instance.charge();\n                None\n            })),\n            None,\n        ));\n    }\n}\n\nfn main() {\n    let mut scheduler = EventScheduler::new();\n    let _car = Car::new(\u0026mut scheduler);\n    scheduler.run_until_max_time(15.0);\n}\n```\n\n# Core Components\n\nThe `Event` struct represents a discrete event in the simulation. Each event has:\n\n- A scheduled time.\n- A closure (the action) to be executed when the event is triggered.\n- Contextual metadata for storing key-value pairs.\n\nThe `EventScheduler` manages the execution of events. It processes events in order of their scheduled times, executing them and then advancing the simulation time.\n\n# Design Philosophy\n\n- Keep it simple.\n- Keep it performant.\n- Keep it to the fundamentals.\n\n","funding_links":[],"categories":["Uncategorized"],"sub_categories":["Uncategorized"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgalenseilis%2FDESRu","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgalenseilis%2FDESRu","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgalenseilis%2FDESRu/lists"}