Skip to content

Commit bb4b072

Browse files
committed
improve code
1 parent b67d9f6 commit bb4b072

File tree

1 file changed

+4
-13
lines changed

1 file changed

+4
-13
lines changed

PathPlanning/AStar/a_star.py

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -92,23 +92,14 @@ def a_star_planning(sx, sy, gx, gy, ox, oy, reso, rr):
9292
current.cost + motion[i][2], c_id)
9393
n_id = calc_index(node, xw, minx, miny)
9494

95-
if not verify_node(node, obmap, minx, miny, maxx, maxy):
96-
continue
97-
9895
if n_id in closedset:
9996
continue
10097

101-
if n_id not in openset:
102-
openset[n_id] = node
103-
104-
# The distance from start to a neighbor.
105-
# The "dist_between" function may vary as per the solution requirements.
106-
if node.cost >= openset[n_id].cost:
107-
continue # This is not a better path.
98+
if not verify_node(node, obmap, minx, miny, maxx, maxy):
99+
continue
108100

109-
# This path is the best until now. Record it!
110-
openset[n_id].cost = node.cost
111-
openset[n_id].pind = c_id
101+
if node.cost < node.cost or n_id not in openset:
102+
openset[n_id] = node # update or insert new node
112103

113104
rx, ry = calc_fianl_path(ngoal, closedset, reso)
114105

0 commit comments

Comments
 (0)