i have fixed it by replacing the line 'import traci' before ' PORT = 8873',
but an other error appears :

"Error: tcpip::Socket::recvAndCheck @ recv: peer shutdown
Quitting (on error)."

2016-07-14 12:21 GMT+01:00 Khadija 20 <[email protected]>:

> hello,
> i'm creating a script with python but when i excute it it shows me this
> error :
>
>
> "Traceback (most recent call last):
>   File "test.py", line 12, in <module>
>     import traci
> ImportError: No module named traci"
>
> this is my script :
>
> #!/usr/bin/env python
> # -*-coding:Latin-1 -*
> import os, sys
> import optparse
> import subprocess
> import random
> import time
> import collections
> import copy
> import subprocess
> import argparse
> import traci
> 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')")
> 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
>
>
>     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="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("data/step.xml")
>     traci.init(PORT)
>     step = 0
>     n = len(PROGRAM)
>     print >> steps , n
>     #"traci.trafficlights.setPhase("0", n)
>     while step < 7200 :
>          print >>  steps, step
>                  traci.simulationStep()
>                  step += 1
>     steps.close()
>
>     raci.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",
> "data/cross.sumocfg", "--tripinfo-output",
>                                     "tripinfo.xml", "--remote-port",
> str(PORT)], stdout=sys.stdout, stderr=sys.stderr)
>     run()
>     sumoProcess.wait()
>
> Thanks for response 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