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_alldifferent_except_0.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

18 lines
657 B
MiniZinc

/** @group globals.alldifferent
Constrain the array of integers \a vs to be all different except those
elements that are assigned the value 0.
*/
predicate fzn_alldifferent_except_0(array[int] of var int: vs) =
% forall(i, j in index_set(vs) where i < j) (
% (vs[i] != 0 /\ vs[j] != 0) -> vs[i] != vs[j]
% );
if length(vs)<=1 then true
else
let {
array[int,int] of var 0..1: x_eq_d = eq_encode(vs)
} in (
% my_trace(" alldifferent_except_0: x[" ++ show(index_set(vs)) ++ "]\n") /\
forall(d in index_set_2of2(x_eq_d) diff {0})( sum(i in index_set_1of2(x_eq_d))( x_eq_d[i,d] ) <= 1 )
)
endif;