help-glpk
[Top][All Lists]

## Re: [Help-glpk] Sets of ordered pairs: Differences between AMPL and GNU

 From: Andrew Makhorin Subject: Re: [Help-glpk] Sets of ordered pairs: Differences between AMPL and GNU MathProg Date: Tue, 18 Nov 2008 18:23:03 +0300

```> There is an inhomogeneity between AMPL and MathProg in the way sets of
> ordered pairs are being iterated over by two (or more) sum{} statements
> which are linked by an iterator variable.

> Consider the following sample:
> ---------------------------

> set A :={1..5};
> set B :={"b1", "b2", "b3", "b4", "b5"};

> set D within {A,B} := {(1,"b2"), (1,"b3"), (1,"b5"), (3,"b3")};

> var X {D};

> minimize z:
>  sum{a in (1..5)} sum {(a,b) in D} X[1,b];

> ---------------------------

> AMPL generates:

> MIN   X[1,b2] + 2 X[1,b3] + X[1,b5]

> MathProg generates:

> MIN   5 X[1,b2] + 5 X[1,b3] + 5 X[1,b5]

> Obviously AMPL links the inner and outer sum{} statements by variable
> 'a' and MathProg doesn't.

> Bug or feature?

Which version of glpk do you use? How did you build it or from where

The point is that glpsol 4.33 works correctly, i.e. it generates the
same instance as ampl (see below). Even if you are using an older
version, it also must produce the same output, because the corresponding
part of the mathprog translator was never changed.

--- bug.mod ---
set A :={1..5};
set B :={"b1", "b2", "b3", "b4", "b5"};

set D within {A,B} := {(1,"b2"), (1,"b3"), (1,"b5"), (3,"b3")};

var X {D};

minimize z:
sum{a in (1..5)} sum {(a,b) in D} X[1,b];

--- command line ---
glpsol --check -m bug.mod --wcpxlp bug.lp --log bug.log

--- bug.log ---
bug.mod:9: warning: unexpected end of file; missing end statement inserted
Generating z...
Model has been successfully generated
glp_write_lp: writing problem data to `bug.lp'...

--- bug.lp ---
\* Problem: bug *\

Minimize
z: + X(1,b2) + 2 X(1,b3) + X(1,b5)

Subject To

Bounds
X(1,b2) free
X(1,b3) free
X(1,b5) free

End

```