-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsimulator.py
38 lines (37 loc) · 959 Bytes
/
simulator.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
import random
from controller import *
from vehicle import *
import sys
class Simulator:
def __init__(self,seed):
random.seed(seed)
limit = 18000
demand = 400.0
ts1 = []
ts2 = []
pct = 0.9
for i in range(int(demand*pct)):
ts1.append(random.randint(0,limit))
for i in range(int(demand*(1.0-pct))):
ts2.append(random.randint(0,limit))
p1 = Phase(300,500, True)
app1 = Approach(p1, 4000, ts1)
p2 = Phase(300,500, False)
app2 = Approach(p2, 4000, ts2)
controller = Controller([p1,p2])
i = 0
while i < limit:
i+=1
app1.advance(i)
app2.advance(i)
veh1 = None
veh2 = None
if len(app1.vehs)>0 :
veh1 = app1.vehs[0]
veh1 = veh1.pastPositions[-1]
if len(app1.vehs) > 1:
veh2 = app1.vehs[1]
veh2 = veh2.pastPositions[-1]
#print("\r"+str(veh1)+"\t"+str(veh2)+"\t"+str(app1.phase.isRed[-1]))
controller.advance()
#print(len(app1.vehs)+len(app2.vehs))