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.
- Parameters:
args – (Var, or list or iterable of Var) 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.
Deprecated since version 12.0: Passing a
tupledict
as thevars
argument is deprecated. To take the AND concatenation over all variables in a tupledicttd
, passtd.values()
.
- 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 or iterable of Var) 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.
Deprecated since version 12.0: Passing a
tupledict
as thevars
argument is deprecated. To take the MAX over all variables in a tupledicttd
, passtd.values()
.
- 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 or iterable of Var) 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.
Deprecated since version 12.0: Passing a
tupledict
as thevars
argument is deprecated. To take the MIN over all variables in a tupledicttd
, passtd.values()
.
- or_(*args)#
Used to set a binary decision variable equal to the logical OR of a list of other binary decision variables.
- Parameters:
args – (Var, or list or iterable of Var) 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.
Deprecated since version 12.0: Passing a
tupledict
as thevars
argument is deprecated. To take the OR concatenation over all variables in a tupledicttd
, passtd.values()
.
- norm(vars, which)#
Used to set a decision variable equal to the norm of other decision variables.
- Parameters:
vars – (list or iterable of Var, 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.
Deprecated since version 12.0: Passing a
tupledict
as thevars
argument is deprecated. To take the NORM over all variables in a tupledicttd
, passtd.values()
.