郑州网站推广单位,wordpress开发人员,食品网站源码,分销系统怎么做使用Sumo以及traci实现交叉口信号灯自适应控制 文章目录 使用Sumo以及traci实现交叉口信号灯自适应控制 使用Sumo以及traci实现交叉口信号灯感应控制一、什么是交叉口感应控制二、Traci中的感应控制实现流程1.感应控制逻辑2.仿真过程 使用Sumo以及traci实现交叉口信号灯感应控制…
使用Sumo以及traci实现交叉口信号灯自适应控制 文章目录 使用Sumo以及traci实现交叉口信号灯自适应控制 使用Sumo以及traci实现交叉口信号灯感应控制一、什么是交叉口感应控制二、Traci中的感应控制实现流程1.感应控制逻辑2.仿真过程 使用Sumo以及traci实现交叉口信号灯感应控制
Sumo作为比较常用的交通仿真软件常用于各范围的路网仿真。今天研究一下怎么通过Python和Traci结合实现交叉口信号灯自适应控制。
一、什么是交叉口感应控制
交通信号控制方式是应用于道路交通信号控制系统为控制和调整交通流运行状态按照交通信号控制方案所执行的特定控制方式。国标《道路交通信号控制系统术语》GB/T 31418-2015)、行标《《道路交通信号控制方式 第1部分通用技术条件》GA/T 527.1-2015、美国《Signal Timing Mannual》对感应控制actuated和自适应控制(adaptive)都做了相关定义和描述。标准中对“感应控制”的描述为道路交通信号控制机根据检测器测得的交通流信息来调节信号显示时间的控制方式。
以行业标准《道路交通信号控制方式 第1部分通用技术条件》GA/T 527.1-2015种描述的“单点感应控制”根据交通流检测器测定到达交叉口进口道的交通需求对预先设定的交通信号控制方案进行执行相位的信号配时优化调整也可选择执行预设相位、优化相序以减少停车延误、排队长度为目标。
根据检测器布设方式可以将感应控制分为半感应控制和全感应控制。半感应控制只在部分进口道上设置检测器这种情况下交叉口仅部分相位有感应请求。而全感应控制在所有进口道上都设置检测器这种情况下交叉口所有相位均有感应请求。结合控制范围可以将感应控制划分为单点感应控制和干线感应协调控制。自适应控制可以划分为单点自适应控制、干线自适应控制、区域自适应控制。
二、Traci中的感应控制实现流程
1.感应控制逻辑
感应控制实现逻辑如下
def run():execute the TraCI control loopstep 0# we start with phase 2 where EW has greentraci.trafficlight.setPhase(0, 2)while traci.simulation.getMinExpectedNumber() 0:traci.simulationStep()if traci.trafficlight.getPhase(0) 2:# we are not already switchingif traci.inductionloop.getLastStepVehicleNumber(0) 0:# there is a vehicle from the north, switchtraci.trafficlight.setPhase(0, 3)else:# otherwise try to keep green for EWtraci.trafficlight.setPhase(0, 2)step 1traci.close()sys.stdout.flush()当有车辆进入布设的线圈内部时检测器检测到车辆存在切换相位。这里对Traci中的这部分代码进行详细讲解
traci.trafficlight.setPhase(0, 2)这里是设置信号灯初始相位为2相位对应的相位信息我们可以在xml文件中进行设置对应的trafficlight的文档中可以看到setPhase的相关内容 可以看到setPhase的作用是切换相位在相位列表中按照每一个相位对应的索引比如[‘南北直行放行’,‘南北左转放行’,’东西直行放行‘,‘东西左转放行’]setPhase(‘0’,2)表示对id为0的信号灯切换到第索引为2的相位即东西直行放行。 那么是怎么对是否有车进入线圈进行判断的这里用的是
traci.inductionloop.getLastStepVehicleNumber()traci.inductionloop.getLastStepVehicleNumber()方法的介绍如下 即参数输入为线圈id返回为上一仿真step中在线圈内的车辆数量这里用了一个判断traci.inductionloop.getLastStepVehicleNumber(’0‘)0,即还有车在上一仿真步长中在线圈内。
2.仿真过程
代码如下示例
#!/usr/bin/env python
# Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
# Copyright (C) 2009-2022 German Aerospace Center (DLR) and others.
# This program and the accompanying materials are made available under the
# terms of the Eclipse Public License 2.0 which is available at
# https://www.eclipse.org/legal/epl-2.0/
# This Source Code may also be made available under the following Secondary
# Licenses when the conditions for such availability set forth in the Eclipse
# Public License 2.0 are satisfied: GNU General Public License, version 2
# or later which is available at
# https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
# SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later# file runner.py
# author Lena Kalleske
# author Daniel Krajzewicz
# author Michael Behrisch
# author Jakob Erdmann
# date 2009-03-26from __future__ import absolute_import
from __future__ import print_functionimport os
import sys
import optparse
import random# we need to import python modules from the $SUMO_HOME/tools directory
if SUMO_HOME in os.environ:tools os.path.join(os.environ[SUMO_HOME], tools)sys.path.append(tools)
else:sys.exit(please declare environment variable SUMO_HOME)from sumolib import checkBinary # noqa
import traci # noqadef generate_routefile():random.seed(42) # make tests reproducibleN 3600 # number of time steps# demand per second from different directionspWE 1. / 10pEW 1. / 11pNS 1. / 30with open(data/cross.rou.xml, w) as routes:print(routesvType idtypeWE accel0.8 decel4.5 sigma0.5 length5 minGap2.5 maxSpeed16.67 \
guiShapepassenger/vType idtypeNS accel0.8 decel4.5 sigma0.5 length7 minGap3 maxSpeed25 guiShapebus/route idright edges51o 1i 2o 52i /route idleft edges52o 2i 1o 51i /route iddown edges54o 4i 3o 53i /, fileroutes)vehNr 0for i in range(N):if random.uniform(0, 1) pWE:print( vehicle idright_%i typetypeWE routeright depart%i / % (vehNr, i), fileroutes)vehNr 1if random.uniform(0, 1) pEW:print( vehicle idleft_%i typetypeWE routeleft depart%i / % (vehNr, i), fileroutes)vehNr 1if random.uniform(0, 1) pNS:print( vehicle iddown_%i typetypeNS routedown depart%i color1,0,0/ % (vehNr, i), fileroutes)vehNr 1print(/routes, fileroutes)# The program looks like this
# tlLogic id0 typestatic programID0 offset0
# the locations of the tls are NESW
# phase duration31 stateGrGr/
# phase duration6 stateyryr/
# phase duration31 staterGrG/
# phase duration6 stateryry/
# /tlLogicdef run():execute the TraCI control loopstep 0# we start with phase 2 where EW has greentraci.trafficlight.setPhase(0, 2)while traci.simulation.getMinExpectedNumber() 0:traci.simulationStep()if traci.trafficlight.getPhase(0) 2:# we are not already switchingif traci.inductionloop.getLastStepVehicleNumber(0) 0:# there is a vehicle from the north, switchtraci.trafficlight.setPhase(0, 3)else:# otherwise try to keep green for EWtraci.trafficlight.setPhase(0, 2)step 1traci.close()sys.stdout.flush()def get_options():optParser optparse.OptionParser()optParser.add_option(--nogui, actionstore_true,defaultFalse, helprun the commandline version of sumo)options, args optParser.parse_args()return options# this is the main entry point of this script
if __name__ __main__:options get_options()# this script has been called from the command line. It will start sumo as a# server, then connect and runif options.nogui:crsumoBinary checkBinary(sumo)else:sumoBinary checkBinary(sumo-gui)# first, generate the route file for this simulationgenerate_routefile()# this is the normal way of using traci. sumo is started as a# subprocess and then the python script connects and runstraci.start([sumoBinary, -c, cross.sumocfg,--tripinfo-output, tripinfo.xml])run()
cross.sumocfg及其相关文件如下把这些文件复制到本地存为以下文件名即可运行前提是你的环境变量配置没有问题。 文件链接如下 链接https://pan.baidu.com/s/1IFs4UJUBPxPM_LUTSrcmSw 提取码Sumo
欢迎交流