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

来源:互联网 发布:护肤品真假查询软件 编辑:程序博客网 时间:2024/06/05 02:18

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

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定义冲突。

报错信息:


0 0