stop is done

This commit is contained in:
StarLee 2016-07-07 13:51:21 +08:00
parent daff5121f9
commit 52a1e4f691
6 changed files with 111 additions and 32 deletions

View File

@ -1,10 +1,7 @@
17栋,18-3,1
601食堂,9-3,10
轻食,16-1,100
超市,14-1,1
102教学楼,9-6,1
101教学楼,9-6,1
103教学楼,9-6,1
PDL,16-8,1
银河楼,13-8,10
航天楼,14-6,1
天河楼,15-12,1
体育馆,11-11,1
博餐,6-16,10
游泳馆,8-14,1
八队,20-16,1
科技楼,2-10,2
博宿舍,5-14,1
1 17栋 天河楼 18-3 15-12 1
2 601食堂 体育馆 9-3 11-11 10 1
3 轻食 博餐 16-1 6-16 100 10
4 超市 游泳馆 14-1 8-14 1
5 102教学楼 八队 9-6 20-16 1
6 101教学楼 科技楼 9-6 2-10 1 2
7 103教学楼 博宿舍 9-6 5-14 1
PDL 16-8 1
银河楼 13-8 10
航天楼 14-6 1

View File

@ -10,6 +10,7 @@ from aiohttp.hdrs import LOCATION
import math
from _overlapped import NULL
import sys
import random
class Point:
def __init__(self,x,y):
self.x,self.y = x,y
@ -213,10 +214,17 @@ class AIPath:
point_start = Point(self.locations[start][0],self.locations[start][1])
point_end = Point(self.locations[end][0],self.locations[end][1])
self.draw_path(self.a_star(point_start,point_end))
path = self.a_star(point_start,point_end)
path.append(point_end)
print (path)
self.draw_path(path)
def find_planning(self):
self.cvs.delete('all')
self.draw_map()
print("规划上半部分>>>>")
self.find_planning_with_nodes("top_nodes.csv")
print("规划下半部分>>>>")
self.find_planning_with_nodes("bottom_nodes.csv")
@ -242,22 +250,35 @@ class AIPath:
frontier.append(point_start)
expanded = list()
#用户缓存记录 建筑物到路径某个点的最短路径
cache_path = dict()
round = 0
while True:
print("------------ planning new round-----------------")
# print("------------ planning new round-----------------")
if len(frontier) == 0:
print("fail")
return
point_to_ep = self.pop_frontier4planning(frontier, sub_nodes)
print("现在判读单节点: %d-%d" %(point_to_ep.x,point_to_ep.y))
point_to_ep = self.pop_frontier4planning(cache_path,frontier, sub_nodes)
# print("现在判读单节点: %d-%d" %(point_to_ep.x,point_to_ep.y))
# print("father:",point_to_ep.father)
print("目前为止路径:",self.get_solution(point_to_ep))
# print("目前为止路径:",self.get_solution(point_to_ep))
if point_to_ep.equals(point_end) or point_to_ep.next_to(point_end):
print("planning succesuss")
path = self.get_solution(point_to_ep)
path.append(point_end)
for sb in sub_nodes:
if sb[0] not in cache_path:
cache_path[sb[0]] = dict()
if point_end not in cache_path[sb[0]]:
cache_path[sb[0]][point_end] = len(self.a_star(point_end, sb[0]))
print (path)
self.draw_path(path)
#求站点
self.set_stop(cache_path,sub_nodes,path)
return
expanded.append(point_to_ep)
@ -277,12 +298,49 @@ class AIPath:
# if(point_to_ep.x == 12 and point_to_ep.y == 3):
# print("你想要的")
# break
print("------------planning round ends----------------")
print("\n")
round += 1
# if round == 3:
# break
def pop_frontier4planning(self,frontier,sub_nodes):
# print("------------planning round ends----------------")
# print("\n")
# def set_stop_k(self,cache,sub_nodes,path):
def set_stop(self,cache,sub_nodes,path):
# temp_path = path[1:len(path)-1]#不要首尾
temp_path = path
n = len(temp_path)
k = 5
left_k = 5-2
stop_cost = dict() #每一种方案的代价
end_n = int(math.pow(n,left_k))
for i in range(0,end_n):
points = list()
points.append(path[0])
points.append(path[len(path)-1])#路径的首尾点图书馆和北门默认是站点
map_key = ''
map_key += path[0].__str__() +','
map_key += path[len(path)-1].__str__() +','
for j in range(0,left_k):
points.append(temp_path[(i%n)])
map_key += path[(i%n)].__str__()+","
i = int(i / n)
count = 0
for sb in sub_nodes:
mins = sys.maxsize
for p in points:
if cache[sb[0]][p]*sb[1] < mins:#考虑人数因素
mins = cache[sb[0]][p]*sb[1]
count += mins
stop_cost[map_key] = count
best = sorted(stop_cost.items(),key=lambda d:d[1])[0]
stops = best[0].split(",")[0:k]
print(stops)
for stop in stops:
xy = stop.split('-')
self.cvs.create_rectangle(int(xy[0])* self.width_m, int(xy[1]) * self.height_m, (int(xy[0])+1)* self.width_m,(int(xy[1])+1)* self.height_m,fill ='yellow',outline = 'yellow')
def pop_frontier4planning(self,cache,frontier,sub_nodes):
min = sys.maxsize
poped = ''
pos = -1
@ -297,7 +355,12 @@ class AIPath:
dis_to_path = sys.maxsize
pf = p
while pf != None:
min_step = len(self.a_star(pf, sb[0]))
if sb[0] not in cache:
cache[sb[0]] = dict()
if pf not in cache[sb[0]]:
cache[sb[0]][pf] = len(self.a_star(pf, sb[0]))
min_step = cache[sb[0]][pf]
#min_step = len(self.a_star(pf, sb[0]))
if min_step*sb[1] < dis_to_path:
dis_to_path = min_step*sb[1]
# if sb[0].mh_dis(pf)*sb[1] < dis_to_path:

View File

@ -3,7 +3,7 @@
0,5,5,5,5,5,6,6,6,6,1,1,1,1,1,1,1,1,1,1,6,6,0
0,2,5,5,5,5,6,6,6,2,1,2,1,6,6,6,6,1,2,1,2,6,0
0,2,5,5,5,5,6,6,6,1,1,2,1,6,6,6,6,1,6,1,5,5,0
0,2,5,5,5,5,6,6,1,1,1,1,1,1,1,1,1,1,6,6,5,5,0
0,2,5,5,5,5,6,6,6,1,1,1,1,1,1,1,1,1,6,6,5,5,0
0,2,5,5,5,5,2,5,1,2,1,2,1,2,2,2,2,1,2,2,5,5,0
0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,5,5,0
0,1,2,1,5,5,5,5,5,5,5,5,1,2,6,1,2,6,2,1,5,5,0

1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
3 0 5 5 5 5 5 6 6 6 6 1 1 1 1 1 1 1 1 1 1 6 6 0
4 0 2 5 5 5 5 6 6 6 2 1 2 1 6 6 6 6 1 2 1 2 6 0
5 0 2 5 5 5 5 6 6 6 1 1 2 1 6 6 6 6 1 6 1 5 5 0
6 0 2 5 5 5 5 6 6 1 6 1 1 1 1 1 1 1 1 1 6 6 5 5 0
7 0 2 5 5 5 5 2 5 1 2 1 2 1 2 2 2 2 1 2 2 5 5 0
8 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 5 5 0
9 0 1 2 1 5 5 5 5 5 5 5 5 1 2 6 1 2 6 2 1 5 5 0

15
main/text.py Normal file
View File

@ -0,0 +1,15 @@
import math
a = [1,2,3,4]
n = len(a)
k = 3
end_n = int(math.pow(n,k))
print(n,end_n)
count = 0
for i in range(0,end_n):
str = ''
for j in range(0,k):
str += "%d-"%a[(i%n)]
i = int(i / n)
count += 1
print (str)
print (count)

View File

@ -1,7 +1,10 @@
天河楼,15-12,1
体育馆,11-11,1
博餐,6-16,1000000
游泳馆,8-14,1
八队,20-16,1
科技楼,2-10,1
博宿舍,5-14,1
17栋,18-3,1
601食堂,9-3,1
轻食,16-1,11
超市,14-1,1
102教学楼,9-6,2
101教学楼,9-6,2
103教学楼,9-6,2
PDL,16-8,3
银河楼,13-8,1
航天楼,14-6,1
1 天河楼 17栋 15-12 18-3 1
2 体育馆 601食堂 11-11 9-3 1
3 博餐 轻食 6-16 16-1 1000000 11
4 游泳馆 超市 8-14 14-1 1
5 八队 102教学楼 20-16 9-6 1 2
6 科技楼 101教学楼 2-10 9-6 1 2
7 博宿舍 103教学楼 5-14 9-6 1 2
8 PDL 16-8 3
9 银河楼 13-8 1
10 航天楼 14-6 1

View File

@ -81,11 +81,12 @@
\label{knn}
\end{figure}
\subsection{两点间最短路径}
\subsection{最短路径}
本次试验支持搜寻两点之间的最短路径具体求解过程用到了A*算法。
\subsection{求解}
\subsection{线路规划}
cache 优化
\begin{table}[!h]