我正在尝试使用 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)'
我见过这个 similar question ,但是,我正在遵循 selected answer 中的建议并使用:
因此,这个问题与另一个问题不同。
最佳答案
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
, this 只能赋一些整数值,因为整数除法的结果总是整数: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
----------
==========
关于MiniZinc:类型错误:找不到具有此签名的函数或谓词: `floor(var int)',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54645630/