Repository navigation
Add path reconstruction to pruning Hamiltonian solver - #5643
Open
OsamaGharibAlWaly wants to merge 1 commit into
Open
OsamaGharibAlWaly wants to merge 1 commit into
OsamaGharibAlWaly wants to merge 1 commit into
Conversation
Expose HamiltonianPath() and rebuild the path from memoized DP costs. Track the solved end node so requests for a different end node re-solve instead of reusing stale state. Add focused tests for path structure, re-solving, and invalid inputs.
OsamaGharibAlWaly
marked this pull request as ready for review
November 25, 2026 14:09
OsamaGharibAlWaly
marked this pull request as draft
November 25, 2026 15:32
OsamaGharibAlWaly
marked this pull request as ready for review
November 25, 2026 15:35
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds
PruningHamiltonianSolver::HamiltonianPath(end_node), resolving the TODO for path reconstruction. The path is rebuilt from the memoized dynamic-programming states without adding a predecessor table.The solver now also records which end node was solved and re-solves when a different end node is requested, so repeated calls do not return stale costs or paths.
Why this is additive
HamiltonianCost()signature is unchanged.Tests
Gr17to validate that the reconstructed path is a permutation of all nodes and has the expected cost.PruningSolverHamiltonianPathcovering the optimal path, re-solving for a different end node, invalid end nodes, empty costs, and a singleton graph.hamiltonian_path_test.ccin WSL: 15/15 tests passed (1 pre-existing disabled test).clang-format --dry-run --Werrorandgit diff --checkpassed.Notes / limitations