Fix #251: [Model] BoundedComponentSpanningForest#655
Open
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #655 +/- ##
==========================================
+ Coverage 96.88% 96.90% +0.01%
==========================================
Files 269 271 +2
Lines 36036 36296 +260
==========================================
+ Hits 34915 35174 +259
- Misses 1121 1122 +1 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Contributor
Author
Implementation SummaryChanges
Deviations from Plan
Open Questions
|
There was a problem hiding this comment.
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
BoundedComponentSpanningForestmodel (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; | ||
| } | ||
| } | ||
|
|
Contributor
Author
Review Pipeline Report
Remaining issues for final review
🤖 Generated by review-pipeline |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
BoundedComponentSpanningForestmodel implementationFixes #251