diff --git a/src/constraint/alldifferent.rs b/src/constraint/alldifferent.rs index c01546a..624dc71 100644 --- a/src/constraint/alldifferent.rs +++ b/src/constraint/alldifferent.rs @@ -37,7 +37,7 @@ impl Constraint for AllDifferent { Box::new(self.vars.iter()) } - fn on_assigned(&self, search: &mut PuzzleSearch, var: VarToken, val: Val) -> PsResult<()> { + fn propagate(&self, search: &mut PuzzleSearch, var: VarToken, val: Val) -> PsResult<()> { for &var2 in self.vars.iter().filter(|&v| *v != var) { search.remove_candidate(var2, val)?; } diff --git a/src/constraint/equality.rs b/src/constraint/equality.rs index 557d5e1..8e66676 100644 --- a/src/constraint/equality.rs +++ b/src/constraint/equality.rs @@ -35,7 +35,7 @@ impl Constraint for Equality { Box::new(self.eqn.coef.keys()) } - fn on_assigned(&self, search: &mut PuzzleSearch, _var: VarToken, _val: Val) -> PsResult<()> { + fn propagate(&self, search: &mut PuzzleSearch, _var: VarToken, _val: Val) -> PsResult<()> { let mut sum = self.eqn.constant; let mut unassigned_var = None; diff --git a/src/constraint/mod.rs b/src/constraint/mod.rs index 0e2ec81..74a733d 100644 --- a/src/constraint/mod.rs +++ b/src/constraint/mod.rs @@ -16,9 +16,7 @@ pub trait Constraint: Debug { fn vars(&self) -> Box + '_>; /// Applied after a variable has been assigned. - fn on_assigned(&self, _search: &mut PuzzleSearch, _var: VarToken, _val: Val) -> PsResult<()> { - Ok(()) - } + fn propagate(&self, _search: &mut PuzzleSearch, _var: VarToken, _val: Val) -> PsResult<()>; /// Applied after a variable's candidates has been modified. fn on_updated(&self, _search: &mut PuzzleSearch) -> PsResult<()> { diff --git a/src/constraint/unify.rs b/src/constraint/unify.rs index 2402ad3..9012b72 100644 --- a/src/constraint/unify.rs +++ b/src/constraint/unify.rs @@ -3,7 +3,7 @@ use std::iter; use std::rc::Rc; -use crate::{Constraint, PsResult, PuzzleSearch, VarToken}; +use crate::{Constraint, PsResult, PuzzleSearch, Val, VarToken}; #[derive(Debug)] pub struct Unify { @@ -39,6 +39,10 @@ impl Constraint for Unify { } } + fn propagate(&self, _search: &mut PuzzleSearch, _var: VarToken, _val: Val) -> PsResult<()> { + Ok(()) + } + fn on_updated(&self, search: &mut PuzzleSearch) -> PsResult<()> { if self.var1 != self.var2 { search.unify(self.var1, self.var2) diff --git a/src/puzzle.rs b/src/puzzle.rs index c4a1dd1..75143b9 100644 --- a/src/puzzle.rs +++ b/src/puzzle.rs @@ -857,7 +857,7 @@ impl<'a> PuzzleSearch<'a> { for cidx in 0..self.constraints.constraints.len() { if self.constraints.wake[idx].contains(cidx) { let constraint = self.constraints.constraints[cidx].clone(); - constraint.on_assigned(self, var, val)?; + constraint.propagate(self, var, val)?; } } diff --git a/tests/queens.rs b/tests/queens.rs index 0bc5ef9..317a264 100644 --- a/tests/queens.rs +++ b/tests/queens.rs @@ -17,7 +17,7 @@ impl Constraint for NoDiagonal { Box::new(self.vars.iter()) } - fn on_assigned(&self, search: &mut PuzzleSearch, var: VarToken, val: Val) -> PsResult<()> { + fn propagate(&self, search: &mut PuzzleSearch, var: VarToken, val: Val) -> PsResult<()> { let y1 = self .vars .iter() diff --git a/tests/takuzu.rs b/tests/takuzu.rs index 5c9544a..2c11ad9 100644 --- a/tests/takuzu.rs +++ b/tests/takuzu.rs @@ -23,7 +23,7 @@ impl Constraint for BinaryRepr { Box::new(iter::once(&self.value).chain(&self.bits)) } - fn on_assigned(&self, search: &mut PuzzleSearch, var: VarToken, val: Val) -> PsResult<()> { + fn propagate(&self, search: &mut PuzzleSearch, var: VarToken, val: Val) -> PsResult<()> { if var == self.value { let mut val = val; for &var in self.bits.iter() {