rou.xml 文件
最基础的生成车流的方式就是直接写 route
文件,这一小节会生成 rou.xml
文件。首先定义的 vTpye
表示的是 vehicle
的类型(也就是最基础的车辆)。定义加速度,减速,长度,最大的速度,车头时距。接着我们定义 route
,表示会通过的 edges
。最后定义两辆车,车辆的类型和形式的路线。我们将下面的文件保存为 test.rou.xml
。
<routes>
<vType id="type1" accel="0.8" decel="4.5" sigma="0.5" length="5" maxSpeed="70"/>
<route id="route0" color="1,1,0" edges="1si 3o"/>
<vehicle id="0" type="type1" route="route0" depart="0" color="1,0,0"/>
<vehicle id="1" type="type1" route="route0" depart="0" color="0,1,0"/>
</routes>
- 首先我们在最上面定义车辆,使用
vType
关键词进行定义。 - 接着我们定义一条路径,也就是使用
route
进行定义,表示车辆从哪些边上行驶。这里需要注意的是,routes 中的 edges 一定要是相互连通的,否则会出现类似下面的报错No connection between edge '1fi' and edge '3o'
. - 最后我们定义了两辆车,两辆车的类型都是 type1,都在 route0 上行驶。
在有了 route 文件之后,只需要新建一个 sumocfg
文件即可,需要指定 net-file
和 route-file
,如下所示:
<configuration>
<input>
<net-file value="test.net.xml"/>
<route-files value="test.rou.xml"/>
</input>
</configuration>
最后运行上面的 sumo config 文件,可以看到有两辆车在指定的路径上行驶。
trip 指定首末位置
直接编写 .rou.xml
文件来生成车流,需要具体定义每一段行程(只给定起点和终点不是不可以的)。如果只给定起点和终点,可能会出现类似下面的报错,No connection between edge '1fi' and edge '3o'
。此时,可以通过trip根据给定的「起点」和「终点」生成车流。
.trip.xml
文件主要保存的内容有车辆 id (id),出发时间 (depart),始发道路 id (from) 和到达道路 id (to)。此时我们只需要定义起点和终点,中间的路程是会自动进行补全的。我们新建一个 test01.trip.xml
文件,内容如下所示(一共有 3 辆车,只给定了起点和终点,没有给中间的具体道路):
<routes>
<trip id="trip0" depart="0" from="1fi" to="2o"/>
<trip id="trip1" depart="10" from="1fi" to="3o"/>
<trip id="trip2" depart="20" from="1fi" to="4o"/>
</routes>
接着我们将其通过 duarouter
转换为 .rou.xml
的文件:
duarouter --route-files=test01.trip.xml --net-file=test01.net.xml --output-file=test01.rou.xml
最后的输出格式如下所示。可以看到我们在 trip 中之设置了起点 「1fi」 和终点 「2o」,这里就会自动补全中间的道路,变成「edges="1fi 1si 2o"
」。
<routes xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://sumo.dlr.de/xsd/routes_file.xsd">
<vehicle id="trip0" depart="0.00">
<route edges="1fi 1si 2o"/>
</vehicle>
<vehicle id="trip1" depart="10.00">
<route edges="1fi 1si 3o"/>
</vehicle>
<vehicle id="trip2" depart="20.00">
<route edges="1fi 1si 4o"/>
</vehicle>
</routes>
最后通过sumocfg进行仿真。