{"id":30733434,"url":"https://github.com/benschza/simcraft","last_synced_at":"2025-09-03T18:17:19.681Z","repository":{"id":309803488,"uuid":"939536964","full_name":"BenSchZA/simcraft","owner":"BenSchZA","description":"A Discrete-Event Simulation (DES) framework for generalised simulation modelling.","archived":false,"fork":false,"pushed_at":"2025-08-13T21:21:28.000Z","size":2159,"stargazers_count":21,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-08-13T23:20:53.299Z","etag":null,"topics":["agent-based-modeling","discrete-event-simulation","simulation-framework","simulation-modeling","system-dynamics"],"latest_commit_sha":null,"homepage":"https://simcraft.io","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/BenSchZA.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,"zenodo":null}},"created_at":"2025-02-26T17:42:35.000Z","updated_at":"2025-08-13T21:21:31.000Z","dependencies_parsed_at":"2025-08-13T23:21:14.987Z","dependency_job_id":null,"html_url":"https://github.com/BenSchZA/simcraft","commit_stats":null,"previous_names":["benschza/simcraft"],"tags_count":null,"template":false,"template_full_name":null,"purl":"pkg:github/BenSchZA/simcraft","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BenSchZA%2Fsimcraft","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BenSchZA%2Fsimcraft/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BenSchZA%2Fsimcraft/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BenSchZA%2Fsimcraft/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/BenSchZA","download_url":"https://codeload.github.com/BenSchZA/simcraft/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BenSchZA%2Fsimcraft/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":273487835,"owners_count":25114626,"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","status":"online","status_checked_at":"2025-09-03T02:00:09.631Z","response_time":76,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["agent-based-modeling","discrete-event-simulation","simulation-framework","simulation-modeling","system-dynamics"],"created_at":"2025-09-03T18:17:15.276Z","updated_at":"2025-09-03T18:17:19.312Z","avatar_url":"https://github.com/BenSchZA.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Simcraft\n[![Build Status](https://github.com/BenSchZA/simcraft/actions/workflows/test-simcraft.yml/badge.svg)](https://github.com/BenSchZA/simcraft/actions/workflows/test-simcraft.yml)\n\nA Discrete-Event Simulation (DES) framework for generalised simulation modelling.\n\n\u003cimg width=\"1443\" alt=\"image\" src=\"https://github.com/user-attachments/assets/646347b9-7d69-4adf-8eec-444ffc320aff\" /\u003e\n\n## Event-Driven Simulation Architecture\n\nAn event-driven simulation architecture provides a flexible framework for implementing various simulation modelling paradigms:\n\n- **System Dynamics:** Events represent the flow of resources or information between interconnected nodes, evolving over time through differential or difference equations. A periodic time-stepping event approximates continuous changes at fixed intervals.\n- **Agent-Based Modelling (ABM):** Events represent agent decisions, message exchanges, and state transitions, allowing agents to interact asynchronously with each other and their environment.\n- **Discrete-Event Simulation (DES):** Events represent state changes occurring at specific points in time, dynamically scheduling the next event without requiring fixed time steps.\n- **Discrete-Time Simulation (DTS):** Events represent updates to the system state at uniform, fixed time steps, ensuring that all changes occur at regular intervals, regardless of necessity.\n\nThe framework is inspired by the [DEVS](https://www.cs.mcgill.ca/~hv/classes/MS/DEVS.pdf) (Discrete EVent System Specification) formalism and the [SimRS](https://simrs.com/) DEVS implementation.\n\n## Resource Flow Model Domain-Specific Language (DSL)\n\nAs a first application of the framework, Simcraft provides a domain-specific language (DSL) for easily defining resource flow models as defined in the [\"Engineering Emergence: Applied Theory for Game Design\"](https://eprints.illc.uva.nl/id/eprint/2118/1/DS-2012-12.text.pdf) paper by Joris Dormans.\n\nThe DSL allows you to define processes (e.g., Source, Pool, Drain nodes) and connections (i.e. flows) between them in a declarative way.\n\n### Basic Usage\n\n```rust\nuse simcraft::dsl::*;\nuse simcraft::simulator::Simulate;\nuse simcraft::utils::errors::SimulationError;\n\nfn main() -\u003e Result\u003c(), SimulationError\u003e {\n    // Create a simulation using the DSL\n    let mut sim = simulation! {\n        processes {\n            source \"source1\" {}\n            pool \"pool1\" {}\n        }\n        connections {\n            \"source1.out\" -\u003e \"pool1.in\" {\n                id: \"conn1\",\n                flow_rate: 1.0\n            }\n        }\n    }?;\n\n    // Run the simulation for 5 steps\n    let results = sim.step_n(5)?;\n\n    // Process the results\n    println!(\"Final time: {}\", results.last().unwrap().time);\n\n    Ok(())\n}\n```\n\nOr equivalent using the framework directly:\n\n```rust\nuse simcraft::prelude::*;\nuse simcraft::model::nodes::{Source, Pool};\nuse simcraft::simulator::simulation_trait::StatefulSimulation;\n\nfn main() -\u003e Result\u003c(), SimulationError\u003e {\n    // Create processes\n    let source = Source::builder()\n        .id(\"source1\")\n        .build()\n        .unwrap();\n    let pool = Pool::builder()\n        .id(\"pool1\")\n        .build()\n        .unwrap();\n\n    // Create connection\n    let connection = Connection::new(\n        \"conn1\".to_string(),\n        \"source1\".to_string(),\n        Some(\"out\".to_string()),\n        \"pool1\".to_string(),\n        Some(\"in\".to_string()),\n        Some(1.0),\n    );\n\n    // Create simulation and add processes\n    let mut sim = Simulation::new(vec![], vec![])?;\n    sim.add_process(source)?;\n    sim.add_process(pool)?;\n    sim.add_connection(connection)?;\n\n    // Run the simulation for 5 steps\n    let _ = sim.step_n(5)?;\n\n    // Get final state\n    let final_state = sim.get_simulation_state();\n    println!(\"Final time: {}\", final_state.time);\n\n    Ok(())\n}\n```\n\nOr equivalent using YAML format:\n\n```yaml\nname: \"Basic Source to Pool\"\ndescription: \"Simple example showing a source flowing to a pool\"\nprocesses:\n  - id: \"source1\"\n    type: \"Source\"\n    triggerMode: \"Automatic\"\n    action: \"PushAny\"\n  - id: \"pool1\"\n    type: \"Pool\"\n    triggerMode: \"Automatic\"\n    action: \"PullAny\"\nconnections:\n  - id: \"conn1\"\n    sourceID: \"source1\"\n    targetID: \"pool1\"\n    flowRate: 1.0\n```\n\n### Process Types\n\nThe DSL supports the following process types:\n\n#### Source\n\nA source process generates resources.\n\n```rust\nsource \"source1\" {\n    // Attributes can be added here\n}\n```\n\n#### Pool\n\nA pool process stores resources.\n\n```rust\npool \"pool1\" {\n    capacity: 10.0  // Optional capacity limit\n}\n```\n\n#### Drain\n\nA drain process consumes resources, effectively removing them from the simulation.\n\n```rust\ndrain \"drain1\" {\n    // Attributes can be added here\n}\n```\n\n#### Delay\n\nA delay process holds resources for a period before releasing them. It can be used to model processing time or transport delays. The delay process supports two modes:\n\n1. **Delay Mode (default)**: Each resource is delayed independently for the specified time period before being released.\n2. **Queue Mode**: Resources are accumulated and released in fixed amounts after the delay period, like a batch processor.\n\n```rust\n// Delay mode (default) - each resource is delayed independently\ndelay \"delay1\" {\n    action: DelayAction::Delay  // Optional: this is the default\n}\n\n// Queue mode - resources are released in batches\ndelay \"delay2\" {\n    action: DelayAction::Queue,\n    release_amount: 2.0  // Optional: amount to release per cycle (default: 1.0)\n}\n```\n\nThe delay time is determined by the `flow_rate` of the outgoing connection, where a flow rate of 1.0 equals one time unit of delay.\n\n### Connections\n\nConnections define how resources flow between processes.\n\n```rust\n\"source1.out\" -\u003e \"pool1.in\" {\n    id: \"conn1\",\n    flow_rate: 1.0  // Optional flow rate\n}\n```\n\nThe connection syntax uses the format `\"process_id.port\"` for both source and target endpoints. If the port is omitted, the default port for the process type is used.\n\n### Running Simulations\n\nYou can use the `run_simulation!` macro to create and run a simulation in one step:\n\n```rust\nlet results = run_simulation! {\n    steps: 5,  // Run for 5 steps\n    processes {\n        source \"source1\" {}\n        pool \"pool1\" {}\n    }\n    connections {\n        \"source1.out\" -\u003e \"pool1.in\" {\n            id: \"conn1\",\n            flow_rate: 1.0\n        }\n    }\n}?;\n```\n\nOr run until a specific time:\n\n```rust\nlet results = run_simulation! {\n    until: 10.0,  // Run until time = 10.0\n    processes {\n        source \"source1\" {}\n        pool \"pool1\" {}\n    }\n    connections {\n        \"source1.out\" -\u003e \"pool1.in\" {\n            id: \"conn1\",\n            flow_rate: 1.0\n        }\n    }\n}?;\n```\n\n## Examples\n\n### Multiple Sources to Pool\n\n```rust\nlet mut sim = simulation! {\n    processes {\n        source \"source1\" {}\n        source \"source2\" {}\n        pool \"pool1\" {}\n    }\n    connections {\n        \"source1.out\" -\u003e \"pool1.in\" {\n            id: \"conn1\",\n            flow_rate: 1.0\n        }\n        \"source2.out\" -\u003e \"pool1.in\" {\n            id: \"conn2\",\n            flow_rate: 2.0\n        }\n    }\n}?;\n```\n\n### Pool with Capacity\n\n```rust\nlet mut sim = simulation! {\n    processes {\n        source \"source1\" {}\n        pool \"pool1\" {\n            capacity: 3.0  // Pool will not accept more than 3.0 resources\n        }\n    }\n    connections {\n        \"source1.out\" -\u003e \"pool1.in\" {\n            id: \"conn1\",\n            flow_rate: 1.0\n        }\n    }\n}?;\n```\n\n### Resource Processing Chain\n\nThis example demonstrates both delay modes in a processing chain:\n\n```rust\nlet mut sim = simulation! {\n    processes {\n        source \"input\" {}\n        delay \"individual_processor\" {\n            action: DelayAction::Delay  // Process each resource independently\n        }\n        delay \"batch_processor\" {\n            action: DelayAction::Queue,\n            release_amount: 3.0  // Process resources in batches of 3\n        }\n        drain \"output\" {}\n    }\n    connections {\n        \"input.out\" -\u003e \"individual_processor.in\" {\n            id: \"input_flow\",\n            flow_rate: 1.0\n        }\n        \"individual_processor.out\" -\u003e \"batch_processor.in\" {\n            id: \"middle_flow\",\n            flow_rate: 2.0  // 2 time units delay\n        }\n        \"batch_processor.out\" -\u003e \"output.in\" {\n            id: \"output_flow\",\n            flow_rate: 1.0\n        }\n    }\n}?;\n```\n\nIn this example:\n1. Resources flow from the source to an individual processor that delays each resource by 1 time unit\n2. Then they pass through a batch processor that accumulates resources and releases them in groups of 3 after a 2 time unit delay\n3. Finally, the processed resources are consumed by the drain\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbenschza%2Fsimcraft","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbenschza%2Fsimcraft","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbenschza%2Fsimcraft/lists"}