How to merge a parameter from two GDX files without increasing the dimension?
Moderator: aileen
Forum rules
Please ask questions in the other sub-forums
Please ask questions in the other sub-forums
How to merge a parameter from two GDX files without increasing the dimension?
How do I merge a parameter from two GDX files without increasing the dimension?
Re: How 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.
Code: Select all
$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 without 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.gdx
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'
$ife errorlevel<>0 $abort problem running gams makegdxsource.gms
*Merge the two gdx files
$call gdxmerge o=merged.gdx para.gdx parb.gdx
$ife errorlevel<>0 $abort problem running gdxmerge
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;