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;
8
9/* Hill climbing acceptor - accepts only improving moves.
10
11This is the simplest acceptor. It only accepts moves that result
12in a strictly better score. This can get stuck in local optima.
13
14# Example
15
16```
17use solverforge_solver::phase::localsearch::HillClimbingAcceptor;
18
19let acceptor = HillClimbingAcceptor::new();
20```
21*/
22#[derive(Debug, Clone, Default)]
23pub struct HillClimbingAcceptor;
24
25impl HillClimbingAcceptor {
26    pub fn new() -> Self {
27        Self
28    }
29}
30
31impl<S: PlanningSolution> Acceptor<S> for HillClimbingAcceptor {
32    fn is_accepted(&mut self, last_step_score: &S::Score, move_score: &S::Score) -> bool {
33        // Accept if the move score is better than the last step score
34        move_score > last_step_score
35    }
36}