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_lex_lesseq_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

50 lines
2.2 KiB
MiniZinc

%-----------------------------------------------------------------------------%
% Requires that the array 'x' is lexicographically less than or equal to
% array 'y'. Compares them from first to last element, regardless of indices
%-----------------------------------------------------------------------------%
predicate fzn_lex_lesseq_bool(array[int] of var bool: x,
array[int] of var bool: y) =
% if (min(card(index_set(x)), card(index_set(y))) <= 25) then
% let { int: size = min(card(index_set(x)), card(index_set(y)));
% } in
% sum(i in 0..size-1)(pow(2, (size-1-i)) * bool2int(x[i+min(index_set(x))]))
% <= sum(i in 0..size-1)(pow(2, (size-1-i)) * bool2int(y[i+min(index_set(y))]))
% else
% my_trace ("lex_lesseq_bool(\(x), \(y))") /\
let { int: lx = min(index_set(x)),
int: ux = max(index_set(x)),
int: ly = min(index_set(y)),
int: uy = max(index_set(y)),
int: size = min(ux - lx, uy - ly),
array[0..size+1] of var bool: b }
% b[i] is true if the lexicographical order holds from position i on.
in
b[0]
/\
forall(i in 0..size) (
b[i] -> ( ( ( x[lx + i] <= y[ly + i] ) ) /\
% bool2int(b[i]) + bool2int(x[lx + i]) + (1-bool2int(y[ly + i])) <= 2 /\
% ( b[i] ->
( x[lx + i] < y[ly + i] \/ b[i+1] ) )
% /\ ( bool2int(b[i]) <= bool2int(x[lx + i] < y[ly + i]) + bool2int(b[i+1]) ) /\
% bool2int(b[i]) + (1-bool2int(x[lx + i])) + (1-bool2int(y[ly + i])) + (1-bool2int(b[i+1])) <= 3
% /\ bool2int(b[i]) + bool2int(x[lx + i]) + bool2int(y[ly + i]) + (1-bool2int(b[i+1])) <= 3
%% This guy is dominated by the 1st one above but helps:
% /\ bool2int(b[i]) + bool2int(x[lx + i]) + (1-bool2int(y[ly + i])) + (1-bool2int(b[i+1])) <= 3
)
/\ b[size+1] = (ux-lx <= uy-ly)
% endif
;
% forall(i in 0..size) (
% ( b[i] == ( x[lx + i] <= y[ly + i] ) )
% /\
% if i < size then
% ( b[i] == ( x[lx + i] < y[ly + i] \/ b[i+1]
% ) ) else true endif
% );
%-----------------------------------------------------------------------------%