Skip to main content

problemreductions/rules/unitdiskmapping/
mod.rs

1//! Graph to grid graph mapping.
2//!
3//! This module implements reductions from arbitrary graphs to unit disk grid graphs
4//! using the copy-line technique from UnitDiskMapping.jl.
5//!
6//! # Modules
7//!
8//! - `ksg`: King's Subgraph (8-connected square grid) mapping
9//! - `triangular`: Triangular lattice mapping
10//!
11//! # Example
12//!
13//! ```rust
14//! use problemreductions::rules::unitdiskmapping::{ksg, triangular};
15//!
16//! let edges = vec![(0, 1), (1, 2), (0, 2)];
17//!
18//! // Map to King's Subgraph (unweighted)
19//! let result = ksg::map_unweighted(3, &edges).unwrap();
20//!
21//! // Map to King's Subgraph (weighted)
22//! let weighted_result = ksg::map_weighted(3, &edges).unwrap();
23//!
24//! // Map to triangular lattice (weighted)
25//! let tri_result = triangular::map_weighted(3, &edges).unwrap();
26//! ```
27
28mod copyline;
29mod grid;
30pub mod ksg;
31pub(crate) mod pathdecomposition;
32mod traits;
33pub mod triangular;
34mod weighted;
35
36// Re-export commonly used items from submodules for convenience
37pub use ksg::{GridKind, MappingResult};
38
39use crate::rules::ReductionError;
40
41fn mapping_invalid(message: impl Into<String>) -> ReductionError {
42    ReductionError::InvalidTarget {
43        source_problem: "Graph",
44        target_problem: "UnitDiskMapping",
45        message: message.into(),
46    }
47}
48
49fn mapping_integer_overflow(operation: impl Into<String>) -> ReductionError {
50    ReductionError::IntegerOverflow {
51        source_problem: "Graph",
52        target_problem: "UnitDiskMapping",
53        operation: operation.into(),
54    }
55}
56
57fn mapping_non_finite(operation: impl Into<String>) -> ReductionError {
58    ReductionError::NonFiniteResult {
59        source_problem: "Graph",
60        target_problem: "UnitDiskMapping",
61        operation: operation.into(),
62    }
63}
64
65// Re-exports for unit tests (only needed in test builds)
66#[cfg(test)]
67pub(crate) use copyline::{
68    copyline_weighted_locations_triangular, create_copylines, mis_overhead_copyline, CopyLine,
69};
70#[cfg(test)]
71pub(crate) use grid::{CellState, MappingGrid};
72#[cfg(test)]
73pub(crate) use traits::{apply_gadget, unapply_gadget, Pattern};
74#[cfg(test)]
75pub(crate) use weighted::{map_weights, trace_centers};
76
77// Hidden re-exports for development tools (examples/export_mapping_stages.rs)
78#[doc(hidden)]
79pub mod _internal {
80    pub use super::copyline::{
81        create_copylines, mis_overhead_copyline, mis_overhead_copyline_triangular, CopyLine,
82    };
83    pub use super::grid::{CellState, MappingGrid};
84}