Constant Variable
AnsweredI have some ILP formulation I came up.
It is very convenient in my formulation to have some binary ( maybe even integer) variables that are constant.
For example a parity variable that for a specific known node it has a value of one.
I went through the documentation and haven't found anything.
Of course I can find a way to not use that variable, but it would create a very messy code.
From what I know I can use the ub and lb attributes to handle this problem (for binary I just need one of them), but I am not sure if gurobi knows how to handle it well (solving the LP problem and then adjusting the variables that are constant sounds costly. One can simply can get read of variables which makes the forumlations much more understandable).
Does Gurobi have some mechanism to handle constants variables?

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.
Eli
0 
Thanks, Eli. This answers exactly what I was concerning!
And greetings from UW:)
Just a quick followup 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.
0 
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.
0
Please sign in to leave a comment.
Comments
3 comments