Defining parameters Topic is solved

Problems with modeling
Post Reply
diabolik
User
User
Posts: 14
Joined: 1 year ago

Defining parameters

Post by diabolik »

Hey,

I have a table on my model and I'm trying to define parameters using the values from that table as follows.

Code: Select all

Sets
k   sample number /1,2,3,4,5,6,7,8,9,10,11,12/
j   criterion /1,2,3,4/
n   class /1, 2, 3/;

Table a(k,j)
    1   2   3   4
1   1   1   1   3
2   1   1   2   2
3   1   2   1   3
4   1   2   2   1
5   1   1   1   3
6   1   1   2   2
7   1   2   1   3
8   1   2   2   1
9   1   1   1   3
10  1   1   2   3
11  1   2   1   3
12  1   2   2   1;

Parameters y(n,j)
y(1,1)=(a(1,1)+a(2,1)+a(3,1)+a(4,1))/4;
y(2,1)=(a(5,1)+a(6,1)+a(7,1)+a(8,1))/4;
y(3,1)=(a(9,1)+a(10,1)+a(11,1)+a(12,1))/4;
y(1,2)=(a(1,2)+a(2,2)+a(3,2)+a(4,2))/4;
y(2,2)=(a(5,2)+a(6,2)+a(7,2)+a(8,2))/4;
y(3,2)=(a(9,2)+a(10,2)+a(11,2)+a(12,2))/4;
y(1,3)=(a(1,3)+a(2,2)+a(3,3)+a(4,3))/4;
y(2,3)=(a(5,3)+a(6,2)+a(7,3)+a(8,3))/4;
y(3,3)=(a(9,3)+a(10,3)+a(11,3)+a(12,3))/4;
However, it gives error and I cannot do it. I searched online but could not find something similar to this. Could anyone help me with this?

Also, is there a way to define these parameters in a more efficient way? I mean as far as I know summation occurs only in the form of sum(x(i),i) and takes all the i values possible. Is there a way to put an upper bound to i?

In addition, Gams cannot read specific values from table such as a(2,4). Is there a way to read them?

Best wishes.
User avatar
bussieck
Moderator
Moderator
Posts: 1042
Joined: 7 years ago

Re: Defining parameters

Post by bussieck »

I suggest to start going through the introductory material of GAMS. GAMS follows a relational data model, GAMS does have no indexes. Every label is a string not a number. So your assignments y(1,1)=(a(1,1)+a(2,1)+a(3,1)+a(4,1))/4; would need to be changed in to y('1','1')=(a('1','1')+a('2','1')+a('3','1')+a('4','1'))/4;. GAMS is all about index assignment statement, very similar to SQL, you calculate from some tables another another table. What you want to do is probably:

Code: Select all

Sets
  k   sample number /1,2,3,4,5,6,7,8,9,10,11,12/
  j   criterion /1,2,3,4/
  n   class /1, 2, 3/
  nk(n,k) / 1.(1*4), 2.(5*8), 3.(9*12) /;

Table a(k,j)
    1   2   3   4
1   1   1   1   3
2   1   1   2   2
3   1   2   1   3
4   1   2   2   1
5   1   1   1   3
6   1   1   2   2
7   1   2   1   3
8   1   2   2   1
9   1   1   1   3
10  1   1   2   3
11  1   2   1   3
12  1   2   2   1;

Parameters y(n,j);
y(n,j) = sum(nk(n,k), a(k,j))/sum(nk(n,k), 1);
-Michael
Post Reply