how to use .lp file with GAMS?

Frequently asked questions about GAMS

Moderator: aileen

Forum rules
Please ask questions in the other sub-forums
Locked
abhosekar
Moderator
Moderator
Posts: 190
Joined: 9 months ago

how to use .lp file with GAMS?

Post by abhosekar » 3 weeks ago

To generate lp file from GAMS, you can use writelp option. An example is shown here using the rotdk model from GAMS model library where the lines before the solve statement demonstrate how to use the option writelp.

Code: Select all

$title Robust Optimization (ROTDK,SEQ=185)

$onText
Robust Optimization.


Laguna, M, Applying Robust Optimization to Capacity Expansion of
One Location in Telecommunications with Demand Uncertainty.
Management Science 44, 11 (1998), 101-110.

Keywords: mixed integer linear programming, robust optimization, capacity expansion,
          time-dependent knapsack problem
$offText

Set
   s 'scenarios'    / 1*1000    /
   t 'time periods' / t1*t12    /
   j 'components'   / C001*C010 /;

Alias (t,tt);

Parameter
   di(s,t) 'increment'
   D(t,s)  'demand'
   c(j)    'capacity size'
   p(j)    'capacity cost'
   mu      'mean capacity parameter'
   sigma   'std capacity parameter';

mu    = 100;
sigma =  10;

c(j) = round(uniform(1,mu));
p(j) = round(mu + c(j) + uniform(-sigma,sigma));

di(s,t)$(ord(s) <= 0.25*card(s)) = round(normal( 50,10));
di(s,t)$(ord(s) >  0.25*card(s) and ord(s) <= 0.75*card(s)) = round(normal(100,20));
di(s,t)$(ord(s) >  0.75*card(s)) = round(normal(150,40));

d(t,s) = sum(tt$(ord(tt) <= ord(t)), di(s,tt));
* display c, p, di, d;

Parameter
   dis(t) 'discount factor'
   w      'shortage penalty';

dis(t) = power(.86,ord(t) - 1);
w      = 5;

Variable
   x(j,t) 'expansion'
   z(s)   'max capacity shortage'
   cap(t) 'installed capacity'
   obj;

Integer  Variable x;
Positive Variable z;

Equation
   capbal(t)   'capacity balance'
   dembal(t,s) 'demand balance'
   objdef;

objdef..      obj =e= sum((j,t), dis(t)*p(j)*x(j,t)) + w/card(s)*sum(s, z(s));

capbal(t)..   cap(t) =e= cap(t-1) + sum(j, c(j)*x(j,t));

dembal(t,s).. cap(t) + z(s) =g= d(t,s);

Model rotdk / all /;

$onEcho > cplex.opt
lazyconstraints 1
dembal.lazy(t,s)$(ord(t) eq 1) 1
dembal.lazy 1
dembal.lazy('t1','s1') 1
$offecho


rotdk.optfile=1;
option limCol = 0, limRow = 0;

* do not reset optcr if already set to a nondefault value
if{(.1 = %gams.optCr%), option optCr = 0.05;};
$onecho > cplex.opt
writelp rotdk.lp
$offecho
rotdk.optfile = 1;
solve rotdk min obj using mip;


Running this code will generate rotdk.lp file. To use this model from lp file instead of using it from GAMS, one can use option probread. This can be done by replacing the option writelp from the above code fragment with probread as follows.

Code: Select all

$onecho > cplex.opt
probread rotdk.lp
$offecho
It should be noted that, since the model passed from GAMS to GAMS/CPLEX might have nothing to do with the model you supplied in rotdk.lp, no solution is returned to GAMS.

Locked