how to use a single subscript variable

Problems with syntax of GAMS
Post Reply
RZoro95
User
User
Posts: 11
Joined: 2 years ago

how to use a single subscript variable

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
bussieck
Moderator
Moderator
Posts: 1043
Joined: 7 years ago

Re: how to use a single subscript variable

Post by bussieck »

Hi, I don't know what you mean by this
But now, having to write it professionally
Almost all GAMS model have multiple indexes, this is as professional as it gets. There are ways to ""flatten" the index space, but that looks very ugly, so before suggesting ways to do this, I would like to understand why you can't use the multi-index.

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

Re: how to use a single subscript variable

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: how to use a single subscript variable

Post by RZoro95 »

bussieck wrote: 9 months ago Hi, I don't know what you mean by this
But now, having to write it professionally
Almost all GAMS model have multiple indexes, this is as professional as it gets. There are ways to ""flatten" the index space, but that looks very ugly, so before suggesting ways to do this, I would like to understand why you can't use the multi-index.

-Michael
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.
User avatar
bussieck
Moderator
Moderator
Posts: 1043
Joined: 7 years ago

Re: how to use a single subscript variable

Post by bussieck »

If each stock belongs exactly to one sector, you can change SC(s,i) to SC(i) because the sector is implicit for a given i. You can work with a map si(s,i) that tells GAMS about what stocks belong to what sector. In your algebra, you can use the map to access the sector (and it's data) if you iterate over stock i but need the corresponding sector. If you need specific help, I suggest that you share your model.

-Michael
Post Reply