Skip to main content

How do I set subset of variables to constant value or disable optimization

Answered

Comments

5 comments

  • Jonasz Staszek
    Community Moderator Community Moderator
    Gurobi-versary
    Thought Leader
    First Question

    Hi!

    This can be efficiently done in two ways:

    1. Add a constraint and set a variable to zero:

    model.addLConstr(x[n,m] == 0)

    By the way, you can sum all the variables you want to be fixed to zero on the left-hand side instead of having variable-many constraints.

    2. Set the bounds on variables you wish to "lock":

    x[n,m].lb = 0
    x[n,m].ub = 0

    This needs to be done for each variable individually.

    Hope this helps.

    Best regards
    Jonasz

    0
  • Danning Xie
    Gurobi-versary
    Conversationalist
    First Question

    Hi,

    Thank you! 

    I wonder by the design of Gurobi, will these two methods help accelerate the optimization or reduce the search space?

     

     

    Danning

    0
  • Jonasz Staszek
    Community Moderator Community Moderator
    Gurobi-versary
    Thought Leader
    First Question

    This question is better suited to Gurobi staff.

    From my own experience, the variables which may only assume one value are removed in the presolve and hence reduce the search space. The more variables you "fix", the smaller the search space becomes and hence you can hope for a faster solution process.

    0
  • Jaromił Najman
    Gurobi Staff Gurobi Staff

    Jonasz is correct. Fixed variables are removed in the presolve step and thus reduce the search space, which in general often results in a faster optimization process.

    Best regards, 
    Jaromił

    0
  • Danning Xie
    Gurobi-versary
    Conversationalist
    First Question

    Thank you Jonasz and Jaromił. This helps a lot.

     

    Danning

    0

Please sign in to leave a comment.