hello ,
i wrote this algoritm with python, but there is no vehicle in the network
during the simulation ?

there is the script :

#!/usr/bin/env python
# -*-coding:Latin-1 -*
import os, sys
import optparse
import subprocess
import random





SUMO_HOME = "/home/khadija/Téléchargements/sumo-0.25.0"

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
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 traci
PORT = 8873

#SIGN CONFIGURATIONS : NESW
NSgreen = "GrGr"
EWgreen = "rGrG"
PROGRAM = (NSgreen,EWgreen)

#generate routefile : define function
def generate_routefile():
    random.seed(42)  # make tests reproducible
    N= 7200
    pEW = 30/3600
    pSN =20/3600
    pWE = 25/3600
    pNS = 40/3600
    T = 60 #temps de cycle par defaut


    routes = open("data2/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="7"
minGap="3" maxSpeed="25" guiShape="bus"/>
        <vType id="typeEW" accel="0.8" decel="4.5" sigma="0.5" length="6"
minGap="2.5" maxSpeed="16.67" guiShape="passenger"/>
        <vType id="typeSN" accel="0.8" decel="4.5" sigma="0.5" length="5.5"
minGap="3" maxSpeed="25" guiShape="passenger"/>


        <route id="right" edges="51o 1i 2o 52i" />
        <route id="left" edges="52o 2i 1o 51i" />
        <route id="down" edges="54o 4i 3o 53i" />
        <route id="up" edges="53o 3i 4o 54i" />"""

    vehNr = 0
    lastVeh = 0
    for i in range(N) :
         if random.uniform(0,30) < pEW:
             print >> routes, '<vehicle id="right_%i" type="typEW"
route="right" depart="%i" />' % (
             vehNr,i)
                 vehNr += 1
                 lastVeh = i
         if random.uniform(0,20) < pSN:
            print >> routes, '<vehicle id="up_%i" type="typeSN"
route="left" depart="%i" />' % (
            vehNr,i)
                vehNr += 1
                lastVeh = i
         if random.uniform(0,25) < pWE:
            print >> routes, '<vehicle id="left_%i" type="typeWE"
route="left" depart="%i" />' % (
            vehNr,i)
                vehNr += 1
                lastVeh = i
         if random.uniform(0,40) < pNS:
             print >> routes, '<vehicle id="down_%i" type="typeNS"
route="left" depart="%i" />' % (
             vehNr,i)
                 vehNr += 1
                 lastVeh = i
    print >> routes, "</routes>"
    routes.close()


def run():

    """execute the TraCI control loop"""
    steps = open("data2/step.txt","w")
    traci.init(PORT)
    step = 0
    n1i = 0
    n1o = 0
    n2i = 0
    n2o = 0
    n3i = 0
    n3o = 0
    n4i = 0
    n4o = 0
    traci.trafficlights.setPhase("0",0)
    while step < 7200:
         if step < 30:
            traci.simulationStep()
            traci.trafficlights.setPhase("0",0)

            step += 1
         else :
               traci.simulationStep()
               traci.trafficlights.setPhase("0",1)
               step += 1





    #k = str(n)
    #steps.write(k)
    #"traci.trafficlights.setPhase("0", n)
   # while step < 7200 :
         #h = str (step)
         #steps.write(h)
                 #traci.simulationStep()
                 #step += 1
    steps.close()

    traci.close()
    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")
    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')

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

    # this is the normal way of using traci. sumo is started as a
    # subprocess and then the python script connects and runs
    sumoProcess = subprocess.Popen([sumoBinary, "-c",
"data2/cross.sumocfg", "--tripinfo-output",
                                    "tripinfo.xml", "--remote-port",
str(PORT)], stdout=sys.stdout, stderr=sys.stderr)
    run()
    sumoProcess.wait()



Thanks for help in advance,
Regards,
------------------------------------------------------------------------------
What NetFlow Analyzer can do for you? Monitors network bandwidth and traffic
patterns at an interface-level. Reveals which users, apps, and protocols are 
consuming the most bandwidth. Provides multi-vendor support for NetFlow, 
J-Flow, sFlow and other flows. Make informed decisions using capacity planning
reports.http://sdm.link/zohodev2dev
_______________________________________________
sumo-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/sumo-user

Reply via email to