use std::fmt::Debug;
use std::marker::PhantomData;
use solverforge_core::domain::PlanningSolution;
use solverforge_scoring::Director;
use super::Termination;
use crate::scope::ProgressCallback;
use crate::scope::SolverScope;
#[derive(Clone)]
pub struct ScoreCalculationCountTermination<S: PlanningSolution> {
limit: u64,
_phantom: PhantomData<fn() -> S>,
}
impl<S: PlanningSolution> Debug for ScoreCalculationCountTermination<S> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("ScoreCalculationCountTermination")
.field("limit", &self.limit)
.finish()
}
}
impl<S: PlanningSolution> ScoreCalculationCountTermination<S> {
pub fn new(limit: u64) -> Self {
Self {
limit,
_phantom: PhantomData,
}
}
}
impl<S: PlanningSolution, D: Director<S>, BestCb: ProgressCallback<S>> Termination<S, D, BestCb>
for ScoreCalculationCountTermination<S>
{
fn is_terminated(&self, solver_scope: &SolverScope<'_, S, D, BestCb>) -> bool {
solver_scope.stats().score_calculations >= self.limit
}
fn install_inphase_limits(&self, solver_scope: &mut SolverScope<S, D, BestCb>) {
let limit = match solver_scope.inphase_score_calc_count_limit {
Some(existing) => existing.min(self.limit),
None => self.limit,
};
solver_scope.inphase_score_calc_count_limit = Some(limit);
}
}