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/std/fzn_arg_min_bool.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

20 lines
930 B
MiniZinc

predicate fzn_minimum_arg_bool(array[int] of var bool: x, var int: i) =
let { int: l = min(index_set(x));
int: u = max(index_set(x));
} in
if exists(j in l..u)(is_fixed(x[j]) /\ not fix(x[j]))
then % special case: min is known to be 0
let { array[l..u] of var bool: d; } in
x[i] = false /\ % ith case must be equal to lb
forall(j in l..u)(not x[j] -> i <= j) /\ % lower bound
d[l] = x[l] /\
forall(j in l+1..u)(d[j] <-> (d[j-1] /\ x[j])) /\
forall(j in l..u)(d[j] -> i >= j+1) % upper bound
else
% general case: min could be 0 or 1
let { array[l..u] of var bool: y;
array[l..u] of var l..u: mi; } in
y[l] = x[l] /\ mi[l] = l /\ i = mi[u] /\
forall (j in l+1 .. u) ( y[j] == (x[j] /\ y[j-1]) /\
mi[j] = if (not y[j-1] \/ x[j]) then mi[j-1] else j endif )
endif;