Skip to content

Fix #217: Add HamiltonianPath model#621

Merged
GiggleLiu merged 8 commits intomainfrom
issue-217-hamiltonian-path
Mar 13, 2026
Merged

Fix #217: Add HamiltonianPath model#621
GiggleLiu merged 8 commits intomainfrom
issue-217-hamiltonian-path

Conversation

@zazabap
Copy link
Collaborator

@zazabap zazabap commented Mar 13, 2026

Summary

  • Add HamiltonianPath satisfaction problem model (graph-based, Metric = bool)
  • Classical NP-complete decision problem: does a graph contain a simple path visiting every vertex exactly once?
  • Includes unit tests, brute-force solver support, CLI dispatch, and example

Fixes #217

@codecov
Copy link

codecov bot commented Mar 13, 2026

Codecov Report

❌ Patch coverage is 97.63780% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 96.82%. Comparing base (291cf56) to head (f0db9e2).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
src/models/graph/hamiltonian_path.rs 93.02% 3 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff            @@
##             main     #621    +/-   ##
========================================
  Coverage   96.82%   96.82%            
========================================
  Files         236      238     +2     
  Lines       31002    31129   +127     
========================================
+ Hits        30017    30140   +123     
- Misses        985      989     +4     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@zazabap
Copy link
Collaborator Author

zazabap commented Mar 13, 2026

Implementation Summary

Changes

  • src/models/graph/hamiltonian_path.rs — New HamiltonianPath<G> satisfaction problem model (Metric = bool)
  • src/unit_tests/models/graph/hamiltonian_path.rs — 10 unit tests (basic eval, brute force, no-solution, complete graph, serialization, edge cases)
  • examples/hamiltonian_path.rs — Example with non-trivial 6-vertex instance
  • src/models/graph/mod.rs, src/models/mod.rs, src/lib.rs — Module registration and re-exports
  • problemreductions-cli/src/dispatch.rs — CLI dispatch for deser_sat and try_ser
  • problemreductions-cli/src/problem_name.rs — Added resolve_alias entry
  • tests/suites/examples.rs — Registered example in integration test suite
  • docs/src/reductions/problem_schemas.json — Regenerated with new problem schema

Deviations from Plan

  • None

Open Questions

  • Paper display-name and problem-def entries not added (no reduction rules yet, so HamiltonianPath won't appear in the reduction graph until a rule connects it)
  • Complexity 1.657^num_vertices follows Björklund (2014) per the issue — may warrant verification

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a new HamiltonianPath satisfaction model to the graph models set, integrating it with tests, CLI JSON dispatch, an example, and generated schema docs so it can participate in the library’s standard model/solver workflows.

Changes:

  • Introduces HamiltonianPath<G> model with evaluation logic and variant declaration.
  • Adds unit tests and an executable example, and wires the example into the examples test suite.
  • Registers the model in library exports/prelude, CLI alias + JSON dispatch, and updates generated problem_schemas.json.

Reviewed changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
src/models/graph/hamiltonian_path.rs New model implementation + schema registration + variants + tests module hook
src/unit_tests/models/graph/hamiltonian_path.rs Unit tests for evaluation, brute force, serialization, helpers
src/models/graph/mod.rs Exposes the new model module and adds it to graph docs/exports
src/models/mod.rs Re-exports HamiltonianPath from models
src/lib.rs Adds HamiltonianPath to the crate prelude
problemreductions-cli/src/problem_name.rs Adds alias resolution for hamiltonianpath
problemreductions-cli/src/dispatch.rs Adds JSON load/serialize dispatch for HamiltonianPath
examples/hamiltonian_path.rs New example demonstrating construction + brute force enumeration
tests/suites/examples.rs Runs the new example under the examples test suite
docs/src/reductions/problem_schemas.json Generated schema entry for HamiltonianPath

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

///
/// Given a graph G = (V, E), determine whether G contains a Hamiltonian path,
/// i.e., a simple path that visits every vertex exactly once.
///
Comment on lines +46 to +49
let solution = solver.find_satisfying(&problem);
assert!(solution.is_some());
assert!(problem.evaluate(&solution.unwrap()));

Comment on lines +53 to +55
for sol in &all {
assert!(problem.evaluate(sol));
}
Comment on lines 211 to 215
"MaximumMatching" => deser_opt::<MaximumMatching<SimpleGraph, i32>>(data),
"MinimumDominatingSet" => deser_opt::<MinimumDominatingSet<SimpleGraph, i32>>(data),
"GraphPartitioning" => deser_opt::<GraphPartitioning<SimpleGraph>>(data),
"HamiltonianPath" => deser_sat::<HamiltonianPath<SimpleGraph>>(data),
"MaxCut" => deser_opt::<MaxCut<SimpleGraph, i32>>(data),
Comment on lines +91 to +94
fn dims(&self) -> Vec<usize> {
let n = self.graph.num_vertices();
vec![n; n]
}
zazabap and others added 2 commits March 13, 2026 14:15
- Document configuration semantics (vertex ordering/permutation) in
  HamiltonianPath struct doc comment, including dims() encoding rationale
- Add explicit `use crate::traits::Problem` import in
  test_hamiltonian_path_brute_force for consistency with other test functions
- Add CLI create support for HamiltonianPath: example_for hint, create_problem
  match arm, create_random match arm, and updated error message

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@zazabap
Copy link
Collaborator Author

zazabap commented Mar 13, 2026

Review Pipeline Report

Check Result
Merge with main clean merge
Copilot comments 5 reviewed, 4 fixed (config docs, test import, CLI create support), 1 acknowledged (dims encoding)
Issue/human comments 3 checked, 0 actionable (quality check reports)
CI green (Clippy, Test, Coverage all passed)
Agentic test passed (library API, CLI create/solve/evaluate, serialization all work)
Board review-agentic → In Review

🤖 Generated by review-pipeline

@zazabap
Copy link
Collaborator Author

zazabap commented Mar 13, 2026

Review Pipeline Report

Check Result
Merge with main clean merge
Copilot comments 5 reviewed, 2 fixed (docs + CLI create), 3 false positives
Issue/human comments 3 checked, 0 actionable
CI green (Clippy, Test, Coverage all pass)
Agentic test passed — all features work (evaluate, brute-force, serialization, CLI)
Board review-agentic → In Review

🤖 Generated by review-pipeline

GiggleLiu and others added 2 commits March 14, 2026 01:09
…-path

# Conflicts:
#	src/lib.rs
#	src/models/mod.rs
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@GiggleLiu GiggleLiu merged commit fa0e238 into main Mar 13, 2026
5 checks passed
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.

[Model] HamiltonianPath

3 participants