A.6 library( clp/clp_distinct ): Weak arc consistent `all_distinct' constraint

Author: Markus Triska

The library(clp/clp_distinct) module provides the following constraints:

The variables in Vars are constrained to be pairwise distinct. All variables must already be assigned domains (via vars_in/2 or vars_in/3) when this constraint is posted.
vars_in(+Vars, +Domain)
Where Vars is a list of variables and Domain is a list of non-negative integers. Each variable of Vars is constrained to be in Domain.
vars_in(+Vars, +From, +To)
Where Vars is a list of variables, and 0 < From < To. Each variable in Vars is constrained to be in the discrete interval [From,To].

A.6.1 Example 1

The all_distinct/1 constraint can detect various inconsistencies:
?- vars_in([X,Y,Z], [1,2]), all_distinct([X,Y,Z]).


A.6.2 Example 2

In this example, 3 is assigned to Z without labeling any variables:
?- vars_in([X,Y], [1,2]), vars_in([Z], [1,2,3]), all_distinct([X,Y,Z]).

X = _G180{1-2}
Y = _G183{1-2}
Z = 3 ;

A.6.3 Example 3

The clp_distinct module can be used in conjunction with clp/bounds. All relevant variables must still be assigned domains via one of the vars_in predicates before all_distinct/1 can be posted:
:- use_module(library(bounds)).
:- use_module(library(clp_distinct)).

?- [X,Y] in 1..2, vars_in([X,Y], [1,2]), all_distinct([X,Y]), label([X,Y]).

X = 1
Y = 2 ;

X = 2
Y = 1 ;