Skip to main content

Binary Varibales get negative -0.0 values

Answered

Comments

6 comments

  • Gwyneth Butera
    • Gurobi Staff

    Have you had a chance to look at our Knowledge Base article Why does Gurobi sometimes return non-integral values for integer variables? 

    0
  • Mert Eroglu
    • Gurobi-versary
    • Conversationalist
    • First Question

    Yeah,

    I set IntFeasTol to 1e-9 and IntegralityFocus to 1, but it didn't changed the outcome.

    Thanks for the fast reply.

    0
  • Mario Ruthmair
    • Gurobi Staff

    Yes, things like this still can happen due to limited precision arithmetics.
    We usually do a very rough test for binary variables in a solution: if x > 0.5 then x=1 else x=0.

    0
  • Mert Eroglu
    • Gurobi-versary
    • Conversationalist
    • First Question
    for j in range(n):
    for i in range(m):
    model.addConstr(y_2022[j,i] >= 0.5 + eps - M*(1-B))
           model.addConstr(y_2022[j,i] <= 0.5 + M*(B))
    model.addConstr((B==1) >> (y_2022[j,i] == 1))
           model.addConstr((B==0) >> (y_2022[j,i] == 0))

    I added something like this, but this time i didn't have any outcome, are there
    something wrong with this?

    Thanks
    0
  • Mario Ruthmair
    • Gurobi Staff

    I probably was not clear with my last comment. The idea is not to add further constraints to ensure that binary variables get exactly value 0 or 1. This is simply not possible on all our machines with limited precision arithmetics.

    The test I proposed is meant for analyzing the solution after the optimization process has already finished. If the value for a binary variable is larger than 0.5, then it is actually 1 (or True) in the solution, 0 otherwise.

    0
  • Mert Eroglu
    • Gurobi-versary
    • Conversationalist
    • First Question

    Oh OK, i thought adding such constraint would delete the - sign on the 0.0's but it's the same thing.

    Thanks for your support.

    0

Please sign in to leave a comment.