Skip to content

Fix #117: [Model] GraphPartitioning#570

Merged
GiggleLiu merged 7 commits intomainfrom
issue-117-graph-partitioning
Mar 12, 2026
Merged

Fix #117: [Model] GraphPartitioning#570
GiggleLiu merged 7 commits intomainfrom
issue-117-graph-partitioning

Conversation

@GiggleLiu
Copy link
Copy Markdown
Contributor

Summary

Add the GraphPartitioning (Minimum Bisection) problem model. Given an undirected graph with an even number of vertices, find a balanced partition into two equal halves minimizing the number of crossing edges.

Fixes #117

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

codecov bot commented Mar 12, 2026

Codecov Report

❌ Patch coverage is 99.24242% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 96.49%. Comparing base (52648df) to head (9f777fa).
⚠️ Report is 6 commits behind head on main.

Files with missing lines Patch % Lines
src/models/graph/graph_partitioning.rs 97.56% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #570      +/-   ##
==========================================
+ Coverage   96.37%   96.49%   +0.11%     
==========================================
  Files         200      206       +6     
  Lines       27871    28301     +430     
==========================================
+ Hits        26861    27309     +448     
+ Misses       1010      992      -18     

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

GiggleLiu and others added 3 commits March 12, 2026 14:25
- Add GraphPartitioning (Minimum Bisection) problem model
- Single type param G (unweighted, counts crossing edges)
- Balanced bisection: requires |A| = |B| = n/2 (even n)
- Direction: Minimize
- Register in CLI (dispatch, aliases, create command)
- Add unit tests (11 tests covering all cases)
- Add problem-def entry in paper with CeTZ visualization

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Assert exact cut value in unbalanced_invalid test
- Warn and round up when random generation gets odd vertex count

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@GiggleLiu
Copy link
Copy Markdown
Contributor Author

Implementation Summary

Changes

  • src/models/graph/graph_partitioning.rs — New model: GraphPartitioning (Minimum Bisection) with single type param G, balanced bisection feasibility check, minimize cut edge count
  • src/unit_tests/models/graph/graph_partitioning.rs — 11 unit tests covering evaluation, solver, odd/even/unbalanced cases, serialization
  • src/models/graph/mod.rs, src/models/mod.rs, src/lib.rs — Module registration and re-export
  • problemreductions-cli/src/dispatch.rs — CLI load/serialize dispatch
  • problemreductions-cli/src/problem_name.rs — Alias resolution
  • problemreductions-cli/src/commands/create.rs — CLI creation + random generation (with even-vertex warning)
  • docs/paper/reductions.typ — Problem definition with formal definition, background, and CeTZ visualization

Deviations from Plan

  • None

Open Questions

  • None

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 NP-hard graph model, GraphPartitioning (Minimum Bisection), to the problemreductions model catalog, with supporting CLI wiring, tests, and paper documentation.

Changes:

  • Introduce GraphPartitioning<SimpleGraph> model with schema registration, variants, and evaluation logic.
  • Add CLI support (alias resolution, JSON dispatch serialization/deserialization, and pred create support including random instance generation).
  • Add unit tests and paper docs entry for Graph Partitioning.

Reviewed changes

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

Show a summary per file
File Description
src/models/graph/graph_partitioning.rs New GraphPartitioning model implementation, schema registration, variants, and tests module hook.
src/models/graph/mod.rs Registers/exposes the new graph model in the graph models module.
src/models/mod.rs Re-exports GraphPartitioning from the top-level models module.
src/lib.rs Exposes GraphPartitioning via the crate prelude.
src/unit_tests/models/graph/graph_partitioning.rs Adds unit tests covering evaluation, direction, serialization, and brute-force solving.
problemreductions-cli/src/problem_name.rs Adds CLI alias mapping for graphpartitioning.
problemreductions-cli/src/dispatch.rs Adds load/serialize dispatch cases for GraphPartitioning<SimpleGraph>.
problemreductions-cli/src/commands/create.rs Adds pred create GraphPartitioning support (explicit graph + random generation).
docs/paper/reductions.typ Adds paper definition + figure entry for Graph Partitioning.

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

Comment thread src/models/graph/graph_partitioning.rs Outdated
Comment on lines +106 to +107
// Check balanced: exactly n/2 vertices in partition 1
let count_ones: usize = config.iter().sum();
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.

count_ones is computed as config.iter().sum(), which treats any value >1 as multiple vertices in partition 1. This allows invalid assignments (e.g., a 2 value) to pass the balance check and produce incorrect cut sizes. Consider validating config is binary (all values <2) and/or counting ones via filter(|&&x| x == 1).count() after a domain check.

Suggested change
// Check balanced: exactly n/2 vertices in partition 1
let count_ones: usize = config.iter().sum();
// Optional: ensure configuration length matches number of vertices
if config.len() != n {
return SolutionSize::Invalid;
}
// Check balanced: exactly n/2 vertices in partition 1, and ensure binary labels
let mut count_ones: usize = 0;
for &x in config.iter() {
if x > 1 {
// Invalid label (must be 0 or 1)
return SolutionSize::Invalid;
}
if x == 1 {
count_ones += 1;
}
}

Copilot uses AI. Check for mistakes.
Comment on lines +12 to +21
inventory::submit! {
ProblemSchemaEntry {
name: "GraphPartitioning",
module_path: module_path!(),
description: "Find minimum cut balanced bisection of a graph",
fields: &[
FieldInfo { name: "graph", type_name: "G", description: "The undirected graph G=(V,E)" },
],
}
}
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.

This repo appears to treat docs/src/reductions/reduction_graph.json as an auto-generated artifact (see examples/export_graph.rs) and it currently does not include GraphPartitioning. After adding a new model, please regenerate and commit the updated JSON so docs/tooling that consume it stay in sync.

Copilot uses AI. Check for mistakes.
Comment on lines +112 to +116
let mut cut = 0i32;
for (u, v) in self.graph.edges() {
if config[u] != config[v] {
cut += 1;
}
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 indexes config[u]/config[v] while iterating edges, but it never checks config.len() == num_vertices(). For shorter configs this will panic at runtime instead of returning SolutionSize::Invalid. Add a length check (and consider using get() like other graph models) before indexing.

Copilot uses AI. Check for mistakes.
GiggleLiu and others added 3 commits March 12, 2026 17:15
…ng::evaluate

Address Copilot review comments: validate config length matches vertex count
and use filter-based counting instead of sum for correct binary detection.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@zazabap zazabap mentioned this pull request Mar 12, 2026
3 tasks
@GiggleLiu GiggleLiu merged commit 2e08ed1 into main Mar 12, 2026
5 checks passed
GiggleLiu added a commit that referenced this pull request Mar 12, 2026
PR #599 (KSat→SubsetSum): Fix imprecise Karp 1972 attribution — the
direct 3-SAT→SubsetSum digit encoding follows Sipser (2012, Thm 7.56)
and CLRS (2022, §34.5.5), not Karp's original reduction tree. Add bib
entries for both textbooks.

PR #570 (GraphPartitioning): Add proper @Citations for Garey, Johnson
& Stockmeyer (1976) and Arora, Rao & Vazirani (2009) instead of
plain-text references. Add bib entries for both papers.

Regenerate problem_schemas.json and reduction_graph.json.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
GiggleLiu added a commit that referenced this pull request Mar 12, 2026
* fix: address issue review comments for #126 and #117

PR #599 (KSat→SubsetSum): Fix imprecise Karp 1972 attribution — the
direct 3-SAT→SubsetSum digit encoding follows Sipser (2012, Thm 7.56)
and CLRS (2022, §34.5.5), not Karp's original reduction tree. Add bib
entries for both textbooks.

PR #570 (GraphPartitioning): Add proper @Citations for Garey, Johnson
& Stockmeyer (1976) and Arora, Rao & Vazirani (2009) instead of
plain-text references. Add bib entries for both papers.

Regenerate problem_schemas.json and reduction_graph.json.

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

* fix: add FPT complexity citation for GraphPartitioning (#117)

Address review comment: explicitly state that brute-force O*(2^n) is
the best known unconditional exact algorithm, and cite Cygan et al.
(STOC 2014 / SICOMP 2019) for the FPT result parameterized by
bisection width.

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

* fix: use sort_by_key per clippy unnecessary_sort_by lint

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

* feat: add merge-with-main conflict resolution step to review-pipeline

Add Step 1a between checkout and Copilot fixes to merge origin/main
into the PR branch. Resolves simple conflicts automatically; aborts
and reports for complex conflicts needing manual resolution.

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

* update pipeline skills: eligibility-first sorting, merge-with-main

project-pipeline: Reorder Steps 0c/0d so eligibility check (source and
target models exist) runs before scoring. Only eligible issues get scored.

review-pipeline: Add Step 1a to merge origin/main into the PR branch
before fixing Copilot comments, catching conflicts early.

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

---------

Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
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] GraphPartitioning

2 participants