[Ipopt] Getting 'has no member' error for added member function to get primal variables out of C++ ipopt object

Alexander Martinez-Marchese alex.martinezmarchese at outlook.com
Tue Aug 29 10:06:54 EDT 2017


Hi,

    I would like to optimize a problem in C++ for different problem settings inside a loop. For that I need to get the primal variables outside of the NS071_NLP object (I kept the same name used in the C++ example). I attached a Rosenbrock problem example using the C++ ipopt interface showing the issue.

In the C++ example there is a parent (base) class TNLP and all its functions are instantiated in the NS071_NLP using virtual functions.

I didn't find any functions in TNLP that give you the optimized values. Are there any? So what I tried for a test was to add a function to NS071_NLP called getvalue() {return thevalue;} that gets the first value of the optimized variables (x[]) and added a variable in the NS071_NLP class called double thevalue.

Then when the finalize_solution(* x, etc) from TNLP is called, the x[] goes into it and I added the line:
thevalue = x[0];

After the problem is optimized I try calling mynlp->getvalue() where mynlp is a smart pointer to an NS071_NLP object and I get:

ipoptexample.cpp: In function ‘int main(int, char**)’:
ipoptexample.cpp:202:21: error: ‘class Ipopt::TNLP’ has no member named ‘getvalue’; did you mean ‘eval_f’?
   thevalue = mynlp->getvalue();
                     ^~~~~~~~

Why doesn't this work? As a last resort I could go and change TNLP and add the function there but I should be able to add functions to the child class.


Thank you,
Alex

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://list.coin-or.org/pipermail/ipopt/attachments/20170829/bc62acae/attachment.html>
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: ipoptexample.cpp
URL: <http://list.coin-or.org/pipermail/ipopt/attachments/20170829/bc62acae/attachment.ksh>


More information about the Ipopt mailing list