输出解析

在本教程中,您将学习如何:

  • 使用边类型(edge types)设置抽象网络,
  • 使用流(flows)创建重复的相同车辆,
  • 动态重新规划车辆路径,使其无限行驶,
  • 使用 sumolib python 库 分析输出文件,

此外,作为附加内容,您还将学习如何:

  • 使用套接字输出进行在线评估并节省磁盘空间。

尽管包含“在线”、“套接字”和“Python API”等关键词,本教程涉及任何 TraCI 相关内容。

网络设置#

目标是构建一个简单的网络,让车辆在其中绕圈行驶。因此,我们在角落设置四个节点,如下所示 (circular.nod.xml):

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

<nodes version="0.13" xmlns:xsi="https://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://sumo.sf.net/xsd/nodes_file.xsd">
    <node id="bottom-left" x="0" y="0"/>
    <node id="bottom-right" x="1250" y="0"/>
    <node id="top-right" x="1250" y="1250"/>
    <node id="top-left" x="0" y="1250"/>
</nodes>

所有连接节点的边应具有相同的车道数和最大速度。为了节省输入时间,我们在单独的文件中定义边类型 (circular.typ.xml):

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

<types xmlns:xsi="https://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://sumo.sf.net/xsd/types_file.xsd">
    <type id="edgeType" numLanes="2" speed="36.1"/>
</types>

最后,我们定义连接节点的边 (circular.edg.xml):

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

<edges version="0.13" xmlns:xsi="https://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://sumo.sf.net/xsd/edges_file.xsd">
    <edge from="bottom-left" id="bottom" to="bottom-right" type="edgeType"/>
    <edge from="bottom-right" id="right" to="top-right" type="edgeType"/>
    <edge from="top-right" id="top" to="top-left" type="edgeType"/>
    <edge from="top-left" id="left" to="bottom-left" type="edgeType"/>
</edges>

netconvert 调用非常直接:

netconvert -n circular.nod.xml -t circular.typ.xml -e circular.edg.xml -o circular.net.xml

为了简化生成的网络(并获得最高的仿真速度),我们省略了掉头车道(turnarounds),并通过移除交叉口内部车道来简化交叉口的移动。完整的 netconvert 配置文件如下 (circular.netccfg):

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

<configuration xmlns:xsi="https://www.w3.org/2001/XMLSchema-instance"
    xsi:noNamespaceSchemaLocation="https://sumo.sf.net/xsd/netconvertConfiguration.xsd">

   <input>
       <node-files value="circular.nod.xml"/>
       <edge-files value="circular.edg.xml"/>
       <type-files value="circular.typ.xml"/>
   </input>

<output>
       <output-file value="circular.net.xml"/>
</output>

   <processing>
       <no-internal-links value="true"/>
       <no-turnarounds value="true"/>
   </processing>

</configuration>

使用此配置文件再次调用 netconvert:

netconvert -c circular.netcfg

尝试运行:

sumo-gui -n circular.net.xml

以查看最终网络。

路径和流设置#

接下来,我们定义路径和交通流。打开一个名为 circular.rou.xml 的新文件,并插入以下针对汽车和卡车的车辆类型定义:

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

<routes xmlns:xsi="https://www.w3.org/2001/XMLSchema-instance"
  xsi:noNamespaceSchemaLocation="https://sumo.sf.net/xsd/routes_file.xsd">
    <vType accel="1.5" decel="4.5" id="car" length="5" maxSpeed="36.1"/>
    <vType accel="0.4" decel="4.5" id="truck" length="12" maxSpeed="22.2"/>
</routes>

更多细节,请参见车辆类型属性描述。 由于我们网络的边是单向的,我们需要定义相应的环形路径,即逆时针方向,如下所示:

    <route id="routeRight" edges="bottom right top left"/>
    <route id="routeLeft" edges="top left bottom right"/>
    <route id="routeTop" edges="right top left bottom"/>
    <route id="routeBottom" edges="left bottom right top"/>

将这些行添加在闭合的 </routes> 元素之前。更多关于定义自定义路径的信息可以在这里找到。 最后,我们在这些路径上定义交通流。对于每条路径,我们分别为汽车和卡车设置一个流:

    <flow begin="0" departPos="free" id="carRight" period="1" number="70" route="routeRight" type="car"/>
    <flow begin="0" departPos="free" id="carTop" period="1" number="70" route="routeTop" type="car"/>
    <flow begin="0" departPos="free" id="carLeft" period="1" number="70" route="routeLeft" type="car"/>
    <flow begin="0" departPos="free" id="carBottom" period="1" number="70" route="routeBottom" type="car"/>
    <flow begin="0" departPos="free" id="truckRight" period="1" number="30" route="routeRight" type="truck"/>
    <flow begin="0" departPos="free" id="truckTop" period="1" number="30" route="routeTop" type="truck"/>
    <flow begin="0" departPos="free" id="truckLeft" period="1" number="30" route="routeLeft" type="truck"/>
    <flow begin="0" departPos="free" id="truckBottom" period="1" number="30" route="routeBottom" type="truck"/>

这些行可以插入在路径定义之后。更多关于 flow 元素属性的信息可以在这里找到。

路径重定向器 (Rerouters)#

目前,所有采用已定义路径的流在到达其路径目的地后都会离开仿真。 为了获得无限行驶的车辆,我们需要定义路径重定向器。 因此,我们创建一个名为 circular.add.xml 的文件,该文件在边 bottomtop 上各定义一个路径重定向器,使得车辆分别继续行驶在路径 routeRightrouteLeft 上。

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

<additional xmlns:xsi="https://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://sumo.sf.net/xsd/additional_file.xsd">
    <rerouter id="rerouterBottom" edges="bottom">
        <interval begin="0" end="100000">
            <routeProbReroute id="routeRight" />
        </interval>
    </rerouter>
    <rerouter id="rerouterTop" edges="top">
        <interval begin="0" end="100000">
            <routeProbReroute id="routeLeft" />
        </interval>
    </rerouter>
</additional>

整合所有文件#

完成所有输入文件(网络、路径、路径重定向器)后,我们可以创建一个 SUMO 配置文件 circular.sumocfg

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

<configuration xmlns:xsi="https://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://sumo.sf.net/xsd/sumoConfiguration.xsd">
    <input>
        <net-file value="circular.net.xml"/>
        <additional-files value="circular.rou.xml,circular.add.xml"/>
    </input>

    <output>
        <netstate-dump value="dump.xml"/>
    </output>

    <time>
        <begin value="0"/>
        <end value="1000"/>
    </time>
</configuration>

请注意,路径文件 circular.rou.xml 在此被声明为附加文件(additionals file),以防止由于输入文件的加载顺序而导致的引用错误。 由于我们希望稍后分析仿真的输出,我们还定义了输出文件 dump.xml,用于存储完整的网络状态(参见输出选项RawDump)。

分析输出#

附加内容:套接字通信#