Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MiniZinc: type error: no function or predicate with this signature found: `floor(var int)'

Tags:

minizinc

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]:

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)'

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.

like image 393
Chris Snow Avatar asked Oct 28 '25 04:10

Chris Snow


1 Answers

The documentation (v. 2.2.3) says that floor() requires an argument of type 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)

In your model, you pass a var float instead of a float to the function floor, thus you get a type error.


Having said this, in your example the floor() function does not seem to be necessary. 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:

function var int: 'div'(var int: x, var int: y)

Thus, my suggestion is to drop floor() altogether.

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
----------
==========
like image 171
Patrick Trentin Avatar answered Oct 31 '25 08:10

Patrick Trentin