gosim

package module
v0.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 2, 2020 License: MIT Imports: 4 Imported by: 0

README

gosim

A simple discrete event simulator in go

Build and Install

go get github.com/fengttt/gosim/...

The examples use pixel for display. Please follow the instruction to install requirements. For example, on ubuntu 18LTS, you need to

sudo apt isntall libgl1-meda-dev xorg-dev libglfw3 libglfw3-dev

If you are using windows, you need to follow build pixel on windows.

Examples

  • conway is a simulator for Conway's Game of Life. It includes several interesting inintial configurations.
go run examples/conway/conway.go diehard
  • spread is a very simple model for infectious disease.
go run examples/spread/spread.go -n 10 -r 0.08

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Agg

type Agg interface {
	Update(ival int64, fval float64)
	Get() (int64, float64)
	Gather(a Agg)
	Reset()
}

type Lp

type Lp interface {
	Run(s *Sim, r *Runner, msgs []interface{}) int64
}

Logic Process, which can run at certain tic. Run should return

  • positive int64, means this lp should be run again, at tic + ret
  • 0, means put this lp to sleep.
  • -1, means this lp should die,

type Lpid

type Lpid struct {
	RunnerId   int
	Id         int
	CreateTick int64
}

LP id

type Runner

type Runner struct {
	// contains filtered or unexported fields
}

Runner runs LPs.

func (*Runner) AddLp

func (r *Runner) AddLp(s *Sim, lp Lp) Lpid

func (*Runner) Rand

func (r *Runner) Rand() *rand.Rand

func (*Runner) RemoveLp

func (r *Runner) RemoveLp(lpid Lpid)

func (*Runner) UpdateAgg

func (r *Runner) UpdateAgg(aggId int, ival int64, fval float64)

type Sim

type Sim struct {
	// contains filtered or unexported fields
}

Sim: Simulation

func New

func New(nr int) *Sim

New creates a Sim with nr runners.

func (*Sim) AddLp

func (s *Sim) AddLp(r int, lp Lp) (Lpid, error)

AddLP adds a runner, returns lp id.

func (*Sim) CreateMax

func (s *Sim) CreateMax() int

CreateMax creates a max agg.

func (*Sim) CreateMin

func (s *Sim) CreateMin() int

CreateMin creates a min agg.

func (*Sim) CreateSum

func (s *Sim) CreateSum() int

CreateSum creates a sum agg.

func (*Sim) CurrentTick

func (s *Sim) CurrentTick() int64

CurrentTick returns current tick

func (*Sim) GetLp

func (s *Sim) GetLp(lpid Lpid) (Lp, error)

GetLP looks up lp from lpid.

func (*Sim) NumRunner

func (s *Sim) NumRunner() int

NumRunner returns Number of runners

func (*Sim) ReadAgg

func (s *Sim) ReadAgg(aggId int) (int64, float64)

ReadAgg reads the value of an agg.

func (*Sim) Run

func (s *Sim) Run(stop func(s *Sim) bool)

Run Sim, with a stop condition.

func (*Sim) RunSteps

func (s *Sim) RunSteps(nStep int64)

Run Sim

func (*Sim) Start

func (s *Sim) Start()

func (*Sim) Stop

func (s *Sim) Stop()

Directories

Path Synopsis
examples

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL