基于sumo实现交通灯控制算法的模板

2024-01-06 06:20

本文主要是介绍基于sumo实现交通灯控制算法的模板,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

基于sumo实现交通灯控制算法的模板

目录

  • 在windows安装
  • run hello world
    • network
    • routes
    • viewsettings & configuration
    • simulation
  • 交通灯控制系统
    • 介绍
    • 文件生成器类(FileGenerator)
    • 道路网络(Network)
    • 辅助函数
    • 生成道路网络(GenerateNetwork)
    • 生成路径(route)
    • 生成车辆(vehicle)
    • 生成交通信号灯(tlLogic)
    • 生成探测器(detector)
    • py程序接口(TraCI)
  • 附录
    • node
    • edge
    • connection
    • route
    • vehicle
    • tlLogic
    • TraCI
    • Detector
    • simulation
    • 参考资料
    • 有关文件

原文地址:https://www.wolai.com/7SsvyQLdZQr5TPikSDG9rR

代码在附录中

在windows安装

SUMO 软件包中的大多数应用程序都是命令行工具,目前只有sumo-gui和netedit不是。

SUMO 应用程序是普通的可执行文件。你只需在命令行中输入其名称即可启动它们;例如,netgenerate的调用方式是

netgenerate.exe

这只是启动应用程序(本例中为netgenerate)。由于没有给出参数,应用程序不知道要做什么,只能打印有关自身的信息:

外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传

SUMO 中有两个gui程序:

  • netedit:生成network、routes等
  • sumo-gui:执行simulation

这两个程序均可通过命令行启动:

启动netedit:

netedit

外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传

启动sumo-gui:

sumo-gui

外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传

run hello world

通过GUI创建和仿真的详细操作参考此处:https://sumo.dlr.de/docs/Tutorials/Hello_World.html

我们接下来要讨论的是通过文件创建和仿真,这将用到如下文件:

  • *.nod.xml:记录节点信息
  • *.edg.xml:记录边信息
  • *.net.xml:记录网络信息,通过 netconvert 生成
  • *.rou.xml:记录车辆信息
  • *.settings.xml:记录仿真界面的配置信息
  • *.sumocfg:记录仿真信息,sumo通过此文件执行仿真

network

所有节点都有一个位置(x 坐标和 y 坐标,描述到原点的距离,以米为单位)和一个 ID,以供将来参考。因此,我们的简单节点文件如下:

<nodes><node id="1" x="-250.0" y="0.0" /><node id="2" x="+250.0" y="0.0" /><node id="3" x="+251.0" y="0.0" />
</nodes>

您可以使用自己选择的文本编辑器编辑文件,并将其保存为hello.nod.xml,其中.nod.xml是 Sumo 节点文件的默认后缀。

现在我们用边来连接节点。这听起来很简单。我们有一个源节点 ID、一个目标节点 ID 和一个边 ID,以备将来参考。边是有方向的,因此每辆车在这条边上行驶时,都会from给出的源节点开始,在给出的to节点结束。

<edges><edge from="1" id="1to2" to="2" /><edge from="2" id="out" to="3" />
</edges>

将这些数据保存到名为hello.edg.xml 的文件中。

现在我们有了节点和边,就可以调用第一个 SUMO 工具来创建网络了。 确保netconvert位于PATH中的某个位置,然后调用

netconvert --node-files=hello.nod.xml --edge-files=hello.edg.xml --output-file=hello.net.xml

这将生成名为hello.net.xml 的网络。

启动netedit并查看文件:

netedit hello.net.xml

外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传

routes

更多信息请参阅"车辆、车辆类型和路线的定义"

定义如下几个字段:

  • vType :车辆类型的信息
  • route :路径的信息
  • vehicle :车辆的信息

如下所示的hello.rou.xml文件:

<routes><vType id="typeCar" accel="0.8" decel="4.5" sigma="0.5" length="5" minGap="2.5" maxSpeed="16.67" guiShape="passenger"/><route id="route0" edges="1to2 out"/><vehicle depart="1" id="veh0" route="route0" type="typeCar" /><vehicle depart="20" id="veh1" route="route0" type="typeCar" />
</routes>

注意:定义多辆车时,应该按照depart属性排序

viewsettings & configuration

使用图形用户界面进行模拟时,添加一个 gui-settings 文件非常有用,这样就不必在启动程序后更改设置。为此,创建一个viewsettings文件:

<viewsettings><viewport y="0" x="250" zoom="100"/><delay value="100"/>
</viewsettings>

将其保存为配置文件中包含的名称,在本例中就是hello.settings.xml

在这里,我们使用视口(viewport)来设置摄像机的位置,并使用延迟(delay)来设置模拟的每一步之间的延迟(毫秒)。

现在,我们将所有内容粘合到一个配置文件中:

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

将其保存到hello.sumocfg

simulation

Using the Command Line Applications - SUMO Documentation (dlr.de)

我们就可以开始模拟了,方法如下:

sumo-gui -c hello.sumocfg

交通灯控制系统

看不懂的参数请看附录

介绍

Quick Start (old style) - SUMO Documentation (dlr.de)

我们的目的是生成如下类型的道路网络:

  • 十字路口的规模是可自定义的
  • 十字路口的道路是有专用转向车道的

外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传

外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传

道路网络network:

  • 节点node
  • 边edge
  • 道路lane:每条边对应多条道路
  • 连接connection:边与边之间的连接关系

外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传

我们的项目按照如下流程进行:

外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传

文件生成器类(FileGenerator)

import os
import subprocess
from sample.NetworkFileGenerator import NetworkFileGenerator
from sample.SumoFileGenerator import SumoFileGeneratorclass FileGenerator:def __init__(self):self._networkGenerator = NetworkFileGenerator()self._sumoGenerator = SumoFileGenerator()self.network = Nonepassdef GenerateAllFile(self, netconvert: str = "netconvert", cwd: str = "", name: str = "sample",height: int = 1, width: int = 1, unity: int = 100,avgCarAmount: int = 5, timePeriod: int = 100):if cwd == "":cwd = os.getcwd() + "/data"  # 输出目录# 生成所需文件self._networkGenerator.GenerateAllFile(cwd, name, width, height, unity)self._sumoGenerator.GenerateAllFile(cwd, name, self._networkGenerator.network, avgCarAmount, timePeriod)p = subprocess.Popen([netconvert,"-c", "%s.netccfg" % (name),"--no-turnarounds.tls", "true"],stdin=subprocess.PIPE, stdout=subprocess.PIPE,cwd=cwd)p.wait()self.network = self._networkGenerator.networkpasspass
  • 负责根据参数生成绝大多数有关文件
  • 支持输出目录的自定义
  • 支持输出文件名的自定义
  • 外界通过调用GenerateAllFile以使用该类

道路网络(Network)

道路网络的数据结构:

from collections import defaultdictclass Network:def __init__(self):"""Node: (int, int)Edge: (Node, Node)Connection: (Node, Node, Node, lane: int)"""self.width = 1  # 水平方向的交通灯数量self.height = 1  # 竖直方向的交通灯数量self.nodes = []  # 节点self.edges = []  # 边self.connections = []  # 连接self.tlNodes = []  # 交通灯节点self.boundaryNodes = []  # 边界节点self.inEdges = defaultdict(list)  # 入边表,Node -> [Edge]self.outEdges = defaultdict(list)  # 出边表,Node -> [Edge]passpass
  • 节点使用二维坐标来描述
  • 边使用两个节点来描述
  • 连接使用三个节点来描述
  • width、height是交通灯的数量信息

辅助函数

def GetNodeId(i: int, j: int) -> str:return "%01d%01d" % (i, j)def GetEdgeId(i: int, j: int, u: int, v: int) -> str:# from (i, j) to (u, v)return "%sto%s" % (GetNodeId(i, j), GetNodeId(u, v))def GetRouteId(i: int, j: int, u: int, v: int, additional: int) -> str:# from (i, j) to (u, v)return "%s_%08d" % (GetEdgeId(i, j, u, v), additional)def GetLaneId(i: int, j: int, u: int, v: int, lane: int) -> str:# from (i, j) to (u, v)return "%s_%1d" % (GetEdgeId(i, j, u, v), lane)def GetDetectorId(i: int, j: int, u: int, v: int, lane: int) -> str:# from (i, j) to (u, v)return "det_%s" % (GetLaneId(i, j, u, v, lane))def IsTrafficLightNode(width: int, height: int, i: int, j: int) -> bool:# [1, width] * [1, height] 范围内是交通灯节点return 1 <= i and i <= width and 1 <= j and j <= heightdef IsBoundaryNode(width: int, height: int, i: int, j: int) -> bool:# [1, width] * [1, height] 范围外的一圈是边界return i == 0 or i == width + 1 or j == 0 or j == height + 1def IsIllegalNode(width: int, height: int, i: int, j: int) -> bool:# [0, width + 1] * [0, height + 1] 范围外是非法的return i < 0 or i > width + 1 or j < 0 or j > height + 1def IsCornerNode(width: int, height: int, i: int, j: int) -> bool:# (0, 0) (width + 1, 0) (0, height + 1) (width + 1, height + 1) 是角落return i == 0 and j == 0 or \i == width + 1 and j == 0 or \i == 0 and j == height + 1 or \i == width + 1 and j == height + 1def GetEdgesOfRoute(path: list) -> str:# 从节点列表,以字符串形式,给出途经的边ret = ""for i in range(1, len(path)):ret += GetEdgeId(*path[i - 1], *path[i]) + " "return retdef ToXMLElement(name: str, *arg: str):import xml.domdoc = xml.dom.minidom.Document()# doc = xml.dom.minidom.Document()element = doc.createElement(name)for i in range(1, len(arg), 2):element.setAttribute(arg[i - 1], arg[i])return elementpass
  • [1, width] * [1, height]是交通灯的坐标
  • [1, width] * [1, height] 范围外的一圈是边界
  • [0, width + 1] * [0, height + 1] 范围外是非法的
  • (0, 0) (width + 1, 0) (0, height + 1) (width + 1, height + 1) 是角落

生成道路网络(GenerateNetwork)

  • 规定方向编号:参考极坐标系,角度与方向编号有线性关系
    • 0:x轴正向
    • 1:y轴正向
    • 2:x轴负向
    • 3:y轴负向
  • 规定转向编号:即方向编号的差分量
    • -1:右转
    • 0:直行
    • 1:左转

这样规定转向编号的原因是,转向编号与sumo的车道编号相对应。sumo的车道编号是从右到左的。

代码如下:

class NetworkFileGenerator:def __init__(self):self.cwd = None  # 输出目录self.name = None  # 文件名self.network = None  # 道路网络self._unity = None  # 单位长passdef GenerateNetwork(self, width: int, height: int) -> Network:self.network = Network()self.network.width = widthself.network.height = heightdx = [1, 0, -1, 0]dy = [0, 1, 0, -1]turn = [-1, 0, 1]  # 车道编号 -> 转向编号,分别对应:右转,直行,左转for i in range(width + 2):for j in range(height + 2):# 生成节点 (i, j)# 角落不需要生成if Utils.IsCornerNode(width, height, i, j):continuenode1 = (i, j)self.network.nodes.append(node1)if Utils.IsTrafficLightNode(self.network.width, self.network.height, i, j):self.network.tlNodes.append(node1)else:self.network.boundaryNodes.append(node1)passfor dir in range(len(dx)):u = i + dx[dir]v = j + dy[dir]# 生成边 (i, j)->(u, v)# 排除非法节点if Utils.IsIllegalNode(width, height, u, v):continue# 角落不需要生成if Utils.IsCornerNode(width, height, u, v):continue# 边界节点与边界节点互不相连,排除if Utils.IsBoundaryNode(width, height, i, j) and Utils.IsBoundaryNode(width, height, u, v):continue# 生成边node2 = (u, v)edge = (node1, node2)self.network.edges.append(edge)self.network.outEdges[node1].append(edge)self.network.inEdges[node2].append(edge)passfor lane in range(len(turn)):dir2 = (dir + turn[lane] + len(dx)) % len(dx)x = u + dx[dir2]y = v + dy[dir2]# (i, j)->(u,v)->(x,y)# 排除非法的if Utils.IsIllegalNode(width, height, x, y):continue# 角落不需要生成if Utils.IsCornerNode(width, height, x, y):continue# 边界节点与边界节点互不相连if Utils.IsBoundaryNode(width, height, u, v) and Utils.IsBoundaryNode(width, height, x, y):continue# 生成连接node3 = (x, y)connection = (node1, node2, node3, lane)self.network.connections.append(connection)passpasspasspassreturn self.network

生成路径(route)

SUMO Road Networks - SUMO Documentation (dlr.de)

我们使用回溯算法生成所有可能的路径。

由于该算法的时间开销较大,如果地图大小超过4*4,那么建议导入路径而不是生成

import xml.dom
import numpy as np
import Utils
from Network import Network
from collections import defaultdictfrom sample.Utils import _GetEdgesOfRouteclass SumoFileGenerator:def __init__(self):self.cwd = None  # 输出目录self.name = None  # 文件名self.network = None  # 道路网络# for dfsself._visit = Noneself._path = Noneself._ans = Nonepassdef _dfsrc(self, nodeP: tuple or None, nodeU: tuple):# 深度优先搜索递归核心 Depth First Search Recursive Coreif nodeU in self.network.boundaryNodes and nodeP is not None:self._ans.append([x for x in self._path])returnfor _, nodeV in self.network.outEdges[nodeU]:if self._visit[nodeV] is True:continueself._visit[nodeV] = Trueself._path.append(nodeV)self._dfsrc(nodeU, nodeV)self._path.pop()self._visit[nodeV] = Falsepassdef _GetRoutes(self, nodeU: tuple) -> list:# 生成所有以 nodeU 为起点的路径self._visit = defaultdict(bool)self._path = []self._ans = []self._visit[nodeU] = Trueself._path.append(nodeU)self._dfsrc(None, nodeU)return self._anspassdef _GenerateRouteFile(self, avgCarAmount, timePeriod)://...pass

生成车辆(vehicle)

用分布来模拟车辆到达,实际上是在采样。因为各个样本点独立同分布

设随机变量X是车辆到达的数量,P{X=k}是有k辆车到达的概率。

我们采取timePeriod个样本,各个样本就对应了各个时刻车辆的到达情况。

    def _GenerateRouteFile(self, avgCarAmount, timePeriod):// ...# 创建车辆arrivals = np.random.poisson(avgCarAmount, timePeriod)vehicleId = 0for time in range(len(arrivals)):for i in range(arrivals[time]):rootElement.appendChild(Utils.ToXMLElement("vehicle","id", "%08d" % (vehicleId),"type", "typeCar","route", routeIds[np.random.randint(0, len(routeIds))],"depart", "%d" % (time),))vehicleId += 1pass// ...pass

生成交通信号灯(tlLogic)

直接遍历network中的交通灯节点,然后生成对应的XML元素,其中:

  • id是节点id
  • programID是随便填的
  • 相位暂时使用默认相位,以进行测试
    def _GenerateDefaultPhases(self) -> list:ret = []phase = "ggggrrgrrgrr"for i in range(4):ret.append(("17", phase))ret.append(("3", phase.replace("g", "y")))phase = phase[3:] + phase[:3]return retpassdef _GenerateTrafficLightFile(self):# *.add.xml,# 创建一个XML文档对象doc = xml.dom.minidom.Document()rootElement = doc.createElement("additional")  # 根节点doc.appendChild(rootElement)defaultPhases = self._GenerateDefaultPhases()  # 使用默认相位进行测试# attribute = ["id", "type", "programID", "offset"]for node in self.network.tlNodes:# 遍历交通灯节点TLElement = doc.createElement("tlLogic")rootElement.appendChild(TLElement)TLElement.setAttribute("id", Utils.GetNodeId(*node))TLElement.setAttribute("type", "static")TLElement.setAttribute("programID", "runner")TLElement.setAttribute("offset", "0")# 交通灯的相位for duration, state in defaultPhases:phaseElement = doc.createElement("phase")phaseElement.setAttribute("duration", duration)phaseElement.setAttribute("state", state)TLElement.appendChild(phaseElement)with open("%s/%s.add.xml" % (self.cwd, self.name), "w") as fileOut:fileOut.write(doc.toprettyxml())pass

生成探测器(detector)

为了使探测器能覆盖整条道路,我们只填入pos属性,而不填入endPos或length属性。

    def _GenerateDetectorFile(self):# *.det.xml,# 创建一个XML文档对象doc = xml.dom.minidom.Document()rootElement = doc.createElement("additional")  # 根节点doc.appendChild(rootElement)# attribute = ["id", "lane", "pos", "file", "friendlyPos"]for (i, j), (u, v) in self.network.edges:for lane in range(3):rootElement.appendChild(Utils.ToXMLElement("laneAreaDetector","id", Utils.GetDetectorId(i, j, u, v, lane),"lane", Utils.GetLaneId(i, j, u, v, lane),"pos", "0",# "endPos", "100",# "length", "%d" % (72.80),"file", "%s/%s.out.xml" % (self.cwd, self.name),"friendlyPos", "true", ))with open("%s/%s.det.xml" % (self.cwd, self.name), "w") as fileOut:fileOut.write(doc.toprettyxml())pass

py程序接口(TraCI)

TraCI 采用基于 TCP 的客户端/服务器架构来访问sumo。因此,使用附加命令行选项启动时,sumo将充当服务器:–remote-port <INT>,其中 是sumo用于监听传入连接的端口。

当使用 –remote-port<INT>选项启动时,sumo只准备模拟,等待所有外部应用程序连接并接管控制权。请注意,当sumo作为 TraCI 服务器运行时,–end <TIME>选项将被忽略。

使用sumo-gui作为服务器时,在处理 TraCI 命令之前,必须通过使用播放按钮或设置选项 –start来启动模拟。

import os
import sys
from FileGenerator import FileGenerator
from Network import Networktry:sys.path.append(os.path.join(os.path.dirname(__file__), '..', '..', '..', '..', "tools"))  # tutorial in testssys.path.append(os.path.join(os.environ.get("SUMO_HOME", os.path.join(os.path.dirname(__file__), "..", "..", "..")), "tools"))  # tutorial in docssys.path.append("/usr/local/Cellar/sumo/1.2.0/share/sumo/tools")from sumolib import checkBinary  # noqa
except ImportError:sys.exit("please declare environment variable 'SUMO_HOME' as the root directory of your sumo installation""(it should contain folders 'bin', 'tools' and 'docs')")import traci# ====================================================================================================# adapted from SUMO tutorials
def run(network: Network):"""execute the TraCI control loop"""# step = 0# amber = 0# waits = []# phase = [0, 0, 0, 0, 0, 0, 0, 0, 0]# for i in range(0, NUM_JUNCTIONS):#     waits.append([0] * len(PHASES))cnt = 0while traci.simulation.getMinExpectedNumber() > 0:  # step <= 900:traci.simulationStep()traci.trafficlight.setPhase("11", cnt % 2)traci.trafficlight.setPhase("22", cnt % 2)cnt = cnt + 1# if step % PHASE_LENGTH == 0:#     for i in range(0, NUM_JUNCTIONS):#         if MAX_WAIT in waits[i]:#             phase[i] = waits[i].index(MAX_WAIT)#         else:#             if noPhaseChange(phase[i], i) != True:#                 phase[i] = backPressure(i)#                 amber = amber + 1#         traci.trafficlight.setPhase("0" + getNodeId(i), phase[i])#         for j in range(0, len(PHASES), 2):#             if j == phase[i]:#                 waits[i][j] = 0#             else:#                 if waits[i][j] < MAX_WAIT:#                     waits[i][j] += 1# step += 1# logging.warning(amber)traci.close()sys.stdout.flush()if __name__ == '__main__':# constCWD = os.getcwd() + "/data"NAME = "sample"OUTPUTDIR = os.getcwd() + "/output"NETCONVERT = checkBinary('netconvert')SUMO = checkBinary('sumo-gui')# maingenerator = FileGenerator()generator.GenerateAllFile(NETCONVERT, CWD, NAME,2, 2, 100,2, 10)  # 生成文件print("GenerateAll finish")traci.start([SUMO,"-c", "%s/%s.sumocfg" % (CWD, NAME),"--tripinfo-output", "%s/%s.tripinfo.xml" % (OUTPUTDIR, NAME),"--summary", "%s/%s.sum.xml" % (OUTPUTDIR, NAME)])run(generator.network)

附录

node

PlainXML - SUMO Documentation (dlr.de)

nod的属性:

属性名称类型说明
idid (string)节点名称
xfloat节点在平面上的 x 位置,以米为单位
yfloat节点在平面上的 y 轴位置,以米为单位
zfloat节点在平面上的 Z 位置,以米为单位
typeenum ( “priority”, “traffic_light”……)节点的可选类型

edge

PlainXML - SUMO Documentation (dlr.de)

edge的属性:

属性名称类型说明
idid (string)边的 ID(必须唯一)
fromreferenced node idThe name of a node within the nodes-file the edge shall start at
toreferenced node idThe name of a node within the nodes-file the edge shall end at
typereferenced type idThe name of a type within the SUMO edge type file

connection

PlainXML - SUMO Documentation (dlr.de)

SUMO Road Networks - SUMO Documentation (dlr.de)

connection的属性:

名称类型说明
fromedge id (string)开始连接的输入边 ID
toedge id (string)连接结束时出线边的 ID
fromLaneindex (unsigned int)开始连接的输入边的车道
toLaneindex (unsigned int)连接结束时出线边缘的车道

route

Definition of Vehicles, Vehicle Types, and Routes - SUMO Documentation (dlr.de)

route 的属性:

属性名称价值类型说明
idid (string)路线名称
edgesid list车辆应行驶的路线,以 ID 表示,用空格隔开

vehicle

Definition of Vehicles, Vehicle Types, and Routes - SUMO Documentation (dlr.de)

vType 的属性:

属性名称价值类型默认值说明
idid (string)-车辆类型名称
accelfloat2.6此类车辆的加速能力(单位:m/s^2)
decelfloat4.5此类车辆的减速能力(单位:m/s^2)
sigmafloat0.5汽车跟随模型参数,见下文
lengthfloat5.0车辆长度(米)
minGapfloat2.5最小车距(米)
maxSpeedfloat55.55(200 km/h),车辆的最大速度(米/秒)
guiShapeshape (enum)“unknown”绘制车辆形状。默认情况下,绘制的是标准客车车身。

外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传

vehicle 的属性:

属性名称价值类型说明
idstring车辆名称
typestring该车辆使用的车辆类型 ID
routestring车辆行驶路线的 ID
departfloat(s)车辆进入网络的时间步长

tlLogic

Traffic Lights - SUMO Documentation (dlr.de)

tlLogic 的属性:

属性名称价值类型说明
idid (string)交通信号灯的 id。必须是 .net.xml 文件中已有的交通信号灯 id。交通信号灯的 id 通常与路口 id 相同。名称可通过右键单击受控路口前的红/绿条获得。
typeenum (static, actuated, delay_based)交通信号灯的类型(固定相位持续时间、基于车辆间时间间隔的相位延长(驱动式)或基于排队车辆累积时间损失的相位延长(基于延迟式) )
programIDid (string)交通灯程序的 id;必须是交通灯 id 的新程序名称。请注意,"off "为保留名,见下文。
offsetint程序的初始时间偏移

phase 的属性:

属性名称价值类型说明
durationtime (int)阶段的持续时间
statelist of signal states该阶段的红绿灯状态如下

外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传

对于控制单个交叉路口的交通信号灯,由 netconvert 生成的默认指数以顺时针方式编号,从 12 点钟方向的 0 开始,右转顺序在直行和左转之前。人行横道总是被分配在最后,也是按顺时针方向。

如果将交通信号灯连接起来,由一个程序控制多个交叉路口,则每个交叉路口的排序保持不变,但指数会根据输入文件中受控路口的顺序增加。

例如:ggrgrrrggrrg对应:

外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传

TraCI

TraCI - SUMO Documentation (dlr.de)

Detector

Detector - SUMO Documentation (dlr.de)

Lanearea Detectors (E2) - SUMO Documentation (dlr.de)

Attribute NameValue TypeDescription
idid (string)A string holding the id of the detector
lanereferenced lane idThe id of the lane the detector shall be laid on. The lane must be a part of the network used. This argument excludes the argument lanes.
posfloatThe position on the first lane covered by the detector. See information about the same attribute within the detector loop description for further information. Per default, the start position is placed at the first lane’s begin.
endPosfloatThe end position on the last lane covered by the detector. Per default the end position is placed at the last lane’s end.
lengthfloatThe length of the detector in meters. If the detector reaches over the lane’s end, it is extended to preceding / consecutive lanes.
filefilenameThe path to the output file. The path may be relative.
friendlyPosboolIf set, no error will be reported if the detector is placed behind the lane. Instead, the detector will be placed 0.1 meters from the lane’s end or at position 0.1, if the position was negative and larger than the lane’s length after multiplication with -1; default: false.

simulation

参考资料

SUMO官方文档

SUMO学习入门(一)SUMO介绍 - 知乎 (zhihu.com)

SUMO 从入门到基础 SUMO入门一篇就够了_sumo文档-CSDN博客

XML - Wikipedia

有关文件

windows安装包:

sumo-win64-1.19.0.msi

这篇关于基于sumo实现交通灯控制算法的模板的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/575461

相关文章

基于Python实现一个图片拆分工具

《基于Python实现一个图片拆分工具》这篇文章主要为大家详细介绍了如何基于Python实现一个图片拆分工具,可以根据需要的行数和列数进行拆分,感兴趣的小伙伴可以跟随小编一起学习一下... 简单介绍先自己选择输入的图片,默认是输出到项目文件夹中,可以自己选择其他的文件夹,选择需要拆分的行数和列数,可以通过

Python中将嵌套列表扁平化的多种实现方法

《Python中将嵌套列表扁平化的多种实现方法》在Python编程中,我们常常会遇到需要将嵌套列表(即列表中包含列表)转换为一个一维的扁平列表的需求,本文将给大家介绍了多种实现这一目标的方法,需要的朋... 目录python中将嵌套列表扁平化的方法技术背景实现步骤1. 使用嵌套列表推导式2. 使用itert

Python使用pip工具实现包自动更新的多种方法

《Python使用pip工具实现包自动更新的多种方法》本文深入探讨了使用Python的pip工具实现包自动更新的各种方法和技术,我们将从基础概念开始,逐步介绍手动更新方法、自动化脚本编写、结合CI/C... 目录1. 背景介绍1.1 目的和范围1.2 预期读者1.3 文档结构概述1.4 术语表1.4.1 核

在Linux中改变echo输出颜色的实现方法

《在Linux中改变echo输出颜色的实现方法》在Linux系统的命令行环境下,为了使输出信息更加清晰、突出,便于用户快速识别和区分不同类型的信息,常常需要改变echo命令的输出颜色,所以本文给大家介... 目python录在linux中改变echo输出颜色的方法技术背景实现步骤使用ANSI转义码使用tpu

Python使用python-can实现合并BLF文件

《Python使用python-can实现合并BLF文件》python-can库是Python生态中专注于CAN总线通信与数据处理的强大工具,本文将使用python-can为BLF文件合并提供高效灵活... 目录一、python-can 库:CAN 数据处理的利器二、BLF 文件合并核心代码解析1. 基础合

Python使用OpenCV实现获取视频时长的小工具

《Python使用OpenCV实现获取视频时长的小工具》在处理视频数据时,获取视频的时长是一项常见且基础的需求,本文将详细介绍如何使用Python和OpenCV获取视频时长,并对每一行代码进行深入解析... 目录一、代码实现二、代码解析1. 导入 OpenCV 库2. 定义获取视频时长的函数3. 打开视频文

golang版本升级如何实现

《golang版本升级如何实现》:本文主要介绍golang版本升级如何实现问题,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录golanwww.chinasem.cng版本升级linux上golang版本升级删除golang旧版本安装golang最新版本总结gola

SpringBoot中SM2公钥加密、私钥解密的实现示例详解

《SpringBoot中SM2公钥加密、私钥解密的实现示例详解》本文介绍了如何在SpringBoot项目中实现SM2公钥加密和私钥解密的功能,通过使用Hutool库和BouncyCastle依赖,简化... 目录一、前言1、加密信息(示例)2、加密结果(示例)二、实现代码1、yml文件配置2、创建SM2工具

Mysql实现范围分区表(新增、删除、重组、查看)

《Mysql实现范围分区表(新增、删除、重组、查看)》MySQL分区表的四种类型(范围、哈希、列表、键值),主要介绍了范围分区的创建、查询、添加、删除及重组织操作,具有一定的参考价值,感兴趣的可以了解... 目录一、mysql分区表分类二、范围分区(Range Partitioning1、新建分区表:2、分

MySQL 定时新增分区的实现示例

《MySQL定时新增分区的实现示例》本文主要介绍了通过存储过程和定时任务实现MySQL分区的自动创建,解决大数据量下手动维护的繁琐问题,具有一定的参考价值,感兴趣的可以了解一下... mysql创建好分区之后,有时候会需要自动创建分区。比如,一些表数据量非常大,有些数据是热点数据,按照日期分区MululbU