Problem about "log(0)"

119 views
Skip to first unread message

Chen Zhang

unread,
Jun 6, 2012, 4:37:11 PM6/6/12
to AMPL Modeling Language
Hi all. In my model, I define a variable "a" with a positive lower
bound (e.g. 0.01), then I use the term log(a) in some equations.
However, AMPL returns the information "can't evaluate log(0)" in these
equations.
Considering that "a" has a positive lower bound, why would the error
still happen?

Thank you! Looking forward to your reply!

Cavern

Paul

unread,
Jun 6, 2012, 7:44:44 PM6/6/12
to am...@googlegroups.com
Do all the references to log(a) occur inside a model (i.e., in constraints and/or the objective function)?  If you do something with it outside the model, such as

param b;
let b := log(a);

you will see that error message, because the initial (pre-solution) value of a is 0, despite the lower bound.  You can avoid that by assigning a default value for a, for instance

var a >= 0.01 default 1.0;

Paul

Cavern Chang

unread,
Jun 7, 2012, 10:44:10 AM6/7/12
to AMPL Modeling Language
Thank you very much! The "log(0)" problem has been settled.

However, now a new problem comes out that when I set "var a
>=0.00000001 default 0.0001" and solve the model by IPOPT under AMPL,
it would return the error information "can't evaluate log(-3.05e-10)"
in equations including the "log(a)" term.
So why would this phenomenon happen? It seems that the lower bound
doesn't take effect. How can I avoid this error?

Looking forward to your reply!

Cavern


Robert Fourer

unread,
Jun 9, 2012, 11:48:34 AM6/9/12
to am...@googlegroups.com
If the "can't evaluate" error message is occurring while IPOPT is running, then IPOPT must be generating an iterate in which the variable a is outside its bounds -- in fact very slightly less than zero. This is an algorithmic issue so you will have to raise it with the developers of IPOPT -- see https://projects.coin-or.org/Ipopt.

You could also try a larger initial value than 0.0001 for a, to see if that makes a difference to IPOPT's iteration path. Consider setting the initial value to a guess of the optimal value. There is no guarantee that this will make a difference, however -- you may get the same error.

There is no rule as to whether you should reformulate by taking the logarithm. The best thing to do is to try solving with different formulations and to use the one that works best for your particular combination of problem and solver.

Bob Fourer
4...@ampl.com


-----Original Message-----
From: am...@googlegroups.com [mailto:am...@googlegroups.com]
On Behalf Of Cavern Chang
Sent: Thursday, June 07, 2012 9:44 AM
To: AMPL Modeling Language
Subject: [AMPL 5879] Re: Problem about "log(0)"

Thank you very much! The "log(0)" problem has been settled.

However, now a new problem comes out that when I set "var a >=0.00000001 default 0.0001" and solve the model by IPOPT under AMPL, it would return the error information "can't evaluate log(-3.05e-10)" in equations including the "log(a)" term. So why would this phenomenon happen? It seems that the lower bound doesn't take effect. How can I avoid this error?

Besides, if there are some terms like exp(a) or a^b (a,b are variables) in equations, do we always need to change them to the logarithm form (e.g. a^b becomes b*log(a) )? Does this reformulation do make the solving process more efficient?
Reply all
Reply to author
Forward
0 new messages