1

I have to get GAMS to find the maximum element of a set. This should result in some linear regression model, where the objective is not the least squares but the least maximum deviation.

My data points are the (x(p), y(p)) points (There is Set p / p1*p1000 / ; given). I managed to solve the regression model as described by amsterdamoptimization:

Variables
  m            Slope
  b            Constant
  objVal       Objective Value
;

Equations
  objFun       Objective Function
  lin(p)       Regression Model
;

objFun ..      objVal =n= 0;
lin(p) ..      y(p) =e= m * x(p) + b;

option lp=ls;
Model Regression / objFun, lin / ;
Solve Regression minimizing objVal using lp;

But what I should hand in is something like

Variables
  m            Slope
  b            Constant
  objVal       Objective Value
;

Equations
  objFun       Regression Model
;

objFun ..      objVal =e= smax(p, abs( y(p) - (m * x(p) + b) ));

Model Regression / objFun / ;
Solve Regression minimizing objVal using lp;

Of course you can read this, but GAMS hates it:

2031  Solve Regression minimizing objVal using lp;
****                                             $51,59,256
Error Messages

 51  Endogenous function argument(s) not allowed in linear models
 59  Endogenous prod smin smax require model type "dnlp"
256  Error(s) in analyzing solve statement. More detail appears
     Below the solve statement above

Yep, it is homework, nevertheless I'm completely stuck.

Serj-Tm
  • 16,581
  • 4
  • 54
  • 61
LDericher
  • 295
  • 1
  • 3
  • 12

1 Answers1

1

Turns out, maximum can be handled easily:

objFun ..      objVal =e= smax(p, abs( y(p) - (m * x(p) + b) ));

Is equivalent to

objFun(p) ..   objVal =g= abs( y(p) - (m * x(p) + b) );

Now GAMS doesn't like abs() used in linear models for obvious reasons, but remember x > abs(y) means (x > y) AND (x > -y), so:

objFun1(p) ..  objVal =g= y(p) - (m * x(p) + b);
objFun2(p) ..  objVal =g= -( y(p) - (m * x(p) + b) );

Which is finally (canonical conformity):

objFun1(p) ..  objVal + x(p) * m + b =g= y(p);
objFun2(p) ..  objVal - x(p) * m - b =g= -y(p);
jmlarson
  • 837
  • 8
  • 31
LDericher
  • 295
  • 1
  • 3
  • 12