Skip to content

Breadth-first search raises KeyError for unreachable goal or start equal to goal #1502

Open

Description

@blessedefe4real

BreadthFirstSearchPlanner.planning in PathPlanning/BreadthFirstSearch/breadth_first_search.py raises KeyError: -1 instead of returning a result in two cases.

1. The goal cannot be reached. When the open set is exhausted the loop only breaks, and calc_final_path then evaluates closedset[ngoal.parent_index] with the goal's initial parent index -1.

2. The start is the goal. The goal is found on the first iteration with parent_index == -1, so the same lookup fails.

Reproduce

from PathPlanning.BreadthFirstSearch import breadth_first_search as m
m.show_animation = False

# square boundary 0..10 with an inner wall at x = 5
ox, oy = [], []
for i in range(11):
    ox += [0.0, 10.0, float(i), float(i), 5.0]
    oy += [float(i), float(i), 0.0, 10.0, float(i)]
planner = m.BreadthFirstSearchPlanner(ox, oy, 1.0, 0.5)

planner.planning(2.0, 5.0, 8.0, 5.0)  # KeyError: -1 (goal behind the wall)
planner.planning(2.0, 5.0, 2.0, 5.0)  # KeyError: -1 (start == goal)

Expected

Tested on current master (61a8b0b), Python 3.13.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions