* * GAMS program for knapsack, med to maengder. * Se ogsaa Wyndor-glass eksemplet for brug af to-dimensionelle tabeller * David Pisinger * $eolcom // option iterlim=999999999,reslim=300,optcr=0.0,optca=0.0,solprint=OFF,mip=XPRESS; SETS i1 'genstand1' /i1, i2, i3, i4, i5/ i2 'genstand2' /i1, i2, i3, i4, i5/ PARAMETERS b 'max energi' / 25 / e1(i1) 'energi1' / i1 12 i2 7 i3 8 i4 11 i5 15 / e2(i2) 'energi2' / i1 12 i2 4 i3 6 i4 13 i5 14 / s1(i1) 'smag1' / i1 13 i2 12 i3 7 i4 8 i5 10 / s2(i2) 'smag2' / i1 21 i2 4 i3 12 i4 8 i5 16 / ; VARIABLES z 'total smag som skal optimeres' binary variables x1(i1) 'beslutningsvariable' binary variables x2(i2) 'beslutningsvariable' EQUATIONS smag 'total smag' energi 'total energi' ; smag .. z =E= sum(i1, s1(i1)*x1(i1)) + sum(i2, s2(i2)*x2(i2)); energi .. sum(i1, e1(i1)*x1(i1)) + sum(i2, e2(i2)*x2(i2)) =L= b ; MODEL knapsack /ALL/ ; knapsack.workspace=10; SOLVE knapsack USING MIP MAXIMIZING z ; DISPLAY z.L; // value of the objective DISPLAY x1.L; // x1.L : Level, i.e. result DISPLAY x2.L; // x2.L : Level, i.e. result