User Tools

Site Tools


gams:getting_the_index_position_of_the_largest_element_of_a_set

Getting the index position of the largest element of a set

I have a problem of choosing indexes for the maximum value of a set. Set i /i1*i5/, j /j1*j10/ a(i,j) is a set of value on i and j. Let

Maxa = smax((i,j), a(i,j));

How do I get the index for i and j which lead to value Maxa?

Try:

sets i /i1 * i5/,
     j /j1 * j4/,
     posmax(i,j) 'position of largest element';
parameter a(i,j) 'some data',
          maxa   'largest element of a';
a(i,j)=uniformint (1,100);
maxa = smax((i,j), a(i,j) ) ;
posmax(i,j) = a(i,j) = maxa ;
option decimals=0;
display a, maxa, posmax;
E x e c u t i o n

----     23 PARAMETER a  some data
            j1          j2          j3          j4
i1          18          85          56          31
i2          30          23          35          86
i3           7          51         100          58
i4         100          77          14          64
i5          16          26          67          44

----     23 PARAMETER maxa                 =          100  largest elements of a

----     23 SET posmax  position of largest element
            j1          j3
i3                     YES
i4         YES
gams/getting_the_index_position_of_the_largest_element_of_a_set.txt · Last modified: 2007/03/19 12:52 (external edit)