17 lines
469 B
MiniZinc
17 lines
469 B
MiniZinc
function tuple(var bool, var int): element_safe(
|
|
array of int: a,
|
|
var int: x
|
|
) =
|
|
let {
|
|
set of int: idx = index_set(x)
|
|
var bool: total = x in idx;
|
|
var idx: xs;
|
|
int: m = min(idx);
|
|
% Give xs the value of x when result is total
|
|
constraint total -> xs = x;
|
|
% Otherwise, give xs the value m instead
|
|
constraint not total -> xs = m;
|
|
% element constraint that is guaranteed to be total
|
|
tuple(var bool, var int): res = (total, element(a, xs));
|
|
} in ret;
|