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

22 lines
925 B
MiniZinc

predicate fzn_maximum_arg_float(array[int] of var float: x, var int: i) =
let { int: l = min(index_set(x));
int: u = max(index_set(x));
float: uy = ub_array(x);
} in
if exists(j in l..u)(lb(x[j]) = uy)
then let { array[l..u] of var bool: d; } in
% max is known to be uy
x[i] = uy /\ % ith case must be equal to ub
forall(j in l..u)(x[j] = uy -> i <= j) /\ % lower bound
d[l] = (x[l] = uy) /\
forall(j in l+1..u)(d[j] <-> (d[j-1] \/ (x[j] = uy))) /\
forall(j in l..u)(not d[j] -> i >= j+1) % upper bound
else
let { float: ly = lb_array(x);
array[l..u] of var ly..uy: 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] == max(x[j],y[j-1]) /\
mi[j] = if y[j-1] >= x[j] then mi[j-1] else j endif )
endif;