gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-04 17:40:37 25 4
gpt4 key购买 nike

我正在尝试使用 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/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com