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)]
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, D: Director<S>, BestCb: BestSolutionCallback<S>> Termination<S, D, BestCb>
32 for StepCountTermination
33{
34 fn is_terminated(&self, solver_scope: &SolverScope<S, D, BestCb>) -> bool {
35 solver_scope.total_step_count() >= self.limit
36 }
37
38 fn install_inphase_limits(&self, solver_scope: &mut SolverScope<S, D, BestCb>) {
39 let limit = match solver_scope.inphase_step_count_limit {
41 Some(existing) => existing.min(self.limit),
42 None => self.limit,
43 };
44 solver_scope.inphase_step_count_limit = Some(limit);
45 }
46}