'Pyomo constraint: use continuous variable as boolean?
I am looking to use a continuous variable in a bool statement. For example, if m.N[t] is the continuous variable, I'd like to do the following:
@m.Constraint(m.t) def success(m,t): if m.N[t] == 0: return m.d[t] = 0
I get the following errors:
ERROR: Rule failed when generating expression for Constraint success with index 0: ValueError: Constraint 'success[0]': rule returned None.
Constraint rules must return either a valid expression, a 2- or 3-member
tuple, or one of Constraint.Skip, Constraint.Feasible, or
Constraint.Infeasible. The most common cause of this error is forgetting
to include the "return" statement at the end of your rule.
ERROR: Constructing component 'success' from data=None failed: ValueError: Constraint 'success[0]': rule returned None.
Constraint rules must return either a valid expression, a 2- or 3-member
tuple, or one of Constraint.Skip, Constraint.Feasible, or
Constraint.Infeasible. The most common cause of this error is forgetting
to include the "return" statement at the end of your rule.
Solution 1:[1]
You cannot do this. There is a way to simulate a binary variable by imposing the constraint
x*(1-x) = 0
but that is much worse than just using a binary variable.
To be complete: there is a GDP (Generalized Disjunctive Programming) extension.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Erwin Kalvelagen |
