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() { if let Some(mut init_updates) = self._push_updates() {
stack.append(&mut init_updates); stack.append(&mut init_updates);
} else { } else {
// Solution is complete
panic!("Could not initialize !"); panic!("Could not initialize !");
} }

View File

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