Skip to main content

solverforge_solver/phase/
traits.rs

1//! Phase trait definition.
2
3use std::fmt::Debug;
4
5use solverforge_core::domain::PlanningSolution;
6use solverforge_scoring::Director;
7
8use crate::scope::BestSolutionCallback;
9use crate::scope::SolverScope;
10
11/// A phase of the solving process.
12///
13/// Phases are executed in sequence by the solver. Each phase has its own
14/// strategy for exploring or constructing solutions.
15///
16/// # Type Parameters
17/// * `S` - The planning solution type
18/// * `D` - The score director type
19/// * `BestCb` - The best-solution callback type (default `()`)
20pub trait Phase<S: PlanningSolution, D: Director<S>, BestCb: BestSolutionCallback<S> = ()>:
21    Send + Debug
22{
23    /// Executes this phase.
24    ///
25    /// The phase should modify the working solution in the solver scope
26    /// and update the best solution when improvements are found.
27    fn solve(&mut self, solver_scope: &mut SolverScope<'_, S, D, BestCb>);
28
29    /// Returns the name of this phase type.
30    fn phase_type_name(&self) -> &'static str;
31}
32
33/// Unit type implements Phase as a no-op (empty phase list).
34impl<S: PlanningSolution, D: Director<S>, BestCb: BestSolutionCallback<S>> Phase<S, D, BestCb>
35    for ()
36{
37    fn solve(&mut self, _solver_scope: &mut SolverScope<'_, S, D, BestCb>) {
38        // No-op: empty phase list does nothing
39    }
40
41    fn phase_type_name(&self) -> &'static str {
42        "NoOp"
43    }
44}