Hello everyone. I’m writing a code in GAMS considering optimal power flow for a power plant. In this code, I import a set of data as a table with 24 rows and 100 columns as a parameter (sample), and then I need to solve the model and get the optimal solution for each column (it is called with j and shows 100 samples). The code is shown as follows, but when I run the project the output table (include the power of the power plant PVPP) has 100 columns with the same values. I have two questions: first, Is it correct to write the table directly code, not in the loop? Why the results are equal and Second, How I can save the result of the loop as a parameter? I would be so thankful to read your useful responses.
SETs
i Index for controllable units /16/
t Index for time periods /114/
j Number of samples /1*100/
VARIABLE
dtup(t,j) ‘Upward Load’
dtdo(t,j) ‘downward Load’
p(t,i) ‘Active power of controllable unit i in time t’
PES(t) ‘Output of energy storage’
PEStotal(t) ‘Total output of energy for 80 battery storage’
E0 ‘initial storage capacity of energy storage elements’
C ‘objective function’
D(t,j) ‘load value after implementation of TOU pricing’
*CIL(t) ‘cost of intruptable load’
PVPP(t,j) ‘output of the VPP’
PG(t) ‘total output of controllable unites’
RVPP(t,j) ‘reserved capacity’
PVPPmax(t,j) ‘Maximum active output’
FES ‘cost of energy storage’
FEStotal ‘total cost for 80 storag unites’
FG ‘controllable unite generation cost’
FGtotal ‘total cost for 6 microturbine’
In(j) ‘income of VPP’
v(j) ‘variance’
B(j) ‘profit of VPP’
scalar
e ‘operating cost of energy storage’ /6.4/
Btup ‘upper limit of upward demand’ /0.08/
Btdo ‘upper limit of downward demand’ /0.07/
eup ’ load elasticity coefficients which define the lower limit of load transfer’ /0.04/
edo ’ load elasticity coefficients which define the lower limit of load transfer’ /0.03/
Pref ‘traded tariff’ /0.56/
r1 ‘coefficients of load’ /0.05/
r2 ‘coefficients of load’ /0.2/
r3 ‘coefficients of load’ /0.15/
DT ‘dispatch period(h)’ /1/
Emin ‘minimum storage capacity of energy storage devices(kw)’ /0/
Emax ‘maximum storage capacity of energy storage devices(kw)’ /1.2/
Pcharmax ‘maximum charge power of energy storage elements(kw)’ /-15/
Pdischarmax ‘maximum discharge power of energy storage elements(kw)’ /15/
B0 ‘expected maximum profit based on the forecast prices’ /33531.604/
parameters
sample(t,j) ‘sample generated matrix’
dl(t) ‘predict load value in time t’
/1 200
2 212
3 247.5
4 282.5
5 300
6 282.5
7 253
8 230
9 222
10 235.5
11 251
12 282.5
13 300
14 311/
Pr(t) ‘prices of time t’
/ 1 0.3819
2 0.6171
3 0.6171
4 0.8789
5 0.8789
6 0.8789
7 0.6171
8 0.6171
9 0.6171
10 0.6171
11 0.6171
12 0.8789
13 0.8789
14 0.8789/
PWT(t)‘predict WT output value in time t’
/
1 101
2 82
3 70
4 62.5
5 74
6 85.5
7 99
8 105
9 105
10 101
11 99.5
12 93.5
13 93.5
14 101/
report(t,j) ‘collect data’
$call GDXXRW.exe GSample.xlsx trace=1 par=sample rng=sheet1!A1:o10001
$GDXIN GSample.gdx
$load sample
$gdxin
EQUATIONs
DD ‘load value after implementation of TOU pricing’
LB ‘load balance’
L1 ‘load adjustment cons1’
L2 ‘load adjustment cons2’
L3 ‘load adjustment cons3’
L4 ‘load adjustment cons4’
L5 ‘load adjustment cons5’
L6 ‘load adjustment cons6’
L7 ‘load adjustment cons7’
P1 ‘power balance cons 1’
P2 ‘power balance cons 2’
P3 ‘power balance cons 3’
P4 ‘power balance cons 4’
P5 ‘power balance cons 5’
P6 ‘power balance cons 6’
C1 ‘controllable unite const 1’
C2 ‘controllable unite const 2’
ES1 ‘energy storage const 1’
ES2 ‘energy storage const 2’
ES3 ‘energy storage const 3’
ES4 ‘energy storage const 4’
ES5 ‘energy storage const 5’
ES6 ‘energy storage const 6’
FES1 ‘cost of energy storage’
FES2
FG1 ‘controllable unite generation cost’
FG2
Cost ‘objective function’;
DD(t,j)… D(t,j)=e=dl(t)+dtup(t,j)-dtdo(t,j);
LB(j) … sum(t,dtup(t,j))=e=sum(t,dtdo(t,j));
L1(t,j)… Btupdl(t)=g=dtup(t,j);
L2(t,j)… Btdodl(t)=g=dtdo(t,j);
L3(t,j)… dtup(t,j)=g=0;
L4(t,j)… dtdo(t,j)=g=0;
L5(t,j)… dtup(t,j)=g=eupdl(t)(1-(Pr(t)/Pref));
L6(t,j)… dtdo(t,j)=g=edodl(t)((Pr(t)/Pref)-1);
L7(t,j) … dtup(t,j)dtdo(t,j)=e=0;
ES1 … sum(t,PES(t)DT)=e=0;
ES2 … Emin=l=(E0-sum(t,(PES(t))DT));
ES3 … E0-sum(t,(PES(t))DT)=l=Emax;
ES4(t) … Pcharmax=l=(PES(t));
ES5(t) … (PES(t))=l=Pdischarmax;
ES6(t) … PEStotal(t)=e=80PES(t);
P1(t,j)…PVPP(t,j)=e=D(t,j);
P2(t,i) … PG(t)=e=6p(t,i);
P3(t,j) … PVPP(t,j)=l=PG(t)+PWT(t)+sample(t,j)+PEStotal(t);
P4(t,j) … RVPP(t,j)=e=(r1D(t,j))+(r2(PWT(t)))+(r3sample(t,j));
P5(t,j) … PVPPmax(t,j)=e=180+PWT(t)+sample(t,j)+PEStotal(t);
P6(t,j) … PVPPmax(t,j)-(D(t,j))=g=RVPP(t,j);
C1(t,i) … p(t,i)=g=0;
C2(t,i) … p(t,i)=l=30;
FES1 … FES=e=sum(t,0.5eabs((PES(t))));
FES2 … FEStotal=e=80FES;
FG1 … FG=e=sum(t,sum(i,(0.0040787p(t,i)p(t,i))+1.475p(t,i)+9.986));
FG2 … FGtotal=e=6FG;
Cost … C=e=FEStotal+FGtotal;
model GaT4 /all/;
alias(j,j2);
loop(j2,
solve GaT4 using DNLP minimizing C;
W(t)= D(jj,t);
);
display PVPP.l,C.l;
execute_unload “GaT4.gdx” PVPP.l,C.l
execute ‘gdxxrw.exe GaT4.gdx var=PVPP.l’
execute ‘gdxxrw.exe GaT4.gdx var=C.l’