[Ipopt] If statement in objective function
A. Ismael F. Vaz
aivaz at dps.uminho.pt
Wed Sep 21 18:43:08 EDT 2011
Dear Greg,
If you have your model in AMPL, you may take a look at the NEOS server
(http://www.neos-server.org/neos/solvers/index.html) for a solver that fits
your problem.
In particular, the PSwarm solver is intended for derivative-free
optimization, where a small number of continuous variables (a few tens) are
considered. The problem may have bound and/or linear constraints only.
Please note that derivative-free means that derivatives of the objective
function will not be used during the optimization process, but in order to
have convergence your objective function needs to be differentiable (which
is not the case). Just give it a try, if it fits your problem structure.
Best regards,
Ismael
De: ipopt-bounces at list.coin-or.org [mailto:ipopt-bounces at list.coin-or.org]
Em nome de Gregory K.
Enviada: quarta-feira, 21 de Setembro de 2011 23:05
Para: Ayotte-Sauvé, Étienne; ipopt at list.coin-or.org; Hans Pirnay
Assunto: Re: [Ipopt] If statement in objective function
Thanks Etienne and Hans for your time that you put in to answer this
question.
As I was saying, I am a bit rusty on theory, and just took my dusty
textbooks out of the basement.
Your proposed solution looks feasible for my simplified objective function,
but in reality it contains multiple if statements of the same form.
Like that
maximize price:
(if x[1]>=a and x[1]<=b then 1 else 0)*(if x[2]>=c
and x[2]<=d then 1 else 0)*...*(if x[n]>=e and x[n]<=f then 1 else 0)
Again, it is still a simplified version but it shows the complexity of my if
statements piled up on one another.
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.
I start to wonder if it's even possible.
Would appreciate your opinion on it.
Thanks,
Greg
_____
From: "Ayotte-Sauvé, Étienne" <Etienne.Ayotte-Sauve at RNCan-NRCan.gc.ca>
To: ipopt at list.coin-or.org
Sent: Tuesday, September 20, 2011 10:01:33 AM
Subject: [Ipopt] FW: If statement in objective function
Hi Greg,
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).
To be more precise, you can reformulate your piecewise function via
complementarity constraints in the following manner
p = y[2];
y[1] + y[2] + y[3] = 1;
(x - xL)*(x - a) - mu - lambda[1] = 0;
(x - a)*(x - b) - mu - lambda[2] = 0;
(x - b)*(x - xU) - mu - lambda[3] = 0;
y[i]*lambda[i] = 0, (i = 1, ..., 3); (*complementarity constraints*)
y[i] >= 0, (i = 1, ..., 3); (*complementarity constraints*)
lambda[i] >= 0, (i = 1, ..., 3), (*complementarity constraints*)
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.
Remarks.
1. The variable mu may take negative values (it is a Lagrange multiplier
corresponding to an equality constraint).
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.
3. Please verify with the book since I wrote the above formulation from
memory (and intuition).
I hope this helps.
Etienne Ayotte-Sauve'
eayottes at nrcan.gc.ca
Mathematician, Research Scientists for Natural Resources Canada (Gov. of
Canada)
-----Original Message-----
From: ipopt-bounces at list.coin-or.org [mailto:ipopt-bounces at list.coin-or.org]
On Behalf Of Hans Pirnay
Sent: September 20, 2011 2:49 AM
To: Gregory K.
Cc: ipopt ipopt
Subject: Re: [Ipopt] If statement in objective function
Hi Greg,
that model is not a smooth nonlinear optimization problem, and therefore not
directly solvable with Ipopt.
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
x <=a, price=0
x >=a, x<=b , price=1
x>=b, price = 0
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).
good luck
Hans
On Mon, Sep 19, 2011 at 11:44 PM, Gregory K. <khoroshylov at yahoo.com> wrote:
> Thank's for your response. To be honest I had finished my CO major
> awhile ago, and a bit rusty on theory.
> On a very simplified level, that's what I am trying to achieve
> maximize price:
> if x>=a and x <=b then 1 else 0
> But IPOPT gives me all zero solution which is obviously is not optimal.
> What should be done to make IPOPT solve it correctly? Am I missing
> anything (any ipopt option)?
> Is it even possible to solve it?
> Or maybe you can recomend any other more suitable solver.
> Thanks a bunch,
> Greg
> ________________________________
> From: Andrea Walther <andrea.walther at uni-paderborn.de>
> To: Stefan Vigerske <stefan at math.hu-berlin.de>
> Cc: Gregory K. <khoroshylov at yahoo.com>; ipopt at list.coin-or.org
> Sent: Monday, September 19, 2011 2:05:14 AM
> Subject: Re: [Ipopt] If statement in objective function
>
> Hi,
>
>> I don't know how AMPL computes derivatives for functions containing
>> if-statements, but you should make sure that you have at least
>> continuous first derivatives for Ipopt to work.
>
> as far as I know, AMPL uses Automatic Differentiation for the
> derivative calculation. Therefore, as long as you are not right at the
> kink caused by the if statement you get a derivative that is valid in
> a certain region around the current point. However, if this point is
> close to the kink the derivative information perhaps is not that
> useful. This might cause the problems in the optimisation process.
>
> Best regards,
>
> Andrea Walther
>
> --
> Prof. Dr. Andrea Walther
> Lehrstuhl fuer Mathematik und ihre Anwendungen Institut fuer
> Mathematik Universitaet Paderborn Warburger Str. 100
> 33098 Paderborn
>
> Email: andrea.walther at uni-paderborn.de
> Phone: ++49 5251 602721
> Fax: ++49 5251 603728
>
> **********
>
>
>
>
> _______________________________________________
> Ipopt mailing list
> Ipopt at list.coin-or.org
> http://list.coin-or.org/mailman/listinfo/ipopt
>
>
_______________________________________________
Ipopt mailing list
Ipopt at list.coin-or.org
http://list.coin-or.org/mailman/listinfo/ipopt
_______________________________________________
Ipopt mailing list
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/20110921/5128b360/attachment.html>
More information about the Ipopt
mailing list