solverforge_solver/termination/
time.rs1use std::time::Duration;
4
5use solverforge_core::domain::PlanningSolution;
6use solverforge_scoring::ScoreDirector;
7
8use super::Termination;
9use crate::scope::SolverScope;
10
11#[derive(Debug, Clone)]
24pub struct TimeTermination {
25 limit: Duration,
26}
27
28impl TimeTermination {
29 pub fn new(limit: Duration) -> Self {
30 Self { limit }
31 }
32
33 pub fn millis(ms: u64) -> Self {
34 Self::new(Duration::from_millis(ms))
35 }
36
37 pub fn seconds(secs: u64) -> Self {
38 Self::new(Duration::from_secs(secs))
39 }
40}
41
42impl<S: PlanningSolution, D: ScoreDirector<S>> Termination<S, D> for TimeTermination {
43 fn is_terminated(&self, solver_scope: &SolverScope<S, D>) -> bool {
44 solver_scope.elapsed().is_some_and(|e| e >= self.limit)
45 }
46}