GDXDIFF

The GDXDIFF tool compares the data of symbols with identical name, type and dimension in two GDX files and writes the differences to a third GDX file. A summary report will be written to standard output.

# Usage

gdxdiff file1 file2 {diffile} {options}


The .gdx file extension can be omitted. Files without a full path name are assumed to be in the current directory when using a command prompt. When using the GAMS IDE, these files are assumed to be in the current project directory. GDXDIFF requires two parameters, the file names of two GDX files. An optional third parameter is the name of the GDX difference file. Without the third parameter, the difference file will be diffile.gdx in the current directory.

diffile = fileName (default = diffile.gdx)

An optional name of the GDX difference file.

# Options

The following options can be used when calling GDXDIFF:

Option Default Description
Eps 0.0 Epsilon for comparison (absolute).
RelEps 0.0 Epsilon for comparison (relative).
field all Specify a single subfield (l, m, up, lo, prior, scale) of a variable or equation to be compared.
fldOnly disabled Write variables and equations as parameters for the selected subfield.
id all Define specific identifiers of the GDX files to be compared.
diffOnly disabled Controls if differences of variables and equations will be written as parameters or not.
cmpDefaults disabled Enables the comparison of default values.
cmpDomains disabled Enables the comparison of symbol domains.
matrixFile disabled Enables the comparison of GAMS matrix files in GDX format.
ignoreOrder disabled Ignores UEL order of input files to reduce size of output file.
setDesc Y Control if associated text of matching set elements is compared.

Some more detailed remarks on the options:

Eps = value (default = 0.0)

Absolute difference for comparisons; see also Comparing numeric values. If the difference between two values exceeds Eps, a difference will be reported. The valid range is

RelEps = value (default = 0.0)

Relative difference for comparisons; see also Comparing numeric values. If the value of RelEps is exceeded, a difference will be reported.

field = fieldName (default = all)

The specified subfield is the only field used for deciding if a variable or equation is different. FieldName is one of the following: l, m, up, lo, prior, scale or all.

fldOnly (disabled by default)

Used in combination with the field option; The variables and equations will be written as parameters for the selected subfield. This option cannot be used in combination with diffOnly and requires field being set to an actual field name but not to all.

id = identifier (default = all)

Limits the comparison to one or more symbols; symbols not specified will be ignored. Multiple identifiers can be specified as: id=id1 id=id2 or as id="id1 id2". When using GDXDIFF from the menu bar in the GAMS IDE (Utilities), this option is not available.

diffOnly (disabled by default)

Differences for variables and equations will be written as parameters; each parameter will have an additional index which is used to store the field name. Only fields that are different will be written. This option cannot be used in combination with fldOnly.

cmpDefaults

Enables the comparison of default values. When using GDXDIFF from the menu bar in the GAMS IDE (Utilities), this option is not available.

cmpDomains (disabled by default)

Enable the comparison of symbol domains. Note that the difference are not listed in particular in the diffile. When using GDXDIFF from the menu bar in the GAMS IDE (Utilities), this option is not available.

matrixFile

This activates a special mode to compare GAMS matrix files in GDX format. This is mostly done for internal use. When using GDXDIFF from the menu bar in the GAMS IDE (Utilities), this option is not available.

ignoreOrder

By default, GDXDiff preserves the UEL order of the input files. If this is set, this is disabled so that records in the output file could show up in a different order than in the input files. Doing this, the output file can be reduced in size.

setDesc = boolean (default = Y)

Enable or disable the comparison of associated texts for set elements.

Criterion for comparing numeric Values
The use of Eps and RelEps is best described by the code fragment below.

AbsDiff := Abs(V1 - V2);
if  AbsDiff <= EpsAbsolute
then
Result := true
else
if EpsRelative > 0.0
then
Result := AbsDiff / (1.0 + DMin(Abs(V1), Abs(V2))) <= EpsRelative
else
Result := false;


Interpreting the Labels in the diffile
Only symbols with the same name, type and dimension will be compared. Tuples with different values are written to the GDX difference file, and a dimension is added to describe the difference using the following labels:

• ins1 indicates that the tuple only occurs in the first file.
• ins2 indicates that the tuple only occurs in the second file.
• dif1 indicates that the tuple occurs in both files; contains the value from the first file.
• dif2 indicates that the tuple occurs in both files; contains the value from the second file.

# Examples

## Compares two GDX Files and writes the Differences to a third GDX File

In the following example, the [trnsport] model is solved twice with different capacity data. GDX files are saved for each run, and compared afterwards using GDXDIFF. The shipments variable is loaded into a new variable used for a display statement. We introduce four new unique elements that are used in the difference file.

* solve and write to unmodified.gdx before manipulating the data
solve transport using lp minimizing z;

* manipulate the data and solve again, write to modified.gdx
a('seattle') = 1.2*a('seattle');
solve transport using lp minimizing z;

execute 'gdxdiff unmodified modified diffile > %system.nullfile%';

* Declare symbols to hold the data for differences
Set difftags / dif1, dif2, ins1, ins2 /;
Variable xdif(i,j,difftags);

display a, xdif.l;


The display statement generates the following output in the listing file:

----    101 PARAMETER a  capacity of plant i in cases

seattle   420.000,    san-diego 600.000

----    101 VARIABLE xdif.L

dif1        dif2

seattle  .new-york      50.000     120.000
san-diego.new-york     275.000     205.000


Alternatively, one can open the diffile in the GAMS IDE or GAMS Studio to display the differences.

This example is also part of the GAMS Data Utilities Library, see model [GDXDIFFExample16] for reference.

GAMS Development Corp.
GAMS Software GmbH

General Information and Sales
U.S. (+1) 202 342-0180
Europe: (+49) 221 949-9170