solverforge_solver/termination/
step_count.rs1use solverforge_core::domain::PlanningSolution;
4use solverforge_scoring::Director;
5
6use super::Termination;
7use crate::scope::BestSolutionCallback;
8use crate::scope::SolverScope;
9
10#[derive(Debug, Clone)]
20pub struct StepCountTermination {
21 limit: u64,
22}
23
24impl StepCountTermination {
25 pub fn new(limit: u64) -> Self {
26 Self { limit }
27 }
28}
29
30impl<S: PlanningSolution, D: Director<S>, BestCb: BestSolutionCallback<S>> Termination<S, D, BestCb>
31 for StepCountTermination
32{
33 fn is_terminated(&self, solver_scope: &SolverScope<S, D, BestCb>) -> bool {
34 solver_scope.total_step_count() >= self.limit
35 }
36
37 fn install_inphase_limits(&self, solver_scope: &mut SolverScope<S, D, BestCb>) {
38 let limit = match solver_scope.inphase_step_count_limit {
40 Some(existing) => existing.min(self.limit),
41 None => self.limit,
42 };
43 solver_scope.inphase_step_count_limit = Some(limit);
44 }
45}