Skip to main content

solverforge_solver/phase/
mod.rs

1//! Solver phases for different solving strategies
2//!
3//! Phases are the main building blocks of solving:
4//! - ConstructionHeuristicPhase: Builds an initial solution
5//! - LocalSearchPhase: Improves an existing solution
6//! - ExhaustiveSearchPhase: Explores entire solution space
7//! - PartitionedSearchPhase: Parallel solving via partitioning
8//! - VndPhase: Variable Neighborhood Descent
9
10pub mod construction;
11pub mod exhaustive;
12pub mod localsearch;
13pub mod partitioned;
14mod tuple_impl;
15pub mod vnd;
16
17use std::fmt::Debug;
18
19use solverforge_core::domain::PlanningSolution;
20use solverforge_scoring::ScoreDirector;
21
22use crate::scope::BestSolutionCallback;
23use crate::scope::SolverScope;
24
25/// A phase of the solving process.
26///
27/// Phases are executed in sequence by the solver. Each phase has its own
28/// strategy for exploring or constructing solutions.
29///
30/// # Type Parameters
31/// * `S` - The planning solution type
32/// * `D` - The score director type
33/// * `BestCb` - The best-solution callback type (default `()`)
34pub trait Phase<S: PlanningSolution, D: ScoreDirector<S>, BestCb: BestSolutionCallback<S> = ()>:
35    Send + Debug
36{
37    /// Executes this phase.
38    ///
39    /// The phase should modify the working solution in the solver scope
40    /// and update the best solution when improvements are found.
41    fn solve(&mut self, solver_scope: &mut SolverScope<'_, S, D, BestCb>);
42
43    /// Returns the name of this phase type.
44    fn phase_type_name(&self) -> &'static str;
45}
46
47/// Unit type implements Phase as a no-op (empty phase list).
48impl<S: PlanningSolution, D: ScoreDirector<S>, BestCb: BestSolutionCallback<S>> Phase<S, D, BestCb>
49    for ()
50{
51    fn solve(&mut self, _solver_scope: &mut SolverScope<'_, S, D, BestCb>) {
52        // No-op: empty phase list does nothing
53    }
54
55    fn phase_type_name(&self) -> &'static str {
56        "NoOp"
57    }
58}