Skip to content

Reset search state for spanning-tree traversal - #90

Open
civilwarinfrance wants to merge 1 commit into
brean:mainfrom
civilwarinfrance:fix/spanning-tree-search-state
Open

civilwarinfrance wants to merge 1 commit into
brean:mainfrom
civilwarinfrance:fix/spanning-tree-search-state

Conversation

@civilwarinfrance

Copy link
Copy Markdown
Contributor

Calling MinimumSpanningTree.tree() twice on a three-cell grid returns all three cells the first time, but only the starting cell the second time. tree() and itertree() do not clean or mark the grid dirty, reset the run counter, or initialize the clock. Consequently, a finite time_limit also makes a fresh tree traversal fail immediately, and tree traversal can interfere with a later route search on the same grid.

Initialize search state in itertree(), which is shared by tree() and find_path(), and remove the duplicate initialization from find_path(). Reset the root's costs as well. The traversal algorithm is unchanged.

Validation on macOS / Python 3.14.6:

  • Before the fix: 14 new regression cases fail and two controls pass.
  • After the fix: all 63 tests pass.
  • Coverage includes repeat traversals with the same or a new finder, alternating tree/A* searches, a partially consumed iterator, per-traversal run budgets, and finite time limits that still expire correctly.
  • Ruff E/F checks at 79 columns and whitespace checks pass.

This PR is based directly on main and does not include the pending smoothing or identical-endpoint patches.

AI assistance: This patch, tests and description were prepared with Codex (GPT-6).

AI-assisted by Codex (GPT-6).
@brean

brean commented Oct 27, 2026

Copy link
Copy Markdown
Owner

This bug does not exist, find_path cleans the tree.

@brean brean closed this Oct 27, 2026
@civilwarinfrance

Copy link
Copy Markdown
Contributor Author

Thanks for checking it! You're right that find_path() already cleans the grid. I meant direct tree()/itertree() calls: on Grid(matrix=[[1, 1]]), calling finder.tree(grid, grid.node(0, 0)) twice returns 2 nodes, then only 1, without going through find_path(). That's the case the tests target. If those methods aren't intended to be used directly, no worries — I'll leave this closed.

@brean brean reopened this Oct 27, 2026
@brean brean self-assigned this Oct 27, 2026
@brean

brean commented Oct 27, 2026

Copy link
Copy Markdown
Owner

Thanks for the clarification, I'll take a deeper look into Grid and if it should call find_path directly later, so I reopened this PR and assigned myself.

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.

2 participants