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 typed move undo for speculative work, use `mutate(...)` for committed
27 arbitrary changes, and update the best solution when improvements are found.
28 */
29 fn solve(&mut self, solver_scope: &mut SolverScope<'_, S, D, BestCb>);
30
31 fn phase_type_name(&self) -> &'static str;
32}
33
34// Unit type implements Phase as a no-op (empty phase list).
35impl<S: PlanningSolution, D: Director<S>, BestCb: ProgressCallback<S>> Phase<S, D, BestCb> for () {
36 fn solve(&mut self, _solver_scope: &mut SolverScope<'_, S, D, BestCb>) {
37 // No-op: empty phase list does nothing
38 }
39
40 fn phase_type_name(&self) -> &'static str {
41 "NoOp"
42 }
43}