u_nesting_core/lib.rs
1//! # U-Nesting Core
2//!
3//! Core traits and abstractions for the U-Nesting spatial optimization engine.
4//!
5//! This crate provides the foundational types and traits that are shared between
6//! the 2D nesting and 3D bin packing modules.
7//!
8//! ## Core Components
9//!
10//! - **Geometry traits**: [`Geometry`], [`Geometry2DExt`], [`Geometry3DExt`]
11//! - **Boundary traits**: [`Boundary`], [`Boundary2DExt`], [`Boundary3DExt`]
12//! - **Solver trait**: [`Solver`] - Common interface for all optimization algorithms
13//! - **GA framework**: [`GaRunner`], [`GaProblem`] - Genetic algorithm infrastructure
14//! - **BRKGA framework**: [`BrkgaRunner`], [`BrkgaProblem`] - Biased Random-Key GA
15//! - **SA framework**: [`SaRunner`], [`SaProblem`] - Simulated Annealing
16//! - **Transform types**: [`Transform2D`], [`Transform3D`], [`AABB2D`], [`AABB3D`]
17//!
18//! ## Optimization Strategies
19//!
20//! The [`Strategy`] enum defines available optimization algorithms:
21//!
22//! | Strategy | Speed | Quality | Description |
23//! |----------|-------|---------|-------------|
24//! | `BottomLeftFill` | Fast | Basic | Greedy bottom-left placement |
25//! | `NfpGuided` | Medium | Good | NFP-based optimal positioning (2D) |
26//! | `GeneticAlgorithm` | Slow | High | GA with permutation encoding |
27//! | `Brkga` | Medium | High | Biased Random-Key GA |
28//! | `SimulatedAnnealing` | Medium | High | Temperature-based optimization |
29//! | `ExtremePoint` | Fast | Good | EP heuristic (3D only) |
30//!
31//! ## Configuration
32//!
33//! Use [`Config`] to configure solver behavior:
34//!
35//! ```rust
36//! use u_nesting_core::{Config, Strategy};
37//!
38//! let config = Config::new()
39//! .with_strategy(Strategy::GeneticAlgorithm)
40//! .with_spacing(2.0)
41//! .with_margin(5.0)
42//! .with_time_limit(30000);
43//! ```
44//!
45//! ## Feature Flags
46//!
47//! - `serde`: Enable serialization/deserialization support
48
49pub mod alns;
50#[cfg(feature = "serde")]
51pub mod api_types;
52pub mod brkga;
53pub mod error;
54pub mod exact;
55pub mod ga;
56pub mod gdrr;
57pub mod geometry;
58pub mod memory;
59pub mod placement;
60pub mod result;
61pub mod robust;
62pub mod sa;
63pub mod solver;
64pub mod timing;
65pub mod transform;
66
67// Re-exports
68pub use alns::{
69 AlnsConfig, AlnsProblem, AlnsProgress, AlnsResult, AlnsRunner, AlnsSolution, DestroyOperatorId,
70 DestroyResult, OperatorStats, RepairOperatorId, RepairResult,
71};
72pub use brkga::{
73 BrkgaConfig, BrkgaProblem, BrkgaProgress, BrkgaResult, BrkgaRunner, RandomKeyChromosome,
74};
75pub use error::{Error, Result};
76pub use exact::{ExactConfig, ExactResult, SolutionStatus};
77pub use ga::{GaConfig, GaProblem, GaProgress, GaResult, GaRunner, Individual};
78pub use gdrr::{
79 GdrrConfig, GdrrProblem, GdrrProgress, GdrrResult, GdrrRunner, GdrrSolution, RecreateResult,
80 RuinResult, RuinType, RuinedItem,
81};
82pub use geometry::{
83 check_quantity, Boundary, Boundary2DExt, Boundary3DExt, Geometry, Geometry2DExt, Geometry3DExt,
84 GeometryId, RotationConstraint,
85};
86pub use placement::Placement;
87pub use result::{SolveResult, SolveSummary, StopReason};
88pub use sa::{
89 CoolingSchedule, NeighborhoodOperator, PermutationSolution, SaConfig, SaProblem, SaProgress,
90 SaResult, SaRunner, SaSolution,
91};
92pub use solver::{Config, ProgressCallback, ProgressInfo, Solver, Strategy};
93pub use transform::{Transform2D, Transform3D, AABB2D, AABB3D};
94
95/// Re-exports from `u-metaheur` for direct access to generic optimization frameworks.
96///
97/// Consumers can use these to access the generic (domain-agnostic) metaheuristic
98/// frameworks from u-metaheur, while the nesting-specific implementations in
99/// this crate's `ga`, `sa`, `brkga`, `alns` modules provide nesting-tailored
100/// abstractions.
101pub mod metaheur {
102 pub use u_metaheur::alns as generic_alns;
103 pub use u_metaheur::brkga as generic_brkga;
104 pub use u_metaheur::ga as generic_ga;
105 pub use u_metaheur::sa as generic_sa;
106}
107
108/// Re-exports from `u-geometry` for direct access to generic computational geometry.
109///
110/// Consumers can use these to access domain-agnostic geometry primitives,
111/// robust predicates, collision detection, and spatial indexing from u-geometry.
112///
113/// The nesting-specific geometry types in this crate's `geometry`, `transform`,
114/// and `robust` modules are generic over `RealField` and include serde support,
115/// while u-geometry provides `f64`-specialized implementations with richer
116/// operations (Minkowski sum, NFP, SAT collision, spatial indexing).
117///
118/// ## Usage
119///
120/// ```rust,ignore
121/// use u_nesting_core::geom;
122///
123/// // Access u-geometry primitives
124/// let p = geom::primitives::Point2::new(1.0, 2.0);
125///
126/// // Access u-geometry polygon operations
127/// let area = geom::polygon::signed_area(&[(0.0,0.0), (10.0,0.0), (10.0,10.0)]);
128///
129/// // Access u-geometry collision detection
130/// let overlap = geom::collision::aabb2_overlap(&aabb_a, &aabb_b);
131/// ```
132pub mod geom {
133 pub use u_geometry::collision;
134 pub use u_geometry::minkowski;
135 pub use u_geometry::nalgebra_types;
136 pub use u_geometry::offset;
137 pub use u_geometry::polygon;
138 pub use u_geometry::primitives;
139 pub use u_geometry::robust as generic_robust;
140 pub use u_geometry::spatial_index;
141 pub use u_geometry::transform as generic_transform;
142}