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::ProgressCallback;
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: ProgressCallback<S> = ()>:
21 Send + Debug
22{
23 /* Executes this phase.
24
25 The phase should inspect the current state through immutable accessors,
26 use `trial(...)` for speculative work, use `mutate(...)` for committed
27 arbitrary changes, and update the best solution when improvements are
28 found.
29 */
30 fn solve(&mut self, solver_scope: &mut SolverScope<'_, S, D, BestCb>);
31
32 fn phase_type_name(&self) -> &'static str;
33}
34
35// Unit type implements Phase as a no-op (empty phase list).
36impl<S: PlanningSolution, D: Director<S>, BestCb: ProgressCallback<S>> Phase<S, D, BestCb> for () {
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}