This is an XY problem, where:
Problem X: My pyomo model, solved using ipopt reports an “optimal” solution. But the values obtained after solving, when substituted into the model, violate 1 or more of the constraints.
Problem Y: How to evaluate Left and Right sides of a pyomo constraint (either inequality or equality), to determine constraint violation? Or how to determine margin of constraint violation? (printing left and right sides of pyomo constraint might be more informative however). Even more useful, would be a method that can take as input an expression, a mapping of variable names, and values (e.g. the reported “optimal” solution by Pyomo), and outputs the expression with the variable evaluated at that value.
The closest I’ve found to this is the “ExpressionReplacementVisitor” Example on the page https://pyomo.readthedocs.io/en/stable/developer_reference/expressions/managing.html#evaluating-expressions. I could envision a method that visits each node in an expression tree, and evaluates it using the given mapping.
Is there an existing method to evaluate an expression using a given mapping? And, is there an easier way to debug Problem “X”?
The model is quite large, or else I’d share some code. Thanks.