forked from agoussia/godes
/
example0.go
45 lines (39 loc) · 1.13 KB
/
example0.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
// Copyright 2013 Alex Goussiatiner. All rights reserved.
// Use of this source code is governed by a MIT
// license that can be found in the LICENSE file.
package main
import (
"fmt"
"godes"
)
// the arrival and service are two random number generators for the uniform distribution
var arrival *godes.UniformDistr = godes.NewUniformDistr()
// 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()
}