[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: GMPL do not detect invalid subscript
From: |
Andrew Makhorin |
Subject: |
Re: GMPL do not detect invalid subscript |
Date: |
Wed, 12 Aug 2020 18:04:53 +0300 |
On Wed, 2020-08-12 at 16:38 +0200, Domingo Alvarez Duarte wrote:
> Hello !
>
> Trying to make changes to make less tuple copies I found that GMPL
> actually do not detect invalid subscripts see the modified huge.mod
> bellow, when we add an arbitry number to the "z" index it would fall
> outside the valid subscript range but actually GMPL do not detect this
> situation and silently goes forward.
>
> =====
>
> /*Arithmetic Mean of a large number of Integers
> - or - solve a very large constraint matrix
> over 1 million rows and columns
> Nigel_Galloway@operamail.com
> March 18th., 2008.
> */
>
> param e := 20;
> #param e := 15;
> /* set Sample := {-2**e..2**e-1}; */
> set Sample := {1..2**e-1};
> printf "card Sample %d : %f\n", card(Sample), sum{i in Sample: i =
> (card(Sample)-100)} i;
> var Mean;
>
> var E{z in Sample};
>
> /* sum of variances is zero */
> zumVariance: sum{z in Sample} E[z+10] = 0; #!!!! +x would fall out of
> valid indexes
>
> /* Mean + variance[n] = Sample[n] */
> variances{z in Sample}: Mean + E[z] = z;
>
> solve;
>
> printf "The arithmetic mean of the integers from 1 to %d is %f\n",
> 2**e-1, Mean;
>
> end;
>
> =====
>
> Cheers !
>
>
>
It works for me.
------
param e := 20;
#param e := 15;
/* set Sample := {-2**e..2**e-1}; */
set Sample := {1..2**e-1};
printf "card Sample %d : %f\n", card(Sample), sum{i in Sample: i =
(card(Sample)-100)} i;
var Mean;
var E{z in Sample};
/* sum of variances is zero */
zumVariance: sum{z in Sample} E[z+10] = 0; #!!!! +x would fall out of valid
indexes
/* Mean + variance[n] = Sample[n] */
variances{z in Sample}: Mean + E[z] = z;
solve;
printf "The arithmetic mean of the integers from 1 to %d is %f\n",
2**e-1, Mean;
end;
------
GLPSOL: GLPK LP/MIP Solver, v4.65
Parameter(s) specified in the command line:
-m foo.mod
Reading model section from foo.mod...
21 lines were read
card Sample 1048575 : 1048475.000000
Generating zumVariance...
foo.mod:11: E[1048576] out of domain
MathProg model processing error