Python读取excel数据进行SUMO仿真
来源:互联网 发布:益云网络 编辑:程序博客网 时间:2024/05/17 00:16
在sumo仿真学习过程中,对方提出需求:提供路口交通流数据,按照数据进行仿真。
提供数据有:交叉口每个方向车辆数据(5分钟刷新一次),路口的Vissim地图等。
我们要根据提供的信息来进行基于SUMO的仿真。我们的步骤是:
1、获取net.xml
2、获取rou.xml
3、进行仿真
1、获取net.xml
因为对方提供的是vissm的路网数据。格式为.inpx。虽然说sumo提供了指令可以实现从.inpx到net.xml的实现,但是对于复杂网络,转换效果并不理想。我们还是直接从OpenStreetMap来下载路网数据。这里我们截取我们进行仿真的区域地图。然后通过netconvert将.osm地图数据转化为.net.xml数据。
Netconvert –osm-file filename.osm –o filename.net.xml
2、获取rou.xml
这里我们使用flow定义来实现五分钟内的车流。这里要做的就是从excel表中将数据筛选出,然后写入rou.xml文件。
算了一下将近3000条数据,人工筛选简直是作死。那么程序筛选。分析给的数据格式,我们首先将给的车辆数据和车辆行驶方向挂钩。比如:
北左1:S_E(即北->东方向),北直2:S_N(即北->南方向)………以此类推
然后分析excel表,从第9行开始,其中0、5、10 、13 、18列为总数,不读取,其他为0 的也不读取。时间按照每行增加。
相关代码:
#!/usr/bin/env python# -*- coding: utf-8 -*-# 读取excel数据from __future__ import print_functionimport xlrddef generate_routefile(): data = xlrd.open_workbook('hefei_jinsong3_liuliang_2016-08-25.xls') table = data.sheets()[0] nrows = table.nrows rouNum = 0 beginTime = 0 endTime = 3000 rouReal = (0,'jinsong3_hefei_S_E','jinsong3_hefei_S_N','jinsong3_hefei_S_N','jinsong3_hefei_S_N', 0,'jinsong3_hefei_E_E','jinsong3_hefei_E_W','jinsong3_hefei_E_W','jinsong3_hefei_E_S', 0,'jinsong3_hefei_N_W','jinsong3_hefei_N_S',0,'jinsong3_hefei_W_W','jinsong3_hefei_W_S', 'jinsong3_hefei_W_E','jinsong3_hefei_W_N',0)#这里的语句相当于routes=open("data/cross.rou.xml","w"),打开文件并赋值 with open("hefei_jinsong3_liuliang_2016-08-25.rou.xml", "w") as routes:#将以下内容写入rou.xml文件中 print("""<?xml version="1.0" encoding="UTF-8"?> <routes> <route id="jinsong3_hefei_E_S" edges="384486711#8 384501552#3"/> <route id="jinsong3_hefei_E_W" edges="384486711#8 384486711#9 384486711#10"/> <route id="jinsong3_hefei_E_N" edges="384486711#8 384486711#9 384501549#2 384501549#3"/> <route id="jinsong3_hefei_E_E" edges="384486711#8 384486711#9 384501549#2 384486722#5 384486722#6"/> <route id="jinsong3_hefei_S_N" edges="384501549#1 384501549#2 384501549#3"/> <route id="jinsong3_hefei_S_W" edges="384501549#1 384486711#10"/> <route id="jinsong3_hefei_S_E" edges="384501549#1 384501549#2 384486722#5 384486722#6"/> <route id="jinsong3_hefei_S_S" edges="384501549#1 384501549#2 384486722#5 384501552#2 384501552#3"/> <route id="jinsong3_hefei_W_N" edges="384486722#4 384501549#3"/> <route id="jinsong3_hefei_W_E" edges="384486722#4 384486722#5 384486722#6"/> <route id="jinsong3_hefei_W_S" edges="384486722#4 384486722#5 384501552#2 384501552#3"/> <route id="jinsong3_hefei_W_W" edges="384486722#4 384486722#5 384501552#2 384486711#9 384486711#10"/> <route id="jinsong3_hefei_N_E" edges="384501552#1 384486722#6"/> <route id="jinsong3_hefei_N_S" edges="384501552#1 384501552#2 384501552#3"/> <route id="jinsong3_hefei_N_W" edges="384501552#1 384501552#2 384486711#9 384486711#10"/> <route id="jinsong3_hefei_N_N" edges="384501552#1 384501552#2 384486711#9 384501549#2 384501549#3"/>""", file=routes) for i in range(92,nrows): for j in range(18): if table.row_values(i)[j] > 0: if j in [0,5,10,13]:continue print(' <flow id="js3_hf_%s" route="%s" begin="%d" end="%d" number="%d" departlane = "random"/>' % (rouNum, str(rouReal[j]), beginTime , endTime,table.row_values(i)[j]), file=routes) rouNum += 1 beginTime = endTime endTime += 3000#至此,写完了rou.xml文件,这里全部都是随机生成的 print("</routes>", file=routes)if __name__ == '__main__':generate_routefile()
最终得到的rou文件内容(部分)如下:
3、仿真
然后编辑配置文件,运行进行仿真即可。
0 0
- Python读取excel数据进行SUMO仿真
- python读取excel数据
- python读取excel数据
- python 读取excel数据
- python读取excel数据
- python读取Excel数据
- python与BeautifulSouop计算SUMO仿真的到达速率
- python之读取Excel数据
- python进行excel数据读写
- MFC对Excel数据进行读取
- 用Python读取excel中的数据
- python 对excel中数据的读取
- SUMO仿真快速入门系列五:SUMO与NS2连接
- python使用xlrd模块对excel进行读取
- selenium webdriver读取excel进行数据驱动测试
- PHPExcel 进行Excel读取
- 读书笔记--python数据可视化--002_读取Excel文件数据
- OMNET++/Veins VANET仿真:SUMO场景生成
- String固定起始位置字符串反转,去除前后或所有空格
- window下装kafka
- 跨时钟域时序的数据同步设计
- HDU5920 Ugly Problem(高精度)
- hadoop伪分布式环境搭建
- Python读取excel数据进行SUMO仿真
- vector
- Android NDK 开发(三)JNI 调用Java属性和方法
- 高级语言中各种数据结构在内存中是如何存储的?
- 第七周项目5-排队看病模拟
- 能让你少写1000行代码的20个正则表达式
- Web基础(1)-HTTP
- PAT乙级1010
- 系统会随机给你一个数组(存放都是数字),你需要将里面值累加,最后四舍五入,保留20位小数