[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
Re: [sumo-user] newbie to sumo
|
Have a look at my code and help me understand what am I doing wrong?
I am used to generating using
.net.xml format and also with
NETEDIT, but I don't understand how to edit a particular network scenario using Python, like adding a car to a network. That's what I'm looking for.
from __future__ import absolute_import
from __future__ import print_function
import os
import sys
import optparse
import subprocess
import random
# we need to import python modules from the $SUMO_HOME/tools directory
try:
sys.path.append(os.path.join(os.path.dirname(
__file__), '..', '..', '..', '..', "tools")) # tutorial in tests
sys.path.append(os.path.join(os.environ.get("SUMO_HOME", os.path.join(
os.path.dirname(__file__), "..", "..", "..")), "tools")) # tutorial in docs
from sumolib import checkBinary # noqa
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')")
import sumolib
import traci
net = sumolib.net.readNet("net3.net.xml", withInternal=True)
edges = net.getEdges()
edgeLengths = {}
for edge in edges:
key = str(edge.getID())
edgeLengths[key] = str(edge.getLength())
def run():
traci.route.add("trip", ["gneE1", "-gneE17"])
traci.vehicle.add("newVeh", "trip", typeID="reroutingType")
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
# 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')
traci.start(
[sumoBinary, "-c", "config_file3.sumocfg", "--tripinfo-output", "tripinfo.xml", "--ignore-route-errors"])
run()