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:
Thus, this question is different from the other question.
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
----------
==========
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With