Open OOAmusat opened 3 weeks ago
The quick, easy fix is to just set the equalities_only
option in get_jacobian
to True
. However, that misses out on potential issues. Equalities shouldn't be near parallel to each other, and equalities shouldn't be near parallel to any inequalities. The nuance comes in when comparing inequalities to other inequalities. I think what we want to do is get normal vectors that point out of the feasible region and check whether the inner product of those normal vectors is greater than zero. We can find a unique normal vector in 2D, but, off the top of my head, I'm not sure what to do in higher dimensions.
@Robbybp , what do you think?
Also, incidentally, why are you using Constraints
here? Setting variable bounds on m.fs[key].hw_tank.T[0]
would generally be better form. The difference is that a solver like IPOPT allows transient violation of Constraints
, but will truncate steps to keep variables within their bounds.
Actually, taking the gradient gives the normal vector already (for some reason I thought it gave a tangent vector), so we should be golden. We just need to partition the Jacobian between equality and inequality constraints, make sure the inequality constraints have appropriate signs based on whether they have lower bounds, upper bounds, or both, then apply the same test without taking the absolute value of the inner product.
Also, incidentally, why are you using
Constraints
here? Setting variable bounds onm.fs[key].hw_tank.T[0]
would generally be better form. The difference is that a solver like IPOPT allows transient violation ofConstraints
, but will truncate steps to keep variables within their bounds.
I set the variable bounds. I came across when I started trying out different formulations for an infeasible model (I wanted to see if using constraints instead of bounds would help).
Yeah, it shouldn't be too hard to exclude inequality-inequality pairs. Although I don't think parallel inequality-equality pairs are too big of a problem, so I'd be happy with just omitting inequalities.
Running the diagnostics toolbox on a model with inequality constraints enforcing variable bounds is throwing up
display_near_parallel_constraints()
warnings:MWE:
Diagnostics box output
According to @andrewlee94, this issue is possibly because we do not distinguish between equality and inequality constraints in the check.