基于最优路径的抢险救援
部分摘要
本文主要对部队在救灾过程中的路线提供最优方案,在灾情中争分夺秒是重中之重,因此良好的路线规划为救灾过程提供了有力的保障。问题一与问题二主要结合Dijkstra算法进行模型的构建,通过构建节点的知识表示,对节点与路线构造为图结构,并通过模型输出满足问题条件的最优路径。
由于问题三在对路径的最优方案上有了更深层次的要求,需要考虑的因素也更为丰富,使用粒子群算法将多种因素纳入其中,对救援方案进行设计。考虑到在现实中从起点到中间的路径错综复杂,且每条路径的路段数量不确定,我们绘制了一般交通网络图。,针对每条路径给出以行驶总时间为变量的正态密度函数。最后对所得函数变形处理,得到判断最优路径的数学模型,并根据模型求出最优路径。
本文构建的模型经检验在解决问题上有着良好的效率,并且提供的最优路径方案与救援方案有着一定的现实意义。
部分符号说明
程序代码
#导入pandas库
import pandas as pd
#定义列表,存储起点与终点
team = [['D1','D2'],['27','28']]
#找到所有从起始点到终点的路径
def all_path_find(graph,start,end,path=[]):
#定义函数,入参为图、起点、终点、路径
path = path +[start]
#存储路径信息
if start == end:
#如果起点和终点一样,返回路径
return [path]
paths = [] #存储所有路径
for node in graph[start]:
#在起点中进行循环
if node not in path:
#如果不在,执行函数进行查找,结果存入newpaths中
newpaths = all_path_find(graph,node,end,path)
#遍历路劲信息,并添加到总paths中
for newpath in newpaths:
paths.append(newpath)
return paths
def short_path_find(graph,start,end,path=[]):
print('start')
# 定义查找最短路径函数,入参为图、起点、终点、路径
path = path +[start]
if start == end:
return path
shortestPath = []
for node in graph[start]:
if node not in path:
newpath = short_path_find(graph,node,end,path)
if newpath:
#判断如果不是最短路径或者长度小于最短路径时,将路径赋值给最短路径
if not shortestPath or len(newpath)<len(shortestPath):
shortestPath = newpath
print('end')
return shortestPath
graph={#定义路线图的字典,key值为点的坐标,values为与此点相邻的点
'1':['2'],
'2':['1','3','47','D2'],
'3':['2','4','33','48','32','D2'],
'4':['3','5','33','50','Z01'],
'5':['4','34','6','49'],
'6':['5','36','7','51'],
'7':['6','8','52','Z04'],
'8':['7','9','42','52'],
'9':['8','10','45','Z03','D1'],
'10':['9','11','45','D1'],
'11':['10','46','D1'],
'12':['D2','13','32'],
'13':['12','21','32','14'],
'14':['15','13','21','35'],
'15':['25','14','16','37'],
'16':['17','39','15','Z06'],
'17':['16','18'],
'18':['29','17','19','41'],
'19':['18','20','31','43'],
'20':['19','31'],
'21':['13','14','22'],
'22':['21','23'],
'23':['24','25','22'],
'24':['25','23','26'],
'25':['15','23','24','Z06'],
'26':['27','24','Z06'],
'27':['26','28'],
'28':['27','29','30','Z06'],
'29':['18','28','30','31'],
'30':['28','29','31'],
'31':['29','30','19','20'],
'32':['12','13','33','D2'],
'33':['3','4','32','34'],
'34':['5','33','35','36'],
'35':['14','34'],
'36':['6','34'],
'37':['15','Z04'],
'38':['42','Z04'],
'39':['16','40'],
'40':['39','42'],
'41':['18','Z05'],
'42':['8','38','40','45'],
'43':['19','44'],
'44':['43','45','46','Z05'],
'45':['9','10','42','44','46'],
'46':['11','44','45'],
'47':['2','48'],
'48':['3','47','Z01'],
'49':['5','50'],
'50':['4','49','53'],
'51':['6','Z02'],
'52':['7','8','Z02','Z03'],
'53':['50','55','56','59'],
'54':['55','57','Z02'],
'55':['53','54','58','59'],
'56':['53','60'],
'57':['54','58','Z03'],
'58':['55','57','59','61'],
'59':['53','55','58','62'],
'60':['56','62'],
'61':['58','Z03'],
'62':['59','60'],
'Z01':['4','48','50'],
'Z02':['51','52','54'],
'Z03':['9','52','57','61','D1'],
'Z04':['7','37','38'],
'Z05':['41','44'],
'Z06':['25','26','28','16'],
'D1':['9','10','11','Z03'],
'D2':['2','3','12','32']
}
shortpath = [] #定义存储最短路径列表
for i in range(0,1):
print(i)
#在所有编号中进行迭代,入参为遍历的所有起点与终点的组合
shortpath.append(short_path_find(graph,str(team[0][i]),str(team[1][i])))
print("最优路径",shortpath)