addGenConstrIndicator ( binvar, binval, lhs, sense=None, rhs=None, name="" )
Add a new general constraint of type GRB.GENCONSTR_INDICATOR to a model.
An INDICATOR constraint states that if the binary indicator variable is equal to , then the linear constraint should hold. On the other hand, if , the linear constraint may be violated. The sense of the linear constraint can also be specified to be or .
Note that the indicator variable of a constraint will be forced to be binary; independently of how it was created.
binvar (Var): The binary indicator variable.
binval (Boolean): The value for the binary indicator variable that would force the linear constraint to be satisfied.
lhs (float, Var, LinExpr, or TempConstr): Left-hand side expression for the linear constraint triggered by the indicator. Can be a constant, a Var, or a LinExpr. Alternatively, a temporary constraint object can be used to define the linear constraint that is triggered by the indicator. The temporary constraint object is created using an overloaded comparison operator. See TempConstr for more information. In this case, the ``sense'' and ``rhs'' parameters must stay at their default values None.
sense (char): Sense for the linear constraint. Options are GRB.LESS_EQUAL, GRB.EQUAL, or GRB.GREATER_EQUAL.
rhs (float): Right-hand-side value for the linear constraint.
name (string, optional): Name for the new general constraint.
# x7 = 1 -> x1 + 2 x3 + x4 = 1 model.addGenConstrIndicator(x7, True, x1 + 2*x2 + x4, GRB.EQUAL, 1.0) # alternative form model.addGenConstrIndicator(x7, True, x1 + 2*x2 + x4 == 1.0)