Records of an element filtered by a subset

Hi all,

I was trying to get a part of a larger parameter using GAMS indexing with a subset. Following is an example from UserGuide:

from gamspy import Container, Set, Parameter, Sum

m = Container()
i = Set(m, "i", records=[(f"i{i}", i) for i in range(10)])

k = Parameter(m, domain=i)
k[i] = 4

j = Set(m, "j", domain=i, records=i.records[0:5])

print(k[j].records)

I would expect that the last line will print the record of the k parameter filtered by subset j. Instead, it still prints the entire parameter records:

i	value
0	i0	4.0
1	i1	4.0
2	i2	4.0
3	i3	4.0
4	i4	4.0
5	i5	4.0
6	i6	4.0
7	i7	4.0
8	i8	4.0
9	i9	4.0

Of course, I can easily filter it after converting to data frames, but I was wondering how it can be achieved using GAMS syntax.

As always, I appreciate your help and time.

Best,

Adam

You can do the following:

from gamspy import Container, Set, Parameter

m = Container()
i = Set(m, "i", records=[(f"i{i}", i) for i in range(10)])

k = Parameter(m, domain=i)
k[i] = 4

j = Set(m, "j", domain=i, records=i.records[0:5])

l = Parameter(m, domain=j)
l[j] = k[j]
print(l.records)

Thanks, Muhammet.

That works for this small example. But practically, I need to conduct complicated calculations that require me to filter many parameters. I would need to introduce a new one for each. Any other alternative?

You can either do that or work with the DataFrames. Since I don’t know what kind of complicated calculations you are going to make, I can’t really offer a better alternative. Do you have a concrete example? And what are your concerns with the current approach?