Closed schmidtmj closed 1 year ago
This is not a bug (although the error you get from generate_standard_repn()
is admittedly less than useful -- that will be at least somewhat resolved by #2823).
The short answer is that you have to transform your model into a MIP before sending it to a MIP solver. There are multiple ways (formulations) that you could use when represending the problem as a MIP, and Pyomo won't guess which one is most appropriate for your model. The new piecewise library provides utilities to convert the model to a MIP in two steps: first a transformation to replace the PiecewiseLinearFunction with equivalent Disjunctions (now the model is a GDP), then in a second step, the GDP is converted to a MIP.
This package is still under development, and we haven't had a chance to complete the documentation for it yet. Until then, you can see the set of supported transformations in pyomo/contrib/piecewise/transform. This includes several conversions from piecewise to GDP (including contrib.piecewise.outer_repn_gdp
, contrib.piecewise.inner_repn_gdp
, and contrib.piecewise.reduced_inner_repn_gdp
), as well as several "convenience" transformations that call both a Piecewise-to-GDP transformation and a GDP-to-MIP transformation (e.g., contrib.convex_combination
, contrib.piecewise.disaggregated_convex_combination
, and contrib.piecewise.multiple_choice
)
Thanks for the kind, informative, and speedy response.
Summary
Hi. I'm new to Pyomo so this may be a user error or a true bug.
I was working with the new pyomo.contrib piecewise library with the hope of using its multi-dimensional piecewise capabilities for an upcoming project. I am able to generate a piecewise function and then use this function to generate an indexed constraint but get an error when trying to solve the model.
It appears that the PiecewiseLinearExpression is an unexpected expression when pyomo generates a standard representation before executing the solver. I got the same error using the 'GLPK' or 'GUROBI' solvers. Maybe this is an issue in how the piecewise linear expression is being generated or registered? but I'm not really a developer so can't quite sort out what has gone wrong.
Happy to answer any other questions. Thanks.
See minimal reproducible example below.
Steps to reproduce the issue
Error Message
Information on your system
Pyomo version: 6.5.1a0 Python version: 3.10.11, running in Jupyter Notebook Operating system: Ubuntu 18.04.6 How Pyomo was installed (PyPI, conda, source): Conda environment with Pip to get latest Pyomo Solver (if applicable): Tried with Gurobi and GLPK and got same result.
Additional information