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'); sos2variables wx(i) wy(j) wd(k) ; positivevariables 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; |