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/gecode/flatzinc/mznlib/fzn_alldifferent_except_0.mzn
Jip J. Dekker 3e72b0e857 Squashed 'software/gecode_on_record/' content from commit 37ed9bda4
git-subtree-dir: software/gecode_on_record
git-subtree-split: 37ed9bda495ea87e63217c19a374b5a93bb0078e
2021-06-16 14:03:52 +10:00

25 lines
801 B
MiniZinc

include "global_cardinality_low_up_closed.mzn";
/** @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) =
if length(vs)==0 then true
else
let {
int: l = lb_array(vs);
int: u = ub_array(vs);
} in
if l != -infinity /\ u != infinity then
global_cardinality_low_up_closed(vs, [i | i in l..u],
[0 | i in l..u],
[if i==0 then length(vs) else 1 endif | i in l..u]
)
else
forall(i, j in index_set(vs) where i < j) (
(vs[i] != 0 /\ vs[j] != 0) -> vs[i] != vs[j]
)
endif
endif;