@@ -74,11 +74,8 @@ def planning(self, sx, sy, gx, gy):
74
74
print ("Open set is empty.." )
75
75
break
76
76
77
- c_id = max (
78
- open_set ,
79
- key = lambda o : open_set [o ].pind )
80
-
81
- current = open_set [c_id ]
77
+ current = open_set .pop (list (open_set .keys ())[- 1 ])
78
+ c_id = self .calc_grid_index (current )
82
79
83
80
# show graph
84
81
if show_animation : # pragma: no cover
@@ -88,29 +85,19 @@ def planning(self, sx, sy, gx, gy):
88
85
plt .gcf ().canvas .mpl_connect ('key_release_event' ,
89
86
lambda event : [exit (
90
87
0 ) if event .key == 'escape' else None ])
91
- if len (closed_set .keys ()) % 10 == 0 :
92
- plt .pause (0.001 )
88
+ plt .pause (0.01 )
93
89
94
90
if current .x == ngoal .x and current .y == ngoal .y :
95
91
print ("Find goal" )
96
92
ngoal .pind = current .pind
97
93
ngoal .cost = current .cost
98
- closed_set [current .pind ] = current
99
94
break
100
95
101
- # Remove the item from the open set
102
- del open_set [c_id ]
103
-
104
- # Add it to the closed set
105
- closed_set [c_id ] = current
106
-
107
- random .shuffle (self .motion )
108
-
109
96
# expand_grid search grid based on motion model
110
97
for i , _ in enumerate (self .motion ):
111
98
node = self .Node (current .x + self .motion [i ][0 ],
112
99
current .y + self .motion [i ][1 ],
113
- current .cost + self .motion [i ][2 ], c_id + 1 , current )
100
+ current .cost + self .motion [i ][2 ], c_id , None )
114
101
n_id = self .calc_grid_index (node )
115
102
116
103
# If the node is not safe, do nothing
@@ -119,6 +106,8 @@ def planning(self, sx, sy, gx, gy):
119
106
120
107
if n_id not in closed_set :
121
108
open_set [n_id ] = node
109
+ closed_set [n_id ] = node
110
+ node .parent = current
122
111
123
112
rx , ry = self .calc_final_path (ngoal , closed_set )
124
113
return rx , ry
0 commit comments