sumo之模拟十字路口转弯

在交通模拟中,十字路口是经常需要遇见的基本单元。在模拟车流通过十字路口时,如果使用前面的方法实现,则需要定义三个车流,并向三个不同的方向运动。但是在sumo中,通过jtrrouter命令实现车流在十字路口转弯的模拟。通过提供三个转向的概率进行车流的模拟。具体的内容可以前往官网查看。

定义一个转向的模拟需要定义三个部分:路网、转向各方向的概率、车流。

在下面的实例中使用前面使用过的十字路口,文件名为cross_rode_2.net.xml

(如果使用前面一模一样的道路文件,有的道路无连接,需要做小改动)

1.编写flow文件

利用前面提到的编写车流的方法编写该文件,代码如下,命名为flows.flows.xml:

<flowdefs>
     <flow id="f1" from='E1' begin='0' end='100' number='100'/>
</flowdefs>

代码中定义了从E1道路驶来的车流。

2.编写turn文件

编写转向的车辆,代码如下,命名为:flows_turn.turns.xml:

<turns>

  <interval begin="0" end="3600">
      <edgeRelation from="E1" to="-E2" probability="0.2"/>
      <edgeRelation from="E1" to="-E3" probability="0.7"/>
      <edgeRelation from="E1" to="E0" probability="0.1"/>

   </interval>

</turns>

代码中定义了从E1驶来的车辆转向各个道路的概率,从上往下分别是左转、直行和右转的概率分别是0.2、0.7、0.1。

3.结合flow和turn生成路由文件

在cmd中,将路径切换到存放文件的位置,我的路径是D:/sumo/project。键入如下命令:

jtrrouter --route-files=flows.flows.xml --turn-ratio-files=flows_turn.turns.xml --net-file=cross_road_2.net.xml --output-file=cross_turn.rou.xml --accept-all-destinations=t

最后的--accept-all-destinations=t 是为了接收所有的到达地。如果不加运行会报错。当然,如果在turn文件后加上<sink edges="<EDGE_ID>[ <EDGE_ID>]*"/>表面能出去的边,也可以。

4.结合前面的部分编写.sumocfg文件。

这部分的代码如下:

<configuration>
    <input>
        <net-file value="cross_road_2.net.xml"/>
        <route-files value="cross_trun.rou.xml"/>
    </input>
 
    <time>
        <begin value="0"/>
        <end value="100000"/>
    </time>
</configuration>

注意路网文件和路由文件的文件名,根据实际情况进行修改。

5.仿真结果

在sumo-gui中打开上述.sumocfg文件就能进行仿真。具体的仿真步骤前面的文章已经介绍过。仿真结果如下:

sumo之模拟十字路口转弯

最后附上路网文件的代码。(因为较前面的有所修改)

<?xml version="1.0" encoding="UTF-8"?>

<!-- generated on 2021-12-20 10:54:31 by Eclipse SUMO netedit Version 1.11.0
<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:\sumo\project\cross_road_2.net.xml"/>
    </input>

    <output>
        <output-file value="D:\sumo\project\cross_road_2.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>

    <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="-100.00,-100.00,100.00,100.00" origBoundary="-10000000000.00,-10000000000.00,10000000000.00,10000000000.00" projParameter="!"/>

    <edge id=":J0_0" function="internal">
        <lane id=":J0_0_0" index="0" speed="6.51" length="9.03" shape="-8.00,13.60 -8.35,11.15 -9.40,9.40 -11.15,8.35 -13.60,8.00"/>
    </edge>
    <edge id=":J0_1" function="internal">
        <lane id=":J0_1_0" index="0" speed="13.89" length="27.20" shape="-8.00,13.60 -8.00,-13.60"/>
        <lane id=":J0_1_1" index="1" speed="13.89" length="27.20" shape="-4.80,13.60 -4.80,-13.60"/>
        <lane id=":J0_1_2" index="2" speed="13.89" length="27.20" shape="-1.60,13.60 -1.60,-13.60"/>
    </edge>
    <edge id=":J0_4" function="internal">
        <lane id=":J0_4_0" index="0" speed="10.36" length="7.98" shape="-1.60,13.60 -0.65,6.95 -0.00,5.87"/>
    </edge>
    <edge id=":J0_19" function="internal">
        <lane id=":J0_19_0" index="0" speed="10.36" length="16.53" shape="-0.00,5.87 2.20,2.20 6.95,-0.65 13.60,-1.60"/>
    </edge>
    <edge id=":J0_5" function="internal">
        <lane id=":J0_5_0" index="0" speed="6.51" length="9.03" shape="13.60,8.00 11.15,8.35 9.40,9.40 8.35,11.15 8.00,13.60"/>
    </edge>
    <edge id=":J0_6" function="internal">
        <lane id=":J0_6_0" index="0" speed="13.89" length="27.20" shape="13.60,8.00 -13.60,8.00"/>
        <lane id=":J0_6_1" index="1" speed="13.89" length="27.20" shape="13.60,4.80 -13.60,4.80"/>
        <lane id=":J0_6_2" index="2" speed="13.89" length="27.20" shape="13.60,1.60 -13.60,1.60"/>
    </edge>
    <edge id=":J0_9" function="internal">
        <lane id=":J0_9_0" index="0" speed="10.36" length="7.98" shape="13.60,1.60 6.95,0.65 5.87,0.00"/>
    </edge>
    <edge id=":J0_20" function="internal">
        <lane id=":J0_20_0" index="0" speed="10.36" length="16.53" shape="5.87,0.00 2.20,-2.20 -0.65,-6.95 -1.60,-13.60"/>
    </edge>
    <edge id=":J0_10" function="internal">
        <lane id=":J0_10_0" index="0" speed="13.89" length="27.20" shape="8.00,-13.60 8.00,13.60"/>
        <lane id=":J0_10_1" index="1" speed="13.89" length="27.20" shape="4.80,-13.60 4.80,13.60"/>
        <lane id=":J0_10_2" index="2" speed="13.89" length="27.20" shape="1.60,-13.60 1.60,13.60"/>
    </edge>
    <edge id=":J0_13" function="internal">
        <lane id=":J0_13_0" index="0" speed="10.36" length="7.98" shape="1.60,-13.60 0.65,-6.95 0.00,-5.87"/>
    </edge>
    <edge id=":J0_21" function="internal">
        <lane id=":J0_21_0" index="0" speed="10.36" length="16.53" shape="0.00,-5.87 -2.20,-2.20 -6.95,0.65 -13.60,1.60"/>
    </edge>
    <edge id=":J0_14" function="internal">
        <lane id=":J0_14_0" index="0" speed="6.51" length="9.03" shape="-13.60,-8.00 -11.15,-8.35 -9.40,-9.40 -8.35,-11.15 -8.00,-13.60"/>
    </edge>
    <edge id=":J0_15" function="internal">
        <lane id=":J0_15_0" index="0" speed="13.89" length="27.20" shape="-13.60,-8.00 13.60,-8.00"/>
        <lane id=":J0_15_1" index="1" speed="13.89" length="27.20" shape="-13.60,-4.80 13.60,-4.80"/>
        <lane id=":J0_15_2" index="2" speed="13.89" length="27.20" shape="-13.60,-1.60 13.60,-1.60"/>
    </edge>
    <edge id=":J0_18" function="internal">
        <lane id=":J0_18_0" index="0" speed="10.36" length="7.98" shape="-13.60,-1.60 -6.95,-0.65 -5.87,-0.00"/>
    </edge>
    <edge id=":J0_22" function="internal">
        <lane id=":J0_22_0" index="0" speed="10.36" length="16.53" shape="-5.87,-0.00 -2.20,2.20 0.65,6.95 1.60,13.60"/>
    </edge>

    <edge id="-E0" from="J1" to="J0" priority="-1">
        <lane id="-E0_0" index="0" speed="13.89" length="86.40" shape="8.00,-100.00 8.00,-13.60"/>
        <lane id="-E0_1" index="1" speed="13.89" length="86.40" shape="4.80,-100.00 4.80,-13.60"/>
        <lane id="-E0_2" index="2" speed="13.89" length="86.40" shape="1.60,-100.00 1.60,-13.60"/>
    </edge>
    <edge id="-E1" from="J0" to="J2" priority="-1">
        <lane id="-E1_0" index="0" speed="13.89" length="86.40" shape="-13.60,8.00 -100.00,8.00"/>
        <lane id="-E1_1" index="1" speed="13.89" length="86.40" shape="-13.60,4.80 -100.00,4.80"/>
        <lane id="-E1_2" index="2" speed="13.89" length="86.40" shape="-13.60,1.60 -100.00,1.60"/>
    </edge>
    <edge id="-E2" from="J0" to="J3" priority="-1">
        <lane id="-E2_0" index="0" speed="13.89" length="86.40" shape="13.60,-8.00 100.00,-8.00"/>
        <lane id="-E2_1" index="1" speed="13.89" length="86.40" shape="13.60,-4.80 100.00,-4.80"/>
        <lane id="-E2_2" index="2" speed="13.89" length="86.40" shape="13.60,-1.60 100.00,-1.60"/>
    </edge>
    <edge id="-E3" from="J0" to="J4" priority="-1">
        <lane id="-E3_0" index="0" speed="13.89" length="86.40" shape="8.00,13.60 8.00,100.00"/>
        <lane id="-E3_1" index="1" speed="13.89" length="86.40" shape="4.80,13.60 4.80,100.00"/>
        <lane id="-E3_2" index="2" speed="13.89" length="86.40" shape="1.60,13.60 1.60,100.00"/>
    </edge>
    <edge id="E0" from="J0" to="J1" priority="-1">
        <lane id="E0_0" index="0" speed="13.89" length="86.40" shape="-8.00,-13.60 -8.00,-100.00"/>
        <lane id="E0_1" index="1" speed="13.89" length="86.40" shape="-4.80,-13.60 -4.80,-100.00"/>
        <lane id="E0_2" index="2" speed="13.89" length="86.40" shape="-1.60,-13.60 -1.60,-100.00"/>
    </edge>
    <edge id="E1" from="J2" to="J0" priority="-1">
        <lane id="E1_0" index="0" speed="13.89" length="86.40" shape="-100.00,-8.00 -13.60,-8.00"/>
        <lane id="E1_1" index="1" speed="13.89" length="86.40" shape="-100.00,-4.80 -13.60,-4.80"/>
        <lane id="E1_2" index="2" speed="13.89" length="86.40" shape="-100.00,-1.60 -13.60,-1.60"/>
    </edge>
    <edge id="E2" from="J3" to="J0" priority="-1">
        <lane id="E2_0" index="0" speed="13.89" length="86.40" shape="100.00,8.00 13.60,8.00"/>
        <lane id="E2_1" index="1" speed="13.89" length="86.40" shape="100.00,4.80 13.60,4.80"/>
        <lane id="E2_2" index="2" speed="13.89" length="86.40" shape="100.00,1.60 13.60,1.60"/>
    </edge>
    <edge id="E3" from="J4" to="J0" priority="-1">
        <lane id="E3_0" index="0" speed="13.89" length="86.40" shape="-8.00,100.00 -8.00,13.60"/>
        <lane id="E3_1" index="1" speed="13.89" length="86.40" shape="-4.80,100.00 -4.80,13.60"/>
        <lane id="E3_2" index="2" speed="13.89" length="86.40" shape="-1.60,100.00 -1.60,13.60"/>
    </edge>

    <tlLogic id="J0" type="static" programID="0" offset="0">
        <phase duration="42" state="GGGGgrrrrrGGGgrrrrr"/>
        <phase duration="3"  state="yyyyyrrrrryyyyrrrrr"/>
        <phase duration="42" state="rrrrrGGGGgrrrrGGGGg"/>
        <phase duration="3"  state="rrrrryyyyyrrrryyyyy"/>
    </tlLogic>

    <junction id="J0" type="traffic_light" x="0.00" y="0.00" incLanes="E3_0 E3_1 E3_2 E2_0 E2_1 E2_2 -E0_0 -E0_1 -E0_2 E1_0 E1_1 E1_2" intLanes=":J0_0_0 :J0_1_0 :J0_1_1 :J0_1_2 :J0_19_0 :J0_5_0 :J0_6_0 :J0_6_1 :J0_6_2 :J0_20_0 :J0_10_0 :J0_10_1 :J0_10_2 :J0_21_0 :J0_14_0 :J0_15_0 :J0_15_1 :J0_15_2 :J0_22_0" shape="-9.60,13.60 9.60,13.60 10.04,11.38 10.60,10.60 11.38,10.04 12.38,9.71 13.60,9.60 13.60,-9.60 11.38,-10.04 10.60,-10.60 10.04,-11.38 9.71,-12.38 9.60,-13.60 -9.60,-13.60 -10.04,-11.38 -10.60,-10.60 -11.38,-10.04 -12.38,-9.71 -13.60,-9.60 -13.60,9.60 -11.38,10.04 -10.60,10.60 -10.04,11.38 -9.71,12.38">
        <request index="0"  response="0000000000000000000" foes="0000000000111000000" cont="0"/>
        <request index="1"  response="1000000001000000000" foes="1111110001111000000" cont="0"/>
        <request index="2"  response="1000000001000000000" foes="1111110001111000000" cont="0"/>
        <request index="3"  response="1000000001000000000" foes="1111110001111000000" cont="0"/>
        <request index="4"  response="1000001111000000000" foes="1111001111111000000" cont="1"/>
        <request index="5"  response="0000001110000000000" foes="0000001110000000000" cont="0"/>
        <request index="6"  response="0000011110000011111" foes="1000011110000011111" cont="0"/>
        <request index="7"  response="0000011110000011111" foes="1000011110000011111" cont="0"/>
        <request index="8"  response="0000011110000011111" foes="1000011110000011111" cont="0"/>
        <request index="9"  response="0111011110000011110" foes="0111011110000011110" cont="1"/>
        <request index="10" response="1000000001000000000" foes="1111000001111110000" cont="0"/>
        <request index="11" response="1000000001000000000" foes="1111000001111110000" cont="0"/>
        <request index="12" response="1000000001000000000" foes="1111000001111110000" cont="0"/>
        <request index="13" response="1000000001000001110" foes="1111000001111001110" cont="1"/>
        <request index="14" response="0000000000000001110" foes="0000000000000001110" cont="0"/>
        <request index="15" response="0000011110000011110" foes="0000011111000011110" cont="0"/>
        <request index="16" response="0000011110000011110" foes="0000011111000011110" cont="0"/>
        <request index="17" response="0000011110000011110" foes="0000011111000011110" cont="0"/>
        <request index="18" response="0000011110111011110" foes="0000011110111011110" cont="1"/>
    </junction>
    <junction id="J1" type="dead_end" x="0.00" y="-100.00" incLanes="E0_0 E0_1 E0_2" intLanes="" shape="0.00,-100.00 -9.60,-100.00 0.00,-100.00"/>
    <junction id="J2" type="dead_end" x="-100.00" y="0.00" incLanes="-E1_0 -E1_1 -E1_2" intLanes="" shape="-100.00,0.00 -100.00,9.60 -100.00,0.00"/>
    <junction id="J3" type="dead_end" x="100.00" y="0.00" incLanes="-E2_0 -E2_1 -E2_2" intLanes="" shape="100.00,0.00 100.00,-9.60 100.00,0.00"/>
    <junction id="J4" type="dead_end" x="0.00" y="100.00" incLanes="-E3_0 -E3_1 -E3_2" intLanes="" shape="0.00,100.00 9.60,100.00 0.00,100.00"/>

    <junction id=":J0_19_0" type="internal" x="-0.00" y="5.87" incLanes=":J0_4_0 -E0_0 -E0_1 -E0_2" intLanes=":J0_6_0 :J0_6_1 :J0_6_2 :J0_9_0 :J0_10_0 :J0_10_1 :J0_10_2 :J0_15_0 :J0_15_1 :J0_15_2 :J0_18_0"/>
    <junction id=":J0_20_0" type="internal" x="5.87" y="0.00" incLanes=":J0_9_0 E1_0 E1_1 E1_2" intLanes=":J0_1_0 :J0_1_1 :J0_1_2 :J0_4_0 :J0_10_0 :J0_10_1 :J0_10_2 :J0_13_0 :J0_14_0 :J0_15_0 :J0_15_1 :J0_15_2"/>
    <junction id=":J0_21_0" type="internal" x="0.00" y="-5.87" incLanes=":J0_13_0 E3_0 E3_1 E3_2" intLanes=":J0_0_0 :J0_1_0 :J0_1_1 :J0_1_2 :J0_6_0 :J0_6_1 :J0_6_2 :J0_9_0 :J0_15_0 :J0_15_1 :J0_15_2 :J0_18_0"/>
    <junction id=":J0_22_0" type="internal" x="-5.87" y="-0.00" incLanes=":J0_18_0 E2_0 E2_1 E2_2" intLanes=":J0_1_0 :J0_1_1 :J0_1_2 :J0_4_0 :J0_5_0 :J0_6_0 :J0_6_1 :J0_6_2 :J0_10_0 :J0_10_1 :J0_10_2 :J0_13_0"/>

    <connection from="-E0" to="-E3" fromLane="0" toLane="0" via=":J0_10_0" tl="J0" linkIndex="10" dir="s" state="O"/>
    <connection from="-E0" to="-E3" fromLane="1" toLane="1" via=":J0_10_1" tl="J0" linkIndex="11" dir="s" state="O"/>
    <connection from="-E0" to="-E3" fromLane="2" toLane="2" via=":J0_10_2" tl="J0" linkIndex="12" dir="s" state="O"/>
    <connection from="-E0" to="-E1" fromLane="2" toLane="2" via=":J0_13_0" tl="J0" linkIndex="13" dir="l" state="o"/>
    <connection from="E1" to="E0" fromLane="0" toLane="0" via=":J0_14_0" tl="J0" linkIndex="14" dir="r" state="o"/>
    <connection from="E1" to="-E2" fromLane="0" toLane="0" via=":J0_15_0" tl="J0" linkIndex="15" dir="s" state="o"/>
    <connection from="E1" to="-E2" fromLane="1" toLane="1" via=":J0_15_1" tl="J0" linkIndex="16" dir="s" state="o"/>
    <connection from="E1" to="-E2" fromLane="2" toLane="2" via=":J0_15_2" tl="J0" linkIndex="17" dir="s" state="o"/>
    <connection from="E1" to="-E3" fromLane="2" toLane="2" via=":J0_18_0" tl="J0" linkIndex="18" dir="l" state="o"/>
    <connection from="E2" to="-E3" fromLane="0" toLane="0" via=":J0_5_0" tl="J0" linkIndex="5" dir="r" state="o"/>
    <connection from="E2" to="-E1" fromLane="0" toLane="0" via=":J0_6_0" tl="J0" linkIndex="6" dir="s" state="o"/>
    <connection from="E2" to="-E1" fromLane="1" toLane="1" via=":J0_6_1" tl="J0" linkIndex="7" dir="s" state="o"/>
    <connection from="E2" to="-E1" fromLane="2" toLane="2" via=":J0_6_2" tl="J0" linkIndex="8" dir="s" state="o"/>
    <connection from="E2" to="E0" fromLane="2" toLane="2" via=":J0_9_0" tl="J0" linkIndex="9" dir="l" state="o"/>
    <connection from="E3" to="-E1" fromLane="0" toLane="0" via=":J0_0_0" tl="J0" linkIndex="0" dir="r" state="O"/>
    <connection from="E3" to="E0" fromLane="0" toLane="0" via=":J0_1_0" tl="J0" linkIndex="1" dir="s" state="O"/>
    <connection from="E3" to="E0" fromLane="1" toLane="1" via=":J0_1_1" tl="J0" linkIndex="2" dir="s" state="O"/>
    <connection from="E3" to="E0" fromLane="2" toLane="2" via=":J0_1_2" tl="J0" linkIndex="3" dir="s" state="O"/>
    <connection from="E3" to="-E2" fromLane="2" toLane="2" via=":J0_4_0" tl="J0" linkIndex="4" dir="l" state="o"/>

    <connection from=":J0_0" to="-E1" fromLane="0" toLane="0" dir="r" state="M"/>
    <connection from=":J0_1" to="E0" fromLane="0" toLane="0" dir="s" state="M"/>
    <connection from=":J0_1" to="E0" fromLane="1" toLane="1" dir="s" state="M"/>
    <connection from=":J0_1" to="E0" fromLane="2" toLane="2" dir="s" state="M"/>
    <connection from=":J0_4" to="-E2" fromLane="0" toLane="2" via=":J0_19_0" dir="l" state="m"/>
    <connection from=":J0_19" to="-E2" fromLane="0" toLane="2" dir="l" state="M"/>
    <connection from=":J0_5" to="-E3" fromLane="0" toLane="0" dir="r" state="M"/>
    <connection from=":J0_6" to="-E1" fromLane="0" toLane="0" dir="s" state="M"/>
    <connection from=":J0_6" to="-E1" fromLane="1" toLane="1" dir="s" state="M"/>
    <connection from=":J0_6" to="-E1" fromLane="2" toLane="2" dir="s" state="M"/>
    <connection from=":J0_9" to="E0" fromLane="0" toLane="2" via=":J0_20_0" dir="l" state="m"/>
    <connection from=":J0_20" to="E0" fromLane="0" toLane="2" dir="l" state="M"/>
    <connection from=":J0_10" to="-E3" fromLane="0" toLane="0" dir="s" state="M"/>
    <connection from=":J0_10" to="-E3" fromLane="1" toLane="1" dir="s" state="M"/>
    <connection from=":J0_10" to="-E3" fromLane="2" toLane="2" dir="s" state="M"/>
    <connection from=":J0_13" to="-E1" fromLane="0" toLane="2" via=":J0_21_0" dir="l" state="m"/>
    <connection from=":J0_21" to="-E1" fromLane="0" toLane="2" dir="l" state="M"/>
    <connection from=":J0_14" to="E0" fromLane="0" toLane="0" dir="r" state="M"/>
    <connection from=":J0_15" to="-E2" fromLane="0" toLane="0" dir="s" state="M"/>
    <connection from=":J0_15" to="-E2" fromLane="1" toLane="1" dir="s" state="M"/>
    <connection from=":J0_15" to="-E2" fromLane="2" toLane="2" dir="s" state="M"/>
    <connection from=":J0_18" to="-E3" fromLane="0" toLane="2" via=":J0_22_0" dir="l" state="m"/>
    <connection from=":J0_22" to="-E3" fromLane="0" toLane="2" dir="l" state="M"/>

</net>

上一篇:android – 如何提供SUMO遥测数据?


下一篇:C#控制台画图形