[Ipopt] Getting 'has no member' error for added member function to get primal variables out of C++ ipopt object
Stefan Vigerske
stefan at math.hu-berlin.de
Tue Aug 29 14:13:56 EDT 2017
Hi,
because mynlp is a pointer to TNLP, which doesn't have a getvalue()
function.
Try either something like ((NS071_NLP*)GetRawPtr(mynlp))->getvalue() or
let mynlp be a pointer to a NS071_NLP:
SmartPtr<NS071_NLP> mynlp = new HS071_NLP();
Stefan
On 08/29/2017 04:06 PM, Alexander Martinez-Marchese wrote:
> 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
>
>
>
>
> _______________________________________________
> Ipopt mailing list
> Ipopt at list.coin-or.org
> https://urldefense.proofpoint.com/v2/url?u=https-3A__list.coin-2Dor.org_mailman_listinfo_ipopt&d=DwICAg&c=Ngd-ta5yRYsqeUsEDgxhcqsYYY1Xs5ogLxWPA_2Wlc4&r=BRcuJnQr5NAzU29t80hk2rsLc4vrlRySBDabuq0O1ZI&m=pnBELr-MG4PMObzu0y0yuh5yFXt5BWmRT6ioQbSj3rI&s=JRMVb0xwmYH4mnsIKb_Y0JAv7eAhsh35D5Y7FGMMMzk&e=
>
--
http://www.gams.com/~stefan
More information about the Ipopt
mailing list