Skip to content

Unexpected result using float variables #159

Closed

Description

@feserafim

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.

Activity

  1. a1880 commented on Apr 10, 2017

    @a1880

    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
    ----------
    ==========
    
  2. Dekker1 commented on Oct 4, 2017

    @Dekker1
    Member

    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;
    
  3. reopened this on Oct 4, 2017
  4. added a commit that references this issue on Oct 6, 2017
    a7b4034
  5. guidotack commented on Oct 6, 2017

    @guidotack
    Member

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

  6. feserafim commented on Oct 20, 2017

    @feserafim
    Author

    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?

  7. Dekker1 commented on Oct 20, 2017

    @Dekker1
    Member

    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)

  8. added theissue type on Jan 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions