2
2
3
3
import numpy as np
4
4
5
+ TPos = tuple [int , int ]
6
+
5
7
6
8
class PriorityQueue :
7
9
def __init__ (self ):
@@ -53,24 +55,24 @@ def get(self):
53
55
return (priority , item )
54
56
55
57
56
- def consistent_heuristic (P , goal ):
58
+ def consistent_heuristic (P : TPos , goal : TPos ):
57
59
# euclidean distance
58
60
a = np .array (P )
59
61
b = np .array (goal )
60
62
return np .linalg .norm (a - b )
61
63
62
64
63
- def heuristic_2 (P , goal ):
65
+ def heuristic_2 (P : TPos , goal : TPos ):
64
66
# integer division by time variable
65
67
return consistent_heuristic (P , goal ) // t
66
68
67
69
68
- def heuristic_1 (P , goal ):
70
+ def heuristic_1 (P : TPos , goal : TPos ):
69
71
# manhattan distance
70
72
return abs (P [0 ] - goal [0 ]) + abs (P [1 ] - goal [1 ])
71
73
72
74
73
- def key (start , i , goal , g_function ):
75
+ def key (start : TPos , i : int , goal : TPos , g_function : dict [ TPos , float ] ):
74
76
ans = g_function [start ] + W1 * heuristics [i ](start , goal )
75
77
return ans
76
78
@@ -117,7 +119,7 @@ def do_something(back_pointer, goal, start):
117
119
quit ()
118
120
119
121
120
- def valid (p ):
122
+ def valid (p : TPos ):
121
123
if p [0 ] < 0 or p [0 ] > n - 1 :
122
124
return False
123
125
if p [1 ] < 0 or p [1 ] > n - 1 :
@@ -215,7 +217,6 @@ def make_common_ground():
215
217
(18 , 1 ),
216
218
(19 , 1 ),
217
219
]
218
- blocks_no = []
219
220
blocks_all = make_common_ground ()
220
221
221
222
@@ -233,7 +234,7 @@ def make_common_ground():
233
234
t = 1
234
235
235
236
236
- def multi_a_star (start , goal , n_heuristic ):
237
+ def multi_a_star (start : TPos , goal : TPos , n_heuristic : int ):
237
238
g_function = {start : 0 , goal : float ("inf" )}
238
239
back_pointer = {start : - 1 , goal : - 1 }
239
240
open_list = []
@@ -243,8 +244,8 @@ def multi_a_star(start, goal, n_heuristic):
243
244
open_list .append (PriorityQueue ())
244
245
open_list [i ].put (start , key (start , i , goal , g_function ))
245
246
246
- close_list_anchor = []
247
- close_list_inad = []
247
+ close_list_anchor : list [ int ] = []
248
+ close_list_inad : list [ int ] = []
248
249
while open_list [0 ].minkey () < float ("inf" ):
249
250
for i in range (1 , n_heuristic ):
250
251
# print(open_list[0].minkey(), open_list[i].minkey())
0 commit comments