Hi,
and id you check whether the vehicle3 really is in the network at the
time in question? Maybe you could send the route and the net file as
well, simply pack everything needed for the scenario in a zip and attach it.
Best regards,
Michael
Am 22.12.2015 um 07:30 schrieb Hayder M Amer:
> Dear Michael,
>
> I am sorry to report the question twice.
>
> Please, find my code below.
>
> import os, subprocess, sys, random
>
> SUMO_HOME = "C:\Users\Hayder\src\sumo-0.22.0"
> try:
> sys.path.append(os.path.join(SUMO_HOME, "tools"))
> # import the library
> import sumolib
> from sumolib import checkBinary
> from sumolib.net import Net
> from sumolib.net import NetReader
> from sumolib.net import Lane
> from sumolib.net import Edge
> from sumolib.net import Node
> from sumolib.net import Connection
> from sumolib.net import Roundabout
>
> 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
> NSGREEN = "GrGr"
> NSYELLOW = "yryr"
> WEGREEN = "rGrG"
> WEYELLOW = "ryry"
> PROGRAM =
> [WEYELLOW,WEYELLOW,WEYELLOW,NSGREEN,NSGREEN,NSGREEN,NSGREEN,NSGREEN,NSGREEN,NSGREEN,NSGREEN,NSYELLOW,NSYELLOW,WEGREEN]
> sumoBinary = checkBinary('sumo-gui')
> sumoConfig = "cologne.sumocfg"
> 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)
> traci.simulationStep()
> programPointer = len(PROGRAM)-1
> i=0
> s=0
> t=0
> k=0
> CTT5cars=[0,0,0,0,0]
> step = 0
> VEH=[]
> EDG=[]
> TIM=[]
> VehCTT=[]
> ED=[]
> ITT=[]
> V=[]
> CTT=[]
> Jun=[]
> L_Veh=[]
> Trav_tim=[]
> traci.edge.setEffort=[]
> VehiD=["0","1"]
> Curr_Trav=[]
> Trav_tim_sys=[]
> A=[]
> sample_vehicle = raw_input("Enter sample vehicle Name: ")
> #print "sample vehicle Name is :", sample_vehicle
> # Get the all Lane in Network
> All = traci.lane.getIDList()
> #print A
> NA=len(All)
> print "NA iss", NA
> for s in range(0,NA):
> LA=traci.lane.getLength(All[s])
> if LA>100:
> A.append(All[s])
> N=len(A)
> print "N is", N
> output = open ("output.txt", "w")
> output.write ("\n\n\n")
> output.write
> ("----------------------------------------------------------------------------------------\n")
> output.write ("Simulation Time\t\t| Fuel Consumption\t\t | CO2 emissions
> \t\t | CO emssions\t\t | Noise emission \t\t | Current Speed \t\t | Current
> Lane\n")
> # Calculate ITT for all Lanes
> for i in range(0,N):
> L=traci.lane.getLength(A[i]) # Get the Length of all Lane
> print " Lane name is", A[i],"\t"
> print " is equal", L,"\n"
> V=traci.lane.getMaxSpeed(A[i]) # Get Maximum Allowed speed
> print "Maximum Allowed Speed for Lane", A[i],"\t"
> print " is", V,"\n"
> ITT= L/V
> print "ITT for Lane", A[i],"\t"
> print " is equal to", ITT,"\n"
> # Set ITT for Lanes
> ED= traci.lane.getEdgeID(A[i])
> traci.edge.setEffort = [A,ITT]
> CTT5cars=[ITT,ITT,ITT,ITT,ITT]
> CTTcheck=0
> # Simulation starts here:
> while step == 0 or traci.simulation.getMinExpectedNumber() > 0:
> print "Simulation Time is", (traci.simulation.getCurrentTime())
> traci.simulationStep()
> programPointer = min(programPointer+1, len(PROGRAM)-1)
> # Calculate CTT for all Lanes
> for j in range(0,N):
> VEH=traci.lane.getLastStepVehicleIDs(A[j])
> EDG= traci.lane.getEdgeID(A[j])
> TIM= traci.simulation.getCurrentTime()
> VehiD[0]=VEH
> if VehiD[0]== '[0]':
> VehCTT=traci.vehicle.getAdaptedTraveltime(VehiD[0],
> TIM[j], EDG[j])
> VehCTT=traci.lane.getTraveltime(A[j])
> if CTTcheck == 0:
> CTT5cars[0]=VehCTT
> CTTcheck=1
> elif CTTcheck == 1:
> CTT5cars[1]=VehCTT
> CTTcheck=2
> elif CTTcheck == 2:
> CTT5cars[2]=VehCTT
> CTTcheck=3
> elif CTTcheck == 3:
> CTT5cars[3]=VehCTT
> CTTcheck=4
> else:
> CTT5cars[4]=VehCTT
> CTTcheck=0
> CTT = sum(CTT5cars)/5
> print "Current Traveling Time (CTT) for Lane", A[j], "is equal
> to", CTT
> traci.edge.setEffort=[A[i],CTT]
> CO=str(traci.vehicle.getCOEmission(sample_vehicle))
> Fue=str(traci.vehicle.getFuelConsumption(sample_vehicle))
> LAV=str(traci.vehicle.getLaneID(sample_vehicle))
> Noise=str(traci.vehicle.getNoiseEmission(sample_vehicle))
> curr_spe=str(traci.vehicle.getSpeed(sample_vehicle))
>
> speed_noTra=str(traci.vehicle.getSpeedWithoutTraCI(sample_vehicle))
> CO2=str(traci.vehicle.getCO2Emission(sample_vehicle))
> current_time = str(traci.simulation.getCurrentTime())
> output.write (current_time), output.write ("\t\t\t")
> output.write (Fue), output.write ("\t\t\t")
> output.write (CO2), output.write ("\t\t\t")
> output.write (CO), output.write ("\t\t\t")
> output.write (Noise), output.write ("\t\t\t")
> output.write (curr_spe), output.write ("\t\t\t")
> output.write (LAV), output.write ("\t\t\t")
> output.write (speed_noTra), output.write ("\t\t\t\n")
> # for Re-routing
> route = traci.vehicle.getRouteID(sample_vehicle)
> print "current route of sample vehicle is", route
> RoutEDG = traci.route.getEdges(route)
> print "RoutEDG", RoutEDG
> EDGN= len(RoutEDG)
> print EDGN
> veh_x,veh_y=traci.vehicle.getPosition(sample_vehicle)
> print "Vehicle position is", veh_x, veh_y
> Jun=traci.junction.getIDList()
> JunS= len(Jun)
> VEH_on_Inter = 0
> PN=0
> # check if Vehicle near the Intersection (less than 1 meter) for Re-routing
> if JunS <1:
> for k in range(0,JunS):
> jun_x,jun_y=traci.junction.getPosition(Jun[k])
> Distance_Veh_Edg = traci.simulation.getDistance2D( jun_x,
> jun_y, veh_x, veh_y, isGeo=False, isDriving=False)
> if Distance_Veh_Edg < 1:
> VEH_on_Inter = 1
> if VEH_on_Inter == 1:
> P_routes=traci.route.getSubscriptionResults()
> PN= len(P_routes)
> TIME= traci.simulation.getCurrentTime()
> VEH_on_Inter = 0
> for d in range(0,PN):
> P_routes_EDG=traci.lane.lanegetEdgeID(P_routes[d])
> Trav_tim = traci.vehicle.getEffort(sample_vehicle, TIME,
> P_routes_EDG[d])
> Curr_Trav = traci.vehicle.getAdaptedTraveltime(sample_vehicle,
> TIME, P_routes_EDG[d])
> Trav_tim_sys = traci.vehicle.rerouteTraveltime(sample_vehicle,
> TIME, P_routes_EDG[d])
> if Trav_tim < Curr_Trav:
> traci.vehicle.rerouteEffort(sample_vehicle)
> elif Trav_tim_sys < Curr_Trav:
> traci.vehicle.rerouteTraveltime(sample_vehicle)
> traci.vehicle.rerouteTraveltime(sample_vehicle)
> no = traci.inductionloop.getLastStepVehicleNumber("0")
> output.close()
> if no > 0:
> programPointer = (0 if programPointer == len(PROGRAM)-1 else 3)
> step += 1
> traci.close()
> sys.stdout.flush()
>
> Best regards,
> Hayder
>
>
> On 21 December 2015 at 17:16, Michael Behrisch <
> [email protected]> wrote:
>
>> Dear Hayder,
>> please send your script or at least the snippet you consider relevant
>> for the error. Maybe the vehicle has not entered the network yet? Which
>> depart time does it have and how many simulation steps did you already do?
>>
>> Best regards
>> Michael
>>
>> PS: Please do not repost the same question if you do not have new
>> information.
>>
>> Am 20.12.2015 um 09:39 schrieb Hayder M Amer:
>>> Hi,
>>>
>>> I'd implemented dynamic re-routing in sumo simulator, but when I run the
>>> code in the command line and after entering the sample vehicle name that
>>> should do re-routing I got all the required info of vehicle but the
>>> simulation doesn't run and I got the error below.
>>>
>>> C:\Users\Hayder\src\sumo-0.22.0\dijkstra_hayder\test>dynamic_routing1.py
>>> Loading configuration... done.
>>> Enter sample vehicle Name: vehicle3
>>> NA iss 51
>>> N is 17
>>> Lane name is 10_0
>>> is equal 453.03
>>>
>>> Maximum Allowed Speed for Lane 10_0
>>> is 12.12
>>>
>>> ITT for Lane 10_0
>>> is equal to 37.3787128713
>>>
>>> Lane name is 11_0
>>> is equal 467.27
>>>
>>> Maximum Allowed Speed for Lane 11_0
>>> is 12.12
>>>
>>> ITT for Lane 11_0
>>> is equal to 38.553630363
>>>
>>> Lane name is 12_0
>>> is equal 286.01
>>>
>>> Maximum Allowed Speed for Lane 12_0
>>> is 12.12
>>>
>>> ITT for Lane 12_0
>>> is equal to 23.5981848185
>>>
>>> Lane name is 13_0
>>> is equal 292.03
>>>
>>> Maximum Allowed Speed for Lane 13_0
>>> is 12.12
>>>
>>> ITT for Lane 13_0
>>> is equal to 24.0948844884
>>>
>>> Lane name is 14_0
>>> is equal 490.01
>>>
>>> Maximum Allowed Speed for Lane 14_0
>>> is 12.12
>>>
>>> ITT for Lane 14_0
>>> is equal to 40.4298679868
>>>
>>> Lane name is 15_0
>>> is equal 798.86
>>>
>>> Maximum Allowed Speed for Lane 15_0
>>> is 12.12
>>>
>>> ITT for Lane 15_0
>>> is equal to 65.9125412541
>>>
>>> Lane name is 16_0
>>> is equal 291.57
>>>
>>> Maximum Allowed Speed for Lane 16_0
>>> is 12.12
>>>
>>> ITT for Lane 16_0
>>> is equal to 24.0569306931
>>>
>>> Lane name is 17_0
>>> is equal 348.36
>>>
>>> Maximum Allowed Speed for Lane 17_0
>>> is 12.12
>>>
>>> ITT for Lane 17_0
>>> is equal to 28.7425742574
>>>
>>> Lane name is 18_0
>>> is equal 479.54
>>>
>>> Maximum Allowed Speed for Lane 18_0
>>> is 12.12
>>>
>>> ITT for Lane 18_0
>>> is equal to 39.5660066007
>>>
>>> Lane name is 1_0
>>> is equal 192.18
>>>
>>> Maximum Allowed Speed for Lane 1_0
>>> is 12.12
>>>
>>> ITT for Lane 1_0
>>> is equal to 15.8564356436
>>>
>>> Lane name is 3_0
>>> is equal 293.11
>>>
>>> Maximum Allowed Speed for Lane 3_0
>>> is 12.12
>>>
>>> ITT for Lane 3_0
>>> is equal to 24.1839933993
>>>
>>> Lane name is 4_0
>>> is equal 381.82
>>>
>>> Maximum Allowed Speed for Lane 4_0
>>> is 12.12
>>>
>>> ITT for Lane 4_0
>>> is equal to 31.50330033
>>>
>>> Lane name is 5_0
>>> is equal 286.71
>>>
>>> Maximum Allowed Speed for Lane 5_0
>>> is 12.12
>>>
>>> ITT for Lane 5_0
>>> is equal to 23.6559405941
>>>
>>> Lane name is 6_0
>>> is equal 577.12
>>>
>>> Maximum Allowed Speed for Lane 6_0
>>> is 12.12
>>>
>>> ITT for Lane 6_0
>>> is equal to 47.6171617162
>>>
>>> Lane name is 7_0
>>> is equal 375.02
>>>
>>> Maximum Allowed Speed for Lane 7_0
>>> is 12.12
>>>
>>> ITT for Lane 7_0
>>> is equal to 30.9422442244
>>>
>>> Lane name is 8_0
>>> is equal 403.46
>>>
>>> Maximum Allowed Speed for Lane 8_0
>>> is 12.12
>>>
>>> ITT for Lane 8_0
>>> is equal to 33.2887788779
>>>
>>> Lane name is 9_0
>>> is equal 189.24
>>>
>>> Maximum Allowed Speed for Lane 9_0
>>> is 12.12
>>>
>>> ITT for Lane 9_0
>>> is equal to 15.6138613861
>>>
>>> Simulation Time is 100
>>> Current Traveling Time (CTT) for Lane 10_0 is equal to 19.9668316832
>>> Traceback (most recent call last):
>>> File
>>> "C:\Users\Hayder\src\sumo-0.22.0\dijkstra_hayder\test\dynamic_routing1.py
>>> ", line 124, in <module>
>>> CO=str(traci.vehicle.getCOEmission(sample_vehicle))
>>> File "C:\Users\Hayder\src\sumo-0.22.0\tools\traci\vehicle.py", line
>> 223,
>>> in ge
>>> tCOEmission
>>> return _getUniversal(tc.VAR_COEMISSION, vehID)
>>> File "C:\Users\Hayder\src\sumo-0.22.0\tools\traci\vehicle.py", line
>> 110,
>>> in _g
>>> etUniversal
>>> result = traci._sendReadOneStringCmd(tc.CMD_GET_VEHICLE_VARIABLE,
>>> varID, veh
>>> ID)
>>> File "C:\Users\Hayder\src\sumo-0.22.0\tools\traci\__init__.py", line
>> 273,
>>> in _
>>> sendReadOneStringCmd
>>> return _checkResult(cmdID, varID, objID)
>>> File "C:\Users\Hayder\src\sumo-0.22.0\tools\traci\__init__.py", line
>> 297,
>>> in _
>>> checkResult
>>> result = _sendExact()
>>> File "C:\Users\Hayder\src\sumo-0.22.0\tools\traci\__init__.py", line
>> 250,
>>> in _
>>> sendExact
>>> raise TraCIException(prefix[1], _RESULTS[prefix[2]], err)
>>> traci.TraCIException: Vehicle 'vehicle3' is not known
>>>
>>> Please, your help and cooperation would be very appreciated.
>>>
>>> Best regards,
>>> Hayder
>>>
>> ------------------------------------------------------------------------------
>>> _______________________________________________
>>> sumo-user mailing list
>>> [email protected]
>>> https://lists.sourceforge.net/lists/listinfo/sumo-user
>>>
>>
>>
>
------------------------------------------------------------------------------
_______________________________________________
sumo-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/sumo-user