Try our new documentation site (beta).


GRBcbsolution

int GRBcbsolution ( void *cbdata,
    const double *solution,
    double *objP )

Provide a new feasible solution for a 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 GRB_CB_MIP, GRB_CB_MIPNODE, or GRB_CB_MIPSOL (see the Callback Codes section for more information).

Heuristics solutions are typically built from the current relaxation solution. To retrieve the relaxation solution at the current node, call GRBcbget with what = GRB_CB_MIPNODE_REL.

When providing a solution, you can specify values for any subset of the variables in the model. To leave a variable value unspecified, set the variable to GRB_UNDEFINED in the solution vector. The Gurobi MIP solver will attempt to extend the specified partial solution to a complete solution.

Note that this method is not supported in a Compute Server environment.

Return value:

A non-zero return value indicates that a problem occurred while adding the new solution. 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 GRBcbsolution().

solution: The solution vector. You must provide one entry for each variable in the model. Note that you can leave an entry unspecified by setting it to GRB_UNDEFINED. The Gurobi optimizer will attempt to find appropriate values for the unspecified variables.

objP: Objective value for solution that results from this call. Returns GRB_INFINITY if no improved solution is found or the function has been called from a callback other than GRB_CB_MIPNODE as, in these contexts, the solution is stored instead of being processed immediately.

Example usage:

  if (where == GRB_CB_MIPNODE) {
    error = GRBcbsolution(cbdata, solution, &obj);
    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