[Ipopt] Passing additional data to TNLP methods

Stefan Vigerske stefan at math.hu-berlin.de
Mon Apr 25 10:49:36 EDT 2011


Hi,

> Ipopt looks like a terrific package, and I am interested in trying it out using the C and C++ interfaces for some statistical estimation problems.  But in going through the documentation and mailing lists, I do not see how one could pass additional objects (like an array of data) to the functions that compute the objective, gradient and Hessian.  Is there a way to do that, or do model parameters need to be hard-coded in?  I've considered using global variables, but that just doesn't seem like it should be the best solution.
>
> Could someone kindly point me to an example of what I need to do?  I should mention up front that I am  new to C++, having done most of my coding in C in the past, so many object-oriented concepts are new to me.  But an example of how to do this would be very helpful.

Well, it was discussed on the mailing list from time to time, see, e.g., 
the "Runtime modification of the model" thread at 
http://list.coin-or.org/pipermail/ipopt/2011-February/thread.html

What you have to do is to derive your own class from the TNLP class such 
that it has some additional members to store your data. You have to pass 
in your data (e.g., in the constructor) to a TNLP instantionation before 
you pass it to the IpoptApplications' OptimizeTNLP method.

So something like
class MyTNLP : public Ipopt::TNLP {
   double a;
public:
   MyTNLP(double& a_)
   : a(a_)
   { }

   /* implementation of usual TNLP functions...
      they can access the member variable a */
}

and use this class via

SmartPtr<TNLP> mytnlp = new MyTNLP(42.0);
ipopt->OptimizeTNLP(mytnlp);

Stefan

>
> Thanks,
>
> Michael Braun
> braunm _at_ mit.edu
>
>
>
>
> _______________________________________________
> Ipopt mailing list
> Ipopt at list.coin-or.org
> http://list.coin-or.org/mailman/listinfo/ipopt
>



More information about the Ipopt mailing list