minizinc:在两个数组索引上的总和约束' k' ,,' j'对于所有索引' i'在3Darray中创建TypeError

发布于 2025-01-29 14:44:09 字数 1437 浏览 2 评论 0原文

正如下面的代码所解释的那样,我想实现一个约束,其中每个“ i”,所有“ j”和'k'的总和在数组中[k,i,j]中的特定“ i”必须小于或等于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)

错误是什么意思,我将如何制定约束?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

北恋 2025-02-05 14:44:10

由于条件(&lt; =)被放置在错误的位置,因此抛出了错误。它应该在sum的主体之外:

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

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]) <= )
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文