0

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?

Jasper
  • 155
  • 1
  • 8

1 Answers1

2

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).

Greg Glockner
  • 5,433
  • 2
  • 20
  • 23
  • Thank you for your quick response! I'm setting the branching priority by hand already, and the less important variables all have branching priority 1, whereas the others have higher values. Does this achieve the same goal, or is there something special about negative branching priorities that I'm missing? – Jasper Jan 16 '18 at 14:26
  • 1
    The key issue is that the low priority variables should have a smaller value of BranchPriority; I assumed you used the default value of BranchPriority (0) for all other variables. – Greg Glockner Jan 16 '18 at 21:37