## Convert Gams files to *.mpi or *.mps Topic is solved

Masood
User
Posts: 3
Joined: 2 years ago

### Convert Gams files to *.mpi or *.mps

Hi,
Does anybody know how to convert the Gams file to *.mpi or *.mps? I have already studied the given information in this webpage: https://www.gams.com/latest/docs/solver ... index.html, but I found the information very confusing. I would be appreciate if anybody could provide me with some clear information about converting Gams files.

Masood

Fred
Posts: 144
Joined: 2 years ago

### Re: Convert Gams files to *.mpi or *.mps

Hi Masood,

The example below is based on the well known transportation problem from the GAMS model library (https://www.gams.com/latest/gamslib_ml/ ... sport.html) and illustrates how to create an MPS file using Convert.

Code: Select all

``````  Sets
i   canning plants   / seattle, san-diego /
j   markets          / new-york, chicago, topeka / ;

Parameters

a(i)  capacity of plant i in cases
/    seattle     350
san-diego   600  /

b(j)  demand at market j in cases
/    new-york    325
chicago     300
topeka      275  / ;

Table d(i,j)  distance in thousands of miles
new-york       chicago      topeka
seattle          2.5           1.7          1.8
san-diego        2.5           1.8          1.4  ;

Scalar f  freight in dollars per case per thousand miles  /90/ ;

Parameter c(i,j)  transport cost in thousands of dollars per case ;

c(i,j) = f * d(i,j) / 1000 ;

Variables
x(i,j)  shipment quantities in cases
z       total transportation costs in thousands of dollars ;

Positive Variable x ;

Equations
cost        define objective function
supply(i)   observe supply limit at plant i
demand(j)   satisfy demand at market j ;

cost ..        z  =e=  sum((i,j), c(i,j)*x(i,j)) ;

supply(i) ..   sum(j, x(i,j))  =l=  a(i) ;

demand(j) ..   sum(i, x(i,j))  =g=  b(j) ;

Model transport /all/ ;

*** Modifications
* choose convert as solver
option lp = convert;
* write convert option file
\$echo fixedMPS transport.mps > convert.opt
* instruct convert to look for a solver option file
transport.optfile = 1;

Solve transport using lp minimizing z ;
``````
I hope this helps!

Fred

Masood
User
Posts: 3
Joined: 2 years ago

### Re: Convert Gams files to *.mpi or *.mps

Hi Ferd,
I am really appreciate your help. I was looking for this piece of code for a couple of weeks. You made my day!!
Thanks again,
Masood

yanzhiping
User
Posts: 85
Joined: 2 years ago

### Re: Convert Gams files to *.mpi or *.mps

you can also choose solver CPlex to write mps or LP file, which will contain the exact variable names in it, good for problem debugging. or you can choose to turn off the names in mps file as well using the option 'names no' in cplex option.

Code: Select all

``````  Sets
i   canning plants   / seattle, san-diego /
j   markets          / new-york, chicago, topeka / ;

Parameters

a(i)  capacity of plant i in cases
/    seattle     350
san-diego   600  /

b(j)  demand at market j in cases
/    new-york    325
chicago     300
topeka      275  / ;

Table d(i,j)  distance in thousands of miles
new-york       chicago      topeka
seattle          2.5           1.7          1.8
san-diego        2.5           1.8          1.4  ;

Scalar f  freight in dollars per case per thousand miles  /90/ ;

Parameter c(i,j)  transport cost in thousands of dollars per case ;

c(i,j) = f * d(i,j) / 1000 ;

Variables
x(i,j)  shipment quantities in cases
z       total transportation costs in thousands of dollars ;

Positive Variable x ;

Equations
cost        define objective function
supply(i)   observe supply limit at plant i
demand(j)   satisfy demand at market j ;

cost ..        z  =e=  sum((i,j), c(i,j)*x(i,j)) ;

supply(i) ..   sum(j, x(i,j))  =l=  a(i) ;

demand(j) ..   sum(i, x(i,j))  =g=  b(j) ;

Model transport /all/ ;

*** Modifications
* choose cplex as solver
option lp = cplex;
* write convert option file
\$echo writeMPS transport.mps > cplex.o98
* instruct convert to look for a solver option file
transport.optfile = 98;

Solve transport using lp minimizing z ;``````
Masood wrote:Hi Ferd,
I am really appreciate your help. I was looking for this piece of code for a couple of weeks. You made my day!!
Thanks again,
Masood

Masood
User
Posts: 3
Joined: 2 years ago

### Re: Convert Gams files to *.mpi or *.mps

Thank you yanzhiping!
Would you please let me know more about "cplex.o98" and "transport.optfile = 98"? Why we need to have "98" and "o98" instead of "1" and "opt"?