<html><body><div style="color:#000; background-color:#fff; font-family:times new roman, new york, times, serif;font-size:12pt"><div><span>Thanks Etienne and Hans for your time that you put in to answer this question.</span></div><div><span>As I was saying, I am a bit rusty on theory, and just took my dusty textbooks out of the basement.</span></div><div><span>Your proposed solution looks feasible for my simplified objective function, but in reality it contains multiple if statements of the same form.</span></div><div><span>Like that</span></div><div><span><br></span></div><div><span>maximize price:</span></div><div><span><span class="Apple-tab-span" style="white-space:pre">                </span>(if x[1]&gt;=a and x[1]&lt;=b then 1 else 0)*</span>(if x[2]&gt;=c and x[2]&lt;=d then 1 else 0)*...*(if x[n]&gt;=e and x[n]&lt;=f then 1 else 0)</div><div><br></div><div>Again, it is still a simplified version but it shows the complexity of my if statements piled up on one
 another.</div><div>My original version of this model didn't involve any IF statements but had thousands of binary variables accompanied by thousands of constraints, which was to big to solve for any MINLP solver. To simplify things I came up with this one complex objective function filled with if statements and by doing that eliminated most of variables and constraints, but now I cannot find a solver that would accept those if statements.</div><div>I start to wonder if it's even possible.</div><div><br></div><div>Would appreciate your opinion on it.</div><div><br></div><div>Thanks,</div><div>Greg</div><div><br></div><div style="font-size: 12pt; font-family: 'times new roman', 'new york', times, serif; "><div style="font-size: 12pt; font-family: 'times new roman', 'new york', times, serif; "><font size="2" face="Arial"><hr size="1"><b><span style="font-weight:bold;">From:</span></b> "Ayotte-Sauvé, Étienne"
 &lt;Etienne.Ayotte-Sauve@RNCan-NRCan.gc.ca&gt;<br><b><span style="font-weight: bold;">To:</span></b> ipopt@list.coin-or.org<br><b><span style="font-weight: bold;">Sent:</span></b> Tuesday, September 20, 2011 10:01:33 AM<br><b><span style="font-weight: bold;">Subject:</span></b> [Ipopt] FW:  If statement in objective function<br></font><br>Hi Greg,<br><br>Another way to model your objective function without invoking binary variables is to use complementarity constraints. However, such constraints cause non-uniqueness and unboundedness of the Lagrange multipliers (i.e. the dual optimization problem will not be well posed in classical terms). I am not an optimization specialist and I'm even less knowledgable with respect to IPOPT (that's in part why I joined this message group), but my guess is you'll be able to tag these complementarity contraints so that IPOPT treats them with adapted subroutines (e.g. relaxation strategies).<br><br>To be more precise,
 you can reformulate your piecewise function via complementarity constraints in the following manner<br><br>p = y[2];<br><br>y[1] + y[2] + y[3] = 1;<br><br>(x - xL)*(x - a) - mu - lambda[1] = 0;<br><br>(x - a)*(x - b) - mu - lambda[2] = 0;<br><br>(x - b)*(x - xU) - mu - lambda[3] = 0;<br><br>y[i]*lambda[i] = 0, (i = 1, ..., 3); (*complementarity constraints*)<br><br>y[i] &gt;= 0, (i = 1, ..., 3); (*complementarity constraints*)<br><br>lambda[i] &gt;= 0, (i = 1, ..., 3), (*complementarity constraints*)<br><br>where p denotes the objective function value defined in your original message; xL and xU denote lower and upper bounds (respectively) on the variable x; y[1], y[2], y[3], lambda[1], lambda[2], lambda[3] and mu are variables originating from a reformulation of your piecewise function via a convex optimization problem which in turn is reformulated via first order optimality conditions (i.e. KKT conditions) - see chapter 11 of "Nonlinear Programming:
 Concepts, Algorithms and Applications to Chemical Processes" by Lorenz Biegler. To help your intuition, note that the variable y[i] takes value 1 if x is in the open interval ] c[i-1], c[i] [ and it takes value 0 if x is NOT in the closed interval [ c[i-1], c[i ] ] (i = 1, 2, 3), where c[0] = xL, c[1] = a, c[2] = b, c[3] = xU.<br><br>Remarks.<br><br>1. The variable mu may take negative values (it is a Lagrange multiplier corresponding to an equality constraint).<br><br>2. For x = a or x = b, the above formulation may yield values of p which are between 0 and 1; for x &lt; a or x &gt; b, this formulation yields p = 0; for a &lt; x &lt; b, it gives p = 1.<br><br>3. Please verify with the book since I wrote the above formulation from memory (and intuition).<br><br>I hope this helps.<br><br>Etienne Ayotte-Sauve'<br><a ymailto="mailto:eayottes@nrcan.gc.ca" href="mailto:eayottes@nrcan.gc.ca">eayottes@nrcan.gc.ca</a><br>Mathematician, Research Scientists for
 Natural Resources Canada (Gov. of Canada) <br><br><br><br><br><br>-----Original Message-----<br>From: <a ymailto="mailto:ipopt-bounces@list.coin-or.org" href="mailto:ipopt-bounces@list.coin-or.org">ipopt-bounces@list.coin-or.org</a> [mailto:<a ymailto="mailto:ipopt-bounces@list.coin-or.org" href="mailto:ipopt-bounces@list.coin-or.org">ipopt-bounces@list.coin-or.org</a>] On Behalf Of Hans Pirnay<br>Sent: September 20, 2011 2:49 AM<br>To: Gregory K.<br>Cc: ipopt ipopt<br>Subject: Re: [Ipopt] If statement in objective function<br><br>Hi Greg,<br><br>that model is not a smooth nonlinear optimization problem, and therefore not directly solvable with Ipopt.<br><br>Here's one simple thing you can do if you only have one constraint of this kind: Solve the problem three times, once with the constraint<br><br>x &lt;=a,&nbsp;  price=0<br>x &gt;=a, x&lt;=b&nbsp;  ,&nbsp; price=1<br>x&gt;=b,&nbsp; price = 0<br><br>If you have several price variables, this approach
 quickly becomes infeasible, and you will need to use an MINLP solver (I don't have any suggestion which, it probably depends on what you can afford, though).<br><br>good luck<br><br>Hans<br><br>On Mon, Sep 19, 2011 at 11:44 PM, Gregory K. &lt;<a ymailto="mailto:khoroshylov@yahoo.com" href="mailto:khoroshylov@yahoo.com">khoroshylov@yahoo.com</a>&gt; wrote:<br>&gt; Thank's for your response. To be honest I had finished my CO major <br>&gt; awhile ago, and a bit rusty on theory.<br>&gt; On a very simplified level, that's what I am trying to achieve <br>&gt; maximize price:<br>&gt; if x&gt;=a and x &lt;=b then 1 else 0<br>&gt; But IPOPT gives me all zero solution which is obviously is not optimal.<br>&gt; What should be done to make IPOPT solve it correctly? Am I missing <br>&gt; anything (any ipopt option)?<br>&gt; Is it even possible to solve it?<br>&gt; Or maybe you can recomend any other more suitable solver.<br>&gt; Thanks a bunch,<br>&gt; Greg<br>&gt;
 ________________________________<br>&gt; From: Andrea Walther &lt;<a ymailto="mailto:andrea.walther@uni-paderborn.de" href="mailto:andrea.walther@uni-paderborn.de">andrea.walther@uni-paderborn.de</a>&gt;<br>&gt; To: Stefan Vigerske &lt;<a ymailto="mailto:stefan@math.hu-berlin.de" href="mailto:stefan@math.hu-berlin.de">stefan@math.hu-berlin.de</a>&gt;<br>&gt; Cc: Gregory K. &lt;<a ymailto="mailto:khoroshylov@yahoo.com" href="mailto:khoroshylov@yahoo.com">khoroshylov@yahoo.com</a>&gt;; <a ymailto="mailto:ipopt@list.coin-or.org" href="mailto:ipopt@list.coin-or.org">ipopt@list.coin-or.org</a><br>&gt; Sent: Monday, September 19, 2011 2:05:14 AM<br>&gt; Subject: Re: [Ipopt] If statement in objective function<br>&gt;<br>&gt; Hi,<br>&gt;<br>&gt;&gt; I don't know how AMPL computes derivatives for functions containing <br>&gt;&gt; if-statements, but you should make sure that you have at least <br>&gt;&gt; continuous first derivatives for Ipopt to
 work.<br>&gt;<br>&gt; as far as I know, AMPL uses Automatic Differentiation for the <br>&gt; derivative calculation. Therefore, as long as you are not right at the <br>&gt; kink caused by the if statement you get a derivative that is valid in <br>&gt; a certain region around the current point. However, if this point is <br>&gt; close to the kink the derivative information perhaps is not that <br>&gt; useful. This might cause the problems in the optimisation process.<br>&gt;<br>&gt; Best regards,<br>&gt;<br>&gt; Andrea Walther<br>&gt;<br>&gt; --<br>&gt; Prof. Dr. Andrea Walther<br>&gt; Lehrstuhl fuer Mathematik und ihre Anwendungen Institut fuer <br>&gt; Mathematik Universitaet Paderborn Warburger Str. 100<br>&gt; 33098 Paderborn<br>&gt;<br>&gt; Email: <a ymailto="mailto:andrea.walther@uni-paderborn.de" href="mailto:andrea.walther@uni-paderborn.de">andrea.walther@uni-paderborn.de</a><br>&gt; Phone: ++49 5251 602721<br>&gt; Fax:&nbsp; ++49 5251
 603728<br>&gt;<br>&gt; **********<br>&gt;<br>&gt;<br>&gt;<br>&gt;<br>&gt; _______________________________________________<br>&gt; Ipopt mailing list<br>&gt; <a ymailto="mailto:Ipopt@list.coin-or.org" href="mailto:Ipopt@list.coin-or.org">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>&gt;<br><br>_______________________________________________<br>Ipopt mailing list<br><a ymailto="mailto:Ipopt@list.coin-or.org" href="mailto:Ipopt@list.coin-or.org">Ipopt@list.coin-or.org</a><br><a href="http://list.coin-or.org/mailman/listinfo/ipopt" target="_blank">http://list.coin-or.org/mailman/listinfo/ipopt</a><br><br>_______________________________________________<br>Ipopt mailing list<br><a ymailto="mailto:Ipopt@list.coin-or.org" href="mailto:Ipopt@list.coin-or.org">Ipopt@list.coin-or.org</a><br><a
 href="http://list.coin-or.org/mailman/listinfo/ipopt" target="_blank">http://list.coin-or.org/mailman/listinfo/ipopt</a><br><br><br></div></div></div></body></html>