on_assing -> propagate
This commit is contained in:
parent
e363a552f0
commit
25a6634069
@ -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)?;
|
||||
}
|
||||
|
@ -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;
|
||||
|
||||
|
@ -16,9 +16,7 @@ pub trait Constraint: Debug {
|
||||
fn vars(&self) -> Box<dyn Iterator<Item = &'_ VarToken> + '_>;
|
||||
|
||||
/// 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<()> {
|
||||
|
@ -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)
|
||||
|
@ -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)?;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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()
|
||||
|
@ -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() {
|
||||
|
Loading…
Reference in New Issue
Block a user