我是靠谱客的博主 落后小鸭子,这篇文章主要介绍Linux环境下利用C++联立sumo交通软件介绍:第一步:第二步:第三步:第四步:,现在分享给大家,希望可以做个参考。

介绍:

    目前各大网站都是利用python中sumo软件,该文档介绍C++联合仿真

第一步:

环境:Ubuntu18.04

            sumo版本:一般官网最新的就好

    Linux环境下命令行安sumo

https://sumo.dlr.de/docs/Downloads.php 

 

第二步:

  1、在终端输入sudo sumo-gui命令行,看sumo的UI界面是否成功弹出

  2、将下面的文件复制到自 test.cpp文件中   

#include <iostream>
#define HAVE_LIBSUMOGUI 
#include <libsumo/libsumo.h>
using namespace libsumo;
int main(int argc, char *argv[])
{
 Simulation::start({"sumo-gui", "-c", "./data/cross.sumocfg"});
 int step = 0;
 int count=libsumo::Vehicle::getIDCount();
 std::cout << count << std::endl;
 while (step < 1200)
 {
   Simulation::step();
   int count=libsumo::Vehicle::getIDCount();
   std::cout << count << std::endl;
   step += 1;
  }
 Simulation::close();
}

注意:

      Simulation::start({"sumo-gui","-c"," 自己的sumocfg文件路径"});

第三步:

以下是我自己的cross.sumocfg

<?xml version="1.0" encoding="UTF-8"?>
<configuration xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://sumo.dlr.de/xsd/sumoConfiguration.xsd">
<input>
<net-file value="Tcross.net.xml"/>
</input>
<time>
<begin value="0"/>
<step-length value="0.1"/>
</time>
<gui_only>
<start value="t"/>
<quit-on-end value="t"/>
</gui_only>
</configuration>

       其中

 <input>

     <net-file value = "Tcross.net.xml">

的  Tcross.net.xml   是由  netedit.exe

画出来的。(在Linux终端中输入netedit命令就会弹出构建路网的软件)

第四步:

 编译:test.cpp

在文件目录下的终端中输入

g++ -o test -std=c++11 -I$SUMO_HOME/src test.cpp -L$SUMO_HOME/bin -lsumocpp

文件目录下的终端执行   ./test 

 成功在Linux下sumo与C++仿真成功

最后

以上就是落后小鸭子最近收集整理的关于Linux环境下利用C++联立sumo交通软件介绍:第一步:第二步:第三步:第四步:的全部内容,更多相关Linux环境下利用C++联立sumo交通软件介绍内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(76)

评论列表共有 0 条评论

立即
投稿
返回
顶部