Skip to main content

Error when building nonlinear constraints using addGenConstrXxx() and addConstr()

Answered

Comments

3 comments

  • Riley Clement
    Gurobi Staff Gurobi Staff

    Hi Christian,

    When I run your code the error that is produced is the following:

    Error code = 10021
    Quadratic equality constraints are non-convex. Set NonConvex parameter to 2 to solve model.

    If you follow the suggestion in the error message, and set the NonConvex parameter to 2:

    environment.set(GRB_IntParam_NonConvex, 2);

    then your model solves quickly.

    To explain the use of this parameter I am pasting an excerpt from our reference manual:

    Solving models with non-convex quadratic constraints is typically much more expensive. To avoid accidentally solving a much harder problem than may have been intended, Gurobi rejects such constraints by default. If you set the NonConvex parameter to 2, however, then Gurobi will accept arbitrary quadratic constraints and attempt to solve the resulting model. 

    - Riley

    0
  • Christian Kallies
    Gurobi-versary
    First Comment
    First Question

    Thanks, setting the parameter solves it.

    In Visual Studio it was just dying without showing the error code.

    0
  • Riley Clement
    Gurobi Staff Gurobi Staff

    Ah, yes I forgot to mention I was error handling:

    try {
    ...
    } catch(GRBException e) {
        cout << "Error code = " << e.getErrorCode() << endl;
      cout << e.getMessage() << endl;
    }

    - Riley

    0

Please sign in to leave a comment.