[Ipopt] How to iteratively solve IPOPT problem using the C++ interface ?

Wendel Melo wendelalexandre at gmail.com
Mon Aug 14 22:04:11 EDT 2017


Hi

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":

For example:

class mynlp : public TNLP {

public:

   double frequency;    //THAT IS A FIELD USED TO STORE THE FREQUENCY USED
BY EVALUATION

   /** Method to return the constraint residuals */
    virtual bool eval_g(Index n, const Number* x, bool new_x, Index m,
Number* g)
    {
        //here you put your evaluation code using frequency field
    }

    ...
}


So, inside your loop, you just have to change the field frequency from the
evaluation object:



 for (//execute as long as file not empty)
        omega2 = // frequency read from file

        mynlp->frequency = omega2

          // Ask Ipopt to solve the problem, using this new frequency, that
will result in a new "eval_g"
         status = app->OptimizeTNLP(mynlp);
  end


Is it clear? If you have questions, you can read about C++ classes or
global variables or contact me!

Hugs

Wendel



2017-08-14 22:32 GMT-03:00 Chintan Pathak <cp84 at uw.edu>:

> Dear All,
>
> 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.
>
> How do I pass these values to 'mynlp' object ?
>
> For example, consider the example C++ code from the IPOPT github repo:
> https://github.com/coin-or/Ipopt/blob/master/Ipopt/
> examples/hs071_cpp/hs071_main.cpp
> <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=>
> .
>
> Here the "mynlp" object is instantiated, while the member functions exist
> in : https://github.com/coin-or/Ipopt/blob/master/Ipopt/
> examples/hs071_cpp/hs071_nlp.cpp
> <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=>
> .
>
> 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" ?
>
> So, ultimately the code would be :
>
>    for (//execute as long as file not empty)
>         omega2 = // frequency read from file
>           // Ask Ipopt to solve the problem, using this new frequency,
> that will result in a new "eval_g"
>          status = app->OptimizeTNLP(mynlp);
>   end
>
>
> Thanks
> Chintan Pathak
> Research Scientist,
> MAPLE Lab, UW
>
>
>
>
> https://about.me/chintanpathak
> <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=>
>
> _______________________________________________
> 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=AEWIZiNSSlppb_
> jyQKA8GtHkg2N4WiI7Ya5btonYBgA&m=eLJOMxVxQsI09epUho-
> KFkK9KZPXe1G4si0S2IMpa6M&s=5VpVVJ6IECv8SViuBhCkGRi70FvjhFR-a7wvCJNVZBU&e=
>
>


-- 
Wendel
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://list.coin-or.org/pipermail/ipopt/attachments/20170814/e929be1b/attachment.html>


More information about the Ipopt mailing list