Skip to content

Fix BFS crash for unreachable goal and start equal to goal (fixes #1502) - #1505

Open
blessedefe4real wants to merge 1 commit into
AtsushiSakai:masterfrom
blessedefe4real:fix/bfs-unreachable-and-start-goal
Open

blessedefe4real wants to merge 1 commit into
AtsushiSakai:masterfrom
blessedefe4real:fix/bfs-unreachable-and-start-goal

Conversation

@blessedefe4real

Copy link
Copy Markdown

Reference issue

Fixes #1502

What does this implement/fix?

BreadthFirstSearchPlanner.planning raised KeyError: -1 when the goal is unreachable and when the start equals the goal, because calc_final_path looked up closedset[ngoal.parent_index] while the goal's parent index was still -1.

  • Return [], [] when the open set is exhausted (same behavior as the Dijkstra fix proposed in Fix Dijkstra failure when goal is unreachable #1418), and document it in the planning docstring.
  • In calc_final_path, use closedset.get(ngoal.parent_index) so a goal without a parent (start == goal) gives the single-point path.

Normal planning is unchanged: main() produces the same path.

Additional information

Added test_unreachable_goal_returns_empty_path and test_start_equal_to_goal_returns_single_point_path to tests/test_breadth_first_search.py. Both raise KeyError: -1 on master and pass with this change. Full suite (pytest tests -Werror, as in runtests.sh): 158 passed; ruff check passes on the changed files.

CheckList

  • Did you add an unittest for your new example or defect fix?
  • Did you add documents for your new example? (not applicable: defect fix)
  • All CIs are green? (You can check it after submitting)

BreadthFirstSearchPlanner.planning raised KeyError(-1) in two cases:

- the goal cannot be reached: the loop broke out on an empty open set
  and calc_final_path looked up the goal's parent index -1;
- the start is the goal: the goal is found immediately with parent
  index -1, causing the same lookup.

Return empty lists when the open set is exhausted, and treat a missing
parent as the start of the path. Add regression tests for both cases.

This branch has not been deployed

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

1 participant