Home > database >  MiniZinc: Constraint for sum over two array indexes 'k','j' for all index '
MiniZinc: Constraint for sum over two array indexes 'k','j' for all index '

Time:05-18

As the code below hopefully explains, I want to implement a constraint where for each 'i', the sum over all 'j' and 'k' for that specific 'i' in ARRAY[k,i,j] must be less than or equal to 1.

constraint forall(i in 1..10)( sum(j in 1..10, k in 1..10)(ARRAY[k,i,j] <= 1) );

However, I get this error:

MiniZinc: type error: no function or predicate with this signature found: `sum(var int)'
Cannot use the following functions or predicates with the same identifier:
function int : sum(array [$T] of int: x);
    (argument 1 expects type array[$_] of int, but type var int given)
function int : sum(array [int] of opt int: x);
    (argument 1 expects type array[int] of opt int, but type var int given)
function var int : sum(array [$T] of var int: x);
    (argument 1 expects type array[$_] of var int, but type var int given)
function var int : sum(array [int] of var opt int: x);
    (argument 1 expects type array[int] of var opt int, but type var int given)
function float : sum(array [$T] of float: x);
    (argument 1 expects type array[$_] of float, but type var int given)
function float : sum(array [int] of opt float: x);
    (argument 1 expects type array[int] of opt float, but type var int given)
function var float : sum(array [$T] of var float: x);
    (argument 1 expects type array[$_] of var float, but type var int given)
function var float : sum(array [int] of var opt float: x);
    (argument 1 expects type array[int] of var opt float, but type var int given)

What does the error mean, and how would I make the constraint do what I want?

CodePudding user response:

The error is thrown since the condition (<=) is placed in the wrong place. It should be outside the body of sum:

constraint forall(i in 1..10)( sum(j in 1..10, k in 1..10)(ARRAY[k,i,j]) <= )
  • Related