solverforge_solver/termination/
step_count.rs

1//! Step count termination.
2
3use std::fmt::Debug;
4
5use solverforge_core::domain::PlanningSolution;
6
7use super::Termination;
8use crate::scope::SolverScope;
9
10/// Terminates after a step count.
11///
12/// # Example
13///
14/// ```
15/// use solverforge_solver::termination::StepCountTermination;
16///
17/// // Terminate after 1000 steps
18/// let term = StepCountTermination::new(1000);
19/// ```
20#[derive(Debug, Clone)]
21pub struct StepCountTermination {
22    limit: u64,
23}
24
25impl StepCountTermination {
26    pub fn new(limit: u64) -> Self {
27        Self { limit }
28    }
29}
30
31impl<S: PlanningSolution> Termination<S> for StepCountTermination {
32    fn is_terminated(&self, solver_scope: &SolverScope<S>) -> bool {
33        solver_scope.total_step_count() >= self.limit
34    }
35}