Skip to main content

Gurobi- Free Variable

Ongoing

Comments

3 comments

  • Ronald van der Velden
    Gurobi Staff Gurobi Staff

    Could you describe a bit more how you want to use that variable - is it continuous or integer and how do you want to use the variable? The challenge is that computers have limited precision so the question becomes "how close to zero is considered zero". See also this article for more detail.

    0
  • Muhammad Arslan Shahid
    Conversationalist
    First Question

    A continuous variable.

    I want to use a free variable (e.g. x) in a constraint that ensures that "x" should not equal zero and takes any value other than zero that is feasible.

    0
  • Ronald van der Velden
    Gurobi Staff Gurobi Staff

    As you can see in the article, the problem with your constraint is that it's not properly defined when something is "close enough to zero". If 0.0 is not allowed, would 0.001 be allowed, or 0.0001 ?

    If you have a properly defined threshold, you may look at indicator constraints.

    • Give your variable lowerbound -GRB.INFINITY and upperbound +GRB.INFINITY
    • Define a binary variable that is 1 when your continuous variable is positive , 0 when negative
    • Add two indicator constraints linking both variables: When the binary is 1, your continuous variable must be at least equal to the threshold. When it's 0, the continuous variable must not be greater than -threshold.

    Hope this helps!

    Kind regards,
    Ronald

    0

Please sign in to leave a comment.