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/comparison_rel_array.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

27 lines
1.2 KiB
MiniZinc

%-----------------------------------------------------------------------------%
% Reflect an array of comparison values onto a comparison value variable using
% a lexicographic interpretation of the array. The comparison values are
% encoded as follows: > | = | < as -1 | 0 | +1.
% Uses of this constraint are generated by Cadmium transformations that
% simplify ordering constraints on expressions of complex types.
%-----------------------------------------------------------------------------%
predicate comparison_rel_array(array[int] of var -1..1: rels, var -1..1: rel) =
let { int: l = min(index_set(rels)),
int: u = max(index_set(rels)),
array[l-1..u] of var -1..1: r }
in
r[l-1] = 0 % initial state (before first array position) is 'equal'
/\
forall (i in l..u) (
% new state: as given array at current position if
% previous state is 'equal', otherwise previous state
%
% r[i] = (if r[i-1] = 0 then rels[i] else r[i-1] endif)
(r[i-1] = 0 -> r[i] = rels[i])
/\
(r[i-1] != 0 -> r[i] = r[i-1])
)
/\
r[u] = rel; % final state (at last array position)