xpress.And
xpress.And |
Purpose
Returns a logical AND of two or more binary variables or expressions.
Synopsis
xpress.And(variables)
Argument
variables
|
A list/array of binary variables or binary expressions
|
Example
The following example shows how to use
and to model various logical constraints:
N = 10 x = xp.vars(N, vartype=xp.binary) # Creates N binary variables c = [1, 4, 7, 3, 5, 7, 8, 4, 4, 9] p = xp.problem(x) # Creates a problem with x, y # Sets a linear objective p.setObjective (xp.Sum(c[i] * x[i] for i in range(N)) # Linear constraint p.addConstraint (xp.Sum(x) <= 6) # Constrains the first x variable to be the conjunction of all other x's p.addConstraint (x[0] == xp.And(x[1:])) # Forces the logical AND between some logical expressions to # be zero, i.e., at least one of them must be zero p.addConstraint (xp.And([x[1] | x[4], x[2] | x[1], x[3] | x[6]]) == 0)
Further information
1. For
AND functions, all variables and expressions must be binary; an error will be generated otherwise.
2. A function call
xpress.And(x1,x2,...,xk) is equivalent to
x1 and (x2 and (x3 and ... xk))...).
3. Note that since
x1,
x2, ...,
xk, are binary variables,
xpress.And(x1,x2,...,xk) is equivalent to
xpress.min(x1,x2,...,xk).
Related topics