Sunday, September 29, 2013

Complex loop vs complex sum in GAMS

My original formulation was a sum. Ugly and complex but it works; unfortunately it took a long time 1616 seconds. After a few “grande dark roasts” I rewrote it as a loop. Much better: 0 seconds! I don’t understand exactly why.

* fast: 0 seconds
loop((TechYieldname,fpumap(fpuall,fpu),cropmap(cropAll,crop),cropjmap(crop,j),LandMap(LandAll,Land),tech,pt(p,t))$UserTechYieldDriver(TechYieldname,FpuAll,CropAll,LandAll,Tech,p),
   YldTechGRX00a(TechYieldname,j,fpu,land,tech,t) =
        UserTechYieldDriver(TechYieldname,FpuAll,CropAll,LandAll,Tech,p);
);


* slow: 1616 seconds

YldTechGRX00b(TechYieldname,j,fpu,land,tech,t) =
sum((fpumap(fpuall,fpu),cropmap(cropAll,crop),cropjmap(crop,j),LandMap(LandAll,Land),pt(p,t)),UserTechYieldDriver(TechYieldname,FpuAll,CropAll,LandAll,Tech,p));

1 comment: