Skip to main content

Constant Variable




  • Eli Towle
    Gurobi Staff Gurobi Staff

    Hi Barak,

    The best way to handle this on your end is to simply set the lower and upper bounds of those variables to the same value. Before doing anything else, Gurobi performs a "presolve" step that is meant to create an equivalent version of the model that is (hopefully) smaller and easier to solve. Gurobi then solves this presolved model and maps the presolved solution back to the original variable space. The presolve step can remove unnecessary constraints and variables, tighten variable bounds, combine variables together, etc. Gurobi replaces fixed variables in the original model with constants in the presolved model, so you don't have to worry about doing this yourself.

    You can read more about presolve here.


  • Yuguang Wu
    First Comment

    Thanks, Eli. This answers exactly what I was concerning!

    And greetings from UW:)

    Just a quick follow-up question: Say I have terms like "parameter*variable" in the objective/constraints. For coding reasons, I prefer to define the "parameter" as a gurobi model variable with lb=ub. Will Presolve easily identify those terms as linear instead of quadratic?

    Btw, the reason for doing this is that I need to repeatedly solve the same model with different parameter values. And it is not very easy to keep track of pointers to the changing parameters. 

  • Eli Towle
    Gurobi Staff Gurobi Staff

    Hi, Yuguang! Yes, presolve should replace the fixed variables with constants. However, it would be more intuitive (and easier, I believe) to accomplish this with the API functions. For example, in C++, you can change constraint coefficients using GRBModel::chgCoeff()/GRBModel::chgCoeffs(). Objective coefficients can be modified by setting the Obj variable attribute.


Please sign in to leave a comment.