GRBCallback.addLazy()


GRBCallback.addLazy()

Add a lazy constraint to the MIP model from within a callback function. Note that this method can only be invoked when thewheremember variable is equal toGRB.CB_MIPNODEorGRB.CB_MIPSOL(see theCallback Codessection in the Reference Manual for more information).

Lazy constraints are typically used when the full set of constraints for a MIP model is too large to represent explicitly. By only including the constraints that are actually violated by solutions found during the branch-and-cut search, it is sometimes possible to find a proven optimal solution while only adding a fraction of the full set of constraints.

You would typically add a lazy constraint by first querying the current node solution (by callinggetSolutionfrom aGRB.CB_MIPSOLcallback, orgetNodeRelfrom aGRB.CB_MIPNODEcallback), and then callingaddLazy()to add a constraint that cuts off the solution. Gurobi guarantees that you will have the opportunity to cut off any solutions that would otherwise be considered feasible.

Your callback should be prepared to cut off solutions that violate any of your lazy constraints, including those that have already been added. Node solutions will usually respect previously added lazy constraints, but not always.

Note that you must set theLazyConstraintsparameter if you want to use lazy constraints.

void addLazy( GRBLinExpr lhsExpr,
char sense,
double rhs )
    Arguments:

    lhsExpr: Left-hand side expression for new lazy constraint.

    sense: Sense for new lazy constraint (GRB.LESS_EQUAL,GRB.EQUAL, orGRB.GREATER_EQUAL).

    rhs: Right-hand side value for new lazy constraint.