[Ipopt] output from Ipopt

Andreas Waechter andreasw at watson.ibm.com
Wed Jun 10 20:31:38 EDT 2009


Hi Crispin,

Sorry for the delayed reply.

If you use the C++ interface for Ipopt, you can put any code you want into 
the finalize_solution method; the HS071 code is just an example.

Typically, you write your own TNLP class, it will have some stuff in the 
constructor for populating the data for optimization problem, maybe some 
other methods to do some data manupilations before you then give your 
class to Ipopt.  After Ipopt is done, it will call the finalize_solution 
method, and there you would typically copy the part of the returned data 
that interests you (usually the values of the optimization variables x) 
into some data member of your TNLP class.  In your main program, you can 
then call some accessor methods of your TNLP class (that you uhave to 
write) to get that data.

Hope this helps,

Andreas

On Fri, 29 May 2009, Dr Crispin H. W. Barnes wrote:

> Hi,
>
> I'm wondering if there is a function I can use to get the final
> solution back to the calling program i.e. something like
>
> double [] results = app->Optimize_TNLP_AND_RETURN_RESULT(mynlp);
>
> in the example we have the function finalize_solution but I don't want
> to write to stdio
>
> void HS071_NLP::finalize_solution(SolverReturn status,
>                                 Index n, const Number* x, const
> Number* z_L, const Number* z_U,
>                                 Index m, const Number* g, const
> Number* lambda,
>                                 Number obj_value,
>                                 const IpoptData* ip_data,
>                                 IpoptCalculatedQuantities* ip_cq)
> {
> // here is where we would store the solution to variables, or write
> to a file, etc
> // so we could use the solution.
>
> // For this example, we write the solution to the console
> printf("\n\nSolution of the primal variables, x\n");
> for (Index i=0; i<n; i++) {
>   printf("x[%d] = %e\n", i, x[i]);
> }
>
> printf("\n\nSolution of the bound multipliers, z_L and z_U\n");
> for (Index i=0; i<n; i++) {
>   printf("z_L[%d] = %e\n", i, z_L[i]);
> }
> for (Index i=0; i<n; i++) {
>   printf("z_U[%d] = %e\n", i, z_U[i]);
> }
>
> printf("\n\nObjective value\n");
> printf("f(x*) = %e\n", obj_value);
>
> printf("\nFinal value of the constraints:\n");
> for (Index i=0; i<m ;i++) {
>   printf("g(%d) = %e\n", i, g[i]);
> }
>
> thanks for you help.
>
> -- 
> Dr Crispin H. W. Barnes
> Thin-Film Magnetism
> Cavendish Laboratory
> University of Cambridge
> J.J. Thomson Ave
> Cambridge CB3 OHE
>
> Tel:  01223 337487
>
> _______________________________________________
> Ipopt mailing list
> Ipopt at list.coin-or.org
> http://list.coin-or.org/mailman/listinfo/ipopt
>
>



More information about the Ipopt mailing list