I am stuck in a problem where the Looping Index is also used as a Domain Variable in a Table. Here Please refer to the code below:

SET m 'operating modes' / A, B, C/
p 'liquid fractions'
/ GO
HN
LD
HD
BR / ;
Table ratio(m,p) ' ratios for different operating modes'
GO HN LD HD BR
A 0.1117 0.0946 0.2004 0.0688 0.5245
B 0.1172 0.0279 0.2621 0.0687 0.524
C 0.1173 0.0279 0.2103 0.1289 0.5156;
VARIABLES
unit(u)
Qfeed(p)
z;
EQUATIONS
Q
Objective;
PARAMETERS
Qfeedm(p,m)
unitm(p,m)
zm(m);
Q(p,m).. QFeed(p) =E= unit(u)*ratio(p,m);
Objective.. z(m) =E= ratio(p,m)*500;
Model test /ALL/
LOOP(m,
*Here I want to LOOP over Parameter ratio, which is in Table form --- I DON'T KNOW HOW?
SOLVE test using LP maximizing z
Qfeedm(p,m) = Qfeed.L(p)
unit(u,m) = unit.L(u)
zm(m) = z.L;

As the “Table ratio(p,m)” also depends on the “Operating Mode”, I don’t know how to add it in the loop.

Hi
Just have a look at this [ur=hCttps://forum.gamsworld.org/viewtopic.php?f=2&p=26821#p26821l]discussion [/url]and see the example I provided (I added the solution to the problem in the answer with “You owe me a beer”).
Cheers
Renger

I actually saw that post. In fact, I learnt to apply Loop on objective function from your post. However, the case is slightly different in my scenario. Here the looping index (m) is also used as a dependent variable in the Table ratio(m,p). Now, how should I define the Loop over the index ‘m’ when ‘m’ also acts as a dependent variable in ‘ratio(p,m)’ ? Unlike your suggested post, ‘m’ is not exactly like an independent variable as ‘time period’.

Hi
If I understand correctly you want to solve your model for every operation mode m.
This means looping over m and making sure that “m” doesn’t appear in your code.
For this, you redefine your variables and parameters used in the model by dropping the index m and assigning the parameters from the original table.
Example:

parameter ratioModel(p), unitModel(p), QfeedModel(p)
...
variable
Z, Q(m), ...
equation Q(p), Objective, ...
...
Q(p).. QFeed(p) =E= unit(u)*ratioModel(p);
Objective..
Z =E= ratioModel(p) * 500;
loop(m,
ratioModel(p) = ratio(m,p);
unitModel(p= unitm(m,p=;
....
* solve model
* save results in parameter indexed over m
);

Are you suggesting to drop looping index(m) from the table as well? In the existing case, the table is 2-dimensional having looping index (m) on x-axis and liquid fractions (p) on y-axis. If I remove ‘m’ from the table then there will be a domain violation.

Hi
In your model you don’t want to have the m-index, so I made a table just over p (ratioModel(p)) and in the loop over the index m I assigned the variables of the original table to the parameter ratioModel:

loop(m,
ratioModel(p) = ratio(m,p);

The equations now have ratioModel(p) and not any longer ratio(m,p).

Q(p).. QFeed(p) =E= unit(u)*ratioModel(p);

I only showed you how to adjust some of the code. The rest is up to you.
Cheers
Renger

No, you should use ratio(p) in your model and assign the values from ratioModel(p,m) to this parameter in the loop.

PARAMETERS
M 'Operating Mode'
/A, B, C/
ratio(p,m)
/
GO.A 0.1117
GO.B 0.1172
GO.C 0.1173
HN.A 0.0946
HN.B 0.0279
HN.C 0.0279
/,
ratiomodel(p) Ratio used in the model;
In the Loop, I defined the code as:
CODE: SELECT ALL
LOOP(m,
ratiomodel(p) = ratio(p,m);