Description
pvde
Small Model of Type : GAMS
Category : GAMS Test library
Main file : gdxrank1.gms
$title 'Tests some rank stuff' (GDXRANK1,SEQ=141)
* pvde
set I /i1 * i6/;
parameter A(I) /i1=+Inf, i2=-Inf, i3=Eps, i4= 10, i5=30, i6=20/;
parameter AIndex(i) 'permutation index of A';
* sort symbol; result in parameter AIndex
executeTool.checkErrorLevel 'alg.rank A AIndex';
$onImplicitAssign
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));
Abort$(Card(C) <> 0) 'sort failed', C;
* Now some $libInclude rank test
option clear=AIndex, clear=ASorted;
$libInclude rank A i AIndex
ASorted(i + (AIndex(i)- Ord(i))) = A(i);
C(i)=Yes$(Ord(i) < Card(i)) and (ASorted(i) > ASorted(i+1));
Abort$(Card(C) <> 0) 'sort failed', C;
* Rank works over the domain so instead of EPS we can have 0
A('i3') = 0;
option clear=AIndex, clear=ASorted;
$libInclude rank A i AIndex
ASorted(i + (AIndex(i)- Ord(i))) = A(i);
C(i)=Yes$(Ord(i) < Card(i)) and (ASorted(i) > ASorted(i+1));
Abort$(Card(C) <> 0) 'sort failed', C;
* Now with some percentiles
Parameter
pct(*) 'Percentiles to be computed' / q0 EPS, q25 25, q50 50, q75 75, q100 100 /;
option clear=AIndex, clear=ASorted;
$libInclude rank A i AIndex pct
ASorted(i + (AIndex(i)- Ord(i))) = A(i);
C(i)=Yes$(Ord(i) < Card(i)) and (ASorted(i) > ASorted(i+1));
Abort$(Card(C) <> 0) 'sort failed', C;
display pct;
* Now with a variable level and some percentiles
variable
xA(I) /i1.l=+Inf, i2.l=-Inf, i3.l=0, i4.l= 10, i5.l=30, i6.l=20/;
Parameter
xPct(*) 'Percentiles to be computed' / q0 EPS, q25 25, q50 50, q75 75, q100 100 /;
option clear=AIndex, clear=ASorted;
$onDotL
$libInclude rank A i AIndex xPct
ASorted(i + (AIndex(i)- Ord(i))) = A(i);
C(i)=Yes$(Ord(i) < Card(i)) and (ASorted(i) > ASorted(i+1));
Abort$(Card(C) <> 0) 'sort failed', C;
display xPct;
* Make sure, it works in a loop
Set
l 'index of loop' / l1 /;
Parameter
r(i) 'order' / /
s(i) 'order';
loop(l,
executeTool.checkErrorLevel 'alg.rank A r';
s(i) = r(i);
);
Abort$(Card(r) <> Card(s)) 'Assignemnt in loop failed', r, s;