Skip to main content

[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?

On Mon, Jul 23, 2018 at 10:10 PM himanshu soni <himanshusoni1333@xxxxxxxxx> wrote:
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.


On Mon, Jul 23, 2018 at 9:31 PM Jakob Erdmann <namdre.sumo@xxxxxxxxx> wrote:
Please take a closer look at the tutorials. They contain links to example files.

2018-07-23 17:34 GMT+02:00 himanshu soni <himanshusoni1333@xxxxxxxxx>:
Thanks for the response, it would be helpful if you could send me a sample project.

On Mon, Jul 23, 2018 at 5:23 PM Jakob Erdmann <namdre.sumo@xxxxxxxxx> wrote:

2018-07-23 11:46 GMT+02:00 himanshu soni <himanshusoni1333@xxxxxxxxx>:
Hello, 
I am a fresher to SUMO. Can anyone tell me if I can control my SUMO simulation with my self-made python programs? If yes, can anyone send me a simple program?

_______________________________________________
sumo-user mailing list
sumo-user@xxxxxxxxxxx
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/sumo-user


_______________________________________________
sumo-user mailing list
sumo-user@xxxxxxxxxxx
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/sumo-user

_______________________________________________
sumo-user mailing list
sumo-user@xxxxxxxxxxx
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/sumo-user


_______________________________________________
sumo-user mailing list
sumo-user@xxxxxxxxxxx
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/sumo-user
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()

Back to the top