Page 1 of 1

assign parameter value using gams

Posted: Mon May 17, 2021 9:29 am
by parag_patil
Hello,

I want to assign the row value of 2D parameter to 1D parameter as follows:

Code: Select all


set 

i /i1*i4/ , j /j1,j2/;

Parameter A(i);

Table Rf(j,i)
        i1	i2	i3	i4
j1       1    2      3        4

j2       8    7     9        8;

Here, I can do as follows:

Code: Select all

A(i) = Rf('j1' , i);
However. I will not be knowing j1 or j2 apriori. Instead, I will be only knowing ord(j).

For instance, I will have to assign Rf('j1' , i) to A(i) if ord(j) = 1.

I can also use if else loop, but can any one tell me, if I can directly use ord(j) to assign appropriate Rf(j,i) to A(i) ?

Thanks

Re: assign parameter value using gams

Posted: Mon May 17, 2021 9:53 am
by bussieck

Code: Select all

A(i) = sum(j$(ord(j)=1),Rf(j, i);
-Michael

Re: assign parameter value using gams

Posted: Mon May 17, 2021 10:12 am
by parag_patil
bussieck wrote: 2 years ago

Code: Select all

A(i) = sum(j$(ord(j)=1),Rf(j, i);
-Michael

Thanks a lot. It really saved my time. Can you please suggest me, where can I get such examples where I can learn similar to what you have said ? I am familiar to MATLAB, therefore, I am not able to do / think directly as you !

Re: assign parameter value using gams

Posted: Tue May 18, 2021 6:21 am
by bussieck
Read the chapters on sets, dynamic set, and conditional expressions and assignment in the GAMS Users Guide. Relational algebra (also used in SQL) with sets is an extremely powerful way to express data transformations and is usually much faster than normal programming loops and conditional (ifthen/else) logic. It takes some time to learn and get used to this. It is worthwhile.

-Michael

Re: assign parameter value using gams

Posted: Tue May 18, 2021 2:21 pm
by parag_patil
I agree with you !