use std::time::Duration;
use solverforge_core::domain::PlanningSolution;
use solverforge_scoring::Director;
use super::Termination;
use crate::scope::ProgressCallback;
use crate::scope::SolverScope;
#[derive(Debug, Clone)]
pub struct TimeTermination {
limit: Duration,
}
impl TimeTermination {
pub fn new(limit: Duration) -> Self {
Self { limit }
}
pub fn millis(ms: u64) -> Self {
Self::new(Duration::from_millis(ms))
}
pub fn seconds(secs: u64) -> Self {
Self::new(Duration::from_secs(secs))
}
}
impl<S: PlanningSolution, D: Director<S>, BestCb: ProgressCallback<S>> Termination<S, D, BestCb>
for TimeTermination
{
fn is_terminated(&self, solver_scope: &SolverScope<S, D, BestCb>) -> bool {
solver_scope.elapsed().is_some_and(|e| e >= self.limit)
}
}