MiniZinc:对 3dArray 中所有索引 'i' 的两个数组索引 'k'、'j' 求和的约束创建 TypeError
MiniZinc: Constraint for sum over two array indexes 'k','j' for all index 'i' in 3dArray creates TypeError
正如下面的代码所解释的那样,我想实现一个约束,其中每个 'i',所有 'j' 和 'k' 的总和对于特定 'i'在 ARRAY[k,i,j] 中必须小于或等于 1.
constraint forall(i in 1..10)( sum(j in 1..10, k in 1..10)(ARRAY[k,i,j] <= 1) );
但是,我得到这个错误:
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)
这个错误是什么意思,我该如何让约束做我想做的事?
由于条件 (<=
) 放置在错误的位置而引发错误。它应该在 sum
:
的正文之外
constraint forall(i in 1..10)( sum(j in 1..10, k in 1..10)(ARRAY[k,i,j]) <= )
正如下面的代码所解释的那样,我想实现一个约束,其中每个 'i',所有 'j' 和 'k' 的总和对于特定 'i'在 ARRAY[k,i,j] 中必须小于或等于 1.
constraint forall(i in 1..10)( sum(j in 1..10, k in 1..10)(ARRAY[k,i,j] <= 1) );
但是,我得到这个错误:
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)
这个错误是什么意思,我该如何让约束做我想做的事?
由于条件 (<=
) 放置在错误的位置而引发错误。它应该在 sum
:
constraint forall(i in 1..10)( sum(j in 1..10, k in 1..10)(ARRAY[k,i,j]) <= )