Skip to content

Commit 0dca0e3

Browse files
committed
Use pop instead of min/del
1 parent ab05ac6 commit 0dca0e3

File tree

1 file changed

+6
-17
lines changed

1 file changed

+6
-17
lines changed

PathPlanning/DepthFirstSearch/depth_first_search.py

+6-17
Original file line numberDiff line numberDiff line change
@@ -74,11 +74,8 @@ def planning(self, sx, sy, gx, gy):
7474
print("Open set is empty..")
7575
break
7676

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)
8279

8380
# show graph
8481
if show_animation: # pragma: no cover
@@ -88,29 +85,19 @@ def planning(self, sx, sy, gx, gy):
8885
plt.gcf().canvas.mpl_connect('key_release_event',
8986
lambda event: [exit(
9087
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)
9389

9490
if current.x == ngoal.x and current.y == ngoal.y:
9591
print("Find goal")
9692
ngoal.pind = current.pind
9793
ngoal.cost = current.cost
98-
closed_set[current.pind] = current
9994
break
10095

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-
10996
# expand_grid search grid based on motion model
11097
for i, _ in enumerate(self.motion):
11198
node = self.Node(current.x + self.motion[i][0],
11299
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)
114101
n_id = self.calc_grid_index(node)
115102

116103
# If the node is not safe, do nothing
@@ -119,6 +106,8 @@ def planning(self, sx, sy, gx, gy):
119106

120107
if n_id not in closed_set:
121108
open_set[n_id] = node
109+
closed_set[n_id] = node
110+
node.parent = current
122111

123112
rx, ry = self.calc_final_path(ngoal, closed_set)
124113
return rx, ry

0 commit comments

Comments
 (0)