智能网站建设维护,大庆建设网站,关键词推广怎么做,深圳市信任网站Sumo中Traci.trafficlight详解#xff08;上#xff09;
记录慢慢学习traci的每一天#xff0c;希望也能帮到你 文章目录 Sumo中Traci.trafficlight详解#xff08;上#xff09;Traci.trafficlight信号灯参数讲解1.getAllProgramLogics(self,tlsID)2.getBlockingVehicle…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 id0 typestatic programID0 offset0phase duration31 stateGrGr/phase duration6 stateyryr/phase duration31 staterGrG/phase duration6 stateryry//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 id0 typestatic programID0 offset0phase duration31 stateGrGr/phase duration6 stateyryr/phase duration31 staterGrG/phase duration6 stateryry//tlLogic1.getAllProgramLogics(self,tlsID)
getAllProgramLogicsself 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( tlsID0)
#(Logic(programID0, type0, currentPhaseIndex2,
#phases(Phase(duration31.0, stateGrGr, minDur31.0, maxDur31.0, next()),
#Phase(duration6.0, stateyryr, minDur6.0, maxDur6.0, next()),
#Phase(duration31.0, staterGrG, minDur31.0, maxDur31.0, next()),
#Phase(duration6.0, stateryry, minDur6.0, maxDur6.0, next())), subParameter{}),)通过getAllProgramLogics(self,tlsID)可以获得当前信号灯配时的全部信息。
2.getBlockingVehicles(self, tlsID, linkIndex)
输入为信号控制灯ID以及信号灯相位索引
getBlockingVehiclesself 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( tlsID0,0)
#返回值为空表示没有阻塞车辆3.getConstraints(self, tlsID, tripId‘’)
getConstraints(self, tlsID, tripId)
getConstraintself 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( tlsID0,0)
#针对轨道信号普通交叉口会报错4.getConstraintsByFoe(self, foeSignal, foeId‘’)
getConstraintByFoeself 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 Lanesself tlsID
getControlledLanes(string) - c
Returns the list of lanes which are controlled by the named traffic light.
返回由命名红绿灯控制的车道列表traci.trafficlight.getControlledLanes(tlsID0)
#(4i_0, 2i_0, 3i_0, 1i_0)返回车道列表id6.getControlledLinks(self, tlsID)
getControlled Linksself 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(tlsID0)
#[[(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)
getNemaPhaseCallsself 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)
getNextSwitchself 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.09.getPhase(self, tlsID) 、getPhaseDuration(self, tlsID)、getPhaseName(self, tlsID)
这三个方法的用法类似放在一起讲
getPhaseself 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)
# 返回值为 2getPhaseDuration(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.0getPhaseNameself tlsID
getPhaseName(string) - string
Returns the name of the current phase.
返回相位名称自定义如果没有定义返回为空字符串traci.trafficlight.getPhaseName(0)仿真示例代码链接如下 链接https://pan.baidu.com/s/1IFs4UJUBPxPM_LUTSrcmSw **提取码**Sumo 欢迎交流