#!/usr/bin/python3

import os
import sys
import optparse

# we need to import some python modules from the $SUMO_HOME/tools directory
if 'SUMO_HOME' in os.environ:
    tools = os.path.join(os.environ['SUMO_HOME'], 'tools')
    sys.path.append(tools)
else:
    sys.exit("please declare environment variable 'SUMO_HOME'")


from sumolib import checkBinary  # Checks for the binary in environ vars
import traci


def get_options():
    opt_parser = optparse.OptionParser()
    opt_parser.add_option("--nogui", action="store_true",
                         default=False, help="run the commandline version of sumo")
    options, args = opt_parser.parse_args()
    return options


# contains TraCI control loop
def run():
    step = 0
    flag = False
    while traci.simulation.getMinExpectedNumber() > 0:
        traci.simulationStep()
        # print(step)

        cur_edge = traci.vehicle.getRoadID("1")
        if step > 100 and cur_edge == "e5":
            traci.vehicle.setRouteID("1", "route_1")
            flag = True

        if flag and cur_edge == "e6":
            traci.vehicle.setRouteID("1", "route_2")

        step += 1

    traci.close()
    sys.stdout.flush()


# main entry point
if __name__ == "__main__":
    options = get_options()

    # check binary
    if options.nogui:
        sumoBinary = checkBinary('sumo')
    else:
        sumoBinary = checkBinary('sumo-gui')

    # traci starts sumo as a subprocess and then this script connects and runs
    traci.start([sumoBinary, "-c", "demo.sumocfg",
                             "--tripinfo-output", "tripinfo.xml"])
    run()
8a92d275fe4dd3696c5020c3074765479ebc139d
<mask token>


def run():
    step = 0
    flag = False
    while traci.simulation.getMinExpectedNumber() > 0:
        traci.simulationStep()
        cur_edge = traci.vehicle.getRoadID('1')
        if step > 100 and cur_edge == 'e5':
            traci.vehicle.setRouteID('1', 'route_1')
            flag = True
        if flag and cur_edge == 'e6':
            traci.vehicle.setRouteID('1', 'route_2')
        step += 1
    traci.close()
    sys.stdout.flush()


<mask token>

<mask token>


def get_options():
    opt_parser = optparse.OptionParser()
    opt_parser.add_option('--nogui', action='store_true', default=False,
        help='run the commandline version of sumo')
    options, args = opt_parser.parse_args()
    return options


def run():
    step = 0
    flag = False
    while traci.simulation.getMinExpectedNumber() > 0:
        traci.simulationStep()
        cur_edge = traci.vehicle.getRoadID('1')
        if step > 100 and cur_edge == 'e5':
            traci.vehicle.setRouteID('1', 'route_1')
            flag = True
        if flag and cur_edge == 'e6':
            traci.vehicle.setRouteID('1', 'route_2')
        step += 1
    traci.close()
    sys.stdout.flush()


<mask token>

<mask token>
if 'SUMO_HOME' in os.environ:
    tools = os.path.join(os.environ['SUMO_HOME'], 'tools')
    sys.path.append(tools)
else:
    sys.exit("please declare environment variable 'SUMO_HOME'")
<mask token>


def get_options():
    opt_parser = optparse.OptionParser()
    opt_parser.add_option('--nogui', action='store_true', default=False,
        help='run the commandline version of sumo')
    options, args = opt_parser.parse_args()
    return options


def run():
    step = 0
    flag = False
    while traci.simulation.getMinExpectedNumber() > 0:
        traci.simulationStep()
        cur_edge = traci.vehicle.getRoadID('1')
        if step > 100 and cur_edge == 'e5':
            traci.vehicle.setRouteID('1', 'route_1')
            flag = True
        if flag and cur_edge == 'e6':
            traci.vehicle.setRouteID('1', 'route_2')
        step += 1
    traci.close()
    sys.stdout.flush()


if __name__ == '__main__':
    options = get_options()
    if options.nogui:
        sumoBinary = checkBinary('sumo')
    else:
        sumoBinary = checkBinary('sumo-gui')
    traci.start([sumoBinary, '-c', 'demo.sumocfg', '--tripinfo-output',
        'tripinfo.xml'])
    run()

import os
import sys
import optparse
if 'SUMO_HOME' in os.environ:
    tools = os.path.join(os.environ['SUMO_HOME'], 'tools')
    sys.path.append(tools)
else:
    sys.exit("please declare environment variable 'SUMO_HOME'")
from sumolib import checkBinary
import traci


def get_options():
    opt_parser = optparse.OptionParser()
    opt_parser.add_option('--nogui', action='store_true', default=False,
        help='run the commandline version of sumo')
    options, args = opt_parser.parse_args()
    return options


def run():
    step = 0
    flag = False
    while traci.simulation.getMinExpectedNumber() > 0:
        traci.simulationStep()
        cur_edge = traci.vehicle.getRoadID('1')
        if step > 100 and cur_edge == 'e5':
            traci.vehicle.setRouteID('1', 'route_1')
            flag = True
        if flag and cur_edge == 'e6':
            traci.vehicle.setRouteID('1', 'route_2')
        step += 1
    traci.close()
    sys.stdout.flush()


if __name__ == '__main__':
    options = get_options()
    if options.nogui:
        sumoBinary = checkBinary('sumo')
    else:
        sumoBinary = checkBinary('sumo-gui')
    traci.start([sumoBinary, '-c', 'demo.sumocfg', '--tripinfo-output',
        'tripinfo.xml'])
    run()

#!/usr/bin/python3

import os
import sys
import optparse

# we need to import some python modules from the $SUMO_HOME/tools directory
if 'SUMO_HOME' in os.environ:
    tools = os.path.join(os.environ['SUMO_HOME'], 'tools')
    sys.path.append(tools)
else:
    sys.exit("please declare environment variable 'SUMO_HOME'")


from sumolib import checkBinary  # Checks for the binary in environ vars
import traci


def get_options():
    opt_parser = optparse.OptionParser()
    opt_parser.add_option("--nogui", action="store_true",
                         default=False, help="run the commandline version of sumo")
    options, args = opt_parser.parse_args()
    return options


# contains TraCI control loop
def run():
    step = 0
    flag = False
    while traci.simulation.getMinExpectedNumber() > 0:
        traci.simulationStep()
        # print(step)

        cur_edge = traci.vehicle.getRoadID("1")
        if step > 100 and cur_edge == "e5":
            traci.vehicle.setRouteID("1", "route_1")
            flag = True

        if flag and cur_edge == "e6":
            traci.vehicle.setRouteID("1", "route_2")

        step += 1

    traci.close()
    sys.stdout.flush()


# main entry point
if __name__ == "__main__":
    options = get_options()

    # check binary
    if options.nogui:
        sumoBinary = checkBinary('sumo')
    else:
        sumoBinary = checkBinary('sumo-gui')

    # traci starts sumo as a subprocess and then this script connects and runs
    traci.start([sumoBinary, "-c", "demo.sumocfg",
                             "--tripinfo-output", "tripinfo.xml"])
    run()