Skip to main content

solverforge_solver/phase/localsearch/acceptor/
traits.rs

1// Acceptor trait definition.
2
3use std::fmt::Debug;
4
5use solverforge_core::domain::PlanningSolution;
6
7use crate::heuristic::r#move::MoveTabuSignature;
8
9/// Trait for accepting or rejecting moves in local search.
10///
11/// Acceptors implement different strategies for escaping local optima,
12/// such as hill climbing, simulated annealing, or tabu search.
13pub trait Acceptor<S: PlanningSolution>: Send + Debug {
14    fn requires_move_signatures(&self) -> bool {
15        false
16    }
17
18    // Returns true if a move resulting in `move_score` should be accepted,
19    // given the previous step's score.
20    fn is_accepted(
21        &mut self,
22        last_step_score: &S::Score,
23        move_score: &S::Score,
24        move_signature: Option<&MoveTabuSignature>,
25    ) -> bool;
26
27    // Called when a phase starts.
28    fn phase_started(&mut self, _initial_score: &S::Score) {}
29
30    // Called when a phase ends.
31    fn phase_ended(&mut self) {}
32
33    // Called when a step starts.
34    fn step_started(&mut self) {}
35
36    // Called when a step ends with an accepted move.
37    fn step_ended(
38        &mut self,
39        _step_score: &S::Score,
40        _accepted_move_signature: Option<&MoveTabuSignature>,
41    ) {
42    }
43}