Try our new documentation site (beta).
Model.cbCut()
cbCut ( lhs, sense, rhs )
Add a new cutting plane to a MIP model from within a callback function.
Note that this method can only be invoked when the
where
value on the callback function is equal to
GRB.Callback.MIPNODE
(see the
Callback Codes section
for more information).
Cutting planes can be added at any node of the branch-and-cut tree. However, they should be added sparingly, since they increase the size of the relaxation model that is solved at each node and can significantly degrade node processing speed.
Cutting planes are typically used to cut off the current relaxation solution. To retrieve the relaxation solution at the current node, you should first call cbGetNodeRel.
You should consider setting parameter PreCrush to value 1 when adding your own cuts. This setting shuts off a few presolve reductions that can sometimes prevent your cut from being applied to the presolved model (which would result in your cut being silently ignored).
One very important note: you should only add cuts that are implied by the constraints in your model. If you cut off an integer solution that is feasible according to the original model constraints, you are likely to obtain an incorrect solution to your MIP problem.
Note that this method also accepts a TempConstr as its first argument. This allows you to use operator overloading to create constraints. See TempConstr for more information.
Arguments:
lhs: Left-hand side for new cut. Can be a constant, a Var, or a LinExpr.
sense: Sense for new cut (GRB.LESS_EQUAL, GRB.EQUAL, or GRB.GREATER_EQUAL).
rhs: Right-hand side for new cut. Can be a constant, a Var, or a LinExpr.
Example usage:
def mycallback(model, where): if where == GRB.Callback.MIPNODE: status = model.cbGet(GRB.Callback.MIPNODE_STATUS) if status == GRB.OPTIMAL: rel = model.cbGetNodeRel([model._vars[0], model._vars[1]]) if rel[0] + rel[1] > 1.1: model.cbCut(model._vars[0] + model._vars[1] <= 1) model._vars = model.getVars() model.optimize(mycallback)