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);