<div dir="ltr"><div><div><div>Hi<br><br>To call Ipopt from the C++ API, you must implement your own class deriving from TNLP (it is called "mynlp" in the examples). So, you just have to create appropriated fields in your new class "mynlp":<br><br>For example:<div><br></div>class mynlp : public TNLP {<br> <br></div>public:<br><br></div> double frequency; //THAT IS A FIELD USED TO STORE THE FREQUENCY USED BY EVALUATION<br><br> /** Method to return the constraint residuals */<br> virtual bool eval_g(Index n, const Number* x, bool new_x, Index m, Number* g)<br> {<br></div> //here you put your evaluation code using frequency field<br><div> } <br><br><div> ... <br><div>}<br><br><br></div><div>So, inside your loop, you just have to change the field frequency from the evaluation object:<br><br> <br><br> for (//execute as long as file not empty)<br> omega2 = // frequency read from file <br><br></div><div> mynlp->frequency = omega2<br></div><div><br><div> // Ask Ipopt to solve the problem, using this new frequency, that will result in a new "eval_g"</div><div> status = app->OptimizeTNLP(mynlp);</div><div> end <br></div></div><div><br><br></div><div>Is it clear? If you have questions, you can read about C++ classes or global variables or contact me! <br><br></div><div>Hugs<br><br></div><div>Wendel<br></div><div><br><br></div></div></div></div><div class="gmail_extra"><br><div class="gmail_quote">2017-08-14 22:32 GMT-03:00 Chintan Pathak <span dir="ltr"><<a href="mailto:cp84@uw.edu" target="_blank">cp84@uw.edu</a>></span>:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Dear All, <div><br></div><div>I am trying to solve an optimization problem, that has to be solved for different values of frequencies, that are to be read from a file. </div><div><br></div><div>How do I pass these values to 'mynlp' object ? </div><div><br></div><div>For example, consider the example C++ code from the IPOPT github repo: <a href="https://urldefense.proofpoint.com/v2/url?u=https-3A__github.com_coin-2Dor_Ipopt_blob_master_Ipopt_examples_hs071-5Fcpp_hs071-5Fmain.cpp&d=DwMFaQ&c=Ngd-ta5yRYsqeUsEDgxhcqsYYY1Xs5ogLxWPA_2Wlc4&r=AEWIZiNSSlppb_jyQKA8GtHkg2N4WiI7Ya5btonYBgA&m=eLJOMxVxQsI09epUho-KFkK9KZPXe1G4si0S2IMpa6M&s=w59Aib_lTzNH9nxH1HUkVsqIPtr6oIpc8BpKTyMsKd8&e=" target="_blank">https://github.com/coin-<wbr>or/Ipopt/blob/master/Ipopt/<wbr>examples/hs071_cpp/hs071_main.<wbr>cpp</a> . </div><div><br></div><div>Here the "mynlp" object is instantiated, while the member functions exist in : <a href="https://urldefense.proofpoint.com/v2/url?u=https-3A__github.com_coin-2Dor_Ipopt_blob_master_Ipopt_examples_hs071-5Fcpp_hs071-5Fnlp.cpp&d=DwMFaQ&c=Ngd-ta5yRYsqeUsEDgxhcqsYYY1Xs5ogLxWPA_2Wlc4&r=AEWIZiNSSlppb_jyQKA8GtHkg2N4WiI7Ya5btonYBgA&m=eLJOMxVxQsI09epUho-KFkK9KZPXe1G4si0S2IMpa6M&s=OM5yd9E9EUbXcEzQen7Q4bgltnNK5xNdyvyrOHHps2Q&e=" target="_blank">https://github.com/coin-or/<wbr>Ipopt/blob/master/Ipopt/<wbr>examples/hs071_cpp/hs071_nlp.<wbr>cpp</a> . </div><div><br></div><div>Now, I want to be able to solve the IPOPT problem iteratively with a different value of frequency that is needed in the "eval_g". To do this, I can write a for loop in "main" to read frequencies from a file, but I want to know, how to pass those values to "eval_g" ?</div><div><br></div><div>So, ultimately the code would be : <br><br> for (//execute as long as file not empty)<br> omega2 = // frequency read from file </div><div> // Ask Ipopt to solve the problem, using this new frequency, that will result in a new "eval_g"</div><div> status = app->OptimizeTNLP(mynlp);</div><div> end </div><div><br></div><div><br></div><div>Thanks </div><div>Chintan Pathak </div><div>Research Scientist, </div><div>MAPLE Lab, UW </div><div><br></div><div><br></div><div><br></div><div><br clear="all"><div><div class="m_-5345816165297187602gmail_signature"><div dir="ltr"><a href="https://urldefense.proofpoint.com/v2/url?u=https-3A__about.me_chintanpathak&d=DwMFaQ&c=Ngd-ta5yRYsqeUsEDgxhcqsYYY1Xs5ogLxWPA_2Wlc4&r=AEWIZiNSSlppb_jyQKA8GtHkg2N4WiI7Ya5btonYBgA&m=eLJOMxVxQsI09epUho-KFkK9KZPXe1G4si0S2IMpa6M&s=nmkCtqOUqlK3pnt4OB1q4OFASdD6RqritOxMx9NHy5Y&e=" target="_blank">https://about.me/chintanpathak</a></div></div></div>
</div></div>
<br>______________________________<wbr>_________________<br>
Ipopt mailing list<br>
<a href="mailto:Ipopt@list.coin-or.org">Ipopt@list.coin-or.org</a><br>
<a href="https://urldefense.proofpoint.com/v2/url?u=https-3A__list.coin-2Dor.org_mailman_listinfo_ipopt&d=DwICAg&c=Ngd-ta5yRYsqeUsEDgxhcqsYYY1Xs5ogLxWPA_2Wlc4&r=AEWIZiNSSlppb_jyQKA8GtHkg2N4WiI7Ya5btonYBgA&m=eLJOMxVxQsI09epUho-KFkK9KZPXe1G4si0S2IMpa6M&s=5VpVVJ6IECv8SViuBhCkGRi70FvjhFR-a7wvCJNVZBU&e=" rel="noreferrer" target="_blank">https://urldefense.proofpoint.<wbr>com/v2/url?u=https-3A__list.<wbr>coin-2Dor.org_mailman_<wbr>listinfo_ipopt&d=DwICAg&c=Ngd-<wbr>ta5yRYsqeUsEDgxhcqsYYY1Xs5ogLx<wbr>WPA_2Wlc4&r=AEWIZiNSSlppb_<wbr>jyQKA8GtHkg2N4WiI7Ya5btonYBgA&<wbr>m=eLJOMxVxQsI09epUho-<wbr>KFkK9KZPXe1G4si0S2IMpa6M&s=<wbr>5VpVVJ6IECv8SViuBhCkGRi70FvjhF<wbr>R-a7wvCJNVZBU&e=</a><br>
<br></blockquote></div><br><br clear="all"><br>-- <br><div class="gmail_signature" data-smartmail="gmail_signature">Wendel</div>
</div>