Skip to content

ida_star: stop looping forever when the goal is unreachable - #93

Open
ducduong97hn wants to merge 1 commit into
brean:mainfrom
ducduong97hn:fix/ida-star-unreachable-goal
Open

ducduong97hn wants to merge 1 commit into
brean:mainfrom
ducduong97hn:fix/ida-star-unreachable-goal

Conversation

@ducduong97hn

Copy link
Copy Markdown

find_path()'s loop only exited early on isinstance(t, bool) and not t, but search() never returns a bool — it only ever returns a float or a Node. That branch is dead code, so the only way out of the loop was finding the goal. With the default time_limit and max_runs (both infinite), a genuinely unreachable goal made find_path() grow cutoff and re-search forever.

search() already returns +inf at the top level when every reachable node has been tried down to a true dead end (no remaining neighbors) without any of them exceeding the cutoff — that case means the whole reachable area has been searched and the goal was not in it, so no cutoff increase will ever find it. This checks for that instead of the dead isinstance(t, bool) branch, and returns an empty path.

Added a regression test for an isolated goal ([[1, 0, 1]], no diagonal movement), with its own time_limit=10 as a safety net in case the fix is ever lost again.

What I verified, and what I didn't: I traced the dead-code path and the +inf exhaustion case by reading search()/find_path() by hand, and I'm confident in the mechanism. I could not run pytest in the environment I wrote this in, so I have not executed the new test or the existing suite (test_path.py in particular, since it already runs IDAStarFinder through path_test_scenarios.json with time_limit=10) to confirm nothing regresses. I'd appreciate a CI run or a local check before merging.

I also wasn't able to reproduce the exact repro in #92 (a fully open map, which should be reachable) to confirm this is the complete explanation for that report rather than a related-but-separate issue — happy to dig further if the fix alone doesn't resolve it there.

Fixes #92

find_path()'s loop only exited early on "isinstance(t, bool) and not t",
but search() never returns a bool: it only ever returns a float or a
Node. That branch is dead code, so the only way out of the loop was
finding the goal. With the default time_limit and max_runs (both
infinite), a genuinely unreachable goal made find_path() grow cutoff
and re-search forever.

search() already returns +inf at the top when every reachable node
has been tried down to a true dead end (no remaining neighbors)
without any of them exceeding the cutoff: that case means the whole
reachable area has been searched and the goal was not in it, so no
cutoff increase will ever find it. Check for that instead and return
an empty path.

Added a regression test for this case. Not fully verified end-to-end
against the exact repro in brean#92 (an open map) with a running
interpreter; I confirmed the dead code and the infinite-loop mechanism
by reading search()/find_path() and traced the +inf exhaustion case by
hand, but could not execute pytest in this environment to check the
open-map case runs quickly too, or run the existing test suite to
confirm nothing else regresses.

Fixes brean#92
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.

IDA* hangs forever

2 participants