User Tools

Site Tools


interfaces:how_to_merge_a_parameter_from_two_gdx_files_without_increasing_the_dimension

How to merge a parameter from two gdx files without increasing the dimension?

Sometimes, you want to merge a parameter from two gdx files without increasing the dimension. The following examples merges parameter parA and parB, from parA.gdx and parB.gdx, respectively. The resulting parameter, par, is written to par.gdx.

$title How to merge a parameter from two gdx files without increasing the dimension
$ontext

This examples shows how to merge parameter parA in file parA.gdx and parameter
parB in file parB.gdx into parameter par wihtout increasing the dimension.
The merging is aborted if a non-unique element is encountered.

Source:
parA.gdx
            p1          p2
a1       1.000       2.000
a2       1.000       2.000

parB.gdx:
            p1          p2
b1       2.000       4.000
b2       3.000       6.000

Output:
par.gxd
            p1          p2
a1       1.000       2.000
a2       1.000       2.000
b1       2.000       4.000
b2       3.000       6.000
$offtext

* Create  parA.gdx and parB.gdx
$onecho > makegdxsource.gms
sets p price     /p1*p2/
     a products of group A /a1*a2/
     b products of group B /b1*b2/;
Parameters parA(a,p), parB(b,p);
parA(a,p)=1*ord(p);
parB('b1',p)=2*ord(p);
parB('b2',p)=3*ord(p);
execute_unload 'parA.gdx' parA=mpar;
execute_unload 'parB.gdx' parB=mpar;
$offecho
$call 'gams makegdxsource.gms'

*Merge the two gdx files
$call gdxmerge o=merged.gdx para.gdx parb.gdx
alias(*,i,j,k)
parameter mpar(i,j,k) Merged parA and parB
           par  (j,k) parA and parB wihtout dimension i;
$gdxin merged.gdx
$load mpar
* Remove the additional index i
par(j,k) = sum(i, mpar(i,j,k));
abort$(card(par) <> card(mpar)) "duplicate entries";
display par;
execute_unload 'par.gdx' par;
interfaces/how_to_merge_a_parameter_from_two_gdx_files_without_increasing_the_dimension.txt · Last modified: 2012/10/25 08:57 by support