Try our new documentation site (beta).


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 constraints. These are typically not treated directly by the solver. Rather, they are transformed by presolve into mathematically equivalent sets of constraints (and variables), chosen from among the fundamental types listed above. These general constraints are provided as a convenience to users. 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:

  • MAX (Model.addGenConstrMax): set a decision variable equal to the maximum value from among a set of decision variables
  • MIN (Model.addGenConstrMin): set a decision variable equal to the minimum value from among a set of decision variables
  • ABS (Model.addGenConstrAbs): set a decision variable equal to the absolute value of some other decision variable
  • AND (Model.addGenConstrAnd): set a binary variable equal to one if and only if all of a set of binary decision variables are equal to one
  • OR (Model.addGenConstrOr): set a binary variable equal to one if and only if at least one variable out of a set of binary decision variables is equal to one
  • INDICATOR (Model.addGenConstrIndicator): whenever a given binary variable takes a certain value, then the given linear constraint must be satisfied

You can also add 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.

Please refer to this section for additional details on general constraints.

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.