plan
is a matrix in data.
for i = 1:5
for j = 1:3
for k = 1:plan(j,i)
C(i,j,k) = SUB(j,i);
end
end
end
How to model same in GAMS
. Please help.
plan
is a matrix in data.
for i = 1:5
for j = 1:3
for k = 1:plan(j,i)
C(i,j,k) = SUB(j,i);
end
end
end
How to model same in GAMS
. Please help.
Loops are often overused by users unfamiliar with GAMS. In GAMS explicit loops are the exception: usually we want to use implicit loops. Like:
c(i,j,k)$(ord(k)<=plan(j,i)) = sub(j,i);
First thing is that you have to think about the final output C as a matrix with given dimensions. That is, the size of the third dimension k must be determined before hand. Probably as the maximum of all plan(j,i) values. So I am going to call the maximum value of the index k as capital K. In that case you can do that as follows:
SET i /1*5/;
SET j /1*3/;
SET k /1*K/;
Loop (i,
Loop (j,
Loop (k,
If (ord(k) <= plan(j,i), C(i,j,k) = SUB(j,i););
);
);
);