Thursday, April 15, 2010

mps –> GAMS

GAMS comes with a tool called mps2gms. With a large MPS file from a client I had some problems using this tool, and I spent some time to make it reproducible with a small example. The problem is related to a ranged equation:

NAME          Error
N  obj
G  c1
E  c2
    x1        obj                  1
    x1        c2                   1
    x2        c1                   1
    x2        c2                   1
    rhs       c1                  10
    range     c1                   2
FR bnd       x1

This model is like the following:

min x1
10 ≤ x2 ≤ 12

The resulting GAMS model is complicated to look at with all data inside a GDX file. However when we run it against the CONVERT solver we can see the scalar GAMS version:

*  RMIP written by GAMS Convert at 04/15/10 19:04:26
*  Equation counts
*      Total        E        G        L        N        X        C
*          3        3        0        0        0        0        0
*  Variable counts
*                   x        b        i      s1s      s2s       sc       si
*      Total     cont   binary  integer     sos1     sos2    scont     sint
*          4        4        0        0        0        0        0        0
*  FX      0        0        0        0        0        0        0        0
*  Nonzero counts
*      Total    const       NL      DLL
*          6        6        0        0
*  Solve m using RMIP minimizing x1;

Variables  x1,x2,x3,x4;

Positive Variables  x3,x4;

Equations  e1,e2,e3;

e1..    x1 - x2 =E= 0;

e2..    x2 + x3 =E= 0;

e3..    x3 - x4 =E= 0;

* set non default bounds

* set non default levels

* set non default marginals

Model m / all /;

m.limrow=0; m.limcol=0;

Solve m using RMIP minimizing x1;

The constants 10 and 12 are not preserved and have disappeared from the model. I suspect that missing is x4.lo=10 and x4.up=12. (This is somewhat difficult to read as x1 and x4 are added to the model, and the mps columns x1 and x2 are renamed to GAMS variables x2 and x3). I have passed this on to GAMS for investigation so this can be fixed.

There was also another issue related to how the ranges section was read. In the end I used one of my own tools to quickly read in the mps file and write a GAMS file:

C:\projects\xxxxxx>\projects\lpsolve\lp2gams 2.mps
lp2gams.exe version 1.3
Erwin Kalvelagen,

lp_solve version
Reading mps file 2.mps
Writing 2.gms
Rows: 5857   Columns: 4235   Nonzero elements: 19228


Update: the mps2gms issues are fixed for the next release.