Skip to main content

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::{
78    GaConfig, GaProblem, GaProgress, GaResult, GaRunner, Individual, PermutationChromosome,
79};
80pub use gdrr::{
81    GdrrConfig, GdrrProblem, GdrrProgress, GdrrResult, GdrrRunner, GdrrSolution, RecreateResult,
82    RecreateType, RuinResult, RuinType, RuinedItem,
83};
84pub use geometry::{
85    Boundary, Boundary2DExt, Boundary3DExt, Geometry, Geometry2DExt, Geometry3DExt, GeometryId,
86    Orientation3D, RotationConstraint,
87};
88pub use placement::Placement;
89pub use result::{SolveResult, SolveSummary};
90pub use sa::{
91    CoolingSchedule, NeighborhoodOperator, PermutationSolution, SaConfig, SaProblem, SaResult,
92    SaRunner, SaSolution,
93};
94pub use solver::{Config, ProgressCallback, ProgressInfo, Solver, Strategy};
95pub use transform::{Transform2D, Transform3D, AABB2D, AABB3D};
96
97/// Re-exports from `u-metaheur` for direct access to generic optimization frameworks.
98///
99/// Consumers can use these to access the generic (domain-agnostic) metaheuristic
100/// frameworks from u-metaheur, while the nesting-specific implementations in
101/// this crate's `ga`, `sa`, `brkga`, `alns` modules provide nesting-tailored
102/// abstractions.
103pub mod metaheur {
104    pub use u_metaheur::alns as generic_alns;
105    pub use u_metaheur::brkga as generic_brkga;
106    pub use u_metaheur::ga as generic_ga;
107    pub use u_metaheur::sa as generic_sa;
108}
109
110/// Re-exports from `u-geometry` for direct access to generic computational geometry.
111///
112/// Consumers can use these to access domain-agnostic geometry primitives,
113/// robust predicates, collision detection, and spatial indexing from u-geometry.
114///
115/// The nesting-specific geometry types in this crate's `geometry`, `transform`,
116/// and `robust` modules are generic over `RealField` and include serde support,
117/// while u-geometry provides `f64`-specialized implementations with richer
118/// operations (Minkowski sum, NFP, SAT collision, spatial indexing).
119///
120/// ## Usage
121///
122/// ```rust,ignore
123/// use u_nesting_core::geom;
124///
125/// // Access u-geometry primitives
126/// let p = geom::primitives::Point2::new(1.0, 2.0);
127///
128/// // Access u-geometry polygon operations
129/// let area = geom::polygon::signed_area(&[(0.0,0.0), (10.0,0.0), (10.0,10.0)]);
130///
131/// // Access u-geometry collision detection
132/// let overlap = geom::collision::aabb2_overlap(&aabb_a, &aabb_b);
133/// ```
134pub mod geom {
135    pub use u_geometry::collision;
136    pub use u_geometry::minkowski;
137    pub use u_geometry::nalgebra_types;
138    pub use u_geometry::offset;
139    pub use u_geometry::polygon;
140    pub use u_geometry::primitives;
141    pub use u_geometry::robust as generic_robust;
142    pub use u_geometry::spatial_index;
143    pub use u_geometry::transform as generic_transform;
144}