[英]MiniZinc: type error: no function or predicate with this signature found: `floor(var int)'
I'm trying to run the following code on Mac OS/X with Minizinc IDE 2.2.3 and Geocode 6.1.0 [built in]:我正在尝试使用 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)"]
The error I receive is:我收到的错误是:
MiniZinc: type error: no function or predicate with this signature found: `floor(var float)'
MiniZinc:类型错误:找不到具有此签名的函数或谓词:`floor(var float)'
I've seen this similar question , however, I'm following the advice in the selected answer and using:我见过这个类似的问题,但是,我正在遵循所选答案中的建议并使用:
Thus, this question is different from the other question.因此,这个问题与另一个问题不同。
The documentation (v. 2.2.3) says that floor()
requires an argument of type float
:文档 (v. 2.2.3)说
floor()
需要一个float
类型的参数:
4.1.11.6.
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)
In your model, you pass a var float
instead of a float
to the function floor
, thus you get a type error .在您的模型中,您将
var float
而不是float
传递给函数floor
,因此您会收到类型错误。
Having said this, in your example the floor()
function does not seem to be necessary.话虽如此,在您的示例中,
floor()
函数似乎不是必需的。 Even though you declare y
to be a var float
, this can only be assigned some integral value, because the result of the integer division is always an integer :即使您将
y
声明为var float
,也只能为其分配一些整数值,因为整数除法的结果始终是integer :
function var int: 'div'(var int: x, var int: y)
Thus, my suggestion is to drop floor()
altogether.因此,我的建议是完全放弃
floor()
。
example例子
var 1..10: x;
var float: y = x div 4;
constraint 1.5 <= y;
solve minimize( (x - 7)^2 );
output ["\(x) \(y)"]
yields产量
~$ minizinc t.mzn
8 2.0
----------
==========
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.