Thursday, April 2, 2009

GAMS: set up a one-to-one mapping

In a model I was working on yesterday, I needed something like:

set i 'jobs' /start1*start10, job1*job100, end1*end10/;
set r 'resources' /r1*r10/;
set startmap(i,r) /
   start1.r1
   start2.r2
   start3.r3
   start4.r4
   start5.r5
   start6.r6
   start7.r7
   start8.r8
   start9.r9
   start10.r10
/;
set endmap(i,r) /
   end1.r1
   end2.r2
   end3.r3
   end4.r4
   end5.r5
   end6.r6
   end7.r7
   end8.r8
   end9.r9
   end10.r10
/;

This “diagonal mapping” can be written more compactly as using some new GAMS syntax:

set i 'jobs' /start1*start10, job1*job100, end1*end10/;
set r 'resources' /r1*r10/;
set startmap(i,r) /
   start1*start10:r1*r10
/;
set endmap(i,r) /
   end1*end10:r1*r10
/;