feat: add 20 problem models with ILP rules#976
Conversation
MAX-2-SAT optimization problem — maximize satisfied 2-literal clauses. Includes model, tests, CLI create support, canonical example, and paper entry. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Direct ILP formulation for MAX-2-SAT: binary clause indicators with linking constraints. Includes closed-loop tests, ILP solver verification, canonical example, and paper entry. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Fixed-charge network flow problem: minimize total price of arcs with nonzero flow subject to capacity, conservation, and flow requirement. ILP formulation uses integer flow + binary indicator variables. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Maximum domatic number: partition vertices into maximum number of disjoint dominating sets. ILP uses n²+n binary variables with partition, domination, and linking constraints. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Metric dimension: minimum resolving set where all vertices have distinct distance vectors. ILP uses n binary variables with n*(n-1)/2 pair-distinguishing constraints from BFS distances. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Permutation-based graph bandwidth minimization: find vertex ordering minimizing maximum edge stretch. ILP uses assignment variables with position-linking and edge-stretch constraints. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
GF(2) minimum-weight codeword problem: find binary vector with minimum Hamming weight satisfying Hx ≡ s (mod 2). ILP linearizes modular constraints with integer slack variables. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Distance-based clustering feasibility problem: partition elements into ≤K clusters with all intra-cluster distances ≤ B. NP-complete for K≥3. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
AND/OR DAG solution subgraph: minimize arc weight subject to AND (all children) and OR (at least one child) gate constraints. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Bipartite matching with target pair sums. ILP creates variables only for compatible (x_i, y_j, B_k) triples where sizes sum to target. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Deductive closure minimization: find smallest axiom subset whose iterative closure under implication rules yields all true sentences. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
DAG fault detection: find minimum input-output path set covering all vertices. Uses BFS reachability for coverage computation. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Circular arc graph coloring for loop register allocation: assign registers minimizing count with no two conflicting variables sharing. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Capacitated spanning tree: minimize edge weight with subtree requirement constraints. ILP uses requirement-weighted flow for connectivity and capacity enforcement. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…ias) (#887) Registers the unit-weight MaxCut variant with alias MaximumBipartiteSubgraph. Complexity: O*(2^(0.7907n)) via Williams 2004. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Wang tiling: place tile types on N×N grid with matching edge colors. NP-complete via reduction from Directed Hamiltonian Path. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Common independent set in three partition matroids: find K elements independent in all three. NP-complete via 3-Dimensional Matching. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #976 +/- ##
==========================================
+ Coverage 98.03% 98.12% +0.09%
==========================================
Files 784 858 +74
Lines 82310 89004 +6694
==========================================
+ Hits 80695 87338 +6643
- Misses 1615 1666 +51 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Use iterator enumerate() instead of range indexing in clustering validation, likelihood ranking ILP objective, and matrix cover ILP. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
One-register machine code generation: find minimum instruction sequence (LOAD/STORE/OP) to evaluate expression DAG. Uses permutation config for evaluation order with greedy register simulation. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Unlimited-register 2-address code generation: minimize instructions (OPs + copies) where left operand register is destroyed by each OP. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Parallel assignment scheduling: find execution ordering minimizing backward dependencies where overwritten variables are still needed. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Object identification via binary tests: find decision tree minimizing total external path length. Config encodes flattened complete binary tree with test assignments at internal nodes. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Two-level logic minimization: find minimum-term DNF via Quine-McCluskey prime implicant enumeration then minimum set cover. Config selects subset of precomputed prime implicants covering all minterms. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Decision version of MinimumVertexCover: given graph G and threshold k, determine whether a vertex cover of size ≤ k exists. One of Karp's 21 NP-complete problems. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…fficiency - MinimumDecisionTree: remove redundant second traversal and dead `object_placed` state in simulate(), use HashSet for leaf uniqueness - VertexCover: reuse `is_vertex_cover_config` from MinimumVertexCover instead of duplicating the covering check - Clustering: extract `is_valid_partition` helper, fix `&Vec` return type to `&[Vec]`, use single-pass cluster grouping - MinimumDisjunctiveNormalForm: use HashSet for QMC dedup (O(1) vs O(n)), drop unused covered-minterms tracking - MinimumMetricDimension: precompute all-pairs BFS distance matrix in constructor to avoid redundant BFS per evaluate() call Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Added problem-def + reduction-rule entries for MaximumDomaticNumber, MinimumMetricDimension, MinimumGraphBandwidth, MinimumCapacitatedSpanningTree. Added reduction-rule entry for MinimumMatrixCover. Fixed QMC prime implicant ordering to be deterministic (sorted). Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
Adds a large batch of new Garey & Johnson problem models and several direct ILP reduction rules, along with unit tests and CLI/paper/example-db wiring, to expand the library’s model/reduction coverage (including an alias registration for MaxCut as MaximumBipartiteSubgraph).
Changes:
- Introduces multiple new models (graph/formula/algebraic/misc/set) with schema registration, canonical examples, and unit tests.
- Adds several new “direct-to-ILP” reduction rules plus closed-loop ILP solver tests.
- Extends CLI creation flags and paper bibliography entries to cover the new models/rules.
Reviewed changes
Copilot reviewed 89 out of 89 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| src/unit_tests/rules/optimumcommunicationspanningtree_ilp.rs | Adds OCST → ILP closed-loop + structural tests. |
| src/unit_tests/rules/numericalmatchingwithtargetsums_ilp.rs | Adds NMTS → ILP tests (closed-loop, structure, unsat). |
| src/unit_tests/rules/minimumweightdecoding_ilp.rs | Adds MinimumWeightDecoding → ILP tests (structure/closed-loop). |
| src/unit_tests/rules/minimummetricdimension_ilp.rs | Adds MinimumMetricDimension → ILP tests. |
| src/unit_tests/rules/minimumgraphbandwidth_ilp.rs | Adds MinimumGraphBandwidth → ILP tests. |
| src/unit_tests/rules/minimumedgecostflow_ilp.rs | Adds MinimumEdgeCostFlow → ILP tests. |
| src/unit_tests/rules/maximumdomaticnumber_ilp.rs | Adds MaximumDomaticNumber → ILP tests. |
| src/unit_tests/rules/maximum2satisfiability_ilp.rs | Adds Maximum2Satisfiability → ILP tests. |
| src/unit_tests/models/misc/numerical_matching_with_target_sums.rs | Adds NMTS model tests (evaluate/serde/solver). |
| src/unit_tests/models/misc/minimum_weight_and_or_graph.rs | Adds MinimumWeightAndOrGraph model tests. |
| src/unit_tests/models/misc/minimum_fault_detection_test_set.rs | Adds MinimumFaultDetectionTestSet model tests. |
| src/unit_tests/models/misc/minimum_disjunctive_normal_form.rs | Adds MinimumDNF model tests (PIs/coverage). |
| src/unit_tests/models/misc/minimum_decision_tree.rs | Adds MinimumDecisionTree model tests. |
| src/unit_tests/models/misc/minimum_code_generation_parallel_assignments.rs | Adds MinimumCodeGenerationParallelAssignments tests. |
| src/unit_tests/models/misc/minimum_axiom_set.rs | Adds MinimumAxiomSet model tests. |
| src/unit_tests/models/graph/vertex_cover.rs | Adds VertexCover (decision) model tests. |
| src/unit_tests/models/graph/minimum_metric_dimension.rs | Adds MinimumMetricDimension model tests. |
| src/unit_tests/models/graph/minimum_edge_cost_flow.rs | Adds MinimumEdgeCostFlow model tests. |
| src/unit_tests/models/graph/maximum_domatic_number.rs | Adds MaximumDomaticNumber model tests. |
| src/unit_tests/models/formula/maximum_2_satisfiability.rs | Adds Maximum2Satisfiability model tests. |
| src/rules/numericalmatchingwithtargetsums_ilp.rs | Implements NMTS → ILP reduction + canonical rule example. |
| src/rules/mod.rs | Wires new ILP rule modules + canonical rule specs aggregation. |
| src/rules/minimumweightdecoding_ilp.rs | Implements MinimumWeightDecoding → ILP reduction + example. |
| src/rules/minimummetricdimension_ilp.rs | Implements MinimumMetricDimension → ILP reduction + example. |
| src/rules/minimumgraphbandwidth_ilp.rs | Implements MinimumGraphBandwidth → ILP reduction + example. |
| src/rules/minimumedgecostflow_ilp.rs | Implements MinimumEdgeCostFlow → ILP reduction + example. |
| src/rules/maximumlikelihoodranking_ilp.rs | Implements MaximumLikelihoodRanking → ILP reduction + example. |
| src/rules/maximumdomaticnumber_ilp.rs | Implements MaximumDomaticNumber → ILP reduction + example. |
| src/rules/maximum2satisfiability_ilp.rs | Implements Maximum2Satisfiability → ILP reduction + example. |
| src/models/set/mod.rs | Registers ThreeMatroidIntersection in set module exports/specs. |
| src/models/mod.rs | Re-exports newly added models across modules. |
| src/models/misc/maximum_likelihood_ranking.rs | Adds MaximumLikelihoodRanking model implementation. |
| src/models/graph/vertex_cover.rs | Adds VertexCover (decision) model implementation. |
| src/models/graph/minimum_vertex_cover.rs | Exposes shared helper for vertex-cover validation. |
| src/models/graph/minimum_graph_bandwidth.rs | Adds MinimumGraphBandwidth model implementation. |
| src/models/graph/maximum_domatic_number.rs | Adds MaximumDomaticNumber model implementation. |
| src/models/graph/max_cut.rs | Adds alias + One-weight variant registration/examples for MaxCut. |
| src/models/formula/mod.rs | Registers Maximum2Satisfiability in formula module exports/specs. |
| src/models/formula/maximum_2_satisfiability.rs | Adds Maximum2Satisfiability model implementation. |
| src/models/algebraic/mod.rs | Registers MinimumWeightDecoding + MinimumMatrixCover in exports/specs. |
| src/models/algebraic/minimum_weight_decoding.rs | Adds MinimumWeightDecoding model implementation. |
| src/models/algebraic/minimum_matrix_cover.rs | Adds MinimumMatrixCover model implementation. |
| src/lib.rs | Updates prelude re-exports for new models. |
| problemreductions-cli/src/problem_name.rs | Adds explicit alias resolutions for new problem names. |
| problemreductions-cli/src/cli.rs | Documents/defines CLI flags for new models. |
| docs/paper/references.bib | Adds bibliography entries for newly added models. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
|
||
| // Collect which vertices belong to each set | ||
| let mut sets: Vec<Vec<usize>> = vec![vec![]; n]; | ||
| for (v, &set_idx) in config.iter().enumerate() { |
There was a problem hiding this comment.
evaluate_partition indexes sets[set_idx] for every entry in config without validating config.len() == n and set_idx < n. A malformed config can panic instead of returning Max(None). Consider early-returning None if the config length is wrong or any set index is out of range, to keep Problem::evaluate() total and consistent with other models’ validation behavior.
| // Collect which vertices belong to each set | |
| let mut sets: Vec<Vec<usize>> = vec![vec![]; n]; | |
| for (v, &set_idx) in config.iter().enumerate() { | |
| // Configuration must assign each vertex to exactly one set. | |
| if config.len() != n { | |
| return None; | |
| } | |
| // Collect which vertices belong to each set | |
| let mut sets: Vec<Vec<usize>> = vec![vec![]; n]; | |
| for (v, &set_idx) in config.iter().enumerate() { | |
| // Each set index must be within bounds of the available sets. | |
| if set_idx >= n { | |
| return None; | |
| } |
| // Linking constraints: y_i <= Σ_v x_{v,i} for each i | ||
| // Rewritten as: Σ_v x_{v,i} - y_i >= 0 | ||
| for i in 0..n { | ||
| let mut terms: Vec<(usize, f64)> = (0..n).map(|v| (v * n + i, 1.0)).collect(); | ||
| terms.push((n * n + i, -1.0)); | ||
| constraints.push(LinearConstraint::ge(terms, 0.0)); | ||
| } |
There was a problem hiding this comment.
The ILP permits vertices to be assigned to a set with y_i = 0, which disables the domination constraints for that set. Since extract_solution() returns the raw set index assignment (x variables only), this can yield an invalid MaximumDomaticNumber configuration even when the ILP optimum is correct, depending on which optimal solution the solver returns. To make extraction sound, add constraints that force y_i = 1 whenever any x_{v,i} = 1 (e.g., x_{v,i} <= y_i for all v,i or Σ_v x_{v,i} - n*y_i <= 0).
Agentic Review ReportStructural CheckBuild Status: Model Structural Completeness (sampled 6 of 25): MinimumMetricDimension, MinimumMatrixCover, Clustering, Maximum2Satisfiability, VertexCover, ThreeMatroidIntersection
Rule Structural Completeness (sampled 4 of 12): minimummetricdimension_ilp, maximum2satisfiability_ilp, numericalmatchingwithtargetsums_ilp, optimumcommunicationspanningtree_ilp
Semantic Review:
Issues Found:
Quality CheckDesign Principles:
Test Quality:
Consistency: OK — All 6 sampled models follow identical structural template. All 4 sampled ILP rules follow the same pattern. Summary: Well-structured batch PR. Two medium issues (duplicated BFS, weak bandwidth test) worth addressing. Agentic Feature TestsBuild: Test 1:
Test 2: Test 3: Test 4:
Test 5:
Test 6: Full Test Suite: All 28 individual test checks PASS. No issues found. Generated by review-pipeline |
… models
- Fix MaximumDomaticNumber ILP linking constraints (per-vertex x_{v,i} ≤ y_i)
and update doc comment + overhead formula to match
- Add bounds checking in MaximumDomaticNumber::evaluate_partition
- Remove duplicate bfs_distances from MetricDimension ILP, reuse public fn
- Strengthen MinimumGraphBandwidth ILP tests with exact value assertions
- Add CLI create support for VertexCover, MinimumDecisionTree,
MinimumDisjunctiveNormalForm, SquareTiling
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Summary
Closes #807, closes #810, closes #817, closes #820, closes #851, closes #869, closes #873, closes #876, closes #878, closes #880, closes #887, closes #897, closes #900, closes #901, closes #902, closes #903, closes #906, closes #923, closes #927, closes #930, closes #931, closes #932, closes #933, closes #935, closes #936, closes #986
Closes #961, closes #962, closes #963, closes #964, closes #965, closes #966, closes #967, closes #968, closes #969, closes #971
Models Added
Not included: #934 (FaultDetectionInLogicCircuits) — moved to Low Priority; the ∀∃ quantifier structure does not fit
Problem::evaluate()naturally.Per-model checklist
Each model includes:
Problemtrait implProblemSchemaEntryregistrationdeclare_variants!with verified complexityexample-db)docs/paper/reductions.typTest plan
make check(fmt + clippy + test) passesmake papercompilescargo test --features "ilp-highs example-db" --workspacepassesILPSolverclosed-loop tests🤖 Generated with Claude Code