Nested variables

Problems with syntax of GAMS
Post Reply
Abhi140
User
User
Posts: 9
Joined: 8 months ago

Nested variables

Post by Abhi140 » 2 months ago

Hi,

My problem is with the definition of variable 'ds' used in equations 1 & 2. Eq 1 & 2 runs for each line. And each line has ns (ns is a parameter in the fdata table) number of steps. Variable 'ds' should be defined for each step in each line. The way I have written variable 'ds' in equations, it will be overwritten of second line onwards. Could anyone help me with the definition of variable 'ds' in such situations? Please let me know if you need any more information.

Set
i 'Gas network buses' / 1*7 /
slack(i) 'Source bus' / 1, 3 /
t 'Time period' / t1*t1 /
mn 'Set to access fdata from excel sheet' /Cjj,Fgmin,Fgmax,ns,nsk/;


Alias (i,j);


$call gdxxrw MultiEnergySystemData.xlsx par=fdata rng=ModifiedNGSystem!A21:G27 cDim=1 rDim=2

*=== Now import data from GDX
Parameter fdata(i,j, mn);
$gdxin MultiEnergySystemData.gdx
$load fdata
$gdxin
display fdata

$ontext
fdata is like this
i j Cjj Fgmin Fgmax ns nsk
1 2 50.6 0 3000 300 300
2 3 50.1 0 1000 100 100
3 4 45.3 0 10 100 100
2 5 45.3 0 2500 250 250
5 6 43.1 0 1200 120 120
6 7 37.5 0 600 100 100

$offtext


Parameter cx(i,j), cxv(i,j);
cx(i,j)$(LN(i,j,'Limit'))= 1;


Variables ds(i,j), fg;


Equation eq1, eq2;
*, eq22, eq25;


eq1(i,j)$cx(i,j)..
fg(i,j) =e= Fgmin(i,j) + sum(ns(i,j),(1/nsk(i,j))*(Fgmax(i,j)-Fgmin(i,j))*ds(ns(i,j)));

eq2(i,j)$cx(i,j)..
sum(ns(i,j),sqr((1/nsk(i,j))*(Fgmax(i,j)-Fgmin(i,j)))*(sqr(ns(i,j))-sqr(ns(i,j)-1))*ds(ns(i,j)));

Abhi140
User
User
Posts: 9
Joined: 8 months ago

Re: Nested variables

Post by Abhi140 » 2 months ago

Equation 2 isn't complete yet. But that won't affect the question asked.

Abhi140
User
User
Posts: 9
Joined: 8 months ago

Re: Nested variables

Post by Abhi140 » 2 months ago

Will it work in the following way?
Defined new set l and nsl. Kept equal number of steps for each line.
Defined variable ds(l,nsl). Now the usage of this variable in the equation is very important. I have written this with the use of operator ord(Cjj(i,j)) for the line number and ns for step number. Summation runs over ns.


Set
i 'Gas network buses' / 1*7 /
slack(i) 'Source bus' / 1, 3 /
t 'Time period' / t1*t1 /
mn 'Set to access fdata from excel sheet' /Cjj,Fgmin,Fgmax/
l 'number of Gas lines' /1*6/
nsl 'steps' /1*250/ ;


Alias (i,j);

*set nGen(i);
*nGen(i) = NOT Gen(i);

*== === Import from Excel using GDX utilities

*=== First unload to GDX file (occurs during compilation phase)

$call gdxxrw MultiEnergySystemData.xlsx par=fdata rng=ModifiedNGSystem!A21:E27 cDim=1 rDim=2

*=== Now import data from GDX
Parameter fdata(i,j, mn);
$gdxin MultiEnergySystemData.gdx
$load fdata
$gdxin
display data

Parameter ns /250/;


$ontext
fdata is like this
i j Cjj Fgmin Fgmax
1 2 50.6 0 3000
2 3 50.1 0 1000
3 4 45.3 0 10
2 5 45.3 0 2500
5 6 43.1 0 1200
6 7 37.5 0 600

$offtext

Parameter cx(i,j), cxv(i,j);
cx(i,j)$(fdata(i,j,'Cjj'))= 1;



Variables ds(l,nsl), fg(i,j);


Equation eq1, eq2;


eq1(i,j)$cx(i,j)..
fg(i,j) =e= Fgmin(i,j) + sum(ns,(1/ns)*(Fgmax(i,j)-Fgmin(i,j))*ds(ord(Cjj(i,j)),ns)));

Abhi140
User
User
Posts: 9
Joined: 8 months ago

Re: Nested variables

Post by Abhi140 » 2 months ago

Any help?

Additional, there was an error in the equation which is corrected in the following equation.
eq1(i,j)$cx(i,j)..
fg(i,j) =e= fdata(i,j,'Fgmin') + sum(nsl,(1/ns)*(fdata(i,j,'Fgmax')-fdata(i,j,'Fgmin'))*ds(ord(fdata(i,j,'Cjj')),nsl));

Post Reply