Merging GDX files

Top  Previous  Next

GDXMERGE is a utility distributed with GAMS that can be used to combine the information from several GDX files into one composite file and in turn can be used to compare their contents. Symbols with the same name, dimension and type that appear in the separate files are combined into a single symbol with an added dimension in the first index position that gives the file name.

 

The procedure is uses as follows :

 gdxmerge filepattern1 filepattern2 .... filepatternn

 

where the filepattern entries represent are either individual file names or a wildcard representation using ? and *.

 

The result will be written to a file called merged.gdx.

 

In the resultant GDX file one cal find all of the data in the source GDX files plus a set named Merged_set_1 that contains the names of all the files processed

during the merge operation.  In that set the explanatory text contains the date and time of the gdx file processed.

 

Notes:

 

The file merged.gdx can and will not be used in a merge operation even if the name matches a file pattern.
Symbols with dimension 20 cannot be merged, because the resulting symbol will have dimension 21 which exceeds the maximum dimension allowed by GAMS.
By default, the program reads all gdx files once and stores all data in memory before writing the merged.gdx file. A parameter big=numbercan be used to specify a cutoff for symbols that will be written one at a time. Each symbol that exceeds the size specified by big will be processed by reading each gdx file and only process the data for that symbol. This can lead to reading the same gdx file many times, but it allows the merging of large data sets. The formula used to calculate the cutoff is: Dimension * TotalNumberOfElements. The number id is doubled for variables and equations.

 

Example (gdxmerge.gms):

 

Suppose we solve the trnsport model from the model library using different LP solvers and wish to compare the runs. To do this After each run, we write all

symbols to a gdx file and then use GDXMERGE to merge the solution information. Then suppose we compare the results or the two dimensional trnsport model solution variable X reading the X from the  merged GDX file into an array called ALLX that has the file names as its first dimension

 

$call gamslib trnsport

$call gams trnsport lp=bdmlp gdx=bdmlp

$call gams trnsport lp=cplex gdx=cplex

$call gams trnsport lp=xpress gdx=xpress

$call gams trnsport lp=conopt gdx=conopt

$call gams trnsport lp=minos gdx=minos

$call gams trnsport lp=snopt gdx=snopt

$call gdxmerge bdmlp.gdx cplex.gdx xpress.gdx conopt.gdx minos.gdx snopt.gdx

set i supply set

   j demand set

   merged_set_1 names of gdx files

variable AllX(merged_set_1,i,j);

*load i and j from one of the solver gdx files

$gdxin bdmlp.gdx

$load i

$load j

*load merged file

$gdxin merged.gdx

$load merged_set_1

$load AllX=X

$gdxin

option AllX:5:1:2;

display i,j,merged_set_1,AllX.L;

 

Instead of using the display statement, we can also use the GAMSIDE to view the merged.gdx file by opening it in the editor and looking at X then dragging the indices around into the order wanted.:

 

         clip0004