1
0
This repository has been archived on 2025-03-06. You can view files and clone it, but cannot push or open issues or pull requests.
on-restart-benchmarks/share/minizinc/linear/fzn_all_different_int.mzn
Jip J. Dekker f2a1c4e389 Squashed 'software/mza/' content from commit f970a59b17
git-subtree-dir: software/mza
git-subtree-split: f970a59b177c13ca3dd8aaef8cc6681d83b7e813
2021-07-11 16:34:30 +10:00

24 lines
853 B
MiniZinc

%-----------------------------------------------------------------------------%
% 'all_different' constrains an array of objects to be all different.
%
% Linear version: equality encoding; see e.g. [Refalo, CP 2000]
%
% For a given d in dom(x), at most one i with x_i = d can exist.
%-----------------------------------------------------------------------------%
include "domain_encodings.mzn";
predicate fzn_all_different_int(array[int] of var int: x) =
if length(x)<=1 then true
else
let {
array[int,int] of var 0..1: x_eq_d = eq_encode(x)
} in (
% my_trace(" all_different_int: x[" ++ show(index_set(x)) ++ "]\n") /\
forall(d in index_set_2of2(x_eq_d))( sum(i in index_set_1of2(x_eq_d))( x_eq_d[i,d] ) <= 1 )
)
endif;
%-----------------------------------------------------------------------------%