General Constraint Helper Functions#

Gurobi general constraint helper functions - used in conjunction with overloaded operators and Model.addConstr or Model.addConstrs to build general constraints.

abs_(argvar)#

Used to set a decision variable equal to the absolute value of another decision variable.

Parameters:

argvar – (Var) The variable whose absolute value will be taken.

Example:
m.addConstr(y == gp.abs_(x))
Returns:

Returns a GenExpr object.

and_(*args)#

Used to set a binary decision variable equal to the logical AND of a list of other binary decision variables.

Note that the Gurobi Python interface includes an equivalent all_() function.

Parameters:

args – (Var, or list of Var, or tupledict of Var values) The variables over which the AND concatenation will be taken.

Example:
m.addConstr(z == gp.and_(x, y))
m.addConstr(z == gp.and_([x, y]))
Returns:

Returns a GenExpr object.

max_(*args, constant=None)#

Used to set a decision variable equal to the maximum of a list of decision variables and, if desired, a constant.

Parameters:
  • args – (Var, or list of Var, or tupledict of Var values) The variables over which the MAX will be taken.

  • constant – (float, optional) The constant value to include among the arguments of the MAX operation.

Example:
m.addConstr(z == gp.max_(x, y, constant=3))
m.addConstr(z == gp.max_([x, y], constant=3))
Returns:

Returns a GenExpr object.

min_(*args, constant=None)#

Used to set a decision variable equal to the minimum of a list of decision variables and, if desired, a constant.

Parameters:
  • args – (Var, or list of Var, or tupledict of Var values) The variables over which the MIN will be taken.

  • constant – (float, optional) The constant value to include among the arguments of the MIN operation.

Example:
m.addConstr(z == gp.min_(x, y, constant=3))
m.addConstr(z == gp.min_([x, y], constant=3))
Returns:

Returns a GenExpr object.

or_(*args)#

Used to set a binary decision variable equal to the logical OR of a list of other binary decision variables.

Note that the Gurobi Python interface includes an equivalent any_() function.

Parameters:

args – (Var, or list of Var, or tupledict of Var values) The variables over which the OR concatenation will be taken.

Example:
m.addConstr(z == gp.or_(x, y))
m.addConstr(z == gp.or_([x, y]))
Returns:

Returns a GenExpr object.

norm(vars, which)#

Used to set a decision variable equal to the norm of other decision variables.

Parameters:
  • vars – (list of Var, or tupledict of Var values, or 1-dim MVar) The variables over which the NORM will be taken. Note that this may not contain duplicates.

  • which – (float) Which norm to use. Options are 0, 1, 2, and any value greater than or equal to GRB.INFINITY.

Example:
x = m.addVars(3)
nx = m.addVar()
m.addConstr(nx == gp.norm(x, 1.0))
Returns:

Returns a GenExpr object.