Coder Social home page Coder Social logo

lunduniversity / scalades Goto Github PK

View Code? Open in Web Editor NEW
8.0 3.0 1.0 1.53 MB

Descrete Event Simulation in Scala

License: GNU Affero General Public License v3.0

Scala 69.04% Java 6.08% Shell 1.94% C 3.88% C++ 3.68% Go 2.22% HTML 2.59% Julia 2.39% Pascal 4.55% Python 3.61%

scalades's Introduction

scalades

scalades is a library for empirical investigation of real-world systems using stochastic Descrete-Event Simulation (DES) models in the Scala programming language.

This library is work in progress in its early stages, so the api is likely to change. Contributions are welcome! Contact [email protected]

scalades follow the terminology and principles of on Stochastic Discrete Event Simulation taught in this course on Simulation at Lund University.

How to use scalades

  • Pre-requisites: install sbt (requires JDK)

  • Clone this repo or download and extract this zip

  • Navigate to the scalades folder and do this in terminal:

$ sbt
sbt:scalades> runMain scalades.example.runMM1 9 10 10000 

You should get an output similar to:

[info] running scalades.example.runMM1 9 10 10000
---- SIMULATION START -----
Number of samples: 9828
Average queue length: 10.33536833536831
Execution time: 0.543 seconds
Last event at time stamp: 9999.9100217340560922411402 time units
SIMULATION END AFTER 10000.0 time units
[success] Total time: 1 s, completed Mar 24, 2021, 11:30:21 PM

Design approach

The main goal of scalades is to provide an easy-to-use library that supports the modelling of systems in the paradigm of stochastic Discrete Event Simulation.

Message passing

The world is modelled using events that are happening when processes send signals among each other. Each event has a decimal timestamp ordered in an event queue, with the event with the soonest time stamp first. The simulation time can directly jump to the time of the occurring next event, allowing efficient simulation of real-world systems in pseudo-time instead of real time.

Non-parallell, co-operative concurrency

Although a process can model behaviour that happens concurrently in the real world, the simulation model itself is executed in one single thread with co-operative, non-parallell concurrency through scheduling of process execution based on synchronous, sequential event dispatching. The Simulation class is responsible for the event dispatching.

Each simulation in a single thread executed in parallell

Multiple simulations can be executed independently of each other in different threads to allow efficient exploration of different simulation parameters in parallell using many CPU threads.

Utilizing the modelling power and execution efficiency of Scala 3

The scalades library is implemented in Scala 3, utilizing new language constructs such as enums for enumerating signals and states, opaque type aliases for unboxed Time values, extension methods and export clauses to shape the api, and contextual abstraction to provide a given simulation context to the implicit using by its processes.

We have conducted a series of benchmarks, indicating that Scala Native is a very promising runtime for scalades that may be even faster than the JVM. When Scala Native is available for Scala 3 our intention is to publish this library also for bare metal execution.

For more information on Scala native performance and further benchmarking using scalades in Scala Native, see this blog post by Wojciech Mazur:Revisiting Scala Native performance

TODO

  • Should Time be a Double or BigDecimal? Floating-point numbers are strange when comparing with >= etc so precision might be an issue especially in long simulations where durations are much smaller than the simulation time stamps. But BigDecimal is significantly slower than Double. This is a trade-off between precision and performance that is interesting to explore in benchmarks.

  • What are the most important use cases left to implement for the Simulation course at Lund university?

  • add help for contributors

  • add more examples

  • do more benchmarks for performance evaluation

  • try out using Scala's Future to run several simulations in parallell on different CPU-threads

scalades's People

Contributors

bjornregnell avatar

Stargazers

 avatar spamegg avatar Jon avatar Gianluca Aguzzi avatar Pinar Oncel avatar Colby Cellador avatar Jeremy Daggett avatar Bengt Ericsson avatar

Watchers

James Cloos avatar  avatar Görel Hedin avatar

Forkers

rogerlarsson

scalades's Issues

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.