| 1 |
/*** |
| 2 |
!Test |
| 3 |
solvers: [gecode, chuffed] |
| 4 |
expected: |
| 5 |
- !Result |
| 6 |
solution: !Solution |
| 7 |
a: |
| 8 |
- [false, false, false, false] |
| 9 |
- [false, false, false, false] |
| 10 |
- [false, false, false, false] |
| 11 |
- [false, false, false, false] |
| 12 |
d: [3, 3, 3, 3] |
| 13 |
***/ |
| 14 |
|
| 15 |
% Regression test for bug #380 - the body of the lex_leq_bool_half was being |
| 16 |
% flattened in a reified context. (The reification context was not being |
| 17 |
% correctly reset after the application arguments had been flattened.) |
| 18 |
|
| 19 |
int: n = 4; |
| 20 |
set of int: N = 1..n; |
| 21 |
|
| 22 |
array[N,N] of var bool: a; |
| 23 |
array[N] of var 3..n-1: d; |
| 24 |
|
| 25 |
int: i = 2; |
| 26 |
|
| 27 |
constraint |
| 28 |
lex_lesseq_bool_half([ a[i,j+1] | j in N where j != i /\ j != i+1 ], |
| 29 |
[ a[i,j] | j in N where j != i /\ j != i+1 ], |
| 30 |
d[i] = d[i+1] ); |
| 31 |
|
| 32 |
solve satisfy; |
| 33 |
|
| 34 |
output ["d = array1d(1..4, ", show(d), ");\n"]; |
| 35 |
|
| 36 |
|
| 37 |
% half reified version of lex_lesseq for Booleans, that is |
| 38 |
% h -> lex_lesseq(x,y) |
| 39 |
predicate lex_lesseq_bool_half(array[int] of var bool: x, |
| 40 |
array[int] of var bool: y, |
| 41 |
var bool: h) = |
| 42 |
let { int: lx = min(index_set(x)), |
| 43 |
int: ux = max(index_set(x)), |
| 44 |
int: ly = min(index_set(y)), |
| 45 |
int: uy = max(index_set(y)), |
| 46 |
int: size = max(ux - lx, uy - ly), |
| 47 |
array[0..size] of var bool: b } |
| 48 |
% b[i] is true if the lexicographical order holds from position i on. |
| 49 |
in |
| 50 |
(h -> b[0]) |
| 51 |
/\ |
| 52 |
forall(i in 0..size) ( |
| 53 |
b[i] = ( x[lx + i] <= y[ly + i] |
| 54 |
/\ |
| 55 |
if i = size then true |
| 56 |
else x[lx + i] < y[ly + i] \/ b[i+1] endif |
| 57 |
) |
| 58 |
); |