Hi folks, I'm working with a GAMS model which has hierarchical sets defined and I have a query about the best way to reference a parameter defined over the parent set based on an index from the child set. To illustrate: SET C 'Set of countries' / C1 C2 /; SET R 'Regions in each country' / C1_R1 C1_R2 C2_R1 C2_R2 /; SET CR 'Set mapping countries to regions' / C1.C1_R1 C1.C1_R2 C2.C2_R1 C2.C2_R2 /; Parameter POP(C) 'Population of each country' / C1=100000 C2=200000 /; Parameter R_POP_F(R) 'Fraction of country's population in each region' / C1_R1=0.2 C1_R2=0.7 C2_R1=0.5 C2_R2=0.5 /; Parameter R_POP(R) 'Absolute population of each region'; R_POP(R)=R_POP_F(R)*POP(C); To find the absolute population in each region, I need to multiply the fraction of the population in each region, R_POP_F(R) by the corresponding country's population, POP(C). How can I do this in one line, similarly to the above  which obviously doesn't work because the set "C" above is uncontrolled. Is it possible to somehow reference the correct POP(C) value using the sets defined above? This may not be the best way of going about this specific problem, but I have created this example to illustrate the issue I have which is part of a much larger problem and I want to avoid altering the fundamental structure of it. Thanks in advance Jody asked 29 Feb '12, 10:10 Jody 
sets C 'Set of countries' / C1, C2 / R 'Regions in each country' / C1_R1, C1_R2, C2_R1, C2_R2 / CR(C,R) 'Set mapping countries to regions' / C1.C1_R1, C1.C1_R2, C2.C2_R1, C2.C2_R2 / ; Parameters POP(C) 'Population of each country' / C1 100000, C2 200000 / R_POP_F(R) "Fraction of country's population in each region" / C1_R1 0.2, C1_R2 0.7, C2_R1 0.5, C2_R2 0.5 / R_POP(R) 'Absolute population of each region' ; R_POP(R)=R_POP_F(R)*sum(cr(c,r),POP(C)); display r_pop; answered 29 Feb '12, 15:30 erwin Someone else added a comment (unfortunately now deleted) that this is a bad modeling structure, that one needs string operations for this and that GAMS can not handle this case. Obviously I don't agree with this. This is a perfectly valid construct. The naming of the set elements is not relevant so we don't need to rely on string operations.
(29 Feb '12, 16:15)
erwin
Many thanks for that  I appreciate it. In the meantime, I actually came up with the following: LOOP( (C,R)$(CR(C,R)), R_POP(R)=R_POP_F(R)*POP(C) ); Is either solution more efficient than the other? Thanks again, Jody
(29 Feb '12, 19:31)
Jody
sorry @erwin, I got the question wrong on first reading; so I removed my earlier comment.
(29 Feb '12, 20:42)
Marco Luebbecke ♦
Both approaches are ok. Sometimes loops are faster, sometimes not (depends on the situation). See e.g. http://yetanothermathprogrammingconsultant.blogspot.com/2010/10/speedofloopsingams.html .
(29 Feb '12, 21:26)
erwin
