Adds basic filter on Domain
This commit is contained in:
@@ -17,13 +17,32 @@ enum Assignment<'a, V> {
|
||||
/// The domain of values that can be assigned to variables
|
||||
#[derive(Clone)]
|
||||
pub struct Domain<V> {
|
||||
values: Vec<V>
|
||||
pub values: Vec<V>
|
||||
}
|
||||
|
||||
impl<V> Domain<V> {
|
||||
pub fn new(values: Vec<V>) -> Domain<V> {
|
||||
Domain { values }
|
||||
}
|
||||
|
||||
/// Returns a new domain with the given filter applied to inner values
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// ```
|
||||
/// # extern crate planner;
|
||||
/// # use planner::solver::Domain;
|
||||
/// let domain = Domain::new(vec![1,2,3]);
|
||||
/// fn even(i: &i32) -> bool { i % 2 == 0 };
|
||||
/// assert_eq!(&domain.filter(even).values, &vec![2]);
|
||||
/// ```
|
||||
pub fn filter(&self, f: fn(&V) -> bool) -> Domain<V>
|
||||
where V: std::clone::Clone
|
||||
{
|
||||
Domain {
|
||||
values: self.values.iter().cloned().filter(f).collect(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<V: fmt::Debug> fmt::Debug for Domain<V> {
|
||||
@@ -32,7 +51,7 @@ impl<V: fmt::Debug> fmt::Debug for Domain<V> {
|
||||
}
|
||||
}
|
||||
|
||||
type Constraint<'a,V> = fn(&Variables<'a,V>) -> bool;
|
||||
pub type Constraint<'a,V> = fn(&Variables<'a,V>) -> bool;
|
||||
|
||||
pub struct Problem<'a, V> {
|
||||
/// The initial assignements map
|
||||
|
||||
Reference in New Issue
Block a user