简体   繁体   English

为什么我的数组是 var int 类型而不是 var set of int?

[英]Why my array is of type var int instead of var set of int?

I have the following problem: I want to call the global constraint at_most but I got an error related to the signature我有以下问题:我想调用全局约束at_most但我收到了与签名相关的错误

constraint forall(i in 0..w-1)(at_most(l_max, [board[i,j] | j in 0..l_max-1], 0..n));

the second argument does not match because it turns out to be var int instead of var set of int but I have previously defined board in this way:第二个参数不匹配,因为结果是 var int 而不是 var set of int 但我以前以这种方式定义了 board:

set of int: VALUES = 0..n;
array[0..w-1,0..l_max-1] of var VALUES: board;

Just as a general message: at_most is among the list of deprecated constraints: https://www.minizinc.org/doc-2.5.5/en/lib-globals.html#deprecated-constraints .正如一般信息: at_most是已弃用的约束列表之一: https : //www.minizinc.org/doc-2.5.5/en/lib-globals.html#deprecated-constraints Instead, you should use a count constraint.相反,您应该使用count约束。 These constraints are more flexible and better supported by the solvers.这些约束更灵活,求解器更好地支持。

In this case there seems to be a misconception about what at_most does.在这种情况下,似乎对at_most作用存在误解。 At most only restrict the number of time a single value occurs.最多只限制单个值出现的次数。 You are.你是。 however, giving it a full set of values.然而,给它一套完整的价值观。

If you are counting all the different values, then you instead can useglobal_cardinality_low_up .如果要计算所有不同的值,则可以改用global_cardinality_low_up (You might also want to look at the closed version). (您可能还想查看封闭版本)。 I think you meant to write the following constraint.我认为您打算编写以下约束。

constraint forall(i in 0..w-1)(
  global_cardinality_low_up([board[i,j] | j in 0..l_max-1], 0..n, [0 | i in 0..n], [l_max | i in 0..n])
);

This constraint insure that for the comprehensions the values in 0..n only occur l_max times.此约束确保对于理解, 0..n的值仅出现l_max次。

Note that if you are using the comprehension to select a full row, then it would be better to use slice notation: board[i,..] .请注意,如果您使用推导式来选择整行,那么最好使用切片符号: board[i,..]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM