I'm trying to find a way to control the traffic lights at multiple junctions in a single simulation. I've a grid of 4 x 4 with 16 traffic lights and I want to test a Global algorithm for optimizing traffic flows at each junction in the grid.
I'm using SUMO and python TRACI for this task. I've implemented several single junction local traffic light controlling algorithms earlier but I'm unable to figure out a simple method for multiple junction simulation. Some explanation/strategy or code snippets would be very helpful for me.
Thanks in advance!
Usually the pattern for a control algorithm with traci is
while traci.simulation.getMinExpectedNumber() > 0:
# retrieve data from detectors
# act on traffic light
traci.simulationStep()
There is nothing wrong with doing the following
while traci.simulation.getMinExpectedNumber() > 0:
# retrieve data from detectors
# act on traffic light 1
# act on traffic light 2
# ...
traci.simulationStep()
or even have multiple data retrieval steps interspersed. You can also use the traci step listener which calls arbitrary additional python functions or even connect multiple clients (although you need to know in advance how many). But in any case you will need to rework your existing algorithms in a way that you can separate the code which is done between two calls of simulation step and they somehow need all to operate at the same frequency.