xpress.Or
xpress.Or |
Purpose
Returns a logical OR of two or more binary variables or expressions.
Synopsis
xpress.Or(variables)
Argument
variables
|
A list/array of binary variables or binary expressions
|
Example
The following example shows how to use
or 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.Or(x[1:])) # Forces the logical OR between some logical expressions to # be one, i.e., at least one of them must be one p.addConstraint (xp.Or([x[1] & x[4], x[2] & x[1], x[3] & x[6]]) == 1)
Further information
1. For
OR functions, all variables and expressions must be binary; an error will be generated otherwise.
2. A function call
xpress.Or(x1,x2,...,xk) is equivalent to
x1 or (x2 or (x3 or ... xk))...).
3. Note that since
x1,
x2, ...,
xk, are binary variables,
xpress.Or(x1,x2,...,xk) is equivalent to
xpress.max(x1,x2,...,xk).
Related topics