Dear Sir,
I have managed to write the code to subscribe for junction i.e. When vehicle reach at the junction color of the vehicle will change.
Issue : But it changes color when it reach to the last subscribed junction.
My aim is to change color at all the junction.
def run():
"""execute the TraCI control loop"""
step = 0
while traci.simulation.getMinExpectedNumber() > 0:
traci.simulationStep()
if(str(traci.junction.getContextSubscriptionResults(junctionID)) != "None"):
dict = traci.junction.getContextSubscriptionResults(junctionID)
key, value = dict.items()[0] #Here Key is Vehicle Id and Value is Speed at junnction
traci.vehicle.setColor(key, (255,0,0))
step += 1
traci.close()
sys.stdout.flush()
def generate_routefile():
# Code for printing to a file
sample = open('dijkstra_000.rou.xml', 'w')
print("""<routes>
<vType id="vehicle1" accel="0.8" decel="4.5" sigma="0.5" length="5" minGap="2.5" maxSpeed="16.67" guiShape="passenger"/>
<flow id="Car" begin="0" end="3600" number="100" from="1" to="18"/> </routes>""", file = sample)
sample.close()
def get_options():
optParser = optparse.OptionParser()
optParser.add_option("--nogui", action=""> default=False, help="run the commandline version of sumo")
options, args = optParser.parse_args()
return options
# this is the main entry point of this script
if __name__ == "__main__":
options = get_options()
# this script has been called from the command line. It will start sumo as a
# server, then connect and run
if options.nogui:
sumoBinary = checkBinary('sumo')
else:
sumoBinary = checkBinary('sumo-gui')
generate_routefile()
# this is the normal way of using traci. sumo is started as a
# subprocess and then the python script connects and runs
traci.start([sumoBinary, "-c", "dijkstra.sumo.cfg", "--tripinfo-output", "tripinfo.xml","--device.emissions.probability","1","--emission-output","emmission_aco.xml"])
JunctioID_list = traci.junction.getIDList()
for junctionID in JunctioID_list:
print(str(junctionID))
traci.junction.subscribeContext(junctionID, tc.CMD_GET_VEHICLE_VARIABLE, 10, [tc.VAR_SPEED])
run()
--