small things

This commit is contained in:
2019-02-14 14:36:44 +01:00
parent 3ee9533faf
commit 3e477945ea
2 changed files with 16 additions and 14 deletions

View File

@@ -122,6 +122,7 @@ impl<'a,V, K: Eq + Hash + Clone> Problem<'a, V, K> {
if let Some(mut init_updates) = self._push_updates() {
stack.append(&mut init_updates);
} else {
// Solution is complete
panic!("Could not initialize !");
}

View File

@@ -136,17 +136,18 @@ mod api {
// Let's hack for now
// BUGGY because template does not generate every variables, needs refactoring
// Find variable in partial
let initial_id = partial.iter().find_map(|slot| {
if slot.value.is_none() { return None; };
let initial_id = partial.iter()
.filter(|slot| slot.value.is_some())
.find_map(|slot| {
//println!("{:?} vs {:?}", slot, var);
if slot.key.0 == var.0
&& slot.key.1 == format!("{:?}",var.1)
{
let id = slot.value.as_ref().unwrap().id;
println!("found initial : recipe with id {}", id);
return Some(id);
Some(id)
} else {
return None;
None
}
});
let ini = if let Some(id) = initial_id {
@@ -158,7 +159,7 @@ mod api {
};
// If found, override initial value
problem = problem.add_variable(var, dom, ini);
}
};
let mut problem = problem
.add_constraint(|_| true)
.finish();