coin-or/Ipopt

I/O via C++

matheusdiogenesandrade opened this issue · 2 comments

Hello.

I would like to know if there is some way of reading an MINLP instance (in format ams, gms, mod, nl, or osil), and inputting it to Ipopt, and retrieving the solution via C++. The example given at Ipopt C++ tutorial, shows how to write an NLP by using the Ipopt::TNLP class, however, I would like to read an NLP file (for instance alan.nl) via C++. Also I would like to know if it is possible to dump solving information after running Ipopt, for instance, storing in variables the results for:

  • Objective;
  • Dual infeasibility;
  • Constraint violation;
  • Variable bound violation;
  • Complementarity;
  • Overall NLP error;
  • Number of objective function evaluations;
  • Number of objective gradient evaluations;
  • Number of equality constraint evaluations;
  • Number of inequality constraint evaluations;
  • Number of equality constraint Jacobian evaluations;
  • Number of inequality constraint Jacobian evaluations;
  • Number of Lagrangian Hessian evaluations;
  • Total seconds.

For doing this, one could write a C++ program that delegates the task to a terminal command, and then apply a grep over the output. However, I would like to know if there is any more elegant way of doing this.

Thanks for the attention, and regards.

The C++ tutorial show how to specify a NLP via evaluation/derivative/etc callbacks, but not how to write a NLP to a file.

Ipopt includes a reader for AMPL's .nl format. You should be able to use this also from C++ by following the logic of the Ipopt executable: https://github.com/coin-or/Ipopt/blob/stable/3.14/src/Apps/AmplSolver/ampl_ipopt.cpp
You'll need to link to libipoptamplinterface as well to use the AMPL/.nl interface.
You need to make ASL available when building Ipopt.

ams, gms, mod are formats of modeling languages. To fully support this, the respective modeling systems (AIMMS, GAMS, AMPL) are necessary. They can read and understand these formats and are responsible to turn an algebraic model into a problem (model instance) that a solver can handle. AMPL writes .nl files for this purpose, GAMS has something similar. The ams/gms/mod instances in MINLPLib may look easy to parse, but they only use a small subset of the constructs available in these modeling languages.

osil is an xml format to describe a specific instance. There is no OSiL reader included with Ipopt itself. OSiL has its origins in the OS project (https://github.com/coin-or/OS), which includes an OSiL reader and Ipopt interface.
OS does not seem to be developed anymore, so I think your best choice is to rely on Ipopt's interface to .nl files.

You can query a SolveStatistics object for various information on the Ipopt solve after the solve (https://coin-or.github.io/Ipopt/classIpopt_1_1IpoptApplication.html#a86eebc7de69fe41afdf308a9b4b04ee5).

The C++ tutorial show how to specify a NLP via evaluation/derivative/etc callbacks, but not how to write a NLP to a file.

Ipopt includes a reader for AMPL's .nl format. You should be able to use this also from C++ by following the logic of the Ipopt executable: https://github.com/coin-or/Ipopt/blob/stable/3.14/src/Apps/AmplSolver/ampl_ipopt.cpp You'll need to link to libipoptamplinterface as well to use the AMPL/.nl interface. You need to make ASL available when building Ipopt.

ams, gms, mod are formats of modeling languages. To fully support this, the respective modeling systems (AIMMS, GAMS, AMPL) are necessary. They can read and understand these formats and are responsible to turn an algebraic model into a problem (model instance) that a solver can handle. AMPL writes .nl files for this purpose, GAMS has something similar. The ams/gms/mod instances in MINLPLib may look easy to parse, but they only use a small subset of the constructs available in these modeling languages.

osil is an xml format to describe a specific instance. There is no OSiL reader included with Ipopt itself. OSiL has its origins in the OS project (https://github.com/coin-or/OS), which includes an OSiL reader and Ipopt interface. OS does not seem to be developed anymore, so I think your best choice is to rely on Ipopt's interface to .nl files.

You can query a SolveStatistics object for various information on the Ipopt solve after the solve (https://coin-or.github.io/Ipopt/classIpopt_1_1IpoptApplication.html#a86eebc7de69fe41afdf308a9b4b04ee5).

Thank you very much.