SUMO文档009:高级教程(下)

在这部分教程中,你将会学习到如何:

l  利用街道类型设置一个抽象的网络

l  利用流创建同样的车辆

l  设置动态路由,这样车辆会一直行驶

l  利用python API分析输出文件

然后作为奖励学习如何:

l  使用套接字输出进行在线评估和节省磁盘空间。Socket编程

尽管关键词在线(the keywords online)、套接字(socket)和python API,但是本教程不包含任何TraCI相关内容。

1、网络设置(Network setup)

目标是构建一个简单的网络,车辆可以在网络上循环行驶。因此我们在角落设置四个节点(nodes),如下(circular.nod.xml):

<?xml version="1.0" encoding="UTF-8"?>
<nodes version="0.13" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://sumo.sf.net/xsd/nodes_file.xsd">
<node id="bottom-left" x="0" y="0"/>
<node id="bottom-right" x="1250" y="0"/>
<node id="top-right" x="1250" y="1250"/>
<node id="top-left" x="0" y="1250"/>
</nodes>

所有连接这些节点的道路必须有相同的车道数目和相同的最大速度。为了保存过固定类型,我们定义了单独的边类型文件(dege type file:circular.typ.xml):

<?xml version="1.0" encoding="UTF-8"?>
<types xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://sumo.sf.net/xsd/types_file.xsd">
<type id="edgeType" numLanes="2" speed="36.1"/>
</types>

最后,我们定义边连接节点(circular.edg.xml):

<?xml version="1.0" encoding="UTF-8"?>
<edges version="0.13" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://sumo.sf.net/xsd/edges_file.xsd">
<edge from="bottom-left" id="bottom" to="bottom-right" type="edgeType"/>
<edge from="bottom-right" id="right" to="top-right" type="edgeType"/>
<edge from="top-right" id="top" to="top-left" type="edgeType"/>
<edge from="top-left" id="left" to="bottom-left" type="edgeType"/>
</edges>

Netconvert的调用是很简单的:

netconvert-n circular.nod.xml -t circular.typ.xml -e circular.nod.xml -o circular.net.xml

为了简化得到的网络(并获得最高速度的模拟),我们省略周转和简化运动通过清除内车道结点。整个netconvert配置文件(circular.netccfg):

<?xml version="1.0" encoding="UTF-8"?>
<configuration xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://sumo.sf.net/xsd/netconvertConfiguration.xsd">
 
<input>
<node-files value="circular.nod.xml"/>
<edge-files value="circular.edg.xml"/>
<type-files value="circular.typ.xml"/>
</input>
 
<output>
<output-file value="circular.net.xml"/>
</output>
 
<processing>
<no-internal-links value="true"/>
<no-turnarounds value="true"/>
</processing>
 
</configuration>

尝试运行:

sumo-gui -n circular.net.xml

查看最后的网络效果。

2、路由和流量设置

<?xml version="1.0" encoding="UTF-8"?>
<routes xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://sumo.sf.net/xsd/routes_file.xsd">
<vType accel="1.5" decel="4.5" id="car" length="5" maxSpeed="36.1"/>
<vType accel="0.4" decel="4.5" id="truck" length="12" maxSpeed="22.2"/>
<route id="routeRight" edges="bottom right top left"/>
<route id="routeLeft" edges="top left bottom right"/>
<route id="routeTop" edges="top left bottom right"/>
<route id="routeBottom" edges="bottom right top left"/>
<flow begin="0" departPos="free" id="carRight" period="1" number="70" route="routeRight" type="car"/>
<flow begin="0" departPos="free" id="carTop" period="1" number="70" route="routeTop" type="car"/>
<flow begin="0" departPos="free" id="carLeft" period="1" number="70" route="routeLeft" type="car"/>
<flow begin="0" departPos="free" id="carBottom" period="1" number="70" route="routeBottom" type="car"/>
<flow begin="0" departPos="free" id="truckRight" period="1" number="30" route="routeRight" type="truck"/>
<flow begin="0" departPos="free" id="truckTop" period="1" number="30" route="routeTop" type="truck"/>
<flow begin="0" departPos="free" id="truckLeft" period="1" number="30" route="routeLeft" type="truck"/>
<flow begin="0" departPos="free" id="truckBottom" period="1" number="30" route="routeBottom" type="truck"/>
</routes>

3、重复如有设置(Rerouters)

<?xml version="1.0" encoding="UTF-8"?>
<additional xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://sumo.sf.net/xsd/additional_file.xsd">
<route id="routeRight" edges="bottom right top left"/>
<route id="routeLeft" edges="top left bottom right"/>
<route id="routeTop" edges="top left bottom right"/>
<route id="routeBottom" edges="bottom right top left"/>
<rerouter id="rerouterBottom" edges="bottom">
<interval begin="0" end="100000">
<routeProbReroute id="routeRight" />
</interval>
</rerouter>
<rerouter id="rerouterTop" edges="top">
<interval begin="0" end="100000">
<routeProbReroute id="routeLeft" />
</interval>
</rerouter>
</additional>

4、把它全部放在一起

<?xml version="1.0" encoding="UTF-8"?>
<configuration xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://sumo.sf.net/xsd/sumoConfiguration.xsd">
<input>
<net-file value="circular.net.xml"/>
<route-files value="circular.rou.xml"/>
<additional-files value="circular.add.xml"/>
</input>
<output>
<netstate-dump value="dump.xml"/>
</output>
 
<begin value="0"/>
<end value="10000"/>
 
</configuration>

分析输出!!!

奖励:Socket通信(这部分没有链接,

作者备注:这部分的实例代码有问题,.rou.xml.add.xml中的id定义冲突。

报错信息:


Sumo软件是一款最先进的交通仿真工具,用于模拟和分析交通流的行为和效果。下面是一个关于Sumo软件入门的简要教程。 首先,在安装Sumo软件之后,用户可以打开软件并开始创建交通仿真场景。用户可以从头开始创建仿真环境,也可以导入现有的地图文件。 接下来,用户需要定义仿真环境中的各种实体,如车辆、交叉口、道路等。通过使用Sumo提供的图形用户界面,用户可以方便地添加和编辑这些实体。 在添加了实体后,用户可以设置车辆,定义其行为和目标。用户可以指定车辆的起始位置和目的地,设置车辆的速度和加速度等参数。 一旦仿真环境和实体设置完毕,用户可以选择仿真的运行方式。Sumo提供了多种仿真模式,如实时仿真、追踪仿真等,用户可以根据需求选择合适的模式。 当仿真开始时,用户可以观察仿真过程中的车辆行为和交通流情况。Sumo还提供了丰富的可视化工具,以帮助用户更好地理解和分析仿真结果。 在仿真过程中,用户还可以对仿真进行实时调整和优化。用户可以根据需要修改实体的行为设置,调整道路网络,以及改变交通流量和信号灯等参数。 最后,在仿真结束后,用户可以通过Sumo提供的报告和分析功能来评估仿真的效果。用户可以查看交通流量、拥堵情况和各个实体的行为数据等。 总而言之,Sumo软件是一个强大而灵活的交通仿真工具,通过上述入门教程,用户可以快速上手并开始进行交通仿真分析。
评论 9
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值