MiniZinc: type error: no function or predicate with this signature found: `floor(var int)'

MiniZinc: type error: no function or predicate with this signature found: `floor(var int)'

我正在尝试使用 Minizinc IDE 2.2.3 和 Geocode 6.1.0 [内置] 运行 Mac OS/X 上的以下代码:

var 1..10: x;
var float: y = x div 4;

constraint y == floor(y);

solve minimize( (x - 7)^2 );

output ["\(x) \(y)"]

我收到的错误是:

MiniZinc: type error: no function or predicate with this signature found: `floor(var float)'

我看过这个 , however, I'm following the advice in the 并且正在使用:

因此,这个问题与另一个问题不同。

documentation (v. 2.2.3) 表示 floor() 需要类型为 float 的参数:

4.1.11.6. Coercion Operations

Round a float towards +∞, −∞, and the nearest integer, respectively.

int: ceil (float)
int: floor(float)
int: round(float)

Explicit casts from one type-inst to another.

    int:          bool2int(    bool)
var int:          bool2int(var bool)
    float:        int2float(    int)
var float:        int2float(var int)
array[int] of $T: set2array(set of $T)

在您的模型中,您将 var float 而不是 float 传递给函数 floor,因此您会得到 类型错误 .


话虽如此,在您的示例中似乎没有必要使用 floor() 函数。即使您将 y 声明为 var float,也只能为其分配一些 整数 值,因为 整数除法 总是 整数 :

function var int: 'div'(var int: x, var int: y)

因此,我的建议是完全放弃 floor()

例子

var 1..10: x;
var float: y = x div 4;

constraint 1.5 <= y;

solve minimize( (x - 7)^2 );

output ["\(x) \(y)"]

产量

~$ minizinc t.mzn 
8 2.0
----------
==========