1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
use crate::solver::RefinementContext;
pub trait Termination {
fn is_termination(&self, refinement_ctx: &mut RefinementContext) -> bool;
fn estimate(&self, refinement_ctx: &RefinementContext) -> f64;
}
mod cost_variation;
pub use self::cost_variation::CostVariation;
mod max_generation;
pub use self::max_generation::MaxGeneration;
mod max_time;
pub use self::max_time::MaxTime;
use crate::utils::compare_floats;
pub struct CompositeTermination {
terminations: Vec<Box<dyn Termination + Send + Sync>>,
}
impl CompositeTermination {
pub fn new(terminations: Vec<Box<dyn Termination + Send + Sync>>) -> Self {
Self { terminations }
}
}
impl Termination for CompositeTermination {
fn is_termination(&self, refinement_ctx: &mut RefinementContext) -> bool {
self.terminations.iter().any(|t| t.is_termination(refinement_ctx))
}
fn estimate(&self, refinement_ctx: &RefinementContext) -> f64 {
self.terminations.iter().map(|t| t.estimate(refinement_ctx)).max_by(|a, b| compare_floats(*a, *b)).unwrap_or(0.)
}
}