use of subset

Problems with modeling
Post Reply
RZoro95
User
User
Posts: 11
Joined: 2 years ago

use of subset

Post by RZoro95 »

Hi, I have a modeling problem on GAMS and I don't know how to proceed.
In practice I should use a variable that takes into account 2 sets, but using only one subscript.
In practice I have 64 companies (shares), and 8 sectors (8 companies per sector 8x8=64). Initially, to run the model, I used a double subscript variable, X_is (which represents the fraction of capital to be invested in share i belonging to sector s), using a matrix with i shares on the rows and s sectors on the columns. This way things work perfectly. But now, having to write it professionally, I need to use only one subscript and therefore only the X_i variable. This is because it is mathematically correct to use only one subscript. How can I proceed? Whereas the X_i has to consider the action in that particular sector? I've thought about using the subset, I just don't really know how to go about it. Could anyone help me? I would be really grateful. Thank you.
User avatar
dirkse
Moderator
Moderator
Posts: 215
Joined: 7 years ago
Location: Fairfax, VA

Re: use of subset

Post by dirkse »

Zorro,

I encourage you to look at the GAMS model library: anywhere is probably useful, but start with the trnsport and dice models if you don't have other ideas. You will observe that using multiply-indexed variables is the normal practice. There is nothing unprofessional about this. It is very much what the professionals do.

-Steve
RZoro95
User
User
Posts: 11
Joined: 2 years ago

Re: use of subset

Post by RZoro95 »

perhaps I misused the term and was misunderstood. I need to use only one index because I'm writing a paper and my teacher insisted that we have to use only one index. And now I have to change the whole model
RZoro95
User
User
Posts: 11
Joined: 2 years ago

Re: use of subset

Post by RZoro95 »

dirkse wrote: 9 months ago Zorro,

I encourage you to look at the GAMS model library: anywhere is probably useful, but start with the trnsport and dice models if you don't have other ideas. You will observe that using multiply-indexed variables is the normal practice. There is nothing unprofessional about this. It is very much what the professionals do.

-Steve
Basically i define a set s (which are sectors), and a set i (which are stocks). In total I have 64 stocks, 8 per sector. We then define a score for each company, which I had previously called SC(s,i) (therefore with a double index) as it indicated the score of stock (company) i in sector s. And like this all works!!! :). In fact, the data were read from an excel sheet in which the various scores are tabulated in a matrix (s,i). Now I have to (for paper reasons and for my professor request) use only one index and therefore SC(i). My question is how can I do that? How can I make sectors s as a sort of attributes of the single stock i ? In practice I have to use only the index i of the shares which are 64 but make sure that the model distinguishes which shares are part of sector 1, or sector 2, 3, 4.. etc. Because in the end I have to model a problem that maximizes the overall portfolio score. Max Sc(i) x X(i). Where X(i) is the fraction of capital to be invested in share i.
Manassaldi
User
User
Posts: 118
Joined: 7 years ago
Location: Rosario - Argentina

Re: use of subset

Post by Manassaldi »

Hello, I think you should define a subset that relates s with i
for example:

Code: Select all

sets
i /i1*i64/
s /s1*s8/
sector(s,i)
;
parameter
SC(i)
/i1 ..
i2 ..
.
.
.
i64 .. /
pi /1/
;
loop(s,
sector(s,i)$(ord(i) ge pi and ord(i) le pi+7)=yes;
pi=pi+8;
);
You must rearrange the 8x8 matrix into a 64-position vector. The first 8 positions correspond to sector 1, the next 8 to sector 2, and so on.
For example, if you want to sum all the fractions in a sector, you can use the subset previously defined:

Code: Select all

eq(s).. Sector(s) =e= sum(i$sector(s,i),X_i(i));
I hope this helps you, this topic is not my expertise, so I hope I'm not mistaken.
Best!
Post Reply