python3 D:\sumo\tools\randomTrips.py -n mytest.net.xml -e 3600 -p 0.5
这个命令 -e 和 -p 后面的参数可以改,
-e 后面的 3600 应该是生成车流的结束时间,意思是3600s之后就不放车了
-p 后面的参数 0.5 官方文档给的意思是行程次数,重复率,具体啥意思我也不知道,简单来说就是这个参数你设的越大车就越少,设的越少车就越多,你可以根据自己的实际情况来调整
trips文件转rou文件
D:\Sumo\bin\duarouter.exe -n mytest.net.xml -t trips.trips.xml -o mytest.rou.xml --ignore-errors
sumo -c mytest.sumocfg --tripinfo-output fcd.xml
python3 D:\Sumo\tools\xml\xml2csv.py fcd.xml
win10 x86_64
python 3.8.2
pycharm 2020.1
import csv
import matplotlib.pyplot as plt
# 解决中文显示问题
plt.rcParams['font.sans-serif'] = ['KaiTi'] # 指定默认字体
plt.rcParams['axes.unicode_minus'] = False # 解决保存图像是负号'-'显示为方块的问题
csv_reader = csv.reader(open("fcd.csv"))
str = ''
time = []
id = []
pos = []
# 车辆经过的路段id,下面仅仅是干道的一个方向的路段,需要根据自己的net文件手动调整
lane_id = ['gneE13_0', 'gneE13_1', 'gneE13_2', 'gneE13_3', 'gneE13_4',
'gneE14_0', 'gneE14_1', 'gneE14_2', 'gneE14_3', 'gneE14_4',
'gneE15_0', 'gneE15_1', 'gneE15_2', 'gneE15_3', 'gneE15_4',
'gneE16_0', 'gneE16_1', 'gneE16_2', 'gneE16_3', 'gneE16_4',
'gneE17_0', 'gneE17_1', 'gneE17_2', 'gneE17_3', 'gneE17_4',
'gneE18_0', 'gneE18_1', 'gneE18_2', 'gneE18_3', 'gneE18_4',
'gneE7_0', 'gneE7_1', 'gneE7_2', 'gneE7_3', 'gneE7_4']
# 下面每个if语句后的路段id,都需要根据自己的net文件手动调整
for row in csv_reader:
str = row[0].split(';')
if str[2] != '' and str[3] in lane_id:
if str[3] == 'gneE14_0' or str[3] == 'gneE14_1' or str[3] == 'gneE14_2' or str[3] == 'gneE14_3' or str[3] == 'gneE14_4':
pos.append(float(str[4]) + 100)
time.append(str[0])
id.append(str[2])
elif str[3] == 'gneE15_0' or str[3] == 'gneE15_1' or str[3] == 'gneE15_2' or str[3] == 'gneE15_3' or str[3] == 'gneE15_4':
pos.append(float(str[4]) + 320)
time.append(str[0])
id.append(str[2])
elif str[3] == 'gneE16_0' or str[3] == 'gneE16_1' or str[3] == 'gneE16_2' or str[3] == 'gneE16_3' or str[3] == 'gneE16_4':
pos.append(float(str[4]) + 420)
time.append(str[0])
id.append(str[2])
elif str[3] == 'gneE17_0' or str[3] == 'gneE17_1' or str[3] == 'gneE17_2' or str[3] == 'gneE17_3' or str[3] == 'gneE17_4':
pos.append(float(str[4]) + 520)
time.append(str[0])
id.append(str[2])
elif str[3] == 'gneE18_0' or str[3] == 'gneE18_1' or str[3] == 'gneE18_2' or str[3] == 'gneE18_3' or str[3] == 'gneE18_4':
pos.append(float(str[4]) + 790)
time.append(str[0])
id.append(str[2])
elif str[3] == 'gneE7_0' or str[3] == 'gneE7_1' or str[3] == 'gneE7_2' or str[3] == 'gneE7_3' or str[3] == 'gneE7_4':
pos.append(float(str[4]) + 890)
time.append(str[0])
id.append(str[2])
elif str[3] == 'gneE14_0' or str[3] == 'gneE14_1' or str[3] == 'gneE14_2' or str[3] == 'gneE14_3' or str[3] == 'gneE14_4':
pos.append(float(str[4]))
time.append(str[0])
id.append(str[2])
del time[0]
del id[0]
del pos[0]
x = []
y = []
plt.figure()
plt.axis([0, 600, 0, 1000])
plt.title("车辆时空图", fontsize=18)
plt.xlabel("t", fontsize=14)
plt.ylabel("x", fontsize=14)
plt.tick_params(axis='both', labelsize=14)
for i in range(0, int(max(id))):
for j in range(0, int(len(id))):
if int(id[j]) == int(i):
x.append(float(time[j]))
y.append(float(pos[j]))
print("------------------")
j += 1
print(x)
print(y)
plt.plot(x, y)
x.clear()
y.clear()
i += 1
plt.show()
print(time)
print(id)
print(pos)
print(len(time))
print(len(id))
print(len(pos))