Skip to main content

solverforge_solver/phase/localsearch/acceptor/
hill_climbing.rs

1// Hill climbing acceptor.
2
3use std::fmt::Debug;
4
5use solverforge_core::domain::PlanningSolution;
6
7use super::Acceptor;
8use crate::heuristic::r#move::MoveTabuSignature;
9
10/* Hill climbing acceptor - accepts only improving moves.
11
12This is the simplest acceptor. It only accepts moves that result
13in a strictly better score. This can get stuck in local optima.
14
15# Example
16
17```
18use solverforge_solver::phase::localsearch::HillClimbingAcceptor;
19
20let acceptor = HillClimbingAcceptor::new();
21```
22*/
23#[derive(Debug, Clone, Default)]
24pub struct HillClimbingAcceptor;
25
26impl HillClimbingAcceptor {
27    pub fn new() -> Self {
28        Self
29    }
30}
31
32impl<S: PlanningSolution> Acceptor<S> for HillClimbingAcceptor {
33    fn is_accepted(
34        &mut self,
35        last_step_score: &S::Score,
36        move_score: &S::Score,
37        _move_signature: Option<&MoveTabuSignature>,
38    ) -> bool {
39        // Accept if the move score is better than the last step score
40        move_score > last_step_score
41    }
42}