本实验主要通过sumo对某个城市进行交通碳排放仿真,仿真对象包括公交车、无接管燃油车、有接管电车和轻型货车。
1.生成路网
在OpenStreetMap中确定某部分地图,导出到sumo下bin文件夹内,默认名称为map.osm。
打开cmd命令框,使用如下命令生成xml文件命令,转换成net.xml文件,网路文件。
netconvert --osm-files map.osm -o map.net.xml
2.随机生成vtype
相关介绍参考sumo官网:https://sumo.dlr.de/docs/Tools/Misc.html#createvehtypedistributionspy
1. 事先准备好如下图的txt文件,以便随机生成vtype。
2.打开cmd,使用如下命令,填入对应的文件名称,自动生成vtype。
python tools/createVehTypeDistribution.py car.config.txt --size 3 --name car --output-file car.add.xml
通过car.config.txt生成3种(size)vtype,命名为“car1”至“car3”,保存在car.add.xml新文件中。如下图所示。
注意,本实验在vtype文件car1中添加了toc设备(自己写),即所有的car1车辆均可实现接管,且所有数据均在ssm_car文件中,相比起在rou文件中vehicle中添加设备,这样更方便,且可实现更多车辆的接管,不会出现报错(例如系统打开太多文件等)。
还可以生成bus、truck等vtype,此处不一一列举。
3.生成trip文件
python tools/randomTrips.py -n map.net.xml --trip-attributes="type=\"car0\"" --additional-file car.add.xml -r trips_car.trip.xml -e 500 -p 0.5 --prefix car_
根据自己生成文件名以及vtype名修改,-e表示结束时间(s),-p表示生成间隔(s),prefix表示生成的trip前缀,car_0,car_1等,主要是防止多种车辆的trip重名。结果如下
4.生成rou文件
根据第三步生成的trip文件,使用如下命令生成rou文件,一定记得加--ignore-errors,否则可能生成不成功。
duarouter -n map.net.xml -r trips_car.trip.xml -o rou_car.rou.xml --ignore-errors
5. 配置cfg文件,运行仿真
配置如下,一定要在additional-files 中将车辆类型的add文件,即上述第二步生成的文件写进去,否则没有vtype的定义。
本实验还用相同的方法生成了bus(公交车)、truck(轻型货车)和无接管汽油车,故additional-files中文件较多。
<configuration>
<input>
<net-file value="map.net.xml"/>
<route-files value="rou_bus.rou.xml, rou_car(notake_g).rou.xml, rou_car.rou.xml, rou_truck.rou.xml"/>
<additional-files value="addition_51_1.add.xml, car.add.xml, car_bus.add.xml, car_gas.add.xml, car_truck.add.xml"/>
</input>
<output>
<battery-output value="Battery.out.xml"/>
<battery-output.precision value="4"/>
<emission-output value="emission.out.xml"/>
<tripinfo-output value="trip.out.xml"/>
</output>
<time>
<begin value="0"/>
<end value="1200"/>
<step-length value="0.1"/>
<default.action-step-length value="0.1"/>
</time>
<processing>
<collision.action value="warn"/>
<collision.stoptime value="10"/>
</processing>
</configuration>