<html dir="ltr">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body bgcolor="#FFFFFF" fpstyle="1" ocsi="0">
<div style="direction: ltr;font-family: Tahoma;color: #000000;font-size: 10pt;">Hi Andreas, Seth,
<div><br>
</div>
<div>I have&nbsp;successfully&nbsp;implemented the use of the &quot;new_x&quot;&nbsp;Boolean and the UserDataPtr which I already used. The performance increase was however not so high for the following reason:</div>
<div><br>
</div>
<div>I am using a finite-differences method (djacobix from Intel MKL) to find the gradient and jacobian, since no analitical expressions can be found (g(x) and f(x) require simulating the system). As a result,&nbsp;unfortunately, to be able to find these finite
 differences the system needs to be simulated entirely for different values of x... Hence, the flag &quot;new_x&quot; is useless in the gradient and jacobian function and can only be used in the&nbsp;</div>
<div><br>
</div>
<div>I also found a jacobian estimator build in IPOPT, but I do not know how efficient this method will be since no information is available in the documentation. It is slightly faster than the intel MKL djacobi function. Is this because it uses the x_new variable
 in a 'smart' way?</div>
<div><br>
</div>
<div>Maybe I have overlooked something here w.r.t. efficient use of finite-differences methods i.c.w. IPOPT. If so, please let me know.</div>
<div><br>
</div>
<div>Best regards,</div>
<div><br>
</div>
<div>Martijn Disse</div>
<div><br>
</div>
<div><br>
</div>
<div><br>
<div style="font-family: Times New Roman; color: #000000; font-size: 16px">
<hr tabindex="-1">
<div id="divRpF517476" style="direction: ltr; "><font face="Tahoma" size="2" color="#000000"><b>Van:</b> ipopt-bounces@list.coin-or.org [ipopt-bounces@list.coin-or.org] namens Andreas Waechter [awaechter.iems@gmail.com]<br>
<b>Verzonden:</b> maandag 10 september 2012 17:53<br>
<b>To:</b> ipopt@list.coin-or.org<br>
<b>Onderwerp:</b> Re: [Ipopt] Algorithm flow calling f(x) and g(x), same decision variables?<br>
</font><br>
</div>
<div></div>
<div>
<div class="moz-cite-prefix">Martijn,<br>
<br>
Also the C interface has a &quot;new_x&quot; input to the function calls.&nbsp; Also, if you want to avoid global variables to carry around information between the different function calls, the &quot;UserDataPtr&quot; might come in handy.<br>
<br>
<pre class="moz-signature" cols="72">Andreas Waechter

Associate Professor
Department of Industrial Engineering and Management Sciences
McCormick School of Engineering
Northwestern University
Evanston, IL 60208
USA
<a class="moz-txt-link-freetext" href="http://users.iems.northwestern.edu/~andreasw/" target="_blank">http://users.iems.northwestern.edu/~andreasw/</a></pre>
On 09/10/2012 09:11 AM, Martijn Disse wrote:<br>
</div>
<blockquote type="cite"><style type="text/css" id="owaParaStyle"></style>
<div style="direction:ltr; font-family:Tahoma; color:#000000; font-size:10pt">Hi Seth,
<div><br>
</div>
<div>Thank you for your reply! Your method sounds similar and very clean indeed. I am however using C and not C&#43;&#43;. Correct me if I am wrong, but that means&nbsp;unfortunately&nbsp;I cannot use the class.</div>
<div><br>
</div>
<div>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?</div>
<div><br>
</div>
<div>Best regards,</div>
<div><br>
</div>
<div>-Martijn<br>
<div style="font-family:Times New Roman; color:#000000; font-size:16px">
<hr tabindex="-1">
<div id="divRpF153139" style="direction:ltr"><font size="2" color="#000000" face="Tahoma"><b>Van:</b> Seth Watts [<a class="moz-txt-link-abbreviated" href="mailto:seth.e.watts@gmail.com" target="_blank">seth.e.watts@gmail.com</a>]<br>
<b>Verzonden:</b> maandag 10 september 2012 15:35<br>
<b>To:</b> Martijn Disse<br>
<b>Cc:</b> Stefan Vigerske; <a class="moz-txt-link-abbreviated" href="mailto:ipopt@list.coin-or.org" target="_blank">
ipopt@list.coin-or.org</a><br>
<b>Onderwerp:</b> Re: [Ipopt] Algorithm flow calling f(x) and g(x), same decision variables?<br>
</font><br>
</div>
<div>Hi Martijn -<br>
<br>
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.
<br>
<br>
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.<br>
<br>
In case I wasn't clear above, here is pseudocode of eval_f:<br>
<br>
bool MyNLP::eval_f(Index n, const Number* x, bool new_x, Number&amp; obj_value)<br>
{<br>
&nbsp;&nbsp;&nbsp; if(new_x)<br>
&nbsp;&nbsp;&nbsp; {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; evaluate(&lt;lots of variables&gt;, my_f, my_g, my_df, my_dg);<br>
&nbsp;&nbsp;&nbsp; }<br>
&nbsp;&nbsp;&nbsp; obj_value = my_f;<br>
}<br>
<br>
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.<br>
<br>
- Seth<br>
<br>
<div class="gmail_quote">On Mon, Sep 10, 2012 at 3:57 AM, Martijn Disse <span dir="ltr">
&lt;<a href="mailto:M.W.Disse@student.tudelft.nl" target="_blank">M.W.Disse@student.tudelft.nl</a>&gt;</span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0
                  .8ex; border-left:1px #ccc solid; padding-left:1ex">
<div>
<div style="direction:ltr; font-size:10pt; font-family:Tahoma">Hi,<br>
<br>
Thank you for your response. Just for sake of completeness on this topic: the documentation mentions x_new as:
<div><br>
<i>&quot;new_x: (in), false if any evaluation method was previously called with the same values in x, true otherwise.&quot;</i>
<div><i><br>
</i></div>
<div>I will investigate how to implement this for my particular case.</div>
<div><br>
</div>
<div>Best regards,</div>
<div><br>
</div>
<div>-Martijn</div>
<div><i><br>
</i>________________________________________<br>
Van: Stefan Vigerske [<a href="mailto:stefan@math.hu-berlin.de" target="_blank">stefan@math.hu-berlin.de</a>]<br>
Verzonden: maandag 10 september 2012 10:39<br>
To: Martijn Disse<br>
Cc: <a href="mailto:ipopt@list.coin-or.org" target="_blank">ipopt@list.coin-or.org</a><br>
Onderwerp: Re: [Ipopt] Algorithm flow calling f(x) and g(x), same decision variables?
<div>
<div class="h5"><br>
<br>
Hi,<br>
<br>
I think Ipopt does not want to give promises on which order functions<br>
are evaluated.<br>
You can check the newx flag that is passed with each function evaluation<br>
to see whether *some* evaluation function has been called for the same<br>
point already.<br>
<br>
Stefan<br>
<br>
On 09/10/2012 10:12 AM, Martijn Disse wrote:<br>
&gt; Dear all,<br>
&gt;<br>
&gt; 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.<br>
&gt;<br>
&gt; 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.<br>
&gt;<br>
&gt; 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:<br>
&gt;<br>
&gt; Does the IPOPT flow ever call cost and constraint with the same decision variables? If so, which one is called first?<br>
&gt;<br>
&gt; 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?<br>
&gt;<br>
&gt; 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 :).<br>
&gt;<br>
&gt; I appreciate you help,<br>
&gt;<br>
&gt; Best regards,<br>
&gt;<br>
&gt; Martijn Disse<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt; _______________________________________________<br>
&gt; Ipopt mailing list<br>
&gt; <a href="mailto:Ipopt@list.coin-or.org" target="_blank">Ipopt@list.coin-or.org</a><br>
&gt; <a href="http://list.coin-or.org/mailman/listinfo/ipopt" target="_blank">http://list.coin-or.org/mailman/listinfo/ipopt</a><br>
&gt;<br>
<br>
</div>
</div>
</div>
</div>
</div>
</div>
</blockquote>
</div>
<br>
</div>
</div>
</div>
</div>
<br>
<fieldset class="mimeAttachmentHeader" target="_blank"></fieldset> <br>
<pre>_______________________________________________
Ipopt mailing list
<a class="moz-txt-link-abbreviated" href="mailto:Ipopt@list.coin-or.org" target="_blank">Ipopt@list.coin-or.org</a>
<a class="moz-txt-link-freetext" href="http://list.coin-or.org/mailman/listinfo/ipopt" target="_blank">http://list.coin-or.org/mailman/listinfo/ipopt</a>
</pre>
</blockquote>
<br>
</div>
</div>
</div>
</div>
</body>
</html>