资源简介
用户平衡流量分配.py
代码片段和文件信息
import networkx as nx
import xlrd
import numpy as np
import xlwt
# 创建一个workbook对象即创建一个excel文件(可中文输入且不压缩)。
workbook = xlwt.Workbook(encoding=‘UTF-8‘ style_compression=0)
# 创建表sheet,表名为“西康路流量统计”,覆盖单元格。
sheet = workbook.add_sheet(“路段流量分配“ cell_overwrite_ok=True)
# 写出表头
sheet.write(0 0 ‘流量‘)
def read_data(path): # 读取文件函数
work_book = xlrd.open_workbook(path)
sheet = work_book.sheets()[0]
nrows = sheet.nrows # 行数
ncols = sheet.ncols # 列数(读取各节点连接状态)
node_data_list = [sheet.row_values(row) for row in range(sheet.nrows)] # 生成节点
return node_data_list nrows ncols
def read(path):#读取文件函数
work_book = xlrd.open_workbook(path)
sheet = work_book.sheets()[0]
data_list = [ sheet.row_values(row) for row in range(sheet.nrows) ]
final_data =np.array(data_list)
return data_listfinal_data
edges_list = []
def get_edges(node_listnrowsncols):#获取连通两点之间的路径
for i in range(nrows):
for j in range(ncols):
if node_list[i][j]==1:
edges_list.append((i+1j+1))
return edges_list
def get_path(edges_list):#获取OD两点之间的路径
graph = nx.DiGraph()
nodes_list = range(1 25 1)
edge_length = [1 + 0.1 * i for i in range(len(edges_list))]
for i e in enumerate(edges_list):
graph.add_edge(*e weight=edge_length[i])
for n in nodes_list:
graph.add_node(n)
start = int(input(“输入起始点:“))#控制台输入的开始节点
end = int(input(“输入终点:“)) #控制台输入的结束的节点
path_iter = nx.all_simple_paths(graph start end)
pathes = []
for p in path_iter:
pathes.append(p)
# print(pathes)
return pathes
def transfer_dict(final_data):
road_dict = {}
rows = final_data.shape[0]
for i in range(rows):
od = (int(final_data[i][0])int(final_data[i][1]))
xuhao = round(final_data[i][2])
road_dict[od]=xuhao
return road_dict
#############################################主程序################################################
path = r“C:\Users\周广京\Desktop\用户均衡资料\节点信息纯表.xlsx“
anotherpath = r“C:\Users\周广京\Desktop\用户均衡资料\自由流时间.xlsx“
getinfo = r“C:\Users\周广京\Desktop\用户均衡资料\路段信息表.xlsx“
get_capacity = r“C:\Users\周广京\Desktop\用户均衡资料\单车道通行能力.xlsx“
node_list nrows ncols = read_data(path)
edges_list = get_edges(node_list nrows ncols)
# first_impedance = read_data(anotherpath)
# print(first_impedance)
paths = get_path(edges_list)
data_listroad_dict = read(getinfo)
data_dict = transfer_dict(road_dict)
# print(data_dict)
dd=[]
final_dict = []
new_dict = []
path=[]
for i in range(len(paths)):
for j in range(len(paths[i])-1):
section = (paths[i][j]paths[i][j+1])
# print(type(section))
# sec = str(tuple(section))
# print(sec)
dd = data_dict[section]
#print(dd)
if len(final_dict) == 1:
final_dict = dd
else:
new_dict = (final_dictdd)
相关资源
- Python网络爬虫实战Scrapy.txt
- baidu.py
- Python接口测试框架实战与自动化进阶
- dtree_c4.5.py
- Spider-Meituan-Merchant.py
- Python3爬虫入门到精通课程视频附软件
- 某网Python3.6电商实战VueDjango.zip
- python大作业.rar
- 寻路.py
- Python串口操作.zip
- python资料.txt
- python检索新浪微博.zip
- Python手机短信轰炸.py
- 零基础:21天搞定Python分布式爬虫入门
- meituan_room.py
- python代码笔记.txt
- sniffer_get_body.py
- 手机短信轰炸.py
- you-get妹子图.py
- Python人工智能AI深度学习全套课程.t
- 千锋python爬虫教程之scrapy框架.txt
- 小甲鱼python课程96集包含源码+课件+课
- 小甲鱼python课程96集含源码课件课后习
- Python从入门到精通教程共40G.txt
- 06窗口摄像(视频).py
- nulindai.py
- 最新Python3.6网络爬虫实战案例5章(基
- 21天学通python.txt
- des.py
- 钉钉自定义机器人发送图片.py
评论
共有 条评论