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

标签 minizinc

我正在尝试使用 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 中的建议并使用:
  • float 决策变量
  • 地理编码求解器

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

    最佳答案

    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/

    相关文章:

    minizinc - 检查 MiniZinc 数组中的项目

    minizinc - 使用 minizinc 计算溶液总数

    installation - 如何在 MiniZinc 中安装 Google 的 CP 求解器 OR-Tools?

    constraints - Minizinc:五天输出,有更好灵活的办法吗?

    minizinc - 指定决策变量时 MiniZinc 中的错误消息

    minizinc - MiniZinc 中的 channel 是什么?你能提供一个简单的例子来解释 channel 吗?最后,什么是逆?

    constraints - 将 MiniZinc 模型转换为 choco 代码

    minizinc - 有没有办法在 minizinc 中自定义 int_search ?

    constraint-programming - 理解Minizincs geost约束的输入格式