<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]>=a and x[1]<=b then 1 else 0)*</span>(if x[2]>=c and x[2]<=d then 1 else 0)*...*(if x[n]>=e and x[n]<=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"
<Etienne.Ayotte-Sauve@RNCan-NRCan.gc.ca><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] >= 0, (i = 1, ..., 3); (*complementarity constraints*)<br><br>lambda[i] >= 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 < a or x > b, this formulation yields p = 0; for a < x < 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 <=a, price=0<br>x >=a, x<=b , price=1<br>x>=b, 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. <<a ymailto="mailto:khoroshylov@yahoo.com" href="mailto:khoroshylov@yahoo.com">khoroshylov@yahoo.com</a>> wrote:<br>> Thank's for your response. To be honest I had finished my CO major <br>> awhile ago, and a bit rusty on theory.<br>> On a very simplified level, that's what I am trying to achieve <br>> maximize price:<br>> if x>=a and x <=b then 1 else 0<br>> But IPOPT gives me all zero solution which is obviously is not optimal.<br>> What should be done to make IPOPT solve it correctly? Am I missing <br>> anything (any ipopt option)?<br>> Is it even possible to solve it?<br>> Or maybe you can recomend any other more suitable solver.<br>> Thanks a bunch,<br>> Greg<br>>
________________________________<br>> From: Andrea Walther <<a ymailto="mailto:andrea.walther@uni-paderborn.de" href="mailto:andrea.walther@uni-paderborn.de">andrea.walther@uni-paderborn.de</a>><br>> To: Stefan Vigerske <<a ymailto="mailto:stefan@math.hu-berlin.de" href="mailto:stefan@math.hu-berlin.de">stefan@math.hu-berlin.de</a>><br>> Cc: Gregory K. <<a ymailto="mailto:khoroshylov@yahoo.com" href="mailto:khoroshylov@yahoo.com">khoroshylov@yahoo.com</a>>; <a ymailto="mailto:ipopt@list.coin-or.org" href="mailto:ipopt@list.coin-or.org">ipopt@list.coin-or.org</a><br>> Sent: Monday, September 19, 2011 2:05:14 AM<br>> Subject: Re: [Ipopt] If statement in objective function<br>><br>> Hi,<br>><br>>> I don't know how AMPL computes derivatives for functions containing <br>>> if-statements, but you should make sure that you have at least <br>>> continuous first derivatives for Ipopt to
work.<br>><br>> as far as I know, AMPL uses Automatic Differentiation for the <br>> derivative calculation. Therefore, as long as you are not right at the <br>> kink caused by the if statement you get a derivative that is valid in <br>> a certain region around the current point. However, if this point is <br>> close to the kink the derivative information perhaps is not that <br>> useful. This might cause the problems in the optimisation process.<br>><br>> Best regards,<br>><br>> Andrea Walther<br>><br>> --<br>> Prof. Dr. Andrea Walther<br>> Lehrstuhl fuer Mathematik und ihre Anwendungen Institut fuer <br>> Mathematik Universitaet Paderborn Warburger Str. 100<br>> 33098 Paderborn<br>><br>> Email: <a ymailto="mailto:andrea.walther@uni-paderborn.de" href="mailto:andrea.walther@uni-paderborn.de">andrea.walther@uni-paderborn.de</a><br>> Phone: ++49 5251 602721<br>> Fax: ++49 5251
603728<br>><br>> **********<br>><br>><br>><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><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>