@@ -75,24 +75,20 @@ def planning(self, sx, sy, gx, gy):
75
75
if len (open_set_A ) == 0 :
76
76
print ("Open set A is empty.." )
77
77
break
78
-
78
+
79
79
if len (open_set_B ) == 0 :
80
80
print ("Open set B is empty.." )
81
81
break
82
82
83
83
c_id_A = min (
84
84
open_set_A ,
85
- key = lambda o : open_set_A [o ].cost + self .calc_heuristic (current_B ,
86
- open_set_A [
87
- o ]))
88
-
85
+ key = lambda o : self .find_lowest_cost (open_set_A , o , current_B ))
86
+
89
87
current_A = open_set_A [c_id_A ]
90
88
91
89
c_id_B = min (
92
90
open_set_B ,
93
- key = lambda o : open_set_B [o ].cost + self .calc_heuristic (current_A ,
94
- open_set_B [
95
- o ]))
91
+ key = lambda o : self .find_lowest_cost (open_set_B , o , current_A ))
96
92
97
93
current_B = open_set_B [c_id_B ]
98
94
@@ -129,46 +125,49 @@ def planning(self, sx, sy, gx, gy):
129
125
continue_B = False
130
126
131
127
child_node_A = self .Node (current_A .x + self .motion [i ][0 ],
132
- current_A .y + self .motion [i ][1 ],
133
- current_A .cost + self .motion [i ][2 ], c_id_A )
128
+ current_A .y + self .motion [i ][1 ],
129
+ current_A .cost + self .motion [i ][2 ], c_id_A )
134
130
135
131
child_node_B = self .Node (current_B .x + self .motion [i ][0 ],
136
- current_B .y + self .motion [i ][1 ],
137
- current_B .cost + self .motion [i ][2 ], c_id_B )
132
+ current_B .y + self .motion [i ][1 ],
133
+ current_B .cost + self .motion [i ][2 ], c_id_B )
138
134
139
135
n_id_A = self .calc_grid_index (child_node_A )
140
136
n_id_B = self .calc_grid_index (child_node_B )
141
137
142
138
# If the node is not safe, do nothing
143
139
if not self .verify_node (child_node_A ):
144
140
continue_A = True
145
-
141
+
146
142
if not self .verify_node (child_node_B ):
147
143
continue_B = True
148
144
149
145
if n_id_A in closed_set_A :
150
146
continue_A = True
151
-
147
+
152
148
if n_id_B in closed_set_B :
153
149
continue_B = True
154
150
155
151
if not (continue_A ):
156
152
if n_id_A not in open_set_A :
157
- open_set_A [n_id_A ] = child_node_A # discovered a new node
153
+ # discovered a new node
154
+ open_set_A [n_id_A ] = child_node_A
158
155
else :
159
156
if open_set_A [n_id_A ].cost > child_node_A .cost :
160
157
# This path is the best until now. record it
161
158
open_set_A [n_id_A ] = child_node_A
162
-
159
+
163
160
if not (continue_B ):
164
161
if n_id_B not in open_set_B :
165
- open_set_B [n_id_B ] = child_node_B # discovered a new node
162
+ # discovered a new node
163
+ open_set_B [n_id_B ] = child_node_B
166
164
else :
167
165
if open_set_B [n_id_B ].cost > child_node_B .cost :
168
166
# This path is the best until now. record it
169
167
open_set_B [n_id_B ] = child_node_B
170
168
171
- rx , ry = self .calc_final_path_bidir (meetpointA , meetpointB , closed_set_A , closed_set_B )
169
+ rx , ry = self .calc_final_path_bidir (
170
+ meetpointA , meetpointB , closed_set_A , closed_set_B )
172
171
173
172
return rx , ry
174
173
@@ -203,6 +202,11 @@ def calc_heuristic(n1, n2):
203
202
d = w * math .hypot (n1 .x - n2 .x , n1 .y - n2 .y )
204
203
return d
205
204
205
+ def find_lowest_cost (self , open_set , lambda_ , n1 ):
206
+ cost = open_set [lambda_ ].cost + \
207
+ self .calc_heuristic (n1 , open_set [lambda_ ])
208
+ return cost
209
+
206
210
def calc_grid_position (self , index , minp ):
207
211
"""
208
212
calc grid position
0 commit comments