MCPcopy Index your code
hub / github.com/agoussia/godes

github.com/agoussia/godes @v1.0

Chat with this repo
repository ↗ · DeepWiki ↗ · release v1.0 ↗ · + Follow
161 symbols 340 edges 14 files 71 documented · 44%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

Godes

Open Source Library to Build Discrete Event Simulation Models in Go/Golang (http://golang.org/)

Copyright (c) 2013-2015 Alex Goussiatiner agoussia@yahoo.com

Features

Godes is the general-purpose simulation library which includes the simulation engine and building blocks for modeling a wide variety of systems at varying levels of details.

Active Objects

All active objects shall implement the RunnerInterface and have Run() method. For each active object Godes creates a goroutine - lightweight thread.

Random Generators

Godes contains set of built-in functions for generating random numbers for commonly used probability distributions. Each of the distrubutions in Godes has one or more parameter values associated with it: Uniform (Min, Max), Normal (Mean and Standard Deviation), Exponential (Lambda), Triangular(Min, Mode, Max)

Queues

Godes implements operations with FIFO and LIFO queues

BooleanControl

Godes uses BooleanControl variable as a lock for synchronizing execution of multiple runners

StatCollector

The Object calculates and prints statistical parameters for set of samples collected during the simulation.

Library Docs

GoDoc

Advantages

  • Godes is easy to learn for the people familiar with the Go and the elementary simulation concept.
  • Godes model executes fast as Go compiles to machine code. Its performace is similar to C++ in performance.
  • Godes model is multiplatform as Go compiler targets the Linux, Mac OS X, FreeBSD, Microsoft Windows,etc.
  • Godes model can be embedded in various computer systems and over the network.
  • Speed of the Godes model compilation is high.
  • Variety of the IDE with debuggers are available for Go and Godes as well.
  • The Godes sumulation model can use all of the GO's features and libraries.
  • Code Security - the Godes includes the source code for the library and Go is an open source project supported by Google.
  • Godes is free open source software under MIT license.

Installation

$ go get github.com/agoussia/godes

Examples

Example 0. Restaurant.Godes Basics

Proces Description

During the working day the visitors are entering the restaurant at random intervals and immediately get the table. The inter arrival interval is the random variable with uniform distribution from 0 to 70 minutes. The last visitor gets admitted not later than 8 hours after the opening. The simulation itself is terminated when the last visitors enters the restaurant.

package main

import (
    "fmt"
    "godes"
)

// the arrival and service are two random number generators for the uniform  distribution
var arrival *godes.UniformDistr = godes.NewUniformDistr(true)

// the Visitor is a Runner
// any type of the Runner should be defined as struct
// with the *godes.Runner as anonimous field
type Visitor struct {
    *godes.Runner
    number int
}

var visitorsCount int = 0

func (vst *Visitor) Run() { // Any runner should have the Run method
    fmt.Printf(" %-6.3f \t Visitor # %v arrives \n", godes.GetSystemTime(), vst.number)
}
func main() {
    var shutdown_time float64 = 8 * 60
    godes.Run()
    for {
        //godes.Stime is the current simulation time
        if godes.GetSystemTime() < shutdown_time {
            //the function acivates the Runner
            godes.AddRunner(&Visitor{&godes.Runner{}, visitorsCount})
            //this advance the system time
            godes.Advance(arrival.Get(0, 70))
            visitorsCount++
        } else {
            break
        }
    }
    // waits for all the runners to finish the Run()
    godes.WaitUntilDone()
}
/*  OUTPUT:
 0.000       Visitor # 0 arrives 
 37.486      Visitor # 1 arrives 
 98.737      Visitor # 2 arrives 
 107.468     Visitor # 3 arrives 
 149.471     Visitor # 4 arrives 
 207.523     Visitor # 5 arrives 
 230.922     Visitor # 6 arrives 
 261.770     Visitor # 7 arrives 
 269.668     Visitor # 8 arrives 
 310.261     Visitor # 9 arrives 
 338.323     Visitor # 10 arrives 
 397.720     Visitor # 11 arrives 
 409.123     Visitor # 12 arrives 
 436.817     Visitor # 13 arrives 
 447.731     Visitor # 14 arrives 
*/

Example 1. Restaurant. Godes Boolean Controls

Proces Description

The restaurant has only one table to sit on. During the working day the visitors are entering the restaurant at random intervals and wait for the table to be available. The inter arrival interval is the random variable with uniform distribution from 0 to 70 minutes.The time spent in the restaurant is the random variable with uniform distribution from 10 to 60 minutes. The last visitor gets admitted not later than 8 hours after the opening. The simulation itself is terminated when the last visitors has left the restaurant.

package main

import (
    "fmt"
    "godes"
)

// the arrival and service are two random number generators for the uniform  distribution
var arrival *godes.UniformDistr = godes.NewUniformDistr(true)
var service *godes.UniformDistr = godes.NewUniformDistr(true)

// tableBusy is the boolean control variable than can be accessed and changed by number of Runners
var tableBusy *godes.BooleanControl = godes.NewBooleanControl()

// the Visitor is a Runner
// any type of the Runner should be defined as struct // with the *godes.Runner as anonimous field
type Visitor struct {
    *godes.Runner
    number int
}

var visitorsCount int = 0

func (vst Visitor) Run() { // Any runner should have the Run method
    fmt.Printf("%-6.3f \t Visitor %v arrives \n", godes.GetSystemTime(), vst.number)
    tableBusy.Wait(false) // this will wait till the tableBusy control becomes false
    tableBusy.Set(true)   // sets the tableBusy control to true - the table is busy
    fmt.Printf("%-6.3f \t Visitor %v gets the table \n", godes.GetSystemTime(), vst.number)
    godes.Advance(service.Get(10, 60)) //the function advance the simulation time by the value in the argument
    tableBusy.Set(false)               // sets the tableBusy control to false - the table is idle
    fmt.Printf("%-6.3f \t Visitor %v leaves \n", godes.GetSystemTime(), vst.number)
}
func main() {
    var shutdown_time float64 = 8 * 60
    godes.Run()
    for {
        //godes.GetSystemTime() is the current simulation time
        if godes.GetSystemTime() < shutdown_time {
            //the function acivates the Runner
            godes.AddRunner(Visitor{&godes.Runner{}, visitorsCount})
            godes.Advance(arrival.Get(0, 70))
            visitorsCount++
        } else {
            break
        }
    }
    godes.WaitUntilDone() // waits for all the runners to finish the Run()
}
/* OUTPUT
0.000    Visitor 0 arrives 
0.000    Visitor 0 gets the table 
13.374   Visitor 0 leaves 
37.486   Visitor 1 arrives 
37.486   Visitor 1 gets the table 
60.558   Visitor 1 leaves 
98.737   Visitor 2 arrives 
98.737   Visitor 2 gets the table 
107.468  Visitor 3 arrives 
146.824  Visitor 2 leaves 
146.824  Visitor 3 gets the table 
149.471  Visitor 4 arrives 
171.623  Visitor 3 leaves 
171.623  Visitor 4 gets the table 
187.234  Visitor 4 leaves 
207.523  Visitor 5 arrives 
207.523  Visitor 5 gets the table 
230.922  Visitor 6 arrives 
245.859  Visitor 5 leaves 
245.859  Visitor 6 gets the table 
261.770  Visitor 7 arrives 
269.668  Visitor 8 arrives 
272.368  Visitor 6 leaves 
272.368  Visitor 7 gets the table 
290.484  Visitor 7 leaves 
290.484  Visitor 8 gets the table 
310.261  Visitor 9 arrives 
333.570  Visitor 8 leaves 
333.570  Visitor 9 gets the table 
338.323  Visitor 10 arrives 
354.874  Visitor 9 leaves 
354.874  Visitor 10 gets the table 
393.826  Visitor 10 leaves 
397.720  Visitor 11 arrives 
397.720  Visitor 11 gets the table 
409.123  Visitor 12 arrives 
436.817  Visitor 13 arrives 
447.731  Visitor 14 arrives 
455.705  Visitor 11 leaves 
455.705  Visitor 13 gets the table 
482.955  Visitor 13 leaves 
482.955  Visitor 12 gets the table 
496.034  Visitor 12 leaves 
496.034  Visitor 14 gets the table 
555.822  Visitor 14 leaves 
*/

Example 2. Restaurant. Godes Queues

Proces Description

During the four working hours the visitors are entering the restaurant at random intervals and form the arrival queue. The inter arrival interval is the random variable with uniform distribution from 0 to 30 minutes. The restaurant employs two waiters who are servicing one visitor in a time. The service time is the random variable with uniform distribution from 10 to 60 minutes. The simulation itself is terminated when * Simulation time passes the four hours * Both waiters have finished servicing
* There are no visitors in the arrival queue.

The model calculates the average (arithmetic mean) of the visitors waiting time

package main

import (
    "fmt"
    "godes"
)

// the arrival and service are two random number generators for the uniform  distribution
var arrival *godes.UniformDistr = godes.NewUniformDistr(true)
var service *godes.UniformDistr = godes.NewUniformDistr(true)

// true when waiter should act
var waitersSwt *godes.BooleanControl = godes.NewBooleanControl()

// FIFO Queue for the arrived
var visitorArrivalQueue *godes.FIFOQueue = godes.NewFIFOQueue("arrivalQueue")

// the Visitor is a Passive Object
type Visitor struct {
    id int
}

// the Waiter is a Runner
type Waiter struct {
    *godes.Runner
    id int
}

var visitorsCount int = 0
var shutdown_time float64 = 4 * 60

func (waiter *Waiter) Run() {

    for {
        waitersSwt.Wait(true)
        if visitorArrivalQueue.Len() > 0 {
            visitor := visitorArrivalQueue.Get()
            if visitorArrivalQueue.Len() == 0 {
                waitersSwt.Set(false)
            }
            fmt.Printf("%-6.3f \t Visitor %v is invited by waiter %v  \n", godes.GetSystemTime(), visitor.(Visitor).id, waiter.id)
            godes.Advance(service.Get(10, 60)) //advance the simulation time by the visitor service time
            fmt.Printf("%-6.3f \t Visitor %v leaves \n", godes.GetSystemTime(), visitor.(Visitor).id)

        }
        if godes.GetSystemTime() > shutdown_time && visitorArrivalQueue.Len() == 0 {
            fmt.Printf("%-6.3f \t Waiter  %v ends the work \n", godes.GetSystemTime(), waiter.id)
            break
        }
    }
}

func main() {

    for i := 0; i < 2; i++ {
        godes.AddRunner(&Waiter{&godes.Runner{}, i})
    }
    godes.Run()
    for {

        visitorArrivalQueue.Place(Visitor{visitorsCount})
        fmt.Printf("%-6.3f \t Visitor %v arrives \n", godes.GetSystemTime(), visitorsCount)
        waitersSwt.Set(true)
        godes.Advance(arrival.Get(0, 30))
        visitorsCount++
        if godes.GetSystemTime() > shutdown_time {
            break
        }
    }
    waitersSwt.Set(true)
    godes.WaitUntilDone() // waits for all the runners to finish the Run()
    fmt.Printf("Average Waiting Time %6.3f  \n", visitorArrivalQueue.GetAverageTime())
}
/* OUTPUT
0.000       Visitor 0 arrives 
0.000       Visitor 0 is invited by waiter 0  
13.374      Visitor 0 leaves 
16.066      Visitor 1 arrives 
16.066      Visitor 1 is invited by waiter 1  
39.137      Visitor 1 leaves 
42.316      Visitor 2 arrives 
42.316      Visitor 2 is invited by waiter 1  
46.058      Visitor 3 arrives 
46.058      Visitor 3 is invited by waiter 0  
64.059      Visitor 4 arrives 
70.857      Visitor 3 leaves 
70.857      Visitor 4 is invited by waiter 0  
86.468      Visitor 4 leaves 
88.938      Visitor 5 arrives 
88.938      Visitor 5 is invited by waiter 0  
90.403      Visitor 2 leaves 
98.966      Visitor 6 arrives 
98.966      Visitor 6 is invited by waiter 1  
112.187     Visitor 7 arrives 
115.572     Visitor 8 arrives 
125.475     Visitor 6 leaves 
125.475     Visitor 7 is invited by waiter 1  
127.275     Visitor 5 leaves 
127.275     Visitor 8 is invited by waiter 0  
132.969     Visitor 9 arrives 
143.591     Visitor 7 leaves 
143.591     Visitor 9 is invited by waiter 1  
144.995     Visitor 10 arrives 
164.895     Visitor 9 leaves 
164.895     Visitor 10 is invited by waiter 1  
170.361     Visitor 8 leaves 
170.451     Visitor 11 arrives 
170.451     Visitor 11 is invited by waiter 0  
175.338     Visitor 12 arrives 
187.207     Visitor 13 arrives 
191.885     Visitor 14 arrives 
203.848     Visitor 10 leaves 
203.848     Visitor 12 is invited by waiter 1  
213.596     Visitor 15 arrives 
228.436     Visitor 11 leaves 
228.436     Visitor 13 is invited by waiter 0  
231.098     Visitor 12 leaves 
231.098     Visitor 14 is invited by waiter 1  
231.769     Visitor 16 arrives 
241.515     Visitor 13 leaves 
241.515     Visitor 15 is invited by waiter 0  
287.864     Visitor 15 leaves 
287.864     Visitor 16 is invited by waiter 0  
290.886     Visitor 14 leaves 
290.886     Waiter  1 ends the work 
330.903     Visitor 16 leaves 
330.903     Waiter  0 ends the work 
Average Waiting Time 15.016  
*/

Example 3. Restaurant. Multiple Runs

Proces Description

This is the same process as in Example 2. Simulation is repeated 5 times. ```go package main

import ( "fmt" "godes" )

// the arrival and service are two random number generators for the uniform distribution var arrival godes.UniformDistr = godes.NewUniformDistr(true) var service godes.UniformDistr = godes.NewUniformDistr(true)

// true when waiter should act var waitersSwt *godes.BooleanControl = godes.NewBooleanControl()

// FIFO Queue for the arrived var visitorArrivalQueue *godes.FIFOQueue = godes.NewFIFOQueue("0")

// the Visitor is a Passive Object type Visitor struct { id int }

// the Waiter is a Runner type Waiter struct { *godes.Runner id int }

var visitorsCount int = 0 var shutdown_time float64 = 4 * 60

func (waiter *Waiter) Run() { for { waitersSwt.Wait(true) if visitorArrivalQueue.Len() > 0 { visitorArrivalQueue.Get() if visitorArrivalQueue.Len() == 0 { waitersSwt.Set(false) } godes.Advance(service.Get(10, 60)) //advance the simulation time by the visitor service time

    }
    if godes.GetSystemTime() > shutdown_time && visitorArrivalQueue.Len() == 0 {
        break
    }

}

}

func main() { for runs := 0; runs < 5; runs++ { for i := 0; i < 2; i++ { godes.AddRunner(&Waiter{&godes.Runner{}, i}) } godes.Run() for { visitorArrivalQueue.Place(Visitor{visitorsCount}) waitersSwt.Set(true) godes.Advance(arrival.Get(0, 30)) visitorsCount++ if godes.GetSystemTime() > shutdown_time { break } } waitersSwt.Set(true) godes.WaitUntilDone() // waits for all the runne

Extension points exported contracts — how you extend this code

RunnerInterface (Interface)
(no doc) [1 implementers]
runner.go

Core symbols most depended-on inside this repo

Get
called by 21
queue.go
Set
called by 20
controls.go
Len
called by 11
queue.go
Run
called by 9
runner.go
setState
called by 9
runner.go
getInternalId
called by 8
runner.go
Wait
called by 6
controls.go
GetSize
called by 6
util.go

Shape

Method 100
Function 34
Struct 26
Interface 1

Languages

Go100%

Modules by API surface

runner.go46 symbols
model.go31 symbols
util.go17 symbols
randgen.go13 symbols
queue.go12 symbols
examples/example7/example7.go7 symbols
controls.go7 symbols
examples/example6/example6.go6 symbols
examples/example4/example4.go5 symbols
examples/example3/example3.go4 symbols
examples/example2/example2.go4 symbols
examples/example5/example5.go3 symbols

For agents

$ claude mcp add godes \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact