-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathalgo.py
70 lines (40 loc) · 1.57 KB
/
algo.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
from __future__ import absolute_import
from __future__ import print_function
import time
import os
import sys
import optparse
import subprocess
import random
import traci
try:
tools=os.path.join(os.environ['SUMO_HOME'],'tools')
sys.path.append(tools)
except ImportError:
sys.exit("please declare environment variable 'SUMO_HOME' as the root directory of your sumo installation (it should contain folders 'bin', 'tools' and 'docs')")
sumoBinary = "C:\\Program Files (x86)\\DLR\\Sumo\\bin\\sumo-gui"
sumoCmd = [sumoBinary, "-c", "C:\\Users\\nived\\Desktop\\sumo_experimentation\\FTM_remastered\\intersection3\\intersection3.sumocfg"]
traffic_lights = []
current_states = []
traci.start(sumoCmd)
while traci.simulation.getMinExpectedNumber() > 0:
traci.simulationStep()
traffic_lights = traci.trafficlights.getIDList()
for i in traffic_lights:
current_states.append(traci.trafficlights.getRedYellowGreenState(i))
throughput1 = []
throughput2 = []
l1 = []
l1.append(traci.inductionloop.getLastStepVehicleNumber("0"))
l1.append(traci.inductionloop.getLastStepVehicleNumber("1"))
l1.append(traci.inductionloop.getLastStepVehicleNumber("2"))
l1.append(traci.inductionloop.getLastStepVehicleNumber("3"))
throughput1.extend(l1)
l2 = []
l2.append(traci.inductionloop.getLastStepVehicleNumber("4"))
l2.append(traci.inductionloop.getLastStepVehicleNumber("5"))
l2.append(traci.inductionloop.getLastStepVehicleNumber("6"))
l2.append(traci.inductionloop.getLastStepVehicleNumber("7"))
throughput2.extend(l2)
print(throughput1,throughput2)
traci.close()