GithubHelp home page GithubHelp logo

aybabtme / desim Goto Github PK

View Code? Open in Web Editor NEW
13.0 2.0 1.0 5.68 MB

Discrete Event Simulations

License: MIT License

Go 100.00%
simulation actors event-scheduler golang golang-package modelling scheduled-events

desim's Introduction

desim

Discrete Event Simulations

Focus on your model, desim handles the rest.

about

desim is a framework that allows one to quickly produce programs that implement a simulation. desim takes care of scheduling events in a simulation and gathering results, and lets you focus on the model you want to simulate.

desim is a simple package for one off simulations, but long term is meant to become a development environment platform for distributed simulations.

example

If you model a clock like this:

func clock(iter int, dur time.Duration) desim.Action {
	pdur := gen.StaticDuration(dur)
	return func(env desim.Env) bool {
		iter--
		env.Log().Event("woke up, about to sleep")

		if env.Sleep(pdur) {
			env.Log().Event("couldn't sleep")
			return false
		}
		return iter > 0
	}
}

And would like to play a simulation with 2 clocks, a fast and a slow one:

slowActor := desim.MakeActor("slow", clock(6, 1*time.Second))
fastActor := desim.MakeActor("fast", clock(6, 500*time.Millisecond))

You can! Just create an event scheduler, some parameters for time, and run your actors to see how they would behave:

var (
	r     = rand.New(rand.NewSource(42))
	start = time.Unix(0, 0).UTC()
	end   = start.Add(10 * time.Second)
)

sim := desim.New(
	desim.NewLocalScheduler,
	r,
	gen.StaticTime(start),
	gen.StaticTime(end),
)

history := sim.Run(
	[]*desim.Actor{
		slowActor,
		fastActor,
	},
	desim.LogJSON(ioutil.Discard),
)

Where history represents what events were scheduled, and desim.LogJSON records what the actors have emitted during that time (in our case, that goes to /dev/null).

performance

Simulations happen in simulated times: time goes as fast as possible. The speed at which the simulation runs grows linearly with the number of events happening over time.

For instance, if we simulate 1 hour worth of N actors performing events every 500ms, we see that the time it takes to simulate this hour is linear with the number of actors involved (and thus, with the frequency of events).

Time to simulate 1h worth of events

Similary, if we have a single actor simulation, but with the actor performing events at a fixed frequency, we see that this linear relation holds:

Time to simulate 1h worth of events

license

MIT license

desim's People

Contributors

aybabtme avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

etsangsplk

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.