Skip to main content

Help setting up an absolute value for expressions

Answered

Comments

5 comments

  • Official comment
    Simranjit Kaur
    Gurobi Staff Gurobi Staff
    This post is more than three years old. Some information may not be up to date. For current information, please check the Gurobi Documentation or Knowledge Base. If you need more help, please create a new post in the community forum. Or why not try our AI Gurobot?.
  • Matthias Miltenberger
    Gurobi Staff Gurobi Staff

    Hi Bill,

    The solution values of z and z1 are numerically 0, i.e., with regards to floating-point tolerances. Please consult our guide on numerics for more details on this.

    Cheers,
    Matthias

    1
  • Bill Edwall
    Gurobi-versary
    Conversationalist
    First Question

    So what you're saying is that the optimizer has made the values so small that they effectivly become 0 and the absolute value of -0 is 0?

    On a more hypothetical note. Would the way the code is currently structured work in your opinion or is there some flaw in it?
    If we were to say that z = -2, would z1 then be equal to 2?

    0
  • Matthias Miltenberger
    Gurobi Staff Gurobi Staff

    Any value close enough to 0 is interpreted as 0. When taking the absolute value of a variable, more things happen behind the scenes of the solver than just taking the absolute value of the value in the solution.

    You should maybe relax the z variable to allow negative values in the first place. By default, all variables are non-negative and you need to specify a specific negative lower bound to change that:

    z = m.addVar(lb=-GRB.INFINITY)

    See also the documentation about variables.

    Cheers,
    Matthias

    1
  • Bill Edwall
    Gurobi-versary
    Conversationalist
    First Question

    Thank you so so so much Matthias. 
    You've helped clear this up something immensly.
    Have a wonderful day!

    Cheers, 
    Bill

    0

Post is closed for comments.