Skip to content

Fix #227: Add PartitionIntoPathsOfLength2 model#638

Open
zazabap wants to merge 6 commits intomainfrom
issue-227-partition-into-paths
Open

Fix #227: Add PartitionIntoPathsOfLength2 model#638
zazabap wants to merge 6 commits intomainfrom
issue-227-partition-into-paths

Conversation

@zazabap
Copy link
Collaborator

@zazabap zazabap commented Mar 13, 2026

Summary

Add the PartitionIntoPathsOfLength2 satisfaction problem model: given a graph G = (V, E) with |V| = 3q, determine whether V can be partitioned into q disjoint triples such that each triple induces at least 2 edges (a path of length 2 or a triangle).

Fixes #227

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

codecov bot commented Mar 13, 2026

Codecov Report

❌ Patch coverage is 98.14815% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 96.86%. Comparing base (d34477e) to head (ba43493).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
...c/models/graph/partition_into_paths_of_length_2.rs 95.23% 3 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff            @@
##             main     #638    +/-   ##
========================================
  Coverage   96.86%   96.86%            
========================================
  Files         264      266     +2     
  Lines       35196    35358   +162     
========================================
+ Hits        34091    34250   +159     
- Misses       1105     1108     +3     

☔ 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 and others added 2 commits March 13, 2026 12:37
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@zazabap
Copy link
Collaborator Author

zazabap commented Mar 13, 2026

Implementation Summary

Changes

  • src/models/graph/partition_into_paths_of_length_2.rs — New model: PartitionIntoPathsOfLength2<G> satisfaction problem with Problem and SatisfactionProblem impls, declare_variants!, and ProblemSchemaEntry
  • src/unit_tests/models/graph/partition_into_paths_of_length_2.rs — 11 unit tests covering creation, evaluation (valid/invalid configs), solver, serialization, panics, edge cases
  • src/models/graph/mod.rs — Module registration and re-export
  • src/models/mod.rs — Re-export in models
  • src/lib.rs — Added to prelude
  • problemreductions-cli/src/dispatch.rsload_problem and serialize_any_problem match arms
  • problemreductions-cli/src/problem_name.rs — Lowercase alias mapping
  • problemreductions-cli/src/commands/create.rs — CLI creation support (--graph flag)
  • problemreductions-cli/src/cli.rs — Added to "Flags by problem type" help table
  • docs/paper/reductions.typdisplay-name entry and problem-def with formal definition and example

Deviations from Plan

  • None

Open Questions

  • None

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 NP-complete satisfaction problem model, PartitionIntoPathsOfLength2, and wires it into the library API surface, CLI, and paper documentation so it can be instantiated/serialized and solved with existing solvers (e.g., BruteForce).

Changes:

  • Introduces PartitionIntoPathsOfLength2<G> graph model with schema registration, variant declaration, serde support, and unit tests.
  • Exposes the new model via models exports and the crate prelude.
  • Adds CLI alias/dispatch/create support and documents the problem in the Typst paper.

Reviewed changes

Copilot reviewed 11 out of 11 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
src/models/graph/partition_into_paths_of_length_2.rs New model implementation + schema registration + variants + tests module hook
src/unit_tests/models/graph/partition_into_paths_of_length_2.rs Unit tests covering satisfiable/unsatisfiable cases, edge cases, and serialization
src/models/graph/mod.rs Registers module + re-export + docs list entry
src/models/mod.rs Re-exports model at crate::models level
src/lib.rs Adds model to prelude exports
problemreductions-cli/src/problem_name.rs Adds lowercase alias resolution for the new problem
problemreductions-cli/src/dispatch.rs Adds load/serialize dispatch arms for the new problem
problemreductions-cli/src/commands/create.rs Adds pred create PartitionIntoPathsOfLength2 support
problemreductions-cli/src/cli.rs Documents required flags for CLI creation
docs/paper/reductions.typ Adds paper definition entry and display name mapping
docs/paper/examples/maximumindependentset_to_maximumclique.json Reorders variant keys (formatting-only change)

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

Comment on lines +126 to +138
// Check each group induces at least 2 edges
for group_id in 0..q {
let mut edge_count = 0;
for (u, v) in self.graph.edges() {
if config[u] == group_id && config[v] == group_id {
edge_count += 1;
}
}
if edge_count < 2 {
return false;
}
}

Comment on lines +15 to +24
inventory::submit! {
ProblemSchemaEntry {
name: "PartitionIntoPathsOfLength2",
module_path: module_path!(),
description: "Partition vertices into triples each inducing a path of length 2",
fields: &[
FieldInfo { name: "graph", type_name: "G", description: "The underlying graph G=(V,E) with |V| divisible by 3" },
],
}
}
Comment on lines +36 to +39
// Invalid partition: {0,1,3}, {2,4,5}, {6,7,8}
// Group {0,1,3}: edges (0,1) and (0,3) and (1, nothing with 3) — 2 edges present, valid
// Group {2,4,5}: edges (4,5) and (2,5) — 2 edges present, valid
// This is actually valid too
//! - [`MaximumMatching`]: Maximum weight matching
//! - [`TravelingSalesman`]: Traveling Salesman (minimum weight Hamiltonian cycle)
//! - [`SpinGlass`]: Ising model Hamiltonian
//! - [`PartitionIntoPathsOfLength2`]: Partition vertices into P3 paths
Comment on lines +555 to +565
// PartitionIntoPathsOfLength2
"PartitionIntoPathsOfLength2" => {
let (graph, _) = parse_graph(args).map_err(|e| {
anyhow::anyhow!(
"{e}\n\nUsage: pred create PartitionIntoPathsOfLength2 --graph 0-1,1-2,3-4,4-5"
)
})?;
(
ser(problemreductions::models::graph::PartitionIntoPathsOfLength2::new(graph))?,
resolved_variant.clone(),
)
ProblemSchemaEntry {
name: "PartitionIntoPathsOfLength2",
module_path: module_path!(),
description: "Partition vertices into triples each inducing a path of length 2",
zazabap and others added 3 commits March 15, 2026 08:16
Merge adds PartitionIntoPathsOfLength2 (PR branch) alongside all new
models from main (HamiltonianPath, MinimumSumMulticenter, etc.) and
adopts main's registry-based dispatch in CLI files.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Fix ProblemSchemaEntry to include new required fields (display_name, aliases, dimensions)
- Add `sat` keyword to declare_variants! macro call
- Optimize is_valid_partition to single-pass edge counting (was O(q*m))
- Fix description to say "at least two edges (P3 or triangle)" instead of just "path of length 2"
- Fix misleading test comment about "invalid partition"
- Add CLI validation for vertex count divisible by 3 (prevents panic)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Fix missing closing bracket in paper problem-def block
- Fix display_name casing to match paper convention (lowercase prepositions)
- Add trait_consistency test entry
- Add canonical model example specs (example-db)
- Register example specs in graph/mod.rs

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

zazabap commented Mar 15, 2026

Review Pipeline Report

Check Result
Merge with main 7 conflicts resolved, build verified
Copilot comments 6 addressed (performance, description, CLI validation, test comments, module doc, schema description)
Issue/human comments 1 checked, already addressed
Structural review 18/18 passed (after fixes: added trait_consistency entry, canonical example specs, paper closing bracket, display_name casing, declare_variants sat keyword, ProblemSchemaEntry new fields)
CI green (Test, Clippy, Coverage all pass)
Agentic test passed (pred list/show/create/create --example all work, invalid input correctly rejected)
Board Review pool → Under review → Final review

Fixes Applied

  • Merged origin/main, resolved 7 file conflicts
  • Updated ProblemSchemaEntry with new required fields (display_name, aliases, dimensions)
  • Added sat keyword to declare_variants! macro (new syntax requirement)
  • Optimized is_valid_partition from O(q·m) to O(m) single-pass edge counting
  • Fixed description: "path of length 2" → "at least two edges (P3 or triangle)"
  • Fixed misleading test comment ("Invalid partition" → "Alternative valid partition")
  • Added CLI validation for vertex count divisible by 3 (prevents panic)
  • Fixed missing closing ] in paper problem-def block (would cause Typst compilation error)
  • Fixed display_name casing to match paper convention (lowercase prepositions)
  • Added trait_consistency test entry
  • Added canonical_model_example_specs function and registration

🤖 Generated by review-pipeline

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] PartitionIntoPathsOfLength2

2 participants