1.exa.sumocfg
<configuration>
<input>
<net-file value="bilibili.net.xml"/>
<route-files value="routes.rou.xml"/>
</input>
<time>
<begin value="0"/>
<end value="10000"/>
<step-length value="0.1"/>
</time>
<report>
<no-step-log value="true"/>
</report>
<gui_only>
<start value="true"/>
<quit-on-end value="true"/>
</gui_only>
</configuration>
2.sim.py
import optparse
import sys
import time
import traci
from sumolib import checkBinary
import os
if 'SUMO_HOME' in os.environ:
sys.path.append(os.path.join(os.environ['SUMO_HOME'], 'tools'))
else:
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
def get_options():
optParser = optparse.OptionParser()
optParser.add_option("--nogui", action="store_true",
default=False, help="run the commandline version of sumo")
options, args = optParser.parse_args()
return options
def run():
while traci.simulation.getMinExpectedNumber() > 0:
traci.simulationStep()
time.sleep(0.1)
ElapsedTime = traci.simulation.getTime()
all_vehicle_id = traci.vehicle.getIDList()
print("ElapsedTime", ElapsedTime, "car_list", all_vehicle_id)
traci.close()
sys.stdout.flush()
if __name__ == "__main__":
options = get_options()
if options.nogui:
sumoBinary = checkBinary('sumo')
else:
sumoBinary = checkBinary('sumo-gui')
sumo_file = "F:\\workSpace\\sumo\\scenario_test\\exa.sumocfg"
traci.start([sumoBinary, "-c", sumo_file])
run()
3.效果图