当前位置: 首页 > news >正文

推荐一下网站谢谢网站建设工作室创业计划书

推荐一下网站谢谢,网站建设工作室创业计划书,哈尔滨市土地局,软件培训机构本文将介绍如何在 SUMO 交通模拟中动态选择车辆绕行指定道路。 绕道是城市驾驶中的常见现象#xff0c;造成原因有很多#xff0c;包括建筑和交通事故等。 无论出于何种原因#xff0c;并非所有车辆都会选择避开这些道路#xff1b; 有些人可能会毫不犹豫地直接开车过去造成原因有很多包括建筑和交通事故等。 无论出于何种原因并非所有车辆都会选择避开这些道路 有些人可能会毫不犹豫地直接开车过去而另一些人可能会走小巷。 我们将模拟这两种行为。 1、准备环境 我假设你已经在计算机上安装了 SUMO 并配置了 PATH 和 SUMO_HOME 环境变量。 阅读文档以了解如何设置。 要测试你的机器是否准备就绪应该能够在终端中执行以下命令 sumo --version sumo-gui python --version netedit 2、SUMO快速入门 如果你熟悉 SUMO 交通模拟或阅读过我的其他教程那么可能已经知道在 SUMO 中运行模拟的基本组件包括 道路网络交通需求 在 SUMO 中默认情况下模拟是确定性的但有多种方法可以引入随机性。 出于我们的目的我们将利用 SUMO 提供的名为交通控制接口简称 TraCI的工具来实时修改模拟。 TraCI 使我们能够引入自定义逻辑以 Python 代码的形式来跟踪和操作模拟的许多方面包括单个车辆的路线。 本文提供了各种源代码示例来帮助你跟进。 三个配置文件分组在一个 config 文件夹中一个 Python 脚本称为 main.py包含运行和操作模拟的所有逻辑。 首先请在你的计算机上模仿此文件夹结构 2.1 创建道路网络 本节重点介绍道路网络。 网络的形状和复杂性无关紧要。 重要的是确定你希望车辆在模拟中避开的边的名称 (id)。 为了清楚起见我将编辑网络以重命名三个边 所有车辆出发的起始边称为“起始点”所有车辆的目的边作为“目的地”以及一些车辆会避开的边称为“封闭”。 如果你不熟悉创建网络请查看我的有关使用 netedit 设计自己的网络的教程。 对于后续操作并希望更多练习使用 netedit 的人我提供了下面两个表其中列出了交汇点junction和边edge的列表你可以在重新创建示例网络时用作参考。 交汇点列表 IDXYJ0-800800J1-700800J2-700700J3-600700j4-600800j5-500800 边列表 ID起止车道数originJ0J12E1J1J21E2J2J31E3J3J41closedJ1J42destinationJ4J52 对于那些懒得绘制自己的网络的人这里是上面所示的示例网络的源代码。 只需将其粘贴到 config 文件夹中名为 network.net.xml 的文件中即可 ?xml version1.0 encodingUTF-8?net version1.9 junctionCornerDetail5 limitTurnSpeed5.50 xmlns:xsihttp://www.w3.org/2001/XMLSchema-instance xsi:noNamespaceSchemaLocationhttp://sumo.dlr.de/xsd/net_file.xsdlocation netOffset0.00,0.00 convBoundary-800.00,700.00,300.00,800.10 origBoundary-10000000000.00,-10000000000.00,10000000000.00,10000000000.00 projParameter!/edge id:J1_0 functioninternallane id:J1_0_0 index0 speed6.53 length9.11 shape-707.20,795.29 -704.74,794.94 -702.99,793.87 -701.94,792.09 -701.59,789.60//edgeedge id:J1_1 functioninternallane id:J1_1_0 index0 speed13.89 length11.20 shape-707.20,795.29 -695.99,795.20/lane id:J1_1_1 index1 speed13.89 length11.20 shape-707.20,798.49 -695.99,798.40//edgeedge id:J2_0 functioninternallane id:J2_0_0 index0 speed3.95 length2.66 shape-701.50,700.10 -701.40,699.35 -701.10,698.82 -700.60,698.51 -699.90,698.40//edgeedge id:J3_0 functioninternallane id:J3_0_0 index0 speed3.86 length2.50 shape-600.00,698.50 -599.30,698.59 -598.80,698.88 -598.50,699.34 -598.40,700.00//edgeedge id:J4_0 functioninternallane id:J4_0_0 index0 speed6.51 length9.03 shape-598.40,789.60 -598.05,792.05 -597.00,793.80 -595.25,794.85 -592.80,795.20//edgeedge id:J4_1 functioninternallane id:J4_1_0 index0 speed13.89 length11.20 shape-604.00,795.20 -592.80,795.20/lane id:J4_1_1 index1 speed13.89 length11.20 shape-604.00,798.40 -592.80,798.40//edgeedge idE1 fromJ1 toJ2 priority-1 shape-700.00,800.00 -699.90,700.10lane idE1_0 index0 speed13.89 length89.50 shape-701.59,789.60 -701.50,700.10//edgeedge idE2 fromJ2 toJ3 priority-1 shape-700.00,700.00 -599.90,700.10lane idE2_0 index0 speed13.89 length99.90 shape-699.90,698.40 -600.00,698.50//edgeedge idE3 fromJ3 toJ4 priority-1lane idE3_0 index0 speed13.89 length89.60 shape-598.40,700.00 -598.40,789.60//edgeedge idclosed fromJ1 toJ4 priority-1lane idclosed_0 index0 speed13.89 length91.99 shape-695.99,795.20 -604.00,795.20/lane idclosed_1 index1 speed13.89 length91.99 shape-695.99,798.40 -604.00,798.40//edgeedge iddestination fromJ4 toJ5 priority-1 shape-600.00,800.00 -400.00,800.00 300.00,800.00 -500.00,800.00lane iddestination_0 index0 speed13.89 length92.80 shape-592.80,795.20 -500.00,795.20/lane iddestination_1 index1 speed13.89 length92.80 shape-592.80,798.40 -500.00,798.40//edgeedge idorigin fromJ0 toJ1 priority-1 shape-800.00,800.00 -699.90,800.10lane idorigin_0 index0 speed13.89 length92.80 shape-800.00,795.20 -707.20,795.29/lane idorigin_1 index1 speed13.89 length92.80 shape-800.00,798.40 -707.20,798.49//edgejunction idJ0 typedead_end x-800.00 y800.00 incLanes intLanes shape-800.00,800.00 -799.99,793.60/junction idJ1 typetraffic_light x-700.00 y800.00 incLanesorigin_0 origin_1 intLanes:J1_0_0 :J1_1_0 :J1_1_1 shape-695.99,800.00 -695.99,793.60 -698.22,793.16 -698.99,792.60 -699.55,791.82 -699.88,790.82 -699.99,789.60 -703.19,789.60 -703.64,791.87 -704.19,792.67 -704.97,793.24 -705.97,793.58 -707.19,793.69 -707.20,800.09 rightOfWayedgePriorityrequest index0 response000 foes000 cont0/request index1 response000 foes000 cont0/request index2 response000 foes000 cont0//junctionjunction idJ2 typepriority x-700.00 y700.00 incLanesE1_0 intLanes:J2_0_0 shape-703.10,700.10 -699.90,700.10 -699.90,696.80 -701.67,697.16 -702.30,697.62 -702.74,698.26 -703.01,699.09request index0 response0 foes0 cont0//junctionjunction idJ3 typepriority x-600.00 y700.00 incLanesE2_0 intLanes:J3_0_0 shape-600.00,700.10 -596.80,700.10 -597.16,698.32 -597.60,697.70 -598.22,697.26 -599.02,696.99 -600.00,696.90request index0 response0 foes0 cont0//junctionjunction idJ4 typepriority x-600.00 y800.00 incLanesE3_0 closed_0 closed_1 intLanes:J4_0_0 :J4_1_0 :J4_1_1 shape-592.80,800.00 -592.80,793.60 -595.02,793.16 -595.80,792.60 -596.36,791.82 -596.69,790.82 -596.80,789.60 -600.00,789.60 -600.44,791.82 -601.00,792.60 -601.78,793.16 -602.78,793.49 -604.00,793.60 -604.00,800.00request index0 response110 foes110 cont0/request index1 response000 foes001 cont0/request index2 response000 foes001 cont0//junctionjunction idJ5 typedead_end x-500.00 y800.00 incLanesdestination_0 destination_1 intLanes shape-500.00,793.60 -500.00,800.00/connection fromE1 toE2 fromLane0 toLane0 via:J2_0_0 dirl stateM/connection fromE2 toE3 fromLane0 toLane0 via:J3_0_0 dirl stateM/connection fromE3 todestination fromLane0 toLane0 via:J4_0_0 dirr statem/connection fromclosed todestination fromLane0 toLane0 via:J4_1_0 dirs stateM/connection fromclosed todestination fromLane1 toLane1 via:J4_1_1 dirs stateM/connection fromorigin toE1 fromLane0 toLane0 uncontrolled1 via:J1_0_0 dirr stateM/connection fromorigin toclosed fromLane0 toLane0 uncontrolled1 via:J1_1_0 dirs stateM/connection fromorigin toclosed fromLane1 toLane1 uncontrolled1 via:J1_1_1 dirs stateM/connection from:J1_0 toE1 fromLane0 toLane0 dirr stateM/connection from:J1_1 toclosed fromLane0 toLane0 dirs stateM/connection from:J1_1 toclosed fromLane1 toLane1 dirs stateM/connection from:J2_0 toE2 fromLane0 toLane0 dirl stateM/connection from:J3_0 toE3 fromLane0 toLane0 dirl stateM/connection from:J4_0 todestination fromLane0 toLane0 dirr stateM/connection from:J4_1 todestination fromLane0 toLane0 dirs stateM/connection from:J4_1 todestination fromLane1 toLane1 dirs stateM//net 2.2 创建交通需求 本节介绍交通需求Traffic Demand这是交通模拟的另一个基本组成部分。 出于我们的目的我们可以使用最初沿着相同路线行驶的少量相同车辆来使事情变得简单。 稍后我们将引入自定义逻辑来动态修改这些路由。 路线route ⇒ 扩展的行程trip包括出发边和目的边以及其间的所有边。行程Trip ⇒ 车辆从一个地方到另一个地方的运动。 在 SUMO 中生成路线的方法有很多种具体选择取决于你的可用输入。 为了满足我们的需求我们知道起始边和目的边。 尽管如此我们可以通过省略中间边并让 SUMO 找出最佳路径来节省时间。 要了解有关交通需求建模的更多信息请阅读文档。 对于示例网络车辆从出发地到目的地只有两条可能的路线。 在下图中这些路线用彩色箭头表示。 默认情况下SUMO 根据边的速度限制和距离来估计行驶时间并为各个车辆选择最佳路径又称路线。 我们先来描述一下行程。 虽然可以使用netedit等工具配置流量需求但在这种情况下直接编写源代码要容易得多。 首先在 config 文件夹中创建一个文件将其命名为 trips.trips.xml。 行程的基本描述只需要标识符id、起始边from和目的边to以及车辆进入网络出发的时间。 如前所述我们利用自动路由在运行时生成路由。 要了解有关自动路由的更多信息请查看文档。 routes xmlns:xsihttp://www.w3.org/2001/XMLSchema-instance xsi:noNamespaceSchemaLocationhttp://sumo.dlr.de/xsd/routes_file.xsdtrip id0 depart0 fromorigin todestination /trip id1 depart2 fromorigin todestination /trip id2 depart3 fromorigin todestination /trip id3 depart5 fromorigin todestination /trip id4 depart7 fromorigin todestination /trip id5 depart8 fromorigin todestination /trip id6 depart9 fromorigin todestination /trip id7 depart10 fromorigin todestination /trip id8 depart11 fromorigin todestination /trip id9 depart12 fromorigin todestination / /routes 2.3 可选的可视化 默认情况下SUMO GUI 使用“标准”视图设置将车辆表示为三角形并将网络着色为灰色。 我更喜欢使用“真实世界”视图设置顾名思义它为模拟中的元素添加了更真实的视觉表示。 打开 SUMO GUI 后你可以在可用视图设置之间切换但要在应用程序加载时更改默认设置需要配置文件 viewSettings.xml viewsettings xmlns:xsihttp://www.w3.org/2001/XMLSchema-instance xsi:noNamespaceSchemaLocationhttp://sumo.dlr.de/xsd/viewsettings_file.xsdscheme namereal world / /viewsettings 3、运行模拟 此时你应该拥有一个类似于简介中所示的项目结构并在 config 文件夹中包含两个可选三个配置文件。 缺少的是编排模拟的运行程序脚本 - 以及随后处理我们的绕道detour逻辑。 本节重点介绍运行脚本所以让我们开始吧 至少运行程序脚本将启动模拟将时钟向前移动并在所有车辆退出后关闭模拟。 3.1 开始模拟 为了简单地运行模拟我们需要 TraCI 将我们的网络和行程文件传输到 SUMO GUISUMO 的图形界面中。 我们将定义一个函数 startSim() 来处理此操作。 以下两个过程包括向前移动模拟时间和停止模拟。 def startSim():Starts the simulation.traci.start([sumoBinary,--net-file, ./config/network.net.xml,--route-files, ./config/trips.trips.xml,--delay, 200,--gui-settings-file, ./config/viewSettings.xml,--start]) 要使用 TraCI我们必须为其提供应用程序和执行选项的二进制文件。 该二进制文件将是 SUMO-GUI我们将使用 sumolib 库中的 checkBinary 函数获取其二进制文件。 执行选项取决于应用程序。 出于我们的目的我们需要使用以下选项 --net-file [FILE] → 读取网络文件。--route-files [FILES] → 读取路线/行程文件。 虽然以下选项是可选的 --delay [FLOAT] → 在模拟步骤之间添加 [FLOAT] 延迟我们将使用它来本质上减慢速度以便人眼可以观看。--gui-settings-file [FILE] → 从文件中读取可视化设置我们将使用该设置将“真实世界”皮肤应用于道路和车辆。--start → 加载后自动启动模拟省去了我们手动按启动按钮的麻烦。 要查看可用执行选项的列表通常的做法是直接在终端中执行应用程序后跟选项  --help。 3.2 增加模拟时钟 如果不指示 TraCI 何时或如何增加模拟时钟模拟将保持时间冻结状态。 我们可以通过调用 traci.simulationStep() 方法轻松增加时钟。 但是此方法仅将时钟移动一秒因此我们需要将其包装在循环中以连续增加时间。 为了防止模拟永远运行我们将创建一个新函数 shouldContinueSim()来检查行程中的所有车辆是否已进入和退出网络。 def shouldContinueSim():Checks that the simulation should continue running.Returns:bool: True if vehicles exist on network. False otherwise.numVehicles traci.simulation.getMinExpectedNumber()return True if numVehicles 0 else False 3.3 关闭模拟 最后为了阻止 TraCI 运行我们将使用它的 traci.close() 方法。 3.4 整合在一起 让我们将所有内容放在 main.py 文件中。 import traci from sumolib import checkBinarysumoBinary checkBinary(sumo-gui)def main():startSim()while shouldContinueSim():traci.simulationStep()traci.close()def startSim():Starts the simulation.traci.start([sumoBinary,--net-file, ./config/network.net.xml,--route-files, ./config/trips.trips.xml,--delay, 200,--gui-settings-file, ./config/viewSettings.xml,--start])def shouldContinueSim():Checks that the simulation should continue running.Returns:bool: True if there are any vehicles on or waiting to enter the network. False otherwise.numVehicles traci.simulation.getMinExpectedNumber()return True if numVehicles 0 else Falseif __name__ __main__:main() 3.5 运行模拟 让我们运行模拟。 在终端中使用命令 python main.py 执行运行程序脚本。 你将看到我们所有的车辆从最左边的边进入网络并朝着最右边的边行驶其最佳路线。 瞧 接下来介绍一下绕行detour逻辑。 4、绕行介绍 我们已经根据行程描述获得了模拟生成车辆及其各自的路线。 现在是时候介绍绕行逻辑了。 在本节中我们将选择一些车辆绕道并更改其颜色以帮助在视觉上将它们与未受影响的车辆区分开来。 4.1 绕行逻辑 我们阻止车辆行驶通过特定边的方法是告诉车辆其通过边的行驶时间将无限大。 如果 SUMO 使用的路由算法在计算中考虑行程时间默认情况下则此方法有效。 每辆车单独考虑边行程时间为了改变对这些估计行程时间的看法TraCI 提供了 traci.vehicle.setAdaptedTraveltime() 方法。 仅改变车辆对边行驶时间的看法不会起作用因为车辆在最初进入网络时就决定了其路线并且不会自动改变它。 我们需要使用 traci.vehicle.rerouteTraveltime() 方法强制它重新计算路线。 这两种方法一起将说服车辆选择替代路线来避开目标边缘。 我们将创建一个函数 avoidEdge()来处理此操作。 def avoidEdge(vehId, edgeId):Sets an edges travel time for a vehicle infinitely high, and reroutes the vehicle based on travel time.Args:vehId (Str): The ID of the vehicle to reroute.edgeId (Str): The ID of the edge to avoid.traci.vehicle.setAdaptedTraveltime(vehId, edgeId, float(inf))traci.vehicle.rerouteTraveltime(vehId) 4.2 将逻辑应用于车辆 现在我们有了逻辑需要选择并将其应用于车辆和要避免的边。 选择车辆的方法有很多但我们将采用最直接的方法并从我们的行程文件中手动记录名称。 此步骤需要了解车辆和边的 ID。 我将使用全局变量数组 VEHICLES 来包含这些车辆的名称并使用另一个变量 EDGE_ID 来包含边的名称。 不幸的是如果在车辆不在网络上时尝试访问特定车辆属性SUMO 可能会抛出错误。 因此在尝试更改任何内容之前我们需要确保车辆存在但没有直接的方法可以做到这一点。 一种技术是使用 traci.simulation.getDepartedIDList() 方法检查其名称是否在这段时间内进入网络的车辆列表中。 我们将创建一个函数 getOurDeparted() 来处理此操作。 def getOurDeparted(filterIds[]):Returns a set of filtered vehicle IDs that departed onto the network during this simulation step.Args:filterIds ([String]): The set of vehicle IDs to filter for.Returns:[String]: A set of vehicle IDs.newlyDepartedIds traci.simulation.getDepartedIDList()filteredDepartedIds newlyDepartedIds if len(filterIds) 0 else set(newlyDepartedIds).intersection(filterIds)return filteredDepartedIds 4.3 改变车辆颜色 接下来但可选的是使用 traci.vehicle.setColor() 方法将车辆的颜色更改为红色。 这将帮助我们在其他车辆中直观地识别它。 我们将创建一个函数 setVehColor() 来处理此操作。 def setVehColor(vehId, color):Changes a vehicles color.Args:vehId (String): The vehicle to color.color ([Int, Int, Int]): The RGB color to apply.traci.vehicle.setColor(vehId, color) 4.4 整合在一起 有了上述所有组件我们就可以启动和停止模拟、增加时钟并更改车辆颜色和路线。 有了这些你的 main.py 文件应如下所示 from sumolib import checkBinary import tracisumoBinary checkBinary(sumo-gui)RED [255, 0, 0] EDGE_ID closed VEHICLES [1, 4, 8]def main():startSim()while shouldContinueSim():for vehId in getOurDeparted(VEHICLES):setVehColor(vehId, RED)avoidEdge(vehId, EDGE_ID)traci.simulationStep()traci.close()def startSim():Starts the simulation.traci.start([sumoBinary,--net-file, ./config/network.net.xml,--route-files, ./config/trips.trips.xml,--delay, 200,--gui-settings-file, ./config/viewSettings.xml,--start])def shouldContinueSim():Checks that the simulation should continue running.Returns:bool: True if vehicles exist on network. False otherwise.numVehicles traci.simulation.getMinExpectedNumber()return True if numVehicles 0 else Falsedef setVehColor(vehId, color):Changes a vehicles color.Args:vehId (String): The vehicle to color.color ([Int, Int, Int]): The RGB color to apply.traci.vehicle.setColor(vehId, color)def avoidEdge(vehId, edgeId):Sets an edges travel time for a vehicle infinitely high, and reroutes the vehicle based on travel time.Args:vehId (Str): The ID of the vehicle to reroute.edgeId (Str): The ID of the edge to avoid.traci.vehicle.setAdaptedTraveltime(vehId, edgeId, float(inf))traci.vehicle.rerouteTraveltime(vehId)def getOurDeparted(filterIds[]):Returns a set of filtered vehicle IDs that departed onto the network during this simulation step.Args:filterIds ([String]): The set of vehicle IDs to filter for.Returns:[String]: A set of vehicle IDs.newlyDepartedIds traci.simulation.getDepartedIDList()filteredDepartedIds newlyDepartedIds if len(filterIds) 0 else set(newlyDepartedIds).intersection(filterIds)return filteredDepartedIdsif __name__ __main__:main() 5、最终结果 假设你现在运行模拟 (python main.py)。 在这种情况下你会注意到我们之前选择的车辆进入网络后会显示为红色。 此外当他们接近第一个十字路口时他们会减速、打信号灯并右转沿小街行驶。 与此同时所有其他黄色车辆继续直行或变道以避免碰撞。 你会记得我们在行程trip描述中没有指定任何中间边 这一切都由 SUMO 处理。 事实上这种行为是动态的并且基于网络和流量的各个方面。 例如通过增加更多的小巷或引入交通信号灯车辆可能会选择单独的路线以避免造成交通拥堵。 恭喜 通过本文你设计了一个网络描述了流量需求配置了可视化设置设置了 TraCI 来管理模拟并引入了动态绕行逻辑。 原文链接SUMO车辆绕行模拟 - BimAnt
http://www.dnsts.com.cn/news/173347.html

相关文章:

  • 南京建设机械网站山东省建设厅的网站
  • 网站开发到上线dw做网站简单吗
  • 设计微信公众号的网站吗网站 微站建设排名
  • 高端企业网站建设公司怎么做实用性网站开发考什么证
  • 肯德基网站建设方案外链seo招聘
  • 做网站常熟旅行社网站 模板
  • 如何给网站做推广怎么做网站解析
  • 江西手机网站建设邯郸市做网站
  • 长宁移动网站建设汽车网站建设方案
  • 机关网站建设前期准备工作物业管理系统的设计与实现
  • 给我一个免费网站吗jsp两种网站开发模式
  • 花店网站模板 html上虞市住房和城乡建设局网站
  • 知名公司百度seo排名如何提升
  • 简单的网站架构一流专业建设方案
  • 网站维护需要用到哪些知识免费网站建设市场
  • 服务网站 建设原则网站建设自评报告
  • 网站开发面试自我介绍网站做推广需要营业执照
  • 网站升级页面连接设置建设网站应达到的目的和作用
  • ps做网站像素大小河北省建设工程管理信息网官网
  • 做的网站里面显示乱码怎么解决简单网站制作实验报告
  • 用vs2012做网站案例wordpress替换首页图片
  • wid2008vps创建网站湘潭网站建设 AA磐石网络
  • 外贸展示型网站建设wordpress 微信内登录
  • 电子商务网站建设模板下载网站建设第一步做什么
  • 镇江做网站的公司网站建设:成都今网科技
  • 网站建设与网站主机的选择电子政务网站建设公司排行榜
  • 开封建站公司同安建设局网站
  • 一微网站建设公司广告设计主要做哪些
  • 网站内容页收录承德很好的网络建站
  • 运用vs2010c 做网站宁波建设工程学校