coin-or / CppAD

A C++ Algorithmic Differentiation Package: Home Page
https://cppad.readthedocs.io
Other
469 stars 95 forks source link

How to write the `.lp` file of a Ipopt model? #164

Closed type-null closed 1 year ago

type-null commented 1 year ago

I am trying to debug the model in CppAD using Ipopt. Is there a way to write the model formulation out as a file, such as .lp file? Thanks

bradbell commented 1 year ago

Have you looked at ipopt_solve ? https://cppad.readthedocs.io/en/latest/ipopt_solve.html

type-null commented 1 year ago

Have you looked at ipopt_solve ? https://cppad.readthedocs.io/en/latest/ipopt_solve.html

Yes. I'm trying to write a complicated model so I wondered if I can print out the model before solving it to debug. I couldn't find any function in this documentation to write out the model formulation.

bradbell commented 1 year ago

The model functions are just a sequence of floating point operations. There is a way to print one out but I do not think it will serve your purpose; see https://cppad.readthedocs.io/en/latest/to_json.html

Not only that, but you can input a function this way, see https://cppad.readthedocs.io/en/latest/from_json.html

bradbell commented 1 year ago

Perhaps you could compute the gradient of your objective and the Jacobian of your constraints and then print then to a csv file so that you can look at it in a spread sheet. Would that help ?

type-null commented 1 year ago

Thanks a lot! I ended up with cout variables of interest to debug...

bradbell commented 1 year ago

This issue 164 will be converted to a discussion.