Try our new documentation site (beta).


GRBcblazy

int GRBcblazy ( void *cbdata,
    int lazylen,
    const int *lazyind,
    const double *lazyval,
    char lazysense,
    double lazyrhs )

Add a new lazy constraint to the MIP model from within a user callback routine. Note that this routine can only be called when the where value on the callback routine is either GRB_CB_MIPNODE or GRB_CB_MIPSOL (see the Callback Codes section 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 querying the current node solution (by calling GRBcbget from a GRB_CB_MIPSOL or GRB_CB_MIPNODE callback, using what=GRB_CB_MIPSOL_SOL or what=GRB_CB_MIPNODE_REL), and then calling GRBcblazy() 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 the LazyConstraints parameter if you want to use lazy constraints.

Return value:

A non-zero return value indicates that a problem occurred while adding the lazy constraint. Refer to the Error Code table for a list of possible return values. Details on the error can be obtained by calling GRBgeterrormsg.

Arguments:

cbdata: The cbdata argument that was passed into the user callback by the Gurobi optimizer. This argument must be passed unmodified from the user callback to GRBcblazy().

lazylen: The number of non-zero coefficients in the new lazy constraint.

lazyind: Variable indices for non-zero values in the new lazy constraint.

lazyval: Numerical values for non-zero values in the new lazy constraint.

lazysense: Sense for the new lazy constraint. Options are GRB_LESS_EQUAL, GRB_EQUAL, or GRB_GREATER_EQUAL.

lazyrhs: Right-hand-side value for the new lazy constraint.

Example usage:

  if (where == GRB_CB_MIPSOL) {
    int lazyind[] = {0, 1};
    double lazyval[] = {1.0, 1.0};
    error = GRBcblazy(cbdata, 2, lazyind, lazyval, GRB_LESS_EQUAL, 1.0);
    if (error) return 0;
  }

Try Gurobi for Free

Choose the evaluation license that fits you best, and start working with our Expert Team for technical guidance and support.

Evaluation License
Get a free, full-featured license of the Gurobi Optimizer to experience the performance, support, benchmarking and tuning services we provide as part of our product offering.
Academic License
Gurobi supports the teaching and use of optimization within academic institutions. We offer free, full-featured copies of Gurobi for use in class, and for research.
Cloud Trial

Request free trial hours, so you can see how quickly and easily a model can be solved on the cloud.

Search

Gurobi Optimization