Trying to organize it all :$

This commit is contained in:
2019-01-30 21:47:21 +01:00
parent 253045c742
commit d4454e7f16
2 changed files with 49 additions and 16 deletions

View File

@@ -13,7 +13,7 @@ enum Assignment<'a, V> {
Clear(String)
}
type Domains<'a, V> = HashMap<String, &'a Domain<V>>;
/// The domain of values that can be assigned to variables
#[derive(Clone)]
pub struct Domain<V> {
@@ -51,13 +51,14 @@ impl<V: fmt::Debug> fmt::Debug for Domain<V> {
}
}
pub type Constraint<'a,V> = fn(&Variables<'a,V>) -> bool;
pub struct Problem<'a, V> {
/// The initial assignements map
variables: Variables<'a, V>,
/// Each variable has its associated domain
domains: HashMap<String, &'a Domain<V>>,
domains: Domains<'a,V>,
/// Set of constraints to validate
constraints: Vec<Constraint<'a,V>>,
}
@@ -141,11 +142,10 @@ impl<'a, V> ProblemBuilder<'a, V> {
})
}
pub fn add_variable(mut self,
name: String,
domain: &'a Domain<V>,
value: Option<&'a V>,
) -> Self {
pub fn add_variable<S>(mut self, name: S, domain: &'a Domain<V>, value: Option<&'a V>) -> Self
where S: Into<String>
{
let name = name.into();
self.0.variables.insert(name.clone(), value);
self.0.domains.insert(name, domain);
self