-
Notifications
You must be signed in to change notification settings - Fork 0
/
run_experiments.go
157 lines (139 loc) · 4.08 KB
/
run_experiments.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
package main
import (
"fmt"
"time"
)
func RunExperiments() {
fmt.Println("Started experiment")
runExperimentCarDistributionTypeExperiment()
varyingAccidentProbExperiment()
intersectionProbabilityExperiment()
laneAccidentProb()
fmt.Println("Completed experiment")
}
func laneAccidentProb() {
fmt.Println("Test varying lane Accident Prob")
config := DefaultGeneralLaneConfig()
config.accidentScaling = false
config.accidentProb = 0
config.numVerticalCars = 10
config.numHorizontalCars = 10
config.numVerticalLanes = 1
config.numHorizontalLanes = 1
config.carMovementP = 1
config.accidentProb = 0
config.reSampleSpeedEveryClk = false
laneSwitchProb := []float64{0, 0.25, 0.5, 0.75, 1}
for _, prob := range laneSwitchProb {
config.probSwitchingLanes = prob
fmt.Println("lane switch probability: ", prob)
lanes := []int{1, 2, 5, 10}
for _, lane := range lanes {
fmt.Println("Lane size of: ", lane)
config.numVerticalLanes = lane
config.numHorizontalLanes = lane
runExperiment(config)
}
}
}
func intersectionProbabilityExperiment() {
fmt.Println("Test varying intersection accident probabilties")
config := DefaultGeneralLaneConfig()
config.accidentScaling = false
config.accidentProb = 0
config.numVerticalCars = 10
config.numHorizontalCars = 10
config.numVerticalLanes = 1
config.numHorizontalLanes = 1
config.carMovementP = 1
config.accidentProb = 0
config.reSampleSpeedEveryClk = false
intersectionAccidentProb := []float64{0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1}
lambas := []float64{0, 0.5, 1, 2, 5}
for _, lambda := range lambas {
config.carClock = lambda
for _, prob := range intersectionAccidentProb {
config.intersectionAccidentProb = prob
fmt.Println("Accident probability: ", prob)
runExperiment(config)
}
}
println("Now with accident scaling")
config.accidentScaling = true
for _, lambda := range lambas {
config.carClock = lambda
for _, prob := range intersectionAccidentProb {
config.intersectionAccidentProb = prob
fmt.Println("Accident probability: ", prob)
runExperiment(config)
}
}
}
func varyingAccidentProbExperiment() {
fmt.Println("Test varying accident probabilities")
config := DefaultGeneralLaneConfig()
config.accidentScaling = false
config.accidentProb = 0
config.numVerticalCars = 10
config.numHorizontalCars = 10
config.numVerticalLanes = 1
config.numHorizontalLanes = 1
config.reSampleSpeedEveryClk = true
config.carMovementP = 1
accidentProbs := []float64{0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1}
for _, prob := range accidentProbs {
config.accidentProb = prob
fmt.Println("Accident probability: ", prob)
runExperiment(config)
}
}
func runExperimentCarDistributionTypeExperiment() {
fmt.Println("Test running time with different car simulations")
config := DefaultGeneralLaneConfig()
config.accidentScaling = false
config.accidentProb = 0
config.numVerticalCars = 10
config.numHorizontalCars = 10
config.numVerticalLanes = 1
config.numHorizontalLanes = 1
config.reSampleSpeedEveryClk = true
config.carMovementP = 1
accidentProbs := []float64{0, 0.25, 0.5, 0.75, 1}
for _, prob := range accidentProbs {
config.accidentProb = prob
fmt.Println("Accident probability: ", prob)
for i := 0; i <= 4; i++ {
config.CarDistributionType = convertToCarDistributionType(i)
fmt.Println("Car Distribution Type", i)
runExperiment(config)
}
}
}
func runExperiment(config *GeneralLaneSimulationConfig) {
fmt.Println("start run simulation")
simulation, err := initMultiLaneSimulation(config)
simulation.setRunningSimulation(true)
if err != nil {
// TODO handle this
}
start := time.Now()
go RunGeneralSimulation(simulation)
for {
if !simulation.isRunningSimulation() {
fmt.Println("General Lane Simulation completed")
t := time.Now()
elapsed := t.Sub(start)
fmt.Println("Time Elapsed ", elapsed)
simulation.runningSimulationLock.Lock()
fmt.Println("Num Accidents ", simulation.numAccidents)
simulation.runningSimulationLock.Unlock()
return
}
select {
case <-simulation.drawUpdateChan:
fmt.Println(simulation)
break
}
time.Sleep(1000)
}
}