容器化 SUMO

本教程展示如何在 Docker 容器内使用 SUMO 运行仿真。

简介#

本教程演示如何在不将软件安装到本地机器的情况下使用 SUMO 运行仿真。

也可以从 Docker 容器运行 GUI 应用程序。 实现方式高度依赖于您的个人设置。 我们尝试在专门的教程中提供相关建议。

获取 Docker 镜像#

您可以通过以下方式从 SUMO Docker 仓库获取最新的 Docker 镜像:

  docker pull ghcr.io/eclipse-sumo/sumo:latest

或者,通过检出 SUMO 仓库 并执行以下命令来构建您自己的本地版本镜像:

  cd build_config/docker
  docker build -t ghcr.io/eclipse-sumo/sumo:latest -f Dockerfile.ubuntu.git .

创建仿真文件#

在本教程中,我们使用 Hello SUMO 教程 中的仿真文件。 请查看该教程以了解这些文件的用途。

创建一个名为 hello_sumo_docker 的目录,并在其中创建 3 个文件:

hello.net.xml#

<?xml version="1.0" encoding="UTF-8"?>
<net version="1.20" 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="250.00,0.00" convBoundary="0.00,0.00,501.00,0.00" origBoundary="-250.00,0.00,251.00,0.00"
              projParameter="!"/>
    <edge id=":2_0" function="internal">
        <lane id=":2_0_0" index="0" speed="13.89" length="0.10" shape="500.00,-1.60 500.00,-1.60"/>
    </edge>
    <edge id="1to2" from="1" to="2" priority="-1">
        <lane id="1to2_0" index="0" speed="13.89" length="500.00" shape="0.00,-1.60 500.00,-1.60"/>
    </edge>
    <edge id="out" from="2" to="3" priority="-1">
        <lane id="out_0" index="0" speed="13.89" length="1.00" shape="500.00,-1.60 501.00,-1.60"/>
    </edge>

    <junction id="1" type="dead_end" x="0.00" y="0.00" incLanes="" intLanes="" shape="0.00,0.00 0.00,-3.20"/>
    <junction id="2" type="priority" x="500.00" y="0.00" incLanes="1to2_0" intLanes=":2_0_0"
              shape="500.00,0.00 500.00,-3.20 500.00,0.00">
        <request index="0" response="0" foes="0" cont="0"/>
    </junction>
    <junction id="3" type="dead_end" x="501.00" y="0.00" incLanes="out_0" intLanes="" shape="501.00,-3.20 501.00,0.00"/>

    <connection from="1to2" to="out" fromLane="0" toLane="0" via=":2_0_0" dir="s" state="M"/>
    <connection from=":2_0" to="out" fromLane="0" toLane="0" dir="s" state="M"/>
</net>

hello.rou.xml#

<routes>
    <vType accel="1.0" decel="5.0" id="Car" length="2.0" maxSpeed="100.0" sigma="0.0"/>
    <route id="route0" edges="1to2 out"/>
    <vehicle depart="1" id="veh0" route="route0" type="Car"/>
</routes>

hello.sumocfg#

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

运行仿真#

要运行仿真,请从镜像启动一个新容器,并使用 -v 选项将目录挂载到容器中。 在 SUMO 命令中添加 --full-output result.xml 以获取仿真结果。 启动容器的命令可能如下所示:

  # 将此替换为仿真文件所在的位置。
  export SIMULATION_FILES_DIR=$PWD

  docker run \
      --rm \
      -v $SIMULATION_FILES_DIR:$SIMULATION_FILES_DIR \
      ghcr.io/eclipse-sumo/sumo:latest \
      sumo --configuration-file $SIMULATION_FILES_DIR/hello.sumocfg --full-output $SIMULATION_FILES_DIR/result.xml

这将运行 hello.sumocfg 中指定的仿真。 之后,将创建一个名为 result.xml 的文件,其中包含仿真的输出。

延伸阅读#

您可以使用 Docker 镜像尝试更多的教程