Coder Social home page Coder Social logo

litesim's Introduction

LiteSim

A discrete-event simulation library.

Features

LiteSim is rougly based on Discrete Event System Specification (DEVS) which allows a modular design of simulations.

  • A simulation is composed out of models which can communicate with each other through connections.
  • Multiple models can be composed together to form a more complex behavior.
  • Model inputs and outputs are type safe.

It's very easy and straightforward to implement new models through a single Model trait with #[litesim_model] annotation:

pub struct Player;

#[litesim_model]
impl<'s> Model<'s> for Player {
    #[input(signal)]
    fn receive(&self, ctx: ModelCtx<'s>) -> Result<(), SimulationError> {
        ctx.schedule_update(Now)?;
        Ok(())
    }

    #[output(signal)]
    fn send(&self);

    fn handle_update(&mut self, ctx: ModelCtx<'s>) -> Result<(), SimulationError> {
        log::info!(
            "Player {} got the ball at {}",
            ctx.model_id.as_ref(),
            ctx.time
        );
        self.send(In(ctx.rand_range(0.0..1.0)))?;
        Ok(())
    }
}

Flags

LiteSim supports multiple different time values which can be controlled through feature flags:

  • f32 - flag: time_f32; default
  • f64 - flag: time_f64
  • chrono - flag: time_chrono

Support for serde is enabled through the serde feature flag.

Support for random value generation can be enabled through the rand feature flag.

Wanted features

  • Serde support for systems as well as simulations in progress.
  • Backtracking support for systems with models that support it.
  • Multithreading support

Alternatives

  • sim - initial inspiration for this library
    • requires more boilerplate to implement models, but supports serde and WASM
  • sequent
    • supports backtracking and serde
  • asynchronix
    • handles events as futures

License

This project is licensed under zlib, MIT, or Apache-2.0 license, choose whichever suits you most.

litesim's People

Contributors

caellian avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.