Skip to main content

Module all_different_except

Module all_different_except 

Source
Expand description

N-ary all-different constraint with a sentinel escape value.

Tests: tests/all_different_except.rs.

Parallel to AllDifferent but permits arbitrarily many variables to share a single sentinel value — useful for modelling partial bipartite assignment, where a dedicated “unmatched” token may be selected by any number of sources simultaneously while every other (real) target must still be picked at most once.

use csp_solver::constraint::AllDifferentExcept;
use csp_solver::domain::BitsetDomain;
use csp_solver::Csp;

// Four variables, each picking a target in 0..4. Value `0` is the
// "unmatched" sentinel — any number of variables may land on it.
let mut csp: Csp<BitsetDomain> = Csp::new();
let vars = csp.add_variables(&BitsetDomain::range(4), 4);
csp.add_constraint_enum(
    csp_solver::constraint::ConstraintEnum::AllDifferentExcept(
        AllDifferentExcept::new(vars, 0),
    ),
);
csp.finalize();

Structs§

AllDifferentExcept
All-different over the scope, except that the configured sentinel value may be assigned to any number of variables.