Skip to content

Fix #251: [Model] BoundedComponentSpanningForest#655

Merged
zazabap merged 13 commits intomainfrom
issue-251-bounded-component-spanning-forest
Mar 16, 2026
Merged

Fix #251: [Model] BoundedComponentSpanningForest#655
zazabap merged 13 commits intomainfrom
issue-251-bounded-component-spanning-forest

Conversation

@GiggleLiu
Copy link
Contributor

@GiggleLiu GiggleLiu commented Mar 15, 2026

Summary

  • add the BoundedComponentSpanningForest model implementation
  • expose it through the CLI, example-db fixtures, exported schemas, and paper/docs
  • add model and CLI coverage, including a lower-allocation validator path for brute-force evaluation

Fixes #251

@codecov
Copy link

codecov bot commented Mar 15, 2026

Codecov Report

❌ Patch coverage is 99.60630% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 97.03%. Comparing base (9eaa786) to head (7ba76c5).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
.../models/graph/bounded_component_spanning_forest.rs 99.24% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #655      +/-   ##
==========================================
+ Coverage   97.01%   97.03%   +0.02%     
==========================================
  Files         280      282       +2     
  Lines       37611    37865     +254     
==========================================
+ Hits        36488    36742     +254     
  Misses       1123     1123              

☔ 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
Copy link
Contributor Author

Implementation Summary

Changes

  • Added the new BoundedComponentSpanningForest graph model in src/models/graph/bounded_component_spanning_forest.rs, registered it in the model exports, and added canonical examples plus trait-consistency coverage.
  • Added focused model tests in src/unit_tests/models/graph/bounded_component_spanning_forest.rs covering valid assignments, disconnected components, overweight components, invalid labels, and constructor invariants.
  • Extended problemreductions-cli create support for BoundedComponentSpanningForest with --graph, --weights, --k, and --bound, including validation for invalid k, negative weights, negative bounds, and out-of-range integer conversion.
  • Regenerated reduction graph/schema exports, example-db fixtures, and paper/docs entries so the new model appears in generated artifacts and documentation.

Deviations from Plan

  • pipeline_worktree.py / pipeline_checks.py falsely matched unrelated PR Fix #534: Add PartiallyOrderedKnapsack model #631 when searching for Fix #251, so I created a fresh issue worktree manually and continued from there.
  • review-implementation reported whitelist failures for expected add-model files (CLI wiring, generated artifacts, trait consistency, fixtures, etc.). I treated those as stale policy drift and relied on targeted review plus full verification instead.
  • There is currently no associated rule issue for this model, so the PR keeps the model as an orphan entry for now.

Open Questions

  • None blocking. The main follow-up is adding a corresponding reduction/rule issue so the new model is no longer orphaned.

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 the new BoundedComponentSpanningForest graph satisfaction model and wires it through the library’s registry/docs/example-db and the pred create CLI flow.

Changes:

  • Introduce BoundedComponentSpanningForest model (schema registration, evaluation logic, variants, and example-db spec).
  • Expose the model through models/prelude, add unit tests, and regenerate example-db fixtures.
  • Add pred create BoundedComponentSpanningForest ... CLI support + CLI tests; regenerate docs reduction JSON and paper definitions.

Reviewed changes

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

Show a summary per file
File Description
src/models/graph/bounded_component_spanning_forest.rs New model implementation, schema registration, example-db spec, and variant declaration.
src/models/graph/mod.rs Registers the new graph model module and re-exports it; includes canonical example specs.
src/models/mod.rs Re-exports BoundedComponentSpanningForest from the graph models umbrella.
src/lib.rs Exposes BoundedComponentSpanningForest in the public prelude.
src/unit_tests/models/graph/bounded_component_spanning_forest.rs Adds unit tests for construction/validation/serialization and brute-force solving.
src/unit_tests/trait_consistency.rs Adds trait conformance check coverage for the new model.
src/example_db/fixtures/examples.json Adds canonical model fixture entry and satisfying solutions for the new model.
src/unit_tests/example_db.rs Refactors formatting in rule fixture verification assertions/loops.
src/unit_tests/export.rs Minor formatting change in a JSON-line assertion.
problemreductions-cli/src/commands/create.rs Adds pred create support for BoundedComponentSpanningForest; tweaks problem resolution logic.
problemreductions-cli/src/cli.rs Documents flags for the new create target; adjusts --bound parsing to allow negative values.
problemreductions-cli/tests/cli_tests.rs Adds CLI tests for creating the model and rejecting invalid inputs.
docs/src/reductions/problem_schemas.json Regenerated schema catalog to include BoundedComponentSpanningForest.
docs/src/reductions/reduction_graph.json Regenerated reduction graph JSON to include the new model node.
docs/paper/reductions.typ Adds name mapping + paper problem definition for the new model.

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

Comment on lines +534 to +538
#problem-def("BoundedComponentSpanningForest")[
Given an undirected graph $G = (V, E)$ with vertex weights $w: V -> ZZ_(gt.eq 0)$, a positive integer $K <= |V|$, and a positive bound $B$, determine whether there exists a partition of $V$ into $t$ non-empty sets $V_1, dots, V_t$ with $1 <= t <= K$ such that each induced subgraph $G[V_i]$ is connected and each part satisfies $sum_(v in V_i) w(v) <= B$.
][
Bounded Component Spanning Forest appears as ND10 in Garey and Johnson @garey1979. It asks for a decomposition into a bounded number of connected pieces, each with bounded total weight, so it naturally captures contiguous districting and redistricting-style constraints where each district must remain connected while respecting a population cap. A direct exact algorithm enumerates all assignments of the $n = |V|$ vertices to at most $K$ component labels and checks connectivity plus the weight bound for each non-empty part, yielding an $O^*(K^n)$ exhaustive-search bound.

Comment on lines +116 to +147
/// Check if a configuration is a valid bounded-component partition.
pub fn is_valid_solution(&self, config: &[usize]) -> bool {
if config.len() != self.graph.num_vertices() {
return false;
}

let mut component_vertices = vec![Vec::new(); self.max_components];
for (vertex, &component) in config.iter().enumerate() {
if component >= self.max_components {
return false;
}
component_vertices[component].push(vertex);
}

for vertices in component_vertices {
if vertices.is_empty() {
continue;
}

let mut total_weight = W::Sum::zero();
for &vertex in &vertices {
total_weight += self.weights[vertex].to_sum();
}
if total_weight > self.max_weight {
return false;
}

if !is_connected_component(&self.graph, &vertices) {
return false;
}
}

@GiggleLiu
Copy link
Contributor Author

Review Pipeline Report

Check Result
Copilot comments 2 fixed
Issue/human comments 3 checked, 1 fixed
Structural review passed
CI green
Agentic test passed with notes
Needs human decision 1 item
Board Review pool -> Under review -> Final review

Remaining issues for final review

  • Decide whether generic CLI help and inspect output should become more problem-aware for BoundedComponentSpanningForest. This was not auto-fixed because it is a repo-wide CLI UX policy choice rather than a correctness defect. Recommended maintainer decision: either keep the current generic UX as-is, or standardize problem-specific hints across create/help/inspect for catalog-only models.

🤖 Generated by review-pipeline

zazabap and others added 7 commits March 16, 2026 16:30
Resolve conflicts to keep both BoundedComponentSpanningForest (PR) and
all models added to main since branch divergence.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- Add CeTZ figure to paper entry showing the 3-component partition
  with colored vertices, weight labels, and region backgrounds
- Relax max_components assertion: K > |V| is mathematically harmless
  (just means fewer than K components will be used)
- Update CLI validation and tests accordingly

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Main branch intentionally removed centralized trait tests in PR #676
(commit 9eaa786). The PR branch diverged before that removal, so our
merge kept the PR's version. Aligning with main's intent by removing it.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Use only g-node, g-edge, and content — the same primitives used by
other figures in the paper. Removes hobby curve regions that could
fail on older CeTZ versions.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- Replace tempdir() with std::env::temp_dir() in CLI test (tempfile
  crate not available in test scope)
- Remove unused cli_flag_name function (superseded by help_flag_name)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
The cli_flag_name function was superseded by help_flag_name but its
general field-name mappings (universe_size->universe, collection->sets,
etc.) were still needed. Merge them into help_flag_name and remove the
redundant function.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@zazabap zazabap merged commit 65de0d3 into main Mar 16, 2026
5 checks passed
@zazabap zazabap deleted the issue-251-bounded-component-spanning-forest branch March 16, 2026 17:00
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] BoundedComponentSpanningForest

3 participants