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

Masood
User
Posts: 3
Joined: 4 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: 270
Joined: 5 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: 4 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: 4 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: 4 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"?

GraceM
User
Posts: 1
Joined: 1 year ago

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

Hi,

Could someone please assist me in converting a gams file to JuMP .jl format? I had used the solution answer as a guideline but it is not working. It is giving the error that JuMP is unknown yet gams convert tool does allow for conversion to this format.

Your assistance will be highly appreciated

Grace

Model transport / all /;

**modifications
option lp=convert;
\$echo jump transport.jl > convert.opt
transport.optfile = 1;
solve transport using lp minimizing z;

dirkse
Moderator
Posts: 169
Joined: 5 years ago
Location: Fairfax, VA

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

Grace,

If you include the .log file from the run you'd make it easier to help you.

I can only guess now: perhaps you are not using the most recent GAMS version. The Jump output from convert is a fairly new feature.

-Steve