GDXRANKExample18.gms : Sorts a parameter, creates a sorted version and verifies that the sort works correctly

Description

This program sorts a parameter, creates a sorted version and
verifies that the sort works correctly.


Category : GAMS Data Utilities library


Main file : GDXRANKExample18.gms   includes :  GDXRANKExample18.gms

$ontext
This program sorts a parameter, creates a sorted version and
verifies that the sort works correctly.

$offtext

set I /i1 * i6/;
parameter A(I) /i1=+Inf, i2=-Inf, i3=Eps, i4= 10, i5=30, i6=20/;
parameter AIndex(i) 'permutation index';
* sort symbol; result in parameter AIndex
executeTool.checkErrorLevel 'alg.rank A AIndex';
* Symbol AIndex has been loaded implicitly by executeTool.checkErrorLevel. The compiler
* instruction in the next line supresses errors about presumably unassigned symbols
$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));
display C;
Abort$(Card(C) <> 0) 'sort failed';