Sunday, November 25, 2012

GAMS qp interface not very coherent

It is possible to write quadratically constrained problems (and QPs in particular) in GAMS and solve them efficiently with solvers like Cplex, Gurobi. But the rules are somewhat ad-hoc and incoherent.

  1. GAMS will not extract a QCP when using the notation x**2 (for a rather obscure reason; this should probably be dealt with in a smarter way)
  2. GAMS will extract a QCP with the notation x*x or sqr(x) or power(x,2)
  3. But GAMS will again not allow power(x,1) or power(x,0) so we can’t write the following:

sets
  g
'generators' /g1,g2/
  d
'degree'   /d0,d1,d2/
;

table cfuelcost(g,d)  'coefficients for fuel cost as quadratic function of output.'
     
d2        d1       d0
g1    0.00889   10.333   200
g2    0.00741   10.833   240
;


parameter v(d);
v(d) =
ord
(d)-1;

variables

   p(g)     
'output'
   fuelcost 
'total fuel cost'
;
positive variable p;

equations

   efuel   
'fuel consumption constraint'
;

* power(x,2) is allowed
* power(x,1) or power(x,0) is not recognized?????
*efuel.. fuelcost =e= sum(g, cfuelcost(g,'d2')*power(p(g),2) + cfuelcost(g,'d1')*p(g) + cfuelcost(g,'d0'));
efuel.. fuelcost =e=
sum((g,d), cfuelcost(g,
d)*power(p(g),v(d)));

model m /all/
;
option
qcp=cplex;
solve
m using qcp minimizing fuelcost;

In forbidden cases you’ll get the poorly worded error message:

*** Could not load data from file: Detected 1 general nonlinear rows in model