Skip to main content

Variable elimination in Gurobi

Answered

Comments

2 comments

  • Jaromił Najman
    Gurobi Staff Gurobi Staff

    You can use any of the two to get the same effect. However, the two approaches differ.

    With model.remove you completely remove a given variable from the model meaning that you cannot re-use it later in the your algorithm and would have to re-add it to the model.

    For the second approach to work you would either have to add a constraint which sets \(x\) to \(0\) or set its lower and upper bound to \(0\).

    model.addConstr(x[i,j] == 0)

    or

    x[i,j].lb = 0
    x[i,j].ub = 0

    This way you would keep the variables in your model and presolve would take care of those (i.e., presolve would remove these fixed variables from the model). Note that if you turn presolve off then these variables will still hang around in the model, possibly slowing it down.

    Usually, I would go with the second approach. This way, you will have all variables in your model and will not have to think about which ones did you remove or not, i.e., you will not significantly alter your model formulation.

    Best regards, 
    Jaromił

    0
  • Krypt
    Curious
    Gurobi-versary
    Conversationalist

    Got it. Thank you for such a clear interpretation!

    0

Please sign in to leave a comment.