SQRT of zero ?

593 views
Skip to first unread message

ism...@gmail.com

unread,
May 7, 2009, 8:42:24 PM5/7/09
to AMPL Modeling Language
I have this constraint in my model file:
subject to rdDistance{i in 1..n}: D[i] = sqrt((x[i] - x[i-1])^2 + (y
[i] - y[i-1])^2);

ampl: display x;
x [*] :=
0 9.4
1 9.4
2 9.4
;

But when I try and solve it with MINLP I get:
MINLP-B&B (20020703): Cannot evaluate constraint(s) at starting point

So I tried it with MINOS, even though I have integer variables in my
problem and it gave me:
Error evaluating constraint rdDistance[1]: can't evaluate sqrt'(0).

So I tried changing it to:
subject to rdDistance{i in 1..n}: D[i] = sqrt(1e-20 + (x[i] - x[i-1])
^2 + (y[i] - y[i-1])^2);

and it magically worked.

Any one know why this happened ?

Robert Fourer

unread,
May 9, 2009, 11:55:26 AM5/9/09
to am...@googlegroups.com, ism...@gmail.com

By default, the initial values of all the variables are zero. But to get
started, MINOS must compute the gradients of the constraint functions, and
that requires it to compute the derivative of the sqrt function at zero --
sqrt'(0) in the error message -- which fails because that derivative of sqrt
at zero is infinite.

One cure is to give nonzero initial values to the variables, which can be
done in definition, say,

var x {i in 1..n} >= 0, := i/10 ;

There's undoubtedly a better choice, but the idea is to make the initial
values different, so that the argument to sqrt won't be zero. Your change
also got around the problem because it had the effect of making the argument
to sqrt nonzero.

Bob Fourer
4...@ampl.com


> -----Original Message-----
> From: am...@googlegroups.com [mailto:am...@googlegroups.com]
> On Behalf Of ism...@gmail.com
> Sent: Thursday, May 07, 2009 7:42 PM
> To: AMPL Modeling Language
> Subject: [AMPL 2489] SQRT of zero ?
>
>
> I have this constraint in my model file:
>
> subject to rdDistance{i in 1..n}:
> D[i] = sqrt((x[i] - x[i-1])^2 + (y[i] - y[i-1])^2);
>
> ampl: display x;
> x [*] :=
> 0 9.4
> 1 9.4
> 2 9.4
> ;
>
> But when I try and solve it with MINLP I get:
> MINLP-B&B (20020703): Cannot evaluate constraint(s) at starting point
>
> So I tried it with MINOS, even though I have integer variables in my
> problem and it gave me:
> Error evaluating constraint rdDistance[1]: can't evaluate sqrt'(0).
>
> So I tried changing it to:
> subject to rdDistance{i in 1..n}:

> D[i] = sqrt(1e-20 + (x[i] - x[i-1])^2 + (y[i] - y[i-1])^2);

Reply all
Reply to author
Forward
0 new messages