Skip to main content

solverforge/
lib.rs

1//! SolverForge - A Constraint Solver in Rust
2//!
3//! SolverForge is a high-performance constraint satisfaction/optimization solver.
4//! It helps you optimize planning and scheduling problems.
5//!
6//! # Quick Start
7//!
8//! ```
9//! use solverforge::prelude::*;
10//!
11//! #[problem_fact]
12//! pub struct Employee {
13//!     #[planning_id]
14//!     pub id: i64,
15//!     pub name: String,
16//! }
17//!
18//! #[planning_entity]
19//! pub struct Shift {
20//!     #[planning_id]
21//!     pub id: i64,
22//!     #[planning_variable]
23//!     pub employee: Option<i64>,
24//! }
25//!
26//! #[planning_solution]
27//! pub struct Schedule {
28//!     #[problem_fact_collection]
29//!     pub employees: Vec<Employee>,
30//!     #[planning_entity_collection]
31//!     pub shifts: Vec<Shift>,
32//!     #[planning_score]
33//!     pub score: Option<HardSoftScore>,
34//! }
35//! ```
36
37// ============================================================================
38// Attribute Macros
39// ============================================================================
40
41pub use solverforge_macros::{planning_entity, planning_solution, problem_fact};
42
43// Derive macros (used by attribute macros, must be at root level)
44pub use solverforge_macros::{PlanningEntityImpl, PlanningSolutionImpl, ProblemFactImpl};
45
46// ============================================================================
47// Score Types
48// ============================================================================
49
50pub use solverforge_core::score::{
51    BendableScore, HardMediumSoftScore, HardSoftDecimalScore, HardSoftScore, Score, SoftScore,
52};
53
54// ============================================================================
55// Constraint API
56// ============================================================================
57
58pub use solverforge_scoring::{
59    ConstraintSet, IncrementalBiConstraint, IncrementalConstraint, IncrementalUniConstraint,
60};
61
62/// Fluent constraint stream API.
63pub mod stream {
64    pub use solverforge_scoring::stream::{joiner, ConstraintFactory};
65}
66
67// ============================================================================
68// Score Director
69// ============================================================================
70
71pub use solverforge_scoring::{Director, ScoreDirector};
72
73// ============================================================================
74// Solver
75// ============================================================================
76
77pub use solverforge_solver::heuristic::selector::DefaultDistanceMeter;
78pub use solverforge_solver::{
79    analyze, run_solver, Analyzable, BasicSpec, ConstraintAnalysis, ListSpec, ScoreAnalysis,
80    Solvable, SolverManager, SolverStatus,
81};
82
83// ============================================================================
84// Console Output (feature-gated)
85// ============================================================================
86
87#[cfg(feature = "console")]
88pub use solverforge_console as console;
89
90// ============================================================================
91// Prelude
92// ============================================================================
93
94pub mod prelude {
95    pub use crate::stream::{joiner, ConstraintFactory};
96    pub use crate::{
97        planning_entity, planning_solution, problem_fact, BendableScore, ConstraintSet, Director,
98        HardMediumSoftScore, HardSoftDecimalScore, HardSoftScore, Score, ScoreDirector, SoftScore,
99    };
100}
101
102// ============================================================================
103// Internal API for Macros
104// ============================================================================
105
106// Internal module for macro-generated code. Not part of public API.
107#[doc(hidden)]
108pub mod __internal {
109    // Initializes console output if the feature is enabled.
110    #[inline]
111    pub fn init_console() {
112        #[cfg(feature = "console")]
113        solverforge_console::init();
114    }
115
116    // Derive macros
117    pub use solverforge_macros::{PlanningEntityImpl, PlanningSolutionImpl, ProblemFactImpl};
118
119    // Domain types
120    pub use solverforge_core::domain::{
121        EntityDescriptor, PlanningEntity, PlanningId, PlanningSolution, ProblemFact,
122        ProblemFactDescriptor, ShadowVariableKind, SolutionDescriptor, TypedEntityExtractor,
123        VariableDescriptor,
124    };
125
126    // Scoring
127    pub use solverforge_scoring::{
128        Director, ScoreDirector, ShadowVariableSupport, SolvableSolution,
129    };
130
131    // Solver infrastructure
132    pub use solverforge_solver::heuristic::selector::{
133        DefaultDistanceMeter, FromSolutionEntitySelector,
134    };
135    pub use solverforge_solver::manager::{
136        KOptPhaseBuilder, ListConstructionPhaseBuilder, PhaseFactory, SolverFactory,
137    };
138    pub use solverforge_solver::{BasicSpec, ListSpec};
139
140    // Config
141    pub use solverforge_config::SolverConfig;
142}