use std::fmt::Debug;
pub trait Domain: Clone + PartialEq + Debug {
type Value: Clone + PartialEq + Debug;
fn size(&self) -> usize;
fn is_empty(&self) -> bool {
self.size() == 0
}
fn is_singleton(&self) -> bool {
self.size() == 1
}
fn singleton_value(&self) -> Option<Self::Value> {
if self.is_singleton() {
self.iter().next()
} else {
None
}
}
fn contains(&self, val: &Self::Value) -> bool;
fn remove(&mut self, val: &Self::Value) -> bool;
fn add(&mut self, val: &Self::Value);
fn values(&self) -> Vec<Self::Value>;
fn iter(&self) -> impl Iterator<Item = Self::Value> {
self.values().into_iter()
}
}
pub trait CostDomain: Domain {
fn cost(&self, val: &Self::Value) -> f64;
fn min_cost(&self) -> f64 {
self.values()
.into_iter()
.map(|v| self.cost(&v))
.fold(f64::INFINITY, f64::min)
}
}
pub trait LatticeDomain: Domain {
fn bottom() -> Self;
fn join(&mut self, other: &Self) -> bool;
}