This is a very simple all different constraint, e.g. - It does not know that if there are more variables than candidates, it has reached a contradiction. - It does not know that, if there are as many variables as candidates, if only one variable can take on a candidate value, then all other candidates for that variable can be eliminated.
33 lines
1.0 KiB
Rust
33 lines
1.0 KiB
Rust
//! Constraint trait, and some common constraints.
|
|
//!
|
|
//! Note that all puzzle states visited during the solution search
|
|
//! share the same set of constraints. This means that you cannot
|
|
//! store additional information about the state (e.g. caches) in the
|
|
//! constraint to reuse later.
|
|
|
|
use ::{PuzzleSearch,Val,VarToken};
|
|
|
|
/// Constraint trait.
|
|
pub trait Constraint {
|
|
/// Applied after a variable has been assigned.
|
|
///
|
|
/// Returns true if the search should continue with these variable
|
|
/// assignments, or false if the constraint found a contradiction.
|
|
fn on_assigned(&self, _search: &mut PuzzleSearch, _var: VarToken, _val: Val)
|
|
-> bool {
|
|
true
|
|
}
|
|
|
|
/// Applied after a variable's candidates has been modified.
|
|
///
|
|
/// Returns true if the search should continue with these variable
|
|
/// assignments, or false if the constraint found a contradiction.
|
|
fn on_updated(&self, _search: &mut PuzzleSearch) -> bool {
|
|
true
|
|
}
|
|
}
|
|
|
|
pub use self::alldifferent::AllDifferent;
|
|
|
|
mod alldifferent;
|