User Tools

Site Tools


gams:getting_the_index_position_of_the_largest_element_of_a_set

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
gams:getting_the_index_position_of_the_largest_element_of_a_set [2007/03/19 13:52]
127.0.0.1 external edit
gams:getting_the_index_position_of_the_largest_element_of_a_set [2020/05/25 17:14] (current)
Lutz Westermann add singleton set variant
Line 1: Line 1:
-====== Getting the index position of the largest element of a set ====== +====== Getting the index position of the largest element of a parameter ​====== 
-I have a problem of choosing indexes for the maximum value of a set+I have a problem of choosing indexes for the maximum value of a parameter
-''​Set i /i1*i5/, j /​j1*j10/'' ​''​a(i,​j)''​ is a set of value on i and j. Let  <​code>​Maxa = smax((i,j), a(i,​j));</​code>​ How do I get the index for i and j which lead to value ''​Maxa''?​+Let ''​a(i,​j)''​ be a parameter with ''​Sets i /i1*i5/, j /​j1*j10/''​. Let  <​code>​Maxa = smax((i,j), a(i,​j));</​code>​ How do I get the index for ''​i'' ​and ''​j'' ​which lead to value ''​Maxa''?​
  
 Try: <​code>​ Try: <​code>​
-sets i /i1 * i5/, +Set i /i1 * i5/, 
-     ​j /j1 * j4/, +    j /j1 * j4/, 
-     ​posmax(i,j) '​position of largest element';​ +    posmax(i,j) '​position of largest element';​ 
-parameter ​a(i,j) 'some data',+      
 +Parameter ​a(i,j) 'some data',
           maxa   '​largest element of a';           maxa   '​largest element of a';
 +
 a(i,​j)=uniformint (1,100); a(i,​j)=uniformint (1,100);
-maxa = smax((i,j), a(i,j) ) ; +maxa = smax((i,j), a(i,j)); 
-posmax(i,j) = a(i,j) = maxa ; +posmax(i,j) = a(i,j) = maxa; 
-option ​decimals=0;+ 
 +Option ​decimals=0;
 display a, maxa, posmax; display a, maxa, posmax;
 </​code>​ </​code>​
 <​code>​ <​code>​
-E x e c u t i o n+----     13 PARAMETER a  some data
  
-----     23 PARAMETER a  some data 
             j1          j2          j3          j4             j1          j2          j3          j4
 +
 i1          18          85          56          31 i1          18          85          56          31
 i2          30          23          35          86 i2          30          23          35          86
Line 26: Line 29:
 i5          16          26          67          44 i5          16          26          67          44
  
-----     23 PARAMETER maxa                 ​= ​         100  largest elements of a 
  
-----     23 SET posmax ​ position of largest element+----     13 PARAMETER maxa                 ​= ​         100  largest element of a 
 + 
 +----     ​13 ​SET posmax ​ position of largest element 
             j1          j3             j1          j3
 +
 i3                     YES i3                     YES
 i4         YES i4         YES
 +</​code>​
 +
 +In case just one element is wanted and not all index positions with the maximum number, one can use a [[https://​www.gams.com/​latest/​docs/​UG_SetDefinition.html#​UG_SetDefinition_SingletonSets|Singleton Set]] like this:
 +
 +<​code>​
 +Singleton Set posmaxS(i,​j);​
 +Option strictSingleton=0;​
 +posmaxS(i,​j) = a(i,j) = maxa;
 +display posmaxS;
 +</​code>​
 +
 +<​code>​
 +----     18 SET posmaxS  ​
 +
 +            j3
 +
 +i3         YES
 </​code>​ </​code>​
  
IMPRESSUM / LEGAL NOTICEPRIVACY POLICY gams/getting_the_index_position_of_the_largest_element_of_a_set.1174308740.txt.gz · Last modified: 2007/03/19 13:52 by 127.0.0.1