简体   繁体   English

MiniZinc:类型错误:找不到具有此签名的函数或谓词:`floor(var int)'

[英]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:我见过这个类似的问题,但是,我正在遵循所选答案中的建议并使用:

  • float decision variable浮动决策变量
  • geocode solver地理编码解算器

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.

相关问题 MiniZinc:类型错误:找不到具有此签名的函数或谓词:`cost(var int,var int)&#39; - MiniZinc: type error: no function or predicate with this signature found: `cost(var int,var int)' MiniZinc类型错误:找不到all_different(var int的array [int]) - MiniZinc type error: all_different(array[int] of var int) not found MiniZinc:类型错误:期望`int的&#39;array [int],var opt int的实际`array [int] - MiniZinc: type error: expected `array[int] of int', actual `array[int] of var opt int 如何在Minizinc中为函数创建等效项以简化谓词 - How to create an equivalent for a function in Minizinc to simplify a predicate Minizinc 错误:无效的类型插入:预期的“浮动”,实际的“浮动浮动” - Minizinc error: invalid type-inst: expected `float', actual `var float' 在 minizinc 的 output 语句中使用 var 集的 function 时遇到问题 - Having trouble using a function of a var set twice in an output statement in minizinc Minizinc的“ var set of int:x”而不是“ int set:x” - Minizinc “var set of int: x” instead of “set of int: x” Minizinc:可变大小的 var 数组 - Minizinc : var array with variable size MiniZinc查找int集 - MiniZinc find the set of int 有没有办法在minizinc谓词中提供搜索注释? - is there a way to provide search annotation in minizinc predicate?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM