-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.py
145 lines (103 loc) · 4.82 KB
/
main.py
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
import sys
import common
import fcfs
import fcfs_AC
import edf
import edf_AC_Basic
import edf_AC_Pro
import llfSimple
import llfSimple_AC_Basic
import llfSimple_AC_Pro
import llfSmart
import llfSmart_AC_Basic
import dsac
import poissonGen
import csvGen
import gc
import vehicle
if len( sys.argv ) != 2:
print 'Wrong Number of Arguments you sent', sys.argv , " .. just interval"
sys.exit()
interval = int( sys.argv[ 1 ] )
common.setInterval(interval)
# ------------------ real simulations -------------------------
# do tons and tons of simulations
arrivalRate = 1
numIterations = 1
arrivalStep = 1
numRunsPerIteration = 5
simulationProfitData = [ ]
simulationSuccessData = [ ]
simulationSuccessDataWithDeclined = [ ]
simulationElapsedTimeData = [ ]
for i in range( numIterations ):
averageRates = [ 0 ] * 11 # a spot for every algo
averageRatesWithDeclined = [ 0 ] * 11
averageProfits = [ 0 ] * 11
averageElapsedTimes = [ 0 ] * 11
for k in range( numRunsPerIteration ):
gc.collect()
#print"--------------------------"
poissonGen.setArrivalRate( arrivalRate )
simulationInterval = poissonGen.simulateInterval()
# don't want a simulation with no cars
while common.numberOfVehiclesInSimulation == 0:
simulationInterval = poissonGen.simulateInterval()
# common.vehicleIdsIn2DList( simulationInterval )
#----------------fcfs----------------
fcfsData = fcfs.simulate( simulationInterval )
fcfsACData = fcfs_AC.simulate( simulationInterval )
#----------------edf----------------
edfData = edf.simulate( simulationInterval )
edfACBasicData = edf_AC_Basic.simulate( simulationInterval )
edfACProData = edf_AC_Pro.simulate( simulationInterval )
#----------------llfSimple----------------
llfSimpleData = llfSimple.simulate( simulationInterval )
llfSimpleACBasicData = llfSimple_AC_Basic.simulate( simulationInterval )
llfSimpleACProData = llfSimple_AC_Pro.simulate( simulationInterval )
#----------------llfSmart----------------
llfSmartData = llfSmart.simulate( simulationInterval )
llfSmartACBasicData = llfSmart_AC_Basic.simulate( simulationInterval )
#----------------dsac----------------
dsacData = dsac.simulate( simulationInterval )
# common.vehicleIdsIn2DList( simulationInterval )
runData = [ fcfsData , fcfsACData, edfData , edfACBasicData , edfACProData , llfSimpleData , llfSimpleACBasicData , llfSimpleACProData , llfSmartData , llfSmartACBasicData , dsacData ]
runProfits = [ 0 ] * 11
runSuccessRates = [ 0 ] * 11
runElapsedTimes = [ 0 ] * 11
runSuccessRatesWithDeclined = [ 0 ] * 11
for index , algoData in enumerate( runData ):
runProfits[ index ] = algoData[ 0 ]
runSuccessRates[ index ] = ( 1.0 * algoData[ 1 ] ) / ( algoData[ 1 ] + algoData[ 2 ] )
runSuccessRatesWithDeclined[ index ] = ( 1.0 * algoData[ 1 ] ) / algoData[ 4 ]
runElapsedTimes[ index ] = algoData[ 5 ]
for index, rate in enumerate( runSuccessRates ):
averageRates[ index ] += rate
for index, rate in enumerate( runSuccessRatesWithDeclined ):
averageRatesWithDeclined[ index ] += rate
for index, profit in enumerate( runProfits ):
averageProfits[ index ] += profit
for index, time in enumerate( runElapsedTimes ):
averageElapsedTimes[ index ] += time
for n in range( len( averageRates ) ):
averageRates[ n ] /= ( numRunsPerIteration * 1.0 )
for n in range( len( averageRatesWithDeclined ) ):
averageRatesWithDeclined[ n ] /= ( numRunsPerIteration * 1.0 )
for n in range( len( averageProfits ) ):
averageProfits[ n ] /= ( numRunsPerIteration * 1.0 )
for n in range( len( averageElapsedTimes ) ):
averageElapsedTimes[ n ] /= ( numRunsPerIteration * 1.0 )
simulationSuccessData.append( [ arrivalRate ] + averageRates )
simulationSuccessDataWithDeclined.append( [ arrivalRate ] + averageRatesWithDeclined )
simulationProfitData.append( [ arrivalRate ] + averageProfits )
simulationElapsedTimeData.append( [ arrivalRate ] + averageElapsedTimes )
arrivalRate += arrivalStep
if i % 10 == 0:
print "iteration: " , i, " arrival rate: ", arrivalRate
print "averageRates: ", averageRates
print "averageRatesWithDeclined", averageRatesWithDeclined
print "averageProfits: ", averageProfits
csvGen.exportSimulationDataToCSV( simulationSuccessData , "Success" )
csvGen.exportSimulationDataToCSV( simulationSuccessDataWithDeclined , "Success With Declines" )
csvGen.exportSimulationDataToCSV( simulationProfitData , "Profits" )
csvGen.exportSimulationDataToCSV( simulationElapsedTimeData , "Elapsed Time" )