Skip to content

Fix #232: Add PartitionIntoTriangles model#609

Merged
GiggleLiu merged 4 commits intomainfrom
issue-232-partition-into-triangles
Mar 13, 2026
Merged

Fix #232: Add PartitionIntoTriangles model#609
GiggleLiu merged 4 commits intomainfrom
issue-232-partition-into-triangles

Conversation

@zazabap
Copy link
Copy Markdown
Collaborator

@zazabap zazabap commented Mar 12, 2026

Summary

  • Implement PartitionIntoTriangles satisfaction problem (GJ GT11)
  • Graph satisfaction problem: partition vertices into triples forming triangles
  • Add CLI registration (dispatch, aliases, create command)
  • Add comprehensive unit tests (8 tests covering basic, solver, serialization, edge cases)

Fixes #232

Implement the Partition Into Triangles satisfaction problem (GJ GT11).
Given a graph G with |V| = 3q, determine if vertices can be partitioned
into q triples each forming a triangle. Includes CLI registration,
unit tests, and brute-force solver support.

Co-Authored-By: Claude Opus 4.6 <[email protected]>
@codecov
Copy link
Copy Markdown

codecov bot commented Mar 12, 2026

Codecov Report

❌ Patch coverage is 96.89922% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 96.77%. Comparing base (88254a0) to head (e901e06).
⚠️ Report is 5 commits behind head on main.

Files with missing lines Patch % Lines
src/models/graph/partition_into_triangles.rs 93.10% 4 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #609      +/-   ##
==========================================
- Coverage   96.77%   96.77%   -0.01%     
==========================================
  Files         226      228       +2     
  Lines       29919    30048     +129     
==========================================
+ Hits        28955    29079     +124     
- Misses        964      969       +5     

☔ 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.

Copy link
Copy Markdown

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 graph satisfaction model, PartitionIntoTriangles (GT11), to the core library and wires it through the CLI so instances can be created, serialized, and solved using existing tooling.

Changes:

  • Introduces PartitionIntoTriangles<G> model with schema registration, variants, and evaluation logic.
  • Integrates the model into public exports and graph module documentation.
  • Registers the model in the CLI (name aliasing, JSON dispatch, pred create support) and adds unit tests.

Reviewed changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
src/models/graph/partition_into_triangles.rs Implements the new satisfaction problem model, schema entry, variants, and evaluation logic.
src/unit_tests/models/graph/partition_into_triangles.rs Adds unit tests covering basic evaluation, solver behavior, serialization, and invalid inputs.
src/models/graph/mod.rs Registers the module and re-exports PartitionIntoTriangles from the graph models module.
src/models/mod.rs Re-exports PartitionIntoTriangles at the top-level models module.
src/lib.rs Exposes PartitionIntoTriangles via the crate prelude.
problemreductions-cli/src/problem_name.rs Adds CLI alias resolution for partitionintotriangles.
problemreductions-cli/src/dispatch.rs Adds JSON (de)serialization dispatch for the new problem type.
problemreductions-cli/src/commands/create.rs Adds pred create PartitionIntoTriangles instance creation support.
problemreductions-cli/src/cli.rs Documents the new problem’s CLI flags in the help text.

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

Comment on lines +125 to +132
// Check each group forms a triangle
for g in 0..q {
let verts: Vec<usize> = config
.iter()
.enumerate()
.filter(|(_, &c)| c == g)
.map(|(i, _)| i)
.collect();
Copy link

Copilot AI Mar 12, 2026

Choose a reason for hiding this comment

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

evaluate() rebuilds verts by scanning the entire config for every group (for g in 0..q), which makes evaluation O(n*q) and allocates a new Vec each iteration. Since brute-force solvers call evaluate() extremely frequently, consider building per-group vertex lists in a single pass over config (e.g., Vec<Vec<usize>> or fixed-size [usize; 3] buffers) and then checking the 3 edges for each group without repeated filtering/allocation.

Suggested change
// Check each group forms a triangle
for g in 0..q {
let verts: Vec<usize> = config
.iter()
.enumerate()
.filter(|(_, &c)| c == g)
.map(|(i, _)| i)
.collect();
// Build per-group vertex lists in a single pass over config.
// Since each group has exactly 3 vertices, we can use fixed-size arrays.
let mut group_verts = vec![[usize::MAX; 3]; q];
let mut group_pos = vec![0usize; q];
for (v, &g) in config.iter().enumerate() {
let pos = group_pos[g];
// `counts` check above guarantees pos will be 0, 1, or 2.
group_verts[g][pos] = v;
group_pos[g] = pos + 1;
}
// Check each group forms a triangle
for g in 0..q {
let verts = group_verts[g];

Copilot uses AI. Check for mistakes.
Comment on lines +453 to +456
(
ser(PartitionIntoTriangles::new(graph))?,
resolved_variant.clone(),
)
Copy link

Copilot AI Mar 12, 2026

Choose a reason for hiding this comment

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

The CLI create path calls PartitionIntoTriangles::new(graph), which asserts (panics) when the vertex count is not divisible by 3. That will crash the CLI with a panic backtrace instead of returning a user-facing error. Consider validating graph.num_vertices() % 3 == 0 here and bail! with a clear message/usage hint (or otherwise converting the precondition failure into a Result).

Copilot uses AI. Check for mistakes.
GiggleLiu and others added 3 commits March 13, 2026 20:01
- Optimize PartitionIntoTriangles::evaluate() to build per-group vertex
  lists in a single pass instead of O(n*q) repeated filtering
- Add vertex count validation in CLI create before calling new() to
  return a user-friendly error instead of panicking

Co-Authored-By: Claude Opus 4.6 <[email protected]>
@GiggleLiu
Copy link
Copy Markdown
Contributor

Review Pipeline Report

Check Result
Merge with main Conflicts resolved (6 files — list/enum additions)
Copilot comments 2 fixed (optimize evaluate() single-pass, CLI input validation)
Issue/human comments 1 checked (quality report — no code changes needed)
CI green (clippy warning fixed)
Agentic test passed (all core functionality works: API, solver, serialization, CLI)
Board review-agentic → In Review

Agentic Test Notes

  • All core functionality works: create instances, evaluate solutions, brute-force solver, serde round-trip, CLI create/solve/evaluate
  • Minor friction: pred solve with default ILP solver fails (no reduction path exists — expected for isolated model), docs could mention --solver brute-force

🤖 Generated by review-pipeline

@GiggleLiu GiggleLiu merged commit 6401e7d into main Mar 13, 2026
5 checks passed
@GiggleLiu GiggleLiu deleted the issue-232-partition-into-triangles branch April 12, 2026 00:53
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] PartitionIntoTriangles

3 participants