9
9
"""
10
10
import math
11
11
12
+
12
13
from sys import maxsize
13
14
14
15
import matplotlib .pyplot as plt
@@ -103,7 +104,7 @@ def process_state(self):
103
104
if y .h <= k_old and x .h > y .h + x .cost (y ):
104
105
x .parent = y
105
106
x .h = y .h + x .cost (y )
106
- elif k_old == x .h :
107
+ if k_old == x .h :
107
108
for y in self .map .get_neighbors (x ):
108
109
if y .t == "new" or y .parent == x and y .h != x .h + x .cost (y ) \
109
110
or y .parent != x and y .h > x .h + x .cost (y ):
@@ -116,7 +117,7 @@ def process_state(self):
116
117
self .insert (y , x .h + x .cost (y ))
117
118
else :
118
119
if y .parent != x and y .h > x .h + x .cost (y ):
119
- self .insert (y , x .h )
120
+ self .insert (x , x .h )
120
121
else :
121
122
if y .parent != x and x .h > y .h + x .cost (y ) \
122
123
and y .t == "close" and y .h > k_old :
@@ -173,6 +174,8 @@ def run(self, start, end):
173
174
s .set_state ("e" )
174
175
tmp = start
175
176
177
+ AddNewObstacle (self .map ) # add new obstacle after the first search finished
178
+
176
179
while tmp != end :
177
180
tmp .set_state ("*" )
178
181
rx .append (tmp .x )
@@ -195,6 +198,15 @@ def modify(self, state):
195
198
if k_min >= state .h :
196
199
break
197
200
201
+ def AddNewObstacle (map :Map ):
202
+ ox , oy = [], []
203
+ for i in range (5 , 21 ):
204
+ ox .append (i )
205
+ oy .append (40 )
206
+ map .set_obstacle ([(i , j ) for i , j in zip (ox , oy )])
207
+ if show_animation :
208
+ plt .pause (0.001 )
209
+ plt .plot (ox , oy , ".g" )
198
210
199
211
def main ():
200
212
m = Map (100 , 100 )
@@ -217,7 +229,6 @@ def main():
217
229
for i in range (0 , 40 ):
218
230
ox .append (40 )
219
231
oy .append (60 - i )
220
- print ([(i , j ) for i , j in zip (ox , oy )])
221
232
m .set_obstacle ([(i , j ) for i , j in zip (ox , oy )])
222
233
223
234
start = [10 , 10 ]
@@ -234,7 +245,7 @@ def main():
234
245
rx , ry = dstar .run (start , end )
235
246
236
247
if show_animation :
237
- plt .plot (rx , ry , "-r" )
248
+ # plt.plot(rx, ry, "-r")
238
249
plt .show ()
239
250
240
251
0 commit comments