Using SOS2 variables to implement a 1D interpolation scheme is fairly easy (see: http://yetanothermathprogrammingconsultant.blogspot.com/2009/06/gams-piecewise-linear-functions-with.html). However, a 2D problem is already much more difficult. Here is an example taken from the Lindo web site:

$ontext 2D Interpolation with SOS2 variables See: http://www.lindo.com/cgi-bin/modelf.cgi?Piecelin2Dsos3.txt;LINGO $offtext $set n1 3 $set n2 3 $eval n3 (%n1%+%n2%-1) sets i /i1*i%n1%/ j /j1*j%n2%/ k /k1*k%n3%/ ; table data(i,j,*) x y f i1.j1 195 1800 20 i1.j2 217 1900 26 i1.j3 240 2000 30 i2.j1 195 3500 52 i2.j2 217 3600 61 i2.j3 240 4100 78 i3.j1 195 5100 69 i3.j2 217 5200 80 i3.j3 240 5600 93 ; parameters xv(i,j) yv(i,j) fv(i,j) ; xv(i,j) = data(i,j,'x'); yv(i,j) = data(i,j,'y'); fv(i,j) = data(i,j,'f'); sos2 variables wx(i) wy(j) wd(k) ; positive variables WGT(i,j) xa ya fa ; variables z; equations xconvex yconvex dconvex ewx ewy ewd compx compy compfv obj ; xconvex.. sum(i, wx(i)) =e= 1; yconvex.. sum(j, wy(j)) =e= 1; dconvex.. sum(k, wd(k)) =e= 1; ewx(i).. wx(i) =e= sum(j, wgt(i,j)); ewy(j).. wy(j) =e= sum(i, wgt(i,j)); ewd(k).. wd(k) =e= sum((i,j)$(ord(i)+ord(j)-1=ord(k)), wgt(i,j)); compx.. xa =e= sum((i,j), xv(i,j)*wgt(i,j)); compy.. ya =e= sum((i,j), yv(i,j)*wgt(i,j)); compfv.. fa =e= sum((i,j), fv(i,j)*wgt(i,j)); obj.. z =e= YA + 15*XA; fa.lo = 67; xa.lo = 227; xa.up = 229; model m /all/; solve m minimizing z using mip; |

Hi ! Can someone pleas explain the data in the table? where are they from ? I mean x, y and f?

ReplyDeleteThank you for your help in advance!

These are data points z=f(x,y).

ReplyDeleteHello Erwin,

ReplyDelete"Anonymous" is a friend of mine, and I must say that I also don't understand the table data very well. I would expect the following table if one wants to represent the surface with points (x_m, y_n, f_{m,n}), where m=1,2,3 and n=1,2,3:

x y f

i1.j1 x_1 y_1 f_{11}

i1.j2 x_1 y_2 f_{12}

i1.j3 x_1 y_3 f_{13}

i2.j1 x_2 y_1 f_{21}

i2.j2 x_2 y_2 f_{22}

i2.j3 x_2 y_3 f_{23}

i3.j1 x_3 y_1 f_{31}

i3.j2 x_3 y_2 f_{32}

i3.j3 x_3 y_3 f_{33}

;

where you should replace the x_m and y_n and f_{mn} with specific numbers. But in the table on this site, there are 9 different y's, and not 3. How is that possible on a 3x3 grid?

Thanks so much for any help! We try to implement a piecewise linear function in two variables in GAMS as part of a master thesis. Your site is awesome and so helpful! Congratulations!

Pieter

I don't think the data points are required to form a grid.

ReplyDelete