Reputation: 1
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.
Upvotes: 0
Views: 243
Reputation: 16724
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.
Upvotes: 0