Пример:
Значение y
ограничено равным
next(x) \/ next(next(x)) \/ ...
до K
уровней вложенности.
function var int: nextr(var int: n) =
if n <= 1 then
2
elseif n <= 8 then
n + 5
elseif n <= 68 then
n + 13
elseif n <= 509 then
n + 34
elseif n <= 3611 then
n + 89
else
n + 233
endif;
int: K = 10;
var int: x;
var int: y;
array[1..K] of var int: rec_up_to_k;
constraint forall (i in 1..K) (
if i == 1 then
rec_up_to_k[i] = nextr(x)
else
rec_up_to_k[i] = nextr(rec_up_to_k[i-1])
endif
);
constraint exists (i in 1..K) (
y = rec_up_to_k[i]
);
constraint x >= 0;
solve satisfy;
выходы:
x = 3612;
y = 3845;
rec_up_to_k = array1d(1..10, [3845, 4078, 4311, 4544, 4777, 5010, 5243, 5476, 5709, 5942]);
----------