Closed mcpiroman closed 3 years ago
I recommend a conditional statement to catch that:
if x>=1:
vars = [m.Var() for i in range(x)]
m.Equation(m.sum(vars) <= 0)
Otherwise the equation is empty on the left side as sum([])<=0
.
There is an active Gekko discussion on StackOverflow. It is easier for others to find questions such as this if you would consider posting future questions there.
Otherwise the equation is empty on the left side as sum([])<=0.
More precisely this gives 0 <= 0
.
I wonder if this shouldn't be handled at the framework level, since such equations are technically correct and always true and so they should be accepted. This would make it easier to work with such cases. Or at least I would clarify the error message to indicate identity, but perhaps this isn't to be done as the gekko level.
Say I have code like:
The problem is, if x becomes zero then
sum(vars)
gives 0 andm.solve()
yields:I guess that's because the equality becomes an identity and at some point the inequality operation is optimized out. Is there a way around that? Or do I have to manually look for identities before invoking
Equation
?