[Ipopt] Algorithm flow calling f(x) and g(x), same decision variables?

Martijn Disse M.W.Disse at student.tudelft.nl
Mon Sep 10 10:11:34 EDT 2012


Hi Seth,

Thank you for your reply! Your method sounds similar and very clean indeed. I am however using C and not C++. Correct me if I am wrong, but that means unfortunately I cannot use the class.

I know that I can solve the problem using a structure, but perhaps there is a better (cleanera and faster) alternative in C. Any ideas?

Best regards,

-Martijn
________________________________
Van: Seth Watts [seth.e.watts at gmail.com]
Verzonden: maandag 10 september 2012 15:35
To: Martijn Disse
Cc: Stefan Vigerske; ipopt at list.coin-or.org
Onderwerp: Re: [Ipopt] Algorithm flow calling f(x) and g(x), same decision variables?

Hi Martijn -

Using the new_x flag is definitely the correct approach. I have a problem similar to yours in that evaluating the system state for a given set of optimization variables is costly, but once this is done, evaluating each of f, g, grad_f, jac_g is relatively easy.

I include the following as class variables in MyNLP.cpp : my_f, my_g, my_grad_f, my_jac_g. Then, if new_x is true, I call a function to update my model and evaluate all of (my_f, my_g, etc.), and then for example the function eval_f would copy my_f to f. If new_x is false, then the function just needs to copy what is currently in my_f to f.

In case I wasn't clear above, here is pseudocode of eval_f:

bool MyNLP::eval_f(Index n, const Number* x, bool new_x, Number& obj_value)
{
    if(new_x)
    {
        evaluate(<lots of variables>, my_f, my_g, my_df, my_dg);
    }
    obj_value = my_f;
}

Since these are class variables, they are visible to the class functions, so you don't need to explicitly create a structure or pass these variables into the functions. It is a fairly clean implementation.

- Seth

On Mon, Sep 10, 2012 at 3:57 AM, Martijn Disse <M.W.Disse at student.tudelft.nl<mailto:M.W.Disse at student.tudelft.nl>> wrote:
Hi,

Thank you for your response. Just for sake of completeness on this topic: the documentation mentions x_new as:

"new_x: (in), false if any evaluation method was previously called with the same values in x, true otherwise."

I will investigate how to implement this for my particular case.

Best regards,

-Martijn

________________________________________
Van: Stefan Vigerske [stefan at math.hu-berlin.de<mailto:stefan at math.hu-berlin.de>]
Verzonden: maandag 10 september 2012 10:39
To: Martijn Disse
Cc: ipopt at list.coin-or.org<mailto:ipopt at list.coin-or.org>
Onderwerp: Re: [Ipopt] Algorithm flow calling f(x) and g(x), same decision variables?


Hi,

I think Ipopt does not want to give promises on which order functions
are evaluated.
You can check the newx flag that is passed with each function evaluation
to see whether *some* evaluation function has been called for the same
point already.

Stefan

On 09/10/2012 10:12 AM, Martijn Disse wrote:
> Dear all,
>
> In both my cost and constraint function I simulate the same system with an input based on the decision variables and some other non-varying user data.
>
> In the case when the cost and constraint function are called with the same decision variables, to avoid redundant computations, I would would not like to simulate the system twice, but only once.
>
> I want to use a userdata structure to pass on the simulation results from cost to constraints or vice versa. Therefore I am trying to find out how the algorithm flow works:
>
> Does the IPOPT flow ever call cost and constraint with the same decision variables? If so, which one is called first?
>
> I have modified the hs071 example and I found out that the constraint function is called first and then the cost function is called with the same decision variables. Is this generally the case?
>
> I have looking into the publications, but was not very succesfull in finding an answer to my question. I am guessing it is quite a common problem, that why I am asking you :).
>
> I appreciate you help,
>
> Best regards,
>
> Martijn Disse
>
>
>
> _______________________________________________
> Ipopt mailing list
> Ipopt at list.coin-or.org<mailto:Ipopt at list.coin-or.org>
> http://list.coin-or.org/mailman/listinfo/ipopt
>


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://list.coin-or.org/pipermail/ipopt/attachments/20120910/509a9257/attachment-0001.html>


More information about the Ipopt mailing list