Sumo中Traci.trafficlight详解(上)
Sumo中Traci.trafficlight详解(上)
记录慢慢学习traci的每一天,希望也能帮到你
文章目录
- Sumo中Traci.trafficlight详解(上)
- Traci.trafficlight
- 信号灯参数讲解
- 1.getAllProgramLogics(self,tlsID)
- 2.getBlockingVehicles(self, tlsID, linkIndex)
- 3.getConstraints(self, tlsID, tripId='')
- 4.getConstraintsByFoe(self, foeSignal, foeId='')
- 5.getControlledLanes(self, tlsID)
- 6.getControlledLinks(self, tlsID)
- 7.getNemaPhaseCalls(self, tlsID)
- 8.getNextSwitch(self, tlsID)
- 9.getPhase(self, tlsID) 、getPhaseDuration(self, tlsID)、getPhaseName(self, tlsID)
Traci.trafficlight
导入库
import traci
#这里不需要全部导入
信号灯参数讲解
getAllProgramLogics(ID)输入为信号灯ID,其中xml文件中对信号灯的定义方式如下:
<tlLogic id="0" type="static" programID="0" offset="0"><phase duration="31" state="GrGr"/><phase duration="6" state="yryr"/><phase duration="31" state="rGrG"/><phase duration="6" state="ryry"/></tlLogic>
从上面可以得出,第一个id为信号控制所在node的id,信号灯的programID为‘0’,当然这个id可以自己给定,数据类型为字符串(str),控制类型为static,即定时信号控制,另外在sumo中还有其它的控制类型:

可以自己多多尝试。duration为当前相位持续时间,单位为s;
state为信号相位,即通行权解释,sumo的信号灯配置比较麻烦,这里详细讲解一下:

每一个state代表一个或者多个流线的放行,如gggrrrrgggrrrr代表南北方向通行,东西方向禁行g[0]g[1]g[2]r[3]r[4]r[5]r[6]按照索引位置进行对应。为了方便讲解,这里以上面给的xml文件中的参数进行trafficlight的相关用法及返回值的讲解
<tlLogic id="0" type="static" programID="0" offset="0"><phase duration="31" state="GrGr"/><phase duration="6" state="yryr"/><phase duration="31" state="rGrG"/><phase duration="6" state="ryry"/></tlLogic>
1.getAllProgramLogics(self,tlsID)
getAllProgramLogics(self, tlsID)= getCompleteRedYellowGreenDefinition
getAllProgramLogics(string) -> list(Logic)返回值为元组数据,功能等同于getCompleteRedYellowGreenDefinition方法Returns a list of Logic objects.Each Logic encodes a traffic light program for the given tlsID.
返回逻辑对象的列表。每个逻辑为给定的tlsID编码一个红绿灯程序。
traci.trafficlight.getAllProgramLogics( tlsID='0')
#(Logic(programID='0', type=0, currentPhaseIndex=2,
#phases=(Phase(duration=31.0, state='GrGr', minDur=31.0, maxDur=31.0, next=()),
#Phase(duration=6.0, state='yryr', minDur=6.0, maxDur=6.0, next=()),
#Phase(duration=31.0, state='rGrG', minDur=31.0, maxDur=31.0, next=()),
#Phase(duration=6.0, state='ryry', minDur=6.0, maxDur=6.0, next=())), subParameter={}),)
通过getAllProgramLogics(self,tlsID)可以获得当前信号灯配时的全部信息。
2.getBlockingVehicles(self, tlsID, linkIndex)
输入为信号控制灯ID以及信号灯相位索引
getBlockingVehicles(self, tlsID, linkIndex)
getBlockingVehicles(string, int) -> int
Returns the list of vehicles that are blocking the subsequent block for the given tls-linkIndex
返回在信号交叉口阻塞的车辆ID列表
代码如下(示例):
traci.trafficlight.getBlockingVehicles( tlsID='0',0)
#返回值为空表示没有阻塞车辆
3.getConstraints(self, tlsID, tripId=‘’)
getConstraints(self, tlsID, tripId='')
getConstraint(self, tlsID, tripId='')
getConstraints(string, string) -> list(Constraint)
Returns the list of rail signal constraints for the given rail signal.
If tripId is not "", only constraints with the given tripId are
returned. Otherwise, all constraints are returned
返回给定轨道信号的轨道信号约束列表。
如果tripId不为“”,则只有具有给定tripId的约束为返回。否则,将返回所有约束
代码如下(示例):
traci.trafficlight.getConstraints( tlsID='0',0)
#针对轨道信号,普通交叉口会报错
4.getConstraintsByFoe(self, foeSignal, foeId=‘’)
getConstraintByFoe(self, foeSignal, foeId='')
getConstraintsByFoe(string, string) -> list(Constraint)
Returns the list of rail signal constraints that have the given rail signal id as their foeSignal.
If foeId is not "", only constraints with the given foeId are
returned. Otherwise, all constraints are returned
返回具有给定轨道的轨道信号约束的列表信号id作为他们的foeSignal。
如果foeId不是“”,则只有具有给定foeId的约束为返回。否则,将返回所有约束
traci.trafficlight.getConstraints( foeSignal, foeId='')
#针对轨道信号,普通交叉口会报错
5.getControlledLanes(self, tlsID)
getControlledLanes(self, tlsID)
getControlled Lanes(self, tlsID)
getControlledLanes(string) -> c
Returns the list of lanes which are controlled by the named traffic light.
返回由命名红绿灯控制的车道列表
traci.trafficlight.getControlledLanes(tlsID='0')
#('4i_0', '2i_0', '3i_0', '1i_0')返回车道列表id
6.getControlledLinks(self, tlsID)
getControlled Links(self, tlsID)
getControlledLinks(string) -> list(list(list(string)))
Returns the links controlled by the traffic light, sorted by the signal index and described by giving
the incoming, outgoing, and via lane.
返回由红绿灯控制的链接,按信号索引排序,并通过给出传入、传出和通过通道。
traci.trafficlight.getControlledLinks(tlsID='0')
#[[('4i_0', '3o_0', ':0_0_0')],
#[('2i_0', '1o_0', ':0_1_0')],
#[('3i_0', '4o_0', ':0_2_0')],
#[('1i_0', '2o_0', ':0_3_0')]]
#返回车道id,这里的车道指的是经过交叉口的所有车道,包括进口道出口道的路径
7.getNemaPhaseCalls(self, tlsID)
getNemaPhaseCalls(self, tlsID)
getNemaPhaseCalls(string) -> list(string)
Get the vehicle calls for the phases.The output is vehicle calls (coming from the detectors) for the phases.
获取车辆对相位的调用。输出为车辆对相位(来自检测器)的调用。
注意:需要是Nema类型的信号灯才可以调用,其它类型调用会报错
8.getNextSwitch(self, tlsID)
getNextSwitch(self, tlsID)
getNextSwitch(string) -> double
Return the absolute simulation time at which the traffic light is schedule to switch to the next phase (in seconds).
返回红绿灯计划切换到下一阶段的绝对模拟时间(以秒为单位)
traci.trafficlight.getNextSwitch('0')
#31.0
9.getPhase(self, tlsID) 、getPhaseDuration(self, tlsID)、getPhaseName(self, tlsID)
这三个方法的用法类似,放在一起讲:
getPhase(self, tlsID)获取当前相位信息
getPhase(string) -> integer
Returns the index of the current phase within the list of all phases of the current program.
返回红绿灯计划切换到下一阶段的绝对模拟时间(以秒为单位)。返回当前程序所有阶段列表中当前阶段的索引。
traci.trafficlight.getPhase('0')
# 返回值为 2
getPhaseDuration(string) -> doubleReturns the total duration of the current phase (in seconds). This value is not affected by the elapsed or remaining duration of the current phase.
返回当前相位的总共时长,不受剩余相位时间影响,相当于返回某个信号周期的某个相位的完整时长
traci.trafficlight.getPhaseDuration('0')
#返回值为31.0
getPhaseName(self, tlsID)
getPhaseName(string) -> string
Returns the name of the current phase.
返回相位名称(自定义,如果没有定义,返回为空字符串)
traci.trafficlight.getPhaseName('0')
仿真示例代码链接如下:
链接:https://pan.baidu.com/s/1IFs4UJUBPxPM_LUTSrcmSw
**提取码:**Sumo
欢迎交流!
相关文章:
Sumo中Traci.trafficlight详解(上)
Sumo中Traci.trafficlight详解(上) 记录慢慢学习traci的每一天,希望也能帮到你 文章目录 Sumo中Traci.trafficlight详解(上)Traci.trafficlight信号灯参数讲解1.getAllProgramLogics(self,tlsID)2.getBlockingVehicle…...
手写Mybatis:第13章-通过注解配置执行SQL语句
文章目录 一、目标:注解配置执行SQL二、设计:注解配置执行SQL三、实现:注解配置执行SQL3.1 工程结构3.2 注解配置执行SQL类图3.3 脚本语言驱动器3.3.1 脚本语言驱动器接口3.3.2 XML语言驱动器 3.4 注解配置构建器3.4.1 定义增删改查注解3.4.2…...
spring security - 快速整合 springboot
1.引入依赖<dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spr…...
NPM 常用命令(二)
目录 1、npm bugs 1.1 配置 browser registry 2、npm cache 2.1 概要 2.2 详情 2.3 关于缓存设计的说明 2.4 配置 cache 3、 npm ci 3.1 描述 3.2 配置 install-strategy legacy-bundling global-style omit strict-peer-deps foreground-scripts ignore-s…...
ctfhub ssrf(3关)
文章目录 内网访问伪协议读取文件扫描端口 内网访问 根据该题目,是让我们访问127.0.0.1/falg.php,访问给出的链接后用bp抓包,修改URL,发送后得到flag: 伪协议读取文件 这题的让我们用伪协议,而网站的目录…...
跨源资源共享(CORS)Access-Control-Allow-Origin
1、浏览器的同源安全策略 没错,就是这家伙干的,浏览器只允许请求当前域的资源,而对其他域的资源表示不信任。那怎么才算跨域呢? 请求协议http,https的不同域domain的不同端口port的不同 好好好,大概就是这么回事啦&…...
【嵌入式软件开发 】学习笔记
本文主要记录 【嵌入式软件开发】 学习笔记,参考相关大佬的文章 1.RTOS 内功修炼笔记 RTOS内功修炼记(一)—— 任务到底应该怎么写? RTOS内功修炼记(二)—— 优先级抢占式调度到底是怎么回事?…...
CentOS 7上安装Python 3.11.5,支持Django
CentOS 7上安装Python 3.11.5,支持Django 今天安装django,报了“Django - deterministicTrue requires SQLite 3.8.3 or higher upon running python manage.py runserver”。查了一番资料,记录下来。 参考链接: 参考链接: Django的web项目…...
COMPFEST 15H「组合数学+容斥」
Problem - H - Codeforces 题意: 定义一个集合S为T的孩子是,对于S中的每一个元素x,在T中都能找到x1。 给定n,k,每一个集合中的元素x必须满足 1 < x < k 1<x<k 1<x<k且 c n t [ x ] < 1 cnt[x…...
react快速开始(三)-create-react-app脚手架项目启动;使用VScode调试react
文章目录 react快速开始(三)-create-react-app脚手架项目启动;使用VScode调试react一、create-react-app脚手架项目启动1. react-scripts2. 关于better-npm-runbetter-npm-run安装 二、使用VScode调试react1. 浏览器插件React Developer Tools2. 【重点】用 VSCode …...
【C++入门】string类常用方法(万字详解)
目录 1.STL简介1.1什么是STL1.2STL的版本1.3STL的六大组件1.4STL的缺陷 2.string类的使用2.1C语言中的字符串2.2标准库中的string类2.3string类的常用接口说明 (只讲解最常用的接口)2.3.1string类对象的常见构造2.3.2 string类对象的容量操作2.3.3string…...
大数据错误
question1 : Could not locate Hadoop executable: D:\hadoop-3.3.1\bin\winutils.exe - 【已解决】Could not locate executable E:\Hadoop\bin\winutils.exe in the Hadoop binaries._could not locate executable e:\hadoop-3.3.1\bin\wi_君问归期魏有期的博客-CSDN博客 q…...
【Node.js】Express-Generator:快速生成Express应用程序的利器
在Node.js世界中,Express是一个广泛使用的、强大的Web应用程序框架。它为开发者提供了一系列的工具和选项,使得创建高效且可扩展的Web应用程序变得轻而易举。然而,对于初学者来说,配置和初始化Express应用程序可能会有些困难。为了…...
SpringMVC的工作流程及入门
目录 一、概述 ( 1 ) 是什么 ( 2 ) 作用 二、工作流程 ( 1 ) 流程 ( 2 ) 步骤 三、入门实例 ( 1 ) 入门实例 ( 2 ) 静态资源处理 给我们带来的收获 一、概述 ( 1 ) 是什么 SpringMVC是一个基于Java的Web应用开发框架,它是Spring Framework的一部…...
logging.level的含义及设置 【java 日志 (logback、log4j)】
日志级别 trace<debug<info<warn<error<fatal 常用的有:debug,info,warn,error 通常我们想设置日志级别,会用到 logging.level.rootinfo logging.level设置日志级别,后面跟生效的区域。r…...
第 3 章 栈和队列(链栈)
1. 背景说明 链栈是指用单链表实现的栈,其存储结构为链式存储,实现类似于队列的链式实现,不过在插入元素时链栈在头部插入,而 链式队列在尾部插入,本示例中实现为带头结点的链栈,即栈顶元素为栈指针的下一…...
嵌入式面试-经典问题
1、c语言内存模型 2、C语言中的变量定义在什么地方 3、C语言代码如何运行的、关于栈的相关 4、指针函数与函数指针的区分 5、Static关键字的作用 6、const作用 7、进程与线程的区别 8、链表与数组的区别 9、#define宏定义与typedef的区别...
ZLMeidaKit在Windows上启动时:计算机中丢失MSVCR110.dll,以及rtmp推流后无法转换为flv视频流解决
场景 ZLMediaKit在Windows上实现Rtmp流媒体服务器以及模拟rtmp推流和http-flv拉流播放: ZLMediaKit在Windows上实现Rtmp流媒体服务器以及模拟rtmp推流和http-flv拉流播放_zlm流媒体服务器_霸道流氓气质的博客-CSDN博客 按照以上教程启动MediaServer.exe时提示&am…...
项目(智慧教室)第二部分,人机交互页面实现,
使用软件: 1.BmCvtST.exe 这是stm32Cubemx工程下的带三方软件。存在STemWin中。 作用: 图片变成.c文件格式。 2.CodeBlock 3.模拟器工程(具体请看上一节) 一。emWin环境的搭建 1.codeBlock下载 开源免费。 2.使用stm的C…...
【docker】docker的一些常用命令-------从小白到大神之路之学习运维第92天
目录 一、安装docker-ce 1、从阿里云下载docker-cer.epo源 2、下载部分依赖 3、安装docker 二、启用docker 1、启动docker和不启动查看docker version 2、启动服务查看docker version 有什么区别?看到了吗? 3、看看docker启动后的镜像仓库都有什…...
超短脉冲激光自聚焦效应
前言与目录 强激光引起自聚焦效应机理 超短脉冲激光在脆性材料内部加工时引起的自聚焦效应,这是一种非线性光学现象,主要涉及光学克尔效应和材料的非线性光学特性。 自聚焦效应可以产生局部的强光场,对材料产生非线性响应,可能…...
在rocky linux 9.5上在线安装 docker
前面是指南,后面是日志 sudo dnf config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo sudo dnf install docker-ce docker-ce-cli containerd.io -y docker version sudo systemctl start docker sudo systemctl status docker …...
vue3 字体颜色设置的多种方式
在Vue 3中设置字体颜色可以通过多种方式实现,这取决于你是想在组件内部直接设置,还是在CSS/SCSS/LESS等样式文件中定义。以下是几种常见的方法: 1. 内联样式 你可以直接在模板中使用style绑定来设置字体颜色。 <template><div :s…...
DBAPI如何优雅的获取单条数据
API如何优雅的获取单条数据 案例一 对于查询类API,查询的是单条数据,比如根据主键ID查询用户信息,sql如下: select id, name, age from user where id #{id}API默认返回的数据格式是多条的,如下: {&qu…...
聊一聊接口测试的意义有哪些?
目录 一、隔离性 & 早期测试 二、保障系统集成质量 三、验证业务逻辑的核心层 四、提升测试效率与覆盖度 五、系统稳定性的守护者 六、驱动团队协作与契约管理 七、性能与扩展性的前置评估 八、持续交付的核心支撑 接口测试的意义可以从四个维度展开,首…...
智能AI电话机器人系统的识别能力现状与发展水平
一、引言 随着人工智能技术的飞速发展,AI电话机器人系统已经从简单的自动应答工具演变为具备复杂交互能力的智能助手。这类系统结合了语音识别、自然语言处理、情感计算和机器学习等多项前沿技术,在客户服务、营销推广、信息查询等领域发挥着越来越重要…...
搭建DNS域名解析服务器(正向解析资源文件)
正向解析资源文件 1)准备工作 服务端及客户端都关闭安全软件 [rootlocalhost ~]# systemctl stop firewalld [rootlocalhost ~]# setenforce 0 2)服务端安装软件:bind 1.配置yum源 [rootlocalhost ~]# cat /etc/yum.repos.d/base.repo [Base…...
BLEU评分:机器翻译质量评估的黄金标准
BLEU评分:机器翻译质量评估的黄金标准 1. 引言 在自然语言处理(NLP)领域,衡量一个机器翻译模型的性能至关重要。BLEU (Bilingual Evaluation Understudy) 作为一种自动化评估指标,自2002年由IBM的Kishore Papineni等人提出以来,…...
从零手写Java版本的LSM Tree (一):LSM Tree 概述
🔥 推荐一个高质量的Java LSM Tree开源项目! https://github.com/brianxiadong/java-lsm-tree java-lsm-tree 是一个从零实现的Log-Structured Merge Tree,专为高并发写入场景设计。 核心亮点: ⚡ 极致性能:写入速度超…...
C#最佳实践:为何优先使用as或is而非强制转换
C#最佳实践:为何优先使用as或is而非强制转换 在 C# 的编程世界里,类型转换是我们经常会遇到的操作。就像在现实生活中,我们可能需要把不同形状的物品重新整理归类一样,在代码里,我们也常常需要将一个数据类型转换为另…...
