gdxrank1.gms : Tests some GDXRANK stuff



Small Model of Type : GAMS

Category : GAMS Test library

Main file : gdxrank1.gms

$title 'Tests some GDXRANK stuff' (GDXRANK1,SEQ=141)

* pvde

set I /i1 * i6/;
parameter A(I) /i1=+Inf, i2=-Inf, i3=Eps, i4= 10, i5=30, i6=20/;
display A;
* write symbol A to gdx file
execute_unload "rank_in.gdx", A;

* sort symbol; result in parameter A also
execute 'gdxrank rank_in.gdx rank_out.gdx > %system.nullfile%';

* load the permutation index
parameter AIndex(i);
execute_load "rank_out.gdx", AIndex=A;
display AIndex;

* create a sorted version
parameter ASorted(i);
   ASorted(i + (AIndex(i)- Ord(i))) = A(i);
display ASorted;

* check that the result is sorted
set C(i);
C(i)=Yes$(Ord(i) < Card(i)) and (ASorted(i) > ASorted(i+1));
display C;
Abort$(Card(C) <> 0) 'sort failed';