Search code examples
pythonlinear-programminggurobiinteger-programmingmixed-integer-programming

GurobiPy; Change continuous [0,1] variable to binary in callback routine


I'm using the Gurobi Python interface gurobipy. I have a model formulation with a lot of variables. I would like to initialize less important variables that are supposed to be binary as continuous variables, and to change them to binary when needed. However, this will not happen very often.

I have tried the solution from the answer to a similar question, but this needs to rebuild the model. Rebuilding the model in the callback routine at GRB.Callback.MIPSOL causes a crash.

Is this possible? Or am I supposed to introduce all variables as binary, and deal with these cases in GRB.Callback.MIPNODE?


Solution

  • Gurobi Optimizer does not support changing variable types (VType attribute) inside a callback. The better way to handle the "less important variables" is to set their BranchPriority attribute to a negative value (< 0).