Ejemplo n.º 1
0
def run_one_simulation(steps=1200):
    PORT = 8813
    """
		Runs one sumo simulation.
		INPUT:no of time steps(1 step = 1 second)
		OUTPUT:trip info file
	"""
    # The whole traci-sumo interface thing.
    if not traci.isEmbedded():
        sumoBinary = checkBinary("/usr/bin/sumo")  # Computer Specific.
        sumoConfig = "/home/venu/Desktop/ATC/atc_files/utc/utc_01.sumo.cfg"  # Computer Specific.
        if len(sys.argv) > 1:
            retCode = subprocess.call("%s -c %s --python-script %s" %
                                      (sumoBinary, sumoConfig, __file__),
                                      shell=True,
                                      stdout=sys.stdout)
            sys.exit(retCode)
        else:
            sumoProcess = subprocess.Popen("%s -c %s" %
                                           (sumoBinary, sumoConfig),
                                           shell=True,
                                           stdout=sys.stdout)
            traci.init(PORT, 3)

    # Simulation code.
    step = 0
    while step < steps:
        traci.simulationStep()
        step += 1
    traci.close()
Ejemplo n.º 2
0
    WEYELLOW,
    WEYELLOW,
    NSGREEN,
    NSGREEN,
    NSGREEN,
    NSGREEN,
    NSGREEN,
    NSGREEN,
    NSGREEN,
    NSGREEN,
    NSYELLOW,
    NSYELLOW,
    WEGREEN,
]

if not traci.isEmbedded():
    N = 9000
    pWE = 1.0 / 10
    pEW = 1.0 / 11
    pNS = 1.0 / 30
    routes = open("data/cross.rou.xml", "w")
    print >> routes, """<routes>
    <vType id="typeWE" accel="0.8" decel="4.5" sigma="0.5" length="5" minGap="2.5" maxSpeed="16.67" guiShape="passenger"/>
    <vType id="typeNS" accel="0.8" decel="4.5" sigma="0.5" length="17" minGap="3" maxSpeed="25" guiShape="bus"/>

    <route id="right" edges="51o 1i 2o 52i" />
    <route id="left" edges="52o 2i 1o 51i" />
    <route id="down" edges="54o 4i 3o 53i" />"""
    lastVeh = 0
    vehNr = 0
    for i in range(N):
Ejemplo n.º 3
0
    optParser.add_option(
        "--embedded",
        action="store_true",
        default=False,
        help=
        "use the sumo-internal python interpreter (sometimes faster). To use this option the featere 'python' must be enabled when compling sumo from source"
    )
    options, args = optParser.parse_args()
    return options


# this is the main entry point of this script
if __name__ == "__main__":
    options = get_options()

    if traci.isEmbedded():
        # this script has been called from the sumo-interal python interpreter
        # only execute the main control procedure
        run()
    else:
        # 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')

        # first, generate the route file for this simulation
        generate_routefile()

        # now execute sumo
Ejemplo n.º 4
0
from sumolib import checkBinary
import traci

PORT = 8813

NSGREEN = "GrGr"
NSYELLOW = "yryr"
WEGREEN = "rGrG"
WEYELLOW = "ryry"

PROGRAM = [
    WEYELLOW, WEYELLOW, WEYELLOW, NSGREEN, NSGREEN, NSGREEN, NSGREEN, NSGREEN,
    NSGREEN, NSGREEN, NSGREEN, NSYELLOW, NSYELLOW, WEGREEN
]

if not traci.isEmbedded():
    N = 9000
    pWE = 1. / 10
    pEW = 1. / 11
    pNS = 1. / 30
    routes = open("data/cross.rou.xml", "w")
    print >> routes, """<routes>
    <vType id="typeWE" accel="0.8" decel="4.5" sigma="0.5" length="5" minGap="2.5" maxSpeed="16.67" guiShape="passenger"/>
    <vType id="typeNS" accel="0.8" decel="4.5" sigma="0.5" length="17" minGap="3" maxSpeed="25" guiShape="bus"/>

    <route id="right" edges="51o 1i 2o 52i" />
    <route id="left" edges="52o 2i 1o 51i" />
    <route id="down" edges="54o 4i 3o 53i" />"""
    lastVeh = 0
    vehNr = 0
    for i in range(N):
Ejemplo n.º 5
0
    sys.stdout.flush()

def get_options():
    optParser = optparse.OptionParser()
    optParser.add_option("--nogui", action="store_true", default=False, help="run the commandline version of sumo")
    optParser.add_option("--embedded", action="store_true", default=False, 
            help="use the sumo-internal python interpreter (sometimes faster). To use this option the featere 'python' must be enabled when compling sumo from source")
    options, args = optParser.parse_args()
    return options


# this is the main entry point of this script
if __name__ == "__main__":
    options = get_options()

    if traci.isEmbedded():
        # this script has been called from the sumo-interal python interpreter
        # only execute the main control procedure
        run()
    else:
        # 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')

        # first, generate the route file for this simulation
        generate_routefile()

        # now execute sumo