assign parameter value using gams Topic is solved

Problems with syntax of GAMS
Post Reply
parag_patil
User
User
Posts: 17
Joined: 3 months ago
Location: Ahmedabad
Contact:

assign parameter value using gams

Post by parag_patil » 2 months ago

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

User avatar
bussieck
Moderator
Moderator
Posts: 614
Joined: 4 years ago

Re: assign parameter value using gams

Post by bussieck » 2 months ago

Code: Select all

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

parag_patil
User
User
Posts: 17
Joined: 3 months ago
Location: Ahmedabad
Contact:

Re: assign parameter value using gams

Post by parag_patil » 2 months ago

bussieck wrote:
2 months 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 !

User avatar
bussieck
Moderator
Moderator
Posts: 614
Joined: 4 years ago

Re: assign parameter value using gams

Post by bussieck » 2 months ago

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

parag_patil
User
User
Posts: 17
Joined: 3 months ago
Location: Ahmedabad
Contact:

Re: assign parameter value using gams

Post by parag_patil » 2 months ago

I agree with you !

Post Reply