Skip to content

Commit 5be5149

Browse files
GiggleLiuclaude
andauthored
Reduce exported functions (#77) (#79)
* refactor: internalize reduction structs and gadgets in rules module Remove public re-exports of ~30 ReductionXToY structs, 6 gadget functions, BoolVar, LogicGadget, and JSON serialization types (EdgeJson, NodeJson, ReductionGraphJson) from rules/mod.rs. Users interact with reductions via the ReduceTo trait or ReductionGraph, never referencing these structs by name. Also remove unused ReductionColoringToILP type alias and suppress dead_code warnings on LogicGadget fields only read in tests. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * refactor: internalize unitdiskmapping implementation details Change internal type re-exports (CopyLine, MappingGrid, CellState, Pattern, etc.) from pub to pub(crate) in unitdiskmapping/mod.rs. Change alpha_tensor and pathdecomposition modules to pub(crate). Add #[cfg(test)] guards on re-exports only needed by unit tests. Add #[doc(hidden)] _internal module for the export_mapping_stages example which needs these types. Keep ksg, triangular modules and GridKind/MappingResult as pub. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * refactor: internalize polynomial/truth_table, delete unused graph_types module - Change polynomial and truth_table modules from pub to pub(crate) since they are only used internally via crate:: imports. - Delete graph_types.rs and its unit test file (zero internal imports, confirmed by codebase audit; actual graph types live in topology/). - Remove truth_table integration tests from tests/suites/reductions.rs (equivalent coverage exists in src/unit_tests/truth_table.rs). - Remove doc example from TruthTable since the module is now internal. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * feat: add is_valid_solution methods to graph problem types Add public is_valid_solution(&self, config: &[usize]) -> bool methods to all graph problem types, delegating to existing private validation helpers. Also add cut_size method to MaxCut for computing partition cut sizes. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * feat: add is_valid_solution methods to set and specialized problems Add public is_valid_solution methods to MaximumSetPacking, MinimumSetCovering, BicliqueCover, CircuitSAT, and Factoring. Each delegates to existing validation logic. PaintShop already has count_switches and BMF is skipped per design. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * refactor: internalize validation free functions, keep as problem methods Change standalone validation free functions (is_independent_set, is_vertex_cover, is_clique, etc.) from pub to pub(crate) with #[cfg(test)] for test-only functions. Functions still used in non-test code (is_valid_coloring, is_hamiltonian_cycle, cut_size) remain pub(crate) without #[cfg(test)]. - Change 17 validation functions from pub to pub(crate) - Add #[cfg(test)] to 14 functions only used in tests - Remove validation function re-exports from graph/set/specialized mod.rs - Make submodules pub(crate) for crate-internal test access - Update graph_models.rs imports to use full module paths Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * refactor: internalize config_to_bits and bits_to_config Change these utility functions from pub to pub(crate) with #[cfg(test)] since they are only used in unit tests. This reduces the public API surface of the config module. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * refactor: slim down prelude to essential items Remove from prelude: config utilities, registry types, variant types, ILP/optimization internals, NumericSize, and WeightElement. These items remain accessible via their full module paths. Add explicit imports to 16 examples, 2 integration test files that previously relied on the broader prelude: - ILP type: 13 examples + 1 test file - K3/K2 variant types: 7 examples + 2 test files - LinearConstraint/ObjectiveSense: 1 example + 1 test file Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
1 parent ddc9f85 commit 5be5149

54 files changed

Lines changed: 244 additions & 295 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

examples/chained_reduction_ksat_to_mis.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ use problemreductions::rules::{MinimizeSteps, ReductionGraph};
1010
use problemreductions::solvers::ILPSolver;
1111
use problemreductions::topology::SimpleGraph;
1212
use problemreductions::types::ProblemSize;
13+
use problemreductions::variant::K3;
1314
// ANCHOR_END: imports
1415

1516
pub fn run() {

examples/export_mapping_stages.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,11 @@
88
//! cargo run --example export_mapping_stages -- petersen triangular
99
1010
use problemreductions::rules::unitdiskmapping::{
11-
create_copylines, ksg, mis_overhead_copyline, mis_overhead_copyline_triangular, triangular,
12-
CopyLine, MappingGrid,
11+
_internal::{
12+
create_copylines, mis_overhead_copyline, mis_overhead_copyline_triangular, CopyLine,
13+
MappingGrid,
14+
},
15+
ksg, triangular,
1316
};
1417
use problemreductions::topology::smallgraph;
1518
use serde::Serialize;
@@ -102,7 +105,7 @@ fn gadget_name(idx: usize) -> String {
102105
// The Typst script converts to 1-indexed for comparison with Julia.
103106
// DO NOT add +1 here - keep 0-indexed!
104107
fn extract_grid_nodes(grid: &MappingGrid) -> Vec<GridNodeExport> {
105-
use problemreductions::rules::unitdiskmapping::CellState;
108+
use problemreductions::rules::unitdiskmapping::_internal::CellState;
106109
let mut nodes = Vec::new();
107110
let (rows, cols) = grid.size();
108111
for r in 0..rows {

examples/reduction_factoring_to_ilp.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
// Exports `docs/paper/examples/factoring_to_ilp.json` for use in paper code blocks.
1919

2020
use problemreductions::export::*;
21+
use problemreductions::models::optimization::ILP;
2122
use problemreductions::prelude::*;
2223
use problemreductions::solvers::ILPSolver;
2324

examples/reduction_ilp_to_qubo.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
// ```
3737

3838
use problemreductions::export::*;
39+
use problemreductions::models::optimization::{ILP, LinearConstraint, ObjectiveSense};
3940
use problemreductions::prelude::*;
4041

4142
pub fn run() {

examples/reduction_kcoloring_to_ilp.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,12 @@
1616
// Exports `docs/paper/examples/kcoloring_to_ilp.json` and `kcoloring_to_ilp.result.json`.
1717

1818
use problemreductions::export::*;
19+
use problemreductions::models::optimization::ILP;
1920
use problemreductions::prelude::*;
2021
use problemreductions::solvers::ILPSolver;
2122
use problemreductions::topology::small_graphs::petersen;
2223
use problemreductions::topology::{Graph, SimpleGraph};
24+
use problemreductions::variant::K3;
2325

2426
pub fn run() {
2527
// 1. Create KColoring instance: Petersen graph (10 vertices, 15 edges) with 3 colors, χ=3

examples/reduction_kcoloring_to_qubo.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ use problemreductions::export::*;
3232
use problemreductions::prelude::*;
3333
use problemreductions::topology::small_graphs::house;
3434
use problemreductions::topology::{Graph, SimpleGraph};
35+
use problemreductions::variant::K3;
3536

3637
pub fn run() {
3738
println!("=== K-Coloring -> QUBO Reduction ===\n");

examples/reduction_ksatisfiability_to_qubo.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838

3939
use problemreductions::export::*;
4040
use problemreductions::prelude::*;
41+
use problemreductions::variant::K3;
4142

4243
pub fn run() {
4344
println!("=== K-Satisfiability (3-SAT) -> QUBO Reduction ===\n");

examples/reduction_maximumclique_to_ilp.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
// Exports `docs/paper/examples/maximumclique_to_ilp.json` and `maximumclique_to_ilp.result.json`.
1616

1717
use problemreductions::export::*;
18+
use problemreductions::models::optimization::ILP;
1819
use problemreductions::prelude::*;
1920
use problemreductions::topology::small_graphs::octahedral;
2021
use problemreductions::topology::{Graph, SimpleGraph};

examples/reduction_maximumindependentset_to_ilp.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
// Exports `docs/paper/examples/maximumindependentset_to_ilp.json` and `maximumindependentset_to_ilp.result.json`.
1515

1616
use problemreductions::export::*;
17+
use problemreductions::models::optimization::ILP;
1718
use problemreductions::prelude::*;
1819
use problemreductions::topology::small_graphs::petersen;
1920
use problemreductions::topology::{Graph, SimpleGraph};

examples/reduction_maximummatching_to_ilp.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
// Exports `docs/paper/examples/maximummatching_to_ilp.json` and `maximummatching_to_ilp.result.json`.
1515

1616
use problemreductions::export::*;
17+
use problemreductions::models::optimization::ILP;
1718
use problemreductions::prelude::*;
1819
use problemreductions::topology::small_graphs::petersen;
1920
use problemreductions::topology::{Graph, SimpleGraph};

0 commit comments

Comments
 (0)