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///
11/// This is the simplest acceptor. It only accepts moves that result
12/// in a strictly better score. This can get stuck in local optima.
13///
14/// # Example
15///
16/// ```
17/// use solverforge_solver::phase::localsearch::HillClimbingAcceptor;
18///
19/// let acceptor = HillClimbingAcceptor::new();
20/// ```
21#[derive(Debug, Clone, Default)]
22pub struct HillClimbingAcceptor;
23
24impl HillClimbingAcceptor {
25 /// Creates a new hill climbing acceptor.
26 pub fn new() -> Self {
27 Self
28 }
29}
30
31impl<S: PlanningSolution> Acceptor<S> for HillClimbingAcceptor {
32 fn is_accepted(&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}