|
Rank |
Top Previous Next |
|
One may also use Rutherford and van der Eijk's RANK libinclude procedure to obtain an array giving the relative sorted position of elements. This procedure implements an O(nlog(n)) algorithm for ranking one-dimensional numeric data within a GAMS program. The routine uses the GDX facility and an external program to sort the data. The syntax for using rank is
$LIBINCLUDE rank arraytosort setofelements rankofitem optionalpercentile
The first three arguments are required. The last is optional. These are defined as following:
Example: GAMS code implementing RANK appears at the bottom of sorted.gms and is as follows
$LIBINCLUDE rank unsort i rankdata put // 'After rank which sorts low' //; loop(asord, loop(i$(rankdata(i)=ord(asord)), put 'In place ' asord.tl:0 ' with value of ' unsort(i):0:0 ' is item ' @42 i.tl:0/)); display r;
The resultant output is
After rank which sorts low
In place 1 with a value of 12 is item a3 In place 2 with a value of 15 is item a4 In place 3 with a value of 22 is item a6 In place 4 with a value of 22 is item a1 In place 5 with a value of 33 is item a2 In place 6 with a value of 47 is item a5 Notes: Rutherford and van der Eijk state:
|