Hi community!
I'm implementing Branch and Cut in Gurobi through Callback and I wish to add a quadratic cut. This quadratic cut is linearized and then will be added to the model.
To linearize the constraint I need to create a new variable and add it to the model. I created a new variable and added to the model, but when I add the restriction that depends on this new variable, the Gurobi sends the message: Error code: 20001. Not in the model
Does the error is due to add a new variable in MIPNODE?
The summary code:
public class Callback extends GRBCallback {
private GRBModel model;
public Callback(GRBModel model ){
this.model = model;
}
protected void callback() {
try {
if( where == GRB.CB_MIPNODE && getIntInfo(GRB.CB_MIPNODE_STATUS) == GRB.OPTIMAL){
varLinear = model.addVar(0.0, Integer.MAX_VALUE, 0.0, GRB.CONTINUOUS, "LinearName" );
this.model.update();
GRBLinExpr linearExpr = new GRBLinExpr();
linearExpr.addTerm(1, varLinear );
linearExpr.addTerm(-BigM, var2 ); // var2 exist
addCut(linearExpr, GRB.LESS_EQUAL, 0);
}
catch (GRBException e) {
System.out.println("Error code: " + e.getErrorCode() + ". " +
e.getMessage());
e.printStackTrace();
}
}
Thanks!