Filter Content By
Version
Languages

Each of the functions described below adds a new general constraint to a model.

Mathematical programming has traditionally defined a set of fundamental constraint types: variable bound constraints, linear constraints, quadratic constraints, integrality constraints, and SOS constraints. These are typically treated directly by the underlying solver (although not always), and are fundamental to the overall algorithm.

Gurobi accepts a number of additional constraint types, which we collectively refer to as general (function) constraints. These are typically not treated directly by the solver. Rather, they are transformed by presolve into constraints (and variables) chosen from among the fundamental types listed above. In some cases, the resulting constraint or constraints are mathematically equivalent to the original; in others, they are approximations. If such constraints appear in your model, but if you prefer to reformulate them yourself using fundamental constraint types instead, you can certainly do so. However, note that Gurobi can sometimes exploit information contained in the other constraints in the model to build a more efficient formulation than what you might create.

The additional constraint types that fall under this general constraint umbrella are:

• addGenConstrMax: • addGenConstrMin: • addGenConstrAbs: • addGenConstrAnd: • addGenConstrOr: • addGenConstrIndicator: (an indicator constraint)
• addGenConstrPWL: (a piecewise-linear function, specified using breakpoints)
• addGenConstrPoly: • addGenConstrExp: • addGenConstrExpA: • addGenConstrLog: • addGenConstrLogA: • addGenConstrPow: • addGenConstrSin: • addGenConstrCos: • addGenConstrTan: You can also add several types of general constraints through addConstr or addConstrs, using overloaded operators and a few general constraint helper functions. The descriptions below will make note of these equivalent, more concise alternatives.