Table as index

Problems with syntax of GAMS
Post Reply
kpetridis
User
User
Posts: 1
Joined: 7 years ago

Table as index

Post by kpetridis »

Hello,

I have the following formulation:
CodeCogsEqn.gif
CodeCogsEqn.gif (779 Bytes) Viewed 3062 times
In the second summation, tj,i is a table containing for example the following values

(j=1,2, and i=1,2,3)

alias(i,k)

Table t(j,i)
1 2 3

1 1.000 3.000 2.000
2 1.000 1.000 1.000

I face the two following problems:

1. How to introduce a table and treat it as a set in the summation?
2. In the summation, for certain values, i index goes out of bounds.

More specifically I have the following:
CodeCogsEqn.gif
CodeCogsEqn.gif (779 Bytes) Viewed 3062 times
since the first elemnt of the table is t(j=1,i=1)=1.

Could you please help me?
Attachments
CodeCogsEqn (1).gif
CodeCogsEqn (1).gif (532 Bytes) Viewed 3062 times
User avatar
Renger
Posts: 639
Joined: 7 years ago

Re: Table as index

Post by Renger »

Hi

Is this you are looking for? I just assumed that the row index of the table starts with 1 instead of 0.

Code: Select all

set j /1,2/,
    i /1,2,3/;

alias(i,k,l);

table t(j,i)
       1        2        3
1   1.000    3.000    2.000
2   1.000    1.000    1.000
;

* Define a set that consists of all combinations of j and i
set tb(j,i) /#j.#i/;

display tb;

parameter w(i,k);

* Assign some numbers as they are not available in the quesion
w(i,k) = ord(i) + ord(k)
;

display w, t;

parameter wantedsum(j,i);

loop(tb(j,i),
        wantedsum(j,i) =  sum(l, sum(k$(ord(k) le t(j,i)), w(l,k)));
    );
display wantedsum;
____________________________________
Enjoy modeling even more: Read my blog on modeling at The lazy economist
Post Reply