fschuetz04 / simgo

Discrete-event simulation in Go using goroutines

Home Page:https://pkg.go.dev/github.com/fschuetz04/simgo

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

SimGo

SimGo is a discrete event simulation framework for Go. It is similar to SimPy and aims to be easy to set up and use.

Processes are defined as simple functions receiving simgo.Process as their first argument. Each process is executed in a separate goroutine, but it is guarantueed that only one process is executed at a time. For examples, look into the examples folder. A short example simulating two clocks ticking in different time intervals looks like this:

package main

import (
    "fmt"

    "github.com/fschuetz04/simgo"
)

func clock(proc simgo.Process, name string, delay float64) {
    for {
        fmt.Println(name, proc.Now())
        proc.Wait(proc.Timeout(delay))
    }
}

func main() {
    sim := simgo.Simulation{}

    sim.ProcessReflect(clock, "slow", 2)
    sim.ProcessReflect(clock, "fast", 1)

    sim.RunUntil(5)
}

When run, the following output is generated:

slow 0
fast 0
fast 1
slow 2
fast 2
fast 3
slow 4
fast 4

You can find more examples in the examples directory.

Copyright and License

Copyright © 2021 Felix Schütz.

Licensed under the MIT License. See the LICENSE file for details.

About

Discrete-event simulation in Go using goroutines

https://pkg.go.dev/github.com/fschuetz04/simgo

License:MIT License


Languages

Language:Go 100.0%