[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
Re: [sumo-user] Changing vehicle behavior via TraCI
|
I have attached my files. Could you have a look and tell me what you think?
<additional >
<inductionLoop id="e1_1" lane="e3_0" pos="500" freq="1" file="e1report.xml" friendlyPos="true" />
<inductionLoop id="e1_2" lane="e3_1" pos="500" freq="1" file="e1report.xml" friendlyPos="true" />
<entryExitDetector id="e3" freq="1" file="e3report.xml" timeThreshold="100" speedThreshold="0">
<detEntry lane="e4_0" pos="100" friendlyPos="true"/>
<detExit lane="e2_0" pos="0" friendlyPos="true" />
<detExit lane="e2_1" pos="0" friendlyPos="true" />
<detEntry lane="e5_0" pos="100" friendlyPos="true"/>
<detExit lane="e3_0" pos="0" friendlyPos="true" />
<detExit lane="e3_1" pos="0" friendlyPos="true" />
</entryExitDetector>
</additional>
<?xml version="1.0" encoding="UTF-8"?>
<!-- generated on 2021-12-20 20:17:51 by Eclipse SUMO netedit Version 1.9.2
<configuration xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://sumo.dlr.de/xsd/netconvertConfiguration.xsd">
<input>
<sumo-net-file value="D:\alimirzaei\app\my_sumo\testforpythontraci\test12_lanechange_1\netbase.net.xml"/>
</input>
<output>
<output-file value="D:\alimirzaei\app\my_sumo\testforpythontraci\test12_lanechange_1\netbase_1.net.xml"/>
</output>
<processing>
<geometry.min-radius.fix.railways value="false"/>
<geometry.max-grade.fix value="false"/>
<offset.disable-normalization value="true"/>
<lefthand value="false"/>
</processing>
<junctions>
<no-turnarounds value="true"/>
<junctions.corner-detail value="5"/>
<junctions.limit-turn-speed value="5.5"/>
<rectangular-lane-cut value="false"/>
</junctions>
<pedestrian>
<walkingareas value="false"/>
</pedestrian>
<netedit>
<route-files value="D:\alimirzaei\app\my_sumo\testforpythontraci\test12_lanechange_1\routebase_1.rou.xml"/>
</netedit>
<report>
<aggregate-warnings value="5"/>
</report>
</configuration>
-->
<net version="1.9" junctionCornerDetail="5" limitTurnSpeed="5.50" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://sumo.dlr.de/xsd/net_file.xsd">
<location netOffset="0.00,0.00" convBoundary="-281.69,54.17,151.14,108.73" origBoundary="-10000000000.00,-10000000000.00,10000000000.00,10000000000.00" projParameter="!"/>
<edge id=":J1_0" function="internal">
<lane id=":J1_0_0" index="0" speed="13.89" length="11.20" shape="20.03,58.97 8.83,58.97"/>
<lane id=":J1_0_1" index="1" speed="13.89" length="11.20" shape="20.03,55.77 8.83,55.77"/>
</edge>
<edge id=":J1_2" function="internal">
<lane id=":J1_2_0" index="0" speed="6.50" length="9.03" shape="14.42,64.57 14.08,62.12 13.03,60.37 11.29,59.32 8.83,58.97"/>
</edge>
<edge id=":j2_0" function="internal">
<lane id=":j2_0_0" index="0" speed="6.51" length="9.02" shape="-137.38,64.56 -137.73,62.12 -138.78,60.37 -140.53,59.32 -142.98,58.97"/>
</edge>
<edge id=":j2_1" function="internal">
<lane id=":j2_1_0" index="0" speed="13.89" length="11.18" shape="-131.79,58.97 -142.98,58.97"/>
<lane id=":j2_1_1" index="1" speed="13.89" length="11.18" shape="-131.79,55.77 -142.98,55.77"/>
</edge>
<edge id="e1" from="s1" to="J1" priority="-1">
<lane id="e1_0" index="0" speed="13.89" length="131.11" shape="151.14,58.97 20.03,58.97"/>
<lane id="e1_1" index="1" speed="13.89" length="131.11" shape="151.14,55.77 20.03,55.77"/>
</edge>
<edge id="e2" from="J1" to="j2" priority="-1">
<lane id="e2_0" index="0" speed="13.89" length="140.63" shape="8.83,58.97 -131.79,58.97"/>
<lane id="e2_1" index="1" speed="13.89" length="140.63" shape="8.83,55.77 -131.79,55.77"/>
</edge>
<edge id="e3" from="j2" to="s2" priority="-1">
<lane id="e3_0" index="0" speed="13.89" length="138.71" shape="-142.98,58.97 -281.69,58.97"/>
<lane id="e3_1" index="1" speed="13.89" length="138.71" shape="-142.98,55.77 -281.69,55.77"/>
</edge>
<edge id="e4" from="s3" to="J1" priority="-1">
<lane id="e4_0" index="0" speed="13.89" length="43.72" shape="14.32,108.30 14.42,64.57"/>
</edge>
<edge id="e5" from="s4" to="j2" priority="-1">
<lane id="e5_0" index="0" speed="13.89" length="44.17" shape="-137.27,108.74 -137.38,64.56"/>
</edge>
<junction id="J1" type="priority" x="16.05" y="54.17" incLanes="e1_0 e1_1 e4_0" intLanes=":J1_0_0 :J1_0_1 :J1_2_0" shape="20.03,60.57 20.03,54.17 8.83,54.17 8.83,60.57 11.06,61.01 11.83,61.57 12.39,62.35 12.72,63.35 12.82,64.57 16.02,64.58 16.47,62.35 17.03,61.57 17.81,61.02 18.81,60.68">
<request index="0" response="000" foes="100" cont="0"/>
<request index="1" response="000" foes="100" cont="0"/>
<request index="2" response="011" foes="011" cont="0"/>
</junction>
<junction id="j2" type="priority" x="-135.80" y="54.17" incLanes="e5_0 e2_0 e2_1" intLanes=":j2_0_0 :j2_1_0 :j2_1_1" shape="-138.98,64.57 -135.78,64.56 -135.34,62.34 -134.79,61.57 -134.01,61.01 -133.01,60.68 -131.79,60.57 -131.79,54.17 -142.98,54.17 -142.98,60.57 -140.76,61.01 -139.98,61.57 -139.42,62.35 -139.09,63.35">
<request index="0" response="110" foes="110" cont="0"/>
<request index="1" response="000" foes="001" cont="0"/>
<request index="2" response="000" foes="001" cont="0"/>
</junction>
<junction id="s1" type="dead_end" x="151.14" y="54.17" incLanes="" intLanes="" shape="151.14,54.17 151.14,60.57"/>
<junction id="s2" type="dead_end" x="-281.69" y="54.17" incLanes="e3_0 e3_1" intLanes="" shape="-281.69,60.57 -281.69,54.17"/>
<junction id="s3" type="dead_end" x="15.92" y="108.30" incLanes="" intLanes="" shape="15.92,108.30 12.72,108.29"/>
<junction id="s4" type="dead_end" x="-135.67" y="108.73" incLanes="" intLanes="" shape="-135.67,108.73 -138.87,108.74"/>
<connection from="e1" to="e2" fromLane="0" toLane="0" via=":J1_0_0" dir="s" state="M"/>
<connection from="e1" to="e2" fromLane="1" toLane="1" via=":J1_0_1" dir="s" state="M"/>
<connection from="e2" to="e3" fromLane="0" toLane="0" via=":j2_1_0" dir="s" state="M"/>
<connection from="e2" to="e3" fromLane="1" toLane="1" via=":j2_1_1" dir="s" state="M"/>
<connection from="e4" to="e2" fromLane="0" toLane="0" via=":J1_2_0" dir="r" state="m"/>
<connection from="e5" to="e3" fromLane="0" toLane="0" via=":j2_0_0" dir="r" state="m"/>
<connection from=":J1_0" to="e2" fromLane="0" toLane="0" dir="s" state="M"/>
<connection from=":J1_0" to="e2" fromLane="1" toLane="1" dir="s" state="M"/>
<connection from=":J1_2" to="e2" fromLane="0" toLane="0" dir="r" state="M"/>
<connection from=":j2_0" to="e3" fromLane="0" toLane="0" dir="r" state="M"/>
<connection from=":j2_1" to="e3" fromLane="0" toLane="0" dir="s" state="M"/>
<connection from=":j2_1" to="e3" fromLane="1" toLane="1" dir="s" state="M"/>
</net>
import os
import sys
# 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'")
# we need to check binary in environment variables.
from sumolib import checkBinary
sumoBinary = checkBinary('sumo-gui') # for running simulation automatically, I use "sumo" instead of "sumo-gui"
sumoCmd = [sumoBinary, "-c", "test12_2.sumocfg", "--random", "true", "--output-prefix", " TIME"]
import traci
#latDist = [0.1, 0.2, 0.3, 0.4, 0.5, 0.6]
def run():
traci.start(sumoCmd)
for veh_id in traci.vehicle.getIDList():
length = traci.vehicle.getLength(veh_id)
if length == 6.5:
traci.vehicle.changeSublane(veh_id, 3.0)
step = 0
while traci.simulation.step(1000):
while traci.vehicle.getMinExpectedNumber() > 0:
traci.simulationStep()
step = 1
step += 1
traci.close()
sys.stdout.flush()
run()
# =============================================================================
# n = 5
# for i in range(n):
# for j in latDist:
# print('j is:', j)
# run(j)
#
#
# mainpath = r'D:/alimirzaei/app/my_sumo/testforpythontraci/test12_lanechange_1/lane_changing_with_aggressive_driver/5_iterations'
# import xml.etree.ElementTree as ET
# import glob
#
# s = glob.glob('{0}/*report.xml'.format(mainpath))
# root_collection = []
# count = 0
# print('s is:', s)
#
# x = []
# y = []
# for filename in s:
# tree = ET.parse(filename)
# root = tree.getroot()
# root_collection.append(root)
# for root in root_collection:
# for child in root:
# a = child.attrib
# b = list(a.keys())
# x.append(b)
# y.append(x[0])
# y.append(x[-1])
#
# import csv
# import pandas as pd
#
# # designating the values of each attribute to it automatically
#
# for k in range(len(s)):
# for l in range(len(y)):
# if k % 2 == 0:
# l = 0
# else:
# l = 1
# tree = ET.parse(s[k])
# root = tree.getroot()
# print('root is:', root)
#
# with open('filename{}.csv'.format(k+1), 'w') as job:
# detectorwriter = csv.writer(job)
# detectorwriter.writerow(y[l])
# for i in root:
# values = [i.attrib[j] for j in y[l]]
# print('values is:', values)
# detectorwriter.writerow(values)
# data = pd.read_csv('filename{}.csv'.format(k+1))
# data.to_csv('filename_final{}.csv'.format(k+1), sep = ',', index = False)
#
# # finding the files ending to digits and extracting the files ending with odd numbers
#
# t = glob.glob('{0}/*final[0-9]*.csv'.format(mainpath))
# print('t is:' , t)
# print('len(t) is:', len(t))
#
# u = []
# v = []
# for k in range(len(t)):
# if (k+1) % 2 == 0:
# t_1 = glob.glob('{0}/*final%s.csv'.format(mainpath) %(k+1))
# #print(t_1)
# u.append(t_1)
# else:
# t_2 = glob.glob('{0}/*final%s.csv'.format(mainpath) %(k+1))
# #print(t_2)
# v.append(t_2)
#
# #print('u is:', u)
# #print('v is:', v)
#
# w_1 = []
#
# for i in u:
# for j in i:
# w_1.append(j)
# print('w_1 is:', w_1)
#
# w_2 = []
# for i in v:
# for j in i:
# w_2.append(j)
# print('w_2 is:', w_2)
#
# z_1 = []
# for k in w_1:
# b = pd.read_csv(k)
# total_passed_cars = b["vehicleSum"].sum()
# z_1.append(total_passed_cars)
# print('z_1 is:', z_1)
#
# z_2 = []
# for k in w_2:
# b = pd.read_csv(k)
# total_passed_cars = b["nVehContrib"].sum()
# z_2.append(total_passed_cars)
# print('z_2 is:', z_2)
#
# # we put all the results coming from the same latDist values in one array
# n = len(latDist)
# z_1_1 = [z_1[i::n] for i in range(n)]
# z_2_2 = [z_2[i::n] for i in range(n)]
# print('z_1_1 is:', z_1_1)
# print('z_2_2 is:', z_2_2)
#
# import numpy as np
# z_1_1_avg = [np.mean(i) for i in z_1_1]
# z_2_2_avg = [np.mean(i) for i in z_2_2]
# # we could write these two above lines without using numpy library as shown in the following:
# #z_1_1_avg = [sum(i) / len(i) for i in z_1_1]
# #z_2_2_avg = [sum(i) / len(i) for i in z_2_2]
# print('z_1_1_ave:', z_1_1_avg)
# print('z_2_2_ave:', z_2_2_avg)
#
# z_1_1_std = []
# z_1_1_numpy = np.array(z_1_1)
# print(z_1_1_numpy)
# for i in z_1_1_numpy:
# x = [(j - np.mean(i))**2 for j in i]
# print('x is:', x)
# y = (sum(x) / (len(i)-1))**0.5
# print('y is:', y)
# z_1_1_std.append(y)
# print('z_1_1_std is:', z_1_1_std)
#
# z_2_2_std = []
# z_2_2_numpy = np.array(z_2_2)
# print(z_2_2_numpy)
# for i in z_2_2_numpy:
# x = [(j - np.mean(i))**2 for j in i]
# print('x is:', x)
# y = (sum(x) / (len(i)-1))**0.5
# print('y is:', y)
# z_2_2_std.append(y)
# print('z_2_2_std is:', z_2_2_std)
#
#
# import matplotlib.pyplot as plt
# x = latDist
# y = z_1_1_avg
# yerror = z_1_1_std
# plt.errorbar(latDist, z_1_1_avg, yerr = yerror, ecolor = 'blue', capsize = 2, color = 'red', linestyle = 'dashed', marker = 'o',label = "passed_vehicles_side_street")
# #plt.plot(latDist, z_2, color = 'blue', linestyle = 'dashed', marker = 'o',label = "passed_vehicles_main_street")
# plt.xlabel('latDist')
# plt.ylabel('total_passed_cars')
# plt.title('report of passed cars', fontsize = 20)
# plt.grid()
# plt.legend()
# plt.show()
# =============================================================================
<?xml version="1.0" encoding="UTF-8"?>
<!-- generated on 2021-12-20 20:21:43 by Eclipse SUMO netedit Version 1.9.2
<configuration xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://sumo.dlr.de/xsd/netconvertConfiguration.xsd">
<input>
<sumo-net-file value="D:\alimirzaei\app\my_sumo\testforpythontraci\test12_lanechange_1\netbase.net.xml"/>
</input>
<output>
<output-file value="D:\alimirzaei\app\my_sumo\testforpythontraci\test12_lanechange_1\netbase_1.net.xml"/>
</output>
<processing>
<geometry.min-radius.fix.railways value="false"/>
<geometry.max-grade.fix value="false"/>
<offset.disable-normalization value="true"/>
<lefthand value="false"/>
</processing>
<junctions>
<no-turnarounds value="true"/>
<junctions.corner-detail value="5"/>
<junctions.limit-turn-speed value="5.5"/>
<rectangular-lane-cut value="false"/>
</junctions>
<pedestrian>
<walkingareas value="false"/>
</pedestrian>
<netedit>
<route-files value="D:\alimirzaei\app\my_sumo\testforpythontraci\test12_lanechange_1\routebase_1.rou.xml"/>
</netedit>
<report>
<aggregate-warnings value="5"/>
</report>
</configuration>
-->
<routes xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://sumo.dlr.de/xsd/routes_file.xsd">
<route edges="e1 e2 e3" color="yellow" id="route_1"/>
<route edges="e4 e2 e3" color="yellow" id="route_2"/>
<route edges="e5 e3" color="yellow" id="route_3"/>
<vType id = "emergency" vClass = "delivery" color = "red" lcSpeedGain = "1000" lcSpeedGainRight = "1" length = "6.5"
lcSublane = "2000" lcPushy = "1" lcPushyGap = "0.2" lcAssertive = "1.5" lcImpatience = "1" />
<vType id = "car1" vClass = "passenger" laneChangeModel = "SL2015" lcKeepRight = "0" length = "5"
accel = "3.5" decel = "2.5" sigma = "0.1" latAlignment = "left" maxSpeed = "7" />
<vType id = "car2" vClass = "hov" length = "7" accel = "1.5" decel = "2.5" sigma = "0.1" latAlignment = "right" maxSpeed = "5" />
<flow id = "type1" type="car1" color="yellow" begin="5" end= "900" departSpeed = " max" departLane = "1"
arrivalLane = "1" probability = "0.2" from = "e1" to = "e3" />
<flow id = "type2" type="car1" color="yellow" begin="5" end= "900" departSpeed = " max" departLane = "0"
arrivalLane = "1" probability = "0.2" from = "e4" to = "e3" />
<flow id = "type3" type="car1" color="yellow" begin="5" end= "900" departSpeed = " max" departLane = "0"
arrivalLane = "1" probability = "0.2" from = "e5" to = "e3" />
<flow id = "type4" type = "car2" color = "cyan" begin = "5" end = "900" departSpeed = "max" departLane = "0"
probability = "0.1" from = "e4" to = "e3" />
<flow id = "type5" type = "car2" color = "cyan" begin = "5" end = "900" departSpeed = "max" departLane = "0"
probability = "0.1" from = "e5" to = "e3" />
<flow id = "type6" type = "car2" color = "cyan" begin = "5" end = "900" departSpeed = "max" departLane = "0"
probability = "0.1" from = "e1" to = "e3" />
<flow id = "type7" type="emergency" color="red" begin="60" end= "900" departSpeed = " max" departLane = "1"
arrivalLane = "0" probability = "0.09" from = "e1" to = "e3" />
</routes>
Attachment:
test12_2.sumocfg
Description: application/sumo