New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unexpected result using float variables #159

Closed
feserafim opened this Issue Apr 10, 2017 · 5 comments

Comments

Projects
None yet
4 participants
@feserafim

feserafim commented Apr 10, 2017

Hello,

I'm getting an unexpected result for the following example:

var 0.0..100.0: a;
var 0.0..100.0: b;
constraint (a > 94.0 /\ b > 94.0) /\ (a > b);
solve minimize b;

Result:

a = 95.0;
b = 95.0;
----------
==========

Why am I getting that result since (a > b) is set in the constraint?

By the way, I'm using the MiniZinc IDE for the execution and the solver is set on "Gecode (bundled)".

Thanks in advance.

@a1880

This comment has been minimized.

a1880 commented Apr 10, 2017

I tried to uncover some rounding problems and modified the example:

float: k = 1e300;
var 0.0..100.0: a;
var 0.0..100.0: b;
constraint (a > 94.0 /\ b > 94.0) /\ (a > b);
solve minimize b;
output ["\na = " ++ show(k * a) 
     ++ "\nb = " ++ show(k * b) 
     ++ "\na - b = " ++ show(k * (a-b))];

The output is:

a = 9.500000000000001e+301
b = 9.500000000000001e+301
a - b = 0.0
----------
==========
@Dekker1

This comment has been minimized.

Member

Dekker1 commented Oct 4, 2017

This bug seems to be caused by a faulty internal transformation. The resulting FlatZinc for this model is:

array [1..2] of float: X_INTRODUCED_0_ = [-1.0,1.0];
var 95.0..100.0: a:: output_var;
var 95.0..100.0: b:: output_var;
constraint float_lin_lt(X_INTRODUCED_0_,[a,b],0.0);
solve  minimize b;
@guidotack

This comment has been minimized.

Member

guidotack commented Oct 6, 2017

The incorrect simplification (changing the bound to 95.0) is now fixed in the compiler. The fact that a>b is violated is a bug in Gecode, not in MiniZinc (I will close this bug here and report it for Gecode).

@feserafim

This comment has been minimized.

feserafim commented Oct 20, 2017

I have just updated MiniZinc IDE (bundled) newest version (2.1.6) and executed

$ path/to/mzn2fzn.exe my-example.mzn

but I am still getting the same result as @Dekker1.

Am I doing anything wrong?

@Dekker1

This comment has been minimized.

Member

Dekker1 commented Oct 20, 2017

Hello @feserafim,

Although Guido managed to fix the flattening bug, the fix has only been implemented on the development branch. (We haven't released any new versions since the bug was fixed). This is also the reason that the issue is still open.

If you are still experiencing problems and you can't wait until the next release, then you might want to try to compile the develop branch and use that mzn2fzn binary. The problem should be fully fixed on that branch. (Although the problem in Gecode is a different issue as Guido mentioned)

@guidotack guidotack closed this in 9aa1173 Jan 10, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment