Table of Contents
LibInclude file gdxservice.gms
to provide functionality of label encoding conversion (GDXEncoding
), sorting (GDXRank
), and label renaming (GDXRename
).
GDXEncoding
This converts the unique elements in the GDX file from one encoding to another one. The GDX string (a sequence of bytes) is decoded using encodingIn (default latin_1
) into a proper unicode string and afterwards encoded again into a GDX string (byte array) using encodingOut (default utf_8
). If verbose is set to 1 (default is 0) the converted unique elements are printed with new and old GDX strings (byte arrays) to the GAMS log. If the number of conversions is necessary in GAMS, a name of a scalar can be passed via numConv (default empty) which will hold the number of unique elements converted. -c
runs this at compile time, -e
at execution time (default).
Usage:
$libInclude gdxservice [-c|-e] GDXEncoding [-encodingIn=abc] [-encodingOut=xyz] [-numConv=sym] [-verbose=0|1] GDXFile
Where:
Argument Description encodingIn
Input encoding of GDX string. encodingOut
Output encoding of GDX string. numConv
GAMS scalar symbol to store the number of actual conversions. verbose
Indicator to print the individual conversion to the GAMS log.
Example:
* UTF-8 encoding
Set c / "côte d'ivoire-3" , "cote d'ivoire-3" /;
Scalar numConv /0/;
$gdxUnload c.gdx c
* Changes the label encoding from UTF-8 to Latin-1:
$libInclude gdxservice -c gdxEncoding -encodingIn=utf_8 -encodingOut=latin_1 -numConv=numConv -verbose=1 c.gdx
The complete example is also part of the GAMS Test Library, see model [gdxencoding1] for reference.
GDXRank
This sorts one dimensional symbol sym
and stores sorted indices in one dimensional parameter symIdx
.
-c
runs this at compile time, -e
at execution time (default).
Usage:
$libInclude gdxservice [-c|-e] GDXRank sym symIdx
Where:
Argument Description sym
One-dimensional symbol. symIdx
One-dimensional parameter containing the sorted indices.
Example:
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
$libInclude gdxservice GDXRank A AIndex
display AIndex;
The complete example is also part of the GAMS Data Utilities Library, see model [GDXRANKExample18] for reference.
GDXRename
This renames the labels in the GDX file using a two dimensional mapSet
. The renaming of the labels only affects the string stored for each label, and does not change the data order for the symbols in the GDX file. Because no data is changing in the GDX file, only the strings for the labels are changed and applied to the GDX file directly and no new GDX file is written. This replaces the labels in the GDX file by the ones in the mapSet
.
-c
runs this at compile time, -e
at execution time (default).
Usage:
$libInclude gdxservice [-c|-e] GDXRename [-reverse=0|1] GDXFile mapSet
Where:
Argument Description -reverse=0|1
Determines if mapSet
with recorda.b
leads to a replace ofa
byb
or toa
replace ofb
bya
(default:-reverse=0
).GDXFile
GDX file to use. mapSet
Set of labels to be used for renaming.
Example:
Set c / r, g, b, y /;
Parameter A(c) / r 1, g 2, b 3, y 4 /;
$gdxOut color.gdx
$unload c A
$gdxOut
Set map(c,*) / r.red, g.green, b.blue, y.yellow /;
$libInclude gdxservice -c GDXRename color.gdx map
The complete example is also part of the GAMS Test Library, see model [gdxrename1] for reference.