Skip to content

Add path reconstruction to pruning Hamiltonian solver - #5643

Open
OsamaGharibAlWaly wants to merge 1 commit into
google:mainfrom
OsamaGharibAlWaly:pr/01-hamiltonian-path-reconstruction
Open

OsamaGharibAlWaly wants to merge 1 commit into
google:mainfrom
OsamaGharibAlWaly:pr/01-hamiltonian-path-reconstruction

Conversation

@OsamaGharibAlWaly

Copy link
Copy Markdown

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

  • New public method and private helper; existing HamiltonianCost() signature is unchanged.
  • Header-only change with no BUILD, wrapper, or new dependency changes.
  • The Hamiltonian-cycle TODO is intentionally left for a follow-up: the pruning solver optimizes a path, not a tour, so a cycle API would need a separate objective change.

Tests

  • Extended Gr17 to validate that the reconstructed path is a permutation of all nodes and has the expected cost.
  • Added PruningSolverHamiltonianPath covering the optimal path, re-solving for a different end node, invalid end nodes, empty costs, and a singleton graph.
  • Full standalone g++ build of hamiltonian_path_test.cc in WSL: 15/15 tests passed (1 pre-existing disabled test).
  • clang-format --dry-run --Werror and git diff --check passed.

Notes / limitations

  • Windows Bazel could not be used because Visual C++ build tools are not installed; WSL g++ was used instead.
  • Zero-cost edges remain a pre-existing limitation of the pruning solver's zero-as-unvisited memoization sentinel and are not covered here.

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
OsamaGharibAlWaly marked this pull request as ready for review November 25, 2026 14:09
@OsamaGharibAlWaly
OsamaGharibAlWaly marked this pull request as draft November 25, 2026 15:32
@OsamaGharibAlWaly
OsamaGharibAlWaly marked this pull request as ready for review November 25, 2026 15:35

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.

1 participant