Skip to content

Commit d2d8361

Browse files
committed
remove erraneous nested loop
1 parent fa798f2 commit d2d8361

1 file changed

Lines changed: 25 additions & 26 deletions

File tree

PathPlanning/ThetaStar/theta_star.py

Lines changed: 25 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -131,32 +131,31 @@ def planning(self, sx, sy, gx, gy):
131131

132132
# expand_grid search grid based on motion model
133133
for i, _ in enumerate(self.motion):
134-
for i, _ in enumerate(self.motion):
135-
node = self.Node(current.x + self.motion[i][0],
136-
current.y + self.motion[i][1],
137-
current.cost + self.motion[i][2], c_id) # cost may later be updated by theta star path compression
138-
n_id = self.calc_grid_index(node)
139-
140-
if not self.verify_node(node):
141-
continue
142-
143-
if n_id in closed_set:
144-
continue
145-
146-
# Theta* modification:
147-
if use_theta_star and current.parent_index != -1 and current.parent_index in closed_set:
148-
grandparent = closed_set[current.parent_index]
149-
if self.line_of_sight(grandparent, node):
150-
# If parent(current) has line of sight to neighbor
151-
node.cost = grandparent.cost + math.hypot(node.x - grandparent.x, node.y - grandparent.y)
152-
node.parent_index = current.parent_index # compress path directly to grandparent
153-
154-
if n_id not in open_set:
155-
open_set[n_id] = node
156-
else:
157-
if open_set[n_id].cost > node.cost:
158-
# This path is the best until now. record it
159-
open_set[n_id] = node
134+
node = self.Node(current.x + self.motion[i][0],
135+
current.y + self.motion[i][1],
136+
current.cost + self.motion[i][2], c_id) # cost may later be updated by theta star path compression
137+
n_id = self.calc_grid_index(node)
138+
139+
if not self.verify_node(node):
140+
continue
141+
142+
if n_id in closed_set:
143+
continue
144+
145+
# Theta* modification:
146+
if use_theta_star and current.parent_index != -1 and current.parent_index in closed_set:
147+
grandparent = closed_set[current.parent_index]
148+
if self.line_of_sight(grandparent, node):
149+
# If parent(current) has line of sight to neighbor
150+
node.cost = grandparent.cost + math.hypot(node.x - grandparent.x, node.y - grandparent.y)
151+
node.parent_index = current.parent_index # compress path directly to grandparent
152+
153+
if n_id not in open_set:
154+
open_set[n_id] = node
155+
else:
156+
if open_set[n_id].cost > node.cost:
157+
# This path is the best until now. record it
158+
open_set[n_id] = node
160159

161160

162161
rx, ry = self.calc_final_path(goal_node, closed_set)

0 commit comments

Comments
 (0)