-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
78 lines (63 loc) · 1.72 KB
/
main.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
package main
import (
"flag"
"fmt"
"log"
"os"
"time"
"github.com/zkmrgirish/iob-dtn/env"
"github.com/zkmrgirish/iob-dtn/env/manager"
"github.com/zkmrgirish/iob-dtn/env/policy"
"github.com/zkmrgirish/iob-dtn/env/sensor"
"github.com/zkmrgirish/iob-dtn/env/util"
)
func main() {
var simulationTime int
flag.IntVar(&simulationTime, "env-time", 30, "simulation time in second")
flag.Parse()
policies := []policy.Policy{
policy.New(policy.KONP_POLICY),
policy.New(policy.NP_POLICY),
policy.New(policy.GPP_POLICY),
policy.New(policy.LC_POLICY),
}
names := []string{"konp", "np", "gpp", "lc"}
for i, p := range policies {
RunSimulationWithPolicy(p, simulationTime, names[i])
}
}
func RunSimulationWithPolicy(p policy.Policy, simulationTime int, name string) {
manager.Erase()
spos := []util.Position{
util.Position{X: 0, Y: 0},
util.Position{X: 25, Y: 25},
util.Position{X: 0, Y: 25},
util.Position{X: 25, Y: 0},
util.Position{X: 5, Y: 15},
util.Position{X: 12, Y: 25},
util.Position{X: 25, Y: 12},
util.Position{X: 13, Y: 6},
util.Position{X: 10, Y: 14},
}
stop := make(chan bool)
var sensors []sensor.Sensor
for i := 1; i <= len(spos)*int(env.Num_cycles_per_station); i++ {
manager.Register(i)
sensors = append(sensors, sensor.New(i, p))
}
envr := env.New(spos, sensors, stop)
envr.StartSimulation()
time.Sleep(time.Duration(simulationTime) * time.Second)
for i := 1; i <= 7*int(env.Num_cycles_per_station); i++ {
stop <- true
}
filename := fmt.Sprintf("result.%s.csv", name)
file, err := os.Create(filename)
if err != nil {
log.Printf("can not create %s\n", filename)
return
}
defer file.Close()
fmt.Fprint(file, manager.Manager)
fmt.Printf("result for %s written\n", name)
}