BESS modeling Error 148 and 258 in obj function.

Problems with syntax of GAMS
Post Reply
GeGo
User
User
Posts: 1
Joined: 1 week ago

BESS modeling Error 148 and 258 in obj function.

Post by GeGo »

Hello i am new in gams and i want help with a battery energy storage system modeling in GAMS,
I get in the last line the following errors. I cant understand why,
*** Error 148 in C:\Users\eirini\Documents\GAMS\Studio\workspace\gams 240\PPA_PV_BESS.gms[ERR:"C:\Users\eirini\Documents\GAMS\Studio\workspace\gams 240\PPA_PV_BESS.gms",115,40][LST:102]
Dimension different - The symbol is referenced with more/less
indices as declared
*** Error 257 in C:\Users\eirini\Documents\GAMS\Studio\workspace\gams 240\PPA_PV_BESS.gms[ERR:"C:\Users\eirini\Documents\GAMS\Studio\workspace\gams 240\PPA_PV_BESS.gms",115,42][LST:102]
Solve statement not checked because of previous errors
--- PPA_PV_BESS.gms(115) 3 Mb 2 Errors[FIL:"C:\Users\eirini\Documents\GAMS\Studio\workspace\gams 240\PPA_PV_BESS.gms",115,0]
*** Status: Compilation error(s)[LST:151]
--- Job PPA_PV_BESS.gms Stop 04/20/24 15:52:36 elapsed 0:00:10.719

I want to maximize income so i am trying to fine the best combination of z and h for all t.

This is my code:
Set t "Time" /t1*t240/;
Set h "hour of bess" /h1*h4/;
Set z 'safety level of contracted energy' /z1*z2/;


Parameters
P_real(t)
P_ppa(t,z)
P_excess(t,z)
pvf(t) pv is in producing
mp(t) more profitable market price
iseop(t,z) there is excess of power P_real-P_ppa>0
SoCz1(t,h) 'state of charge time, hours of batery, z1'
SoCz2(t,h) 'state of charge time, hours of batery, z2'
SoC(t,h,z) 'state of charge time, hours of batery, safety level'
P_b2g(t,z) 'Power battery to grid';


$CALL GDXXRW P_r.xlsx trace=3 par=P_real rng=New_Sheet! rdim=1
$CALL GDXXRW P_p.xlsx trace=3 par=P_ppa rng=New_Sheet! rdim=1 cdim=1
$CALL GDXXRW P_e.xlsx trace=3 par=P_excess rng=Sheet1! rdim=1 cdim=1
$CALL GDXXRW pvf.xlsx trace=3 par=pvf rng=New_Sheet! rdim=1
$CALL GDXXRW iseop.xlsx trace=3 par=iseop rng=Sheet1! rdim=1 cdim=1
$CALL GDXXRW mp.xlsx trace=3 par=mp rng=New_Sheet! rdim=1
$CALL GDXXRW P_b2g.xlsx trace=3 par=P_b2g rng=Sheet1! rdim=1 cdim=1
$CALL GDXXRW SoC_z1.xlsx trace=3 par=SoCz1 rng=New_Sheet! rdim=1 cdim=1
$CALL GDXXRW SoC_z2.xlsx trace=3 par=SoCz2 rng=New_Sheet! rdim=1 cdim=1


$GDXIN P_r.gdx
$LOAD P_real
$GDXIN
*Display P_real;


$GDXIN P_p.gdx
$LOAD P_ppa
$GDXIN

$GDXIN P_e.gdx
$LOAD P_excess
$GDXIN

$GDXIN pvf.gdx
$LOAD pvf
$GDXIN

$GDXIN mp.gdx
$LOAD mp
$GDXIN

$GDXIN P_b2g.gdx
$LOAD P_b2g
$GDXIN

$GDXIN iseop.gdx
$LOAD iseop
$GDXIN

$GDXIN SoC_z1.gdx
$LOAD SoCz1
$GDXIN

$GDXIN SoC_z2.gdx
$LOAD SoCz2
$GDXIN

SoC(t,h,z)$(ord(z)=1) = SoCz1(t,h);
SoC(t,h,z)$(ord(z)=2) = SoCz2(t,h);

Scalar P_pv_max max PV power out put same as battery /8/;
Scalar SP_ppa strike price of the PPA /85/;


Parameter hb(h) hours of battery
/h1 1
h2 2
h3 4
h4 6/;




Variables
obj(h,z) objective function
C(h) 'variable for CAPEX'
ppa_i(z) 'income through ppa';



*SP_ppa.up = 195;
*SP_ppa.lo = 175;


Equations
Income ObjetiveFunction
CAPEX 'capital cost of pv+storage'
ppa_income 'income through ppa'
con_ppa_income_lb 'income through ppa lower bound';


*sto 2o athrisma tis antikimenikis sinartisis prepei na mpi mia diadiki metavliti
*b=1 otan SoC(T)>0, b=0 otan SoC(T)<=0 mporei na gini xoris senaria?
Income(h,z) .. obj(h,z) =e= sum(t,(P_ppa(t,z)/1000)*SP_ppa) + sum(t,(mp(t)*(1-pvf(t))*(P_b2g(t,z))))
+sum(t,(182*(P_excess(t,z)/1000)*(1-iseop(t,z))*pvf(t)))-C(h);

CAPEX(h) .. C(h) =e= (200000*P_pv_max+220000*hb(h)*P_pv_max)*240/(12*8760);
ppa_income(z).. ppa_i(z) =e= sum(t,(P_ppa(t,z)/1000)*SP_ppa);
con_ppa_income_lb(h,z).. ppa_i(z) =g= 0.5*C(h);



Model PP_PV_BESS /all/ ;
Option mip=cplex;
Solve PP_PV_BESS using lp maximizing obj ;
User avatar
bussieck
Moderator
Moderator
Posts: 1043
Joined: 7 years ago

Re: BESS modeling Error 148 and 258 in obj function.

Post by bussieck »

Hi,

First the is a very nice formatting control to copy and paste code. Please use that. On the particular question. You have an objective variable obj(h,z), so for every h and z there is a variable and you ask the solver to optimize it. A solver can only optimize a single variable not h times z many. So GAMS assumes your obj is a scalar variable and hence complains that you use z as a 2-dim variable in the declaration and equations and as a scalar variable in the solve statement. Perhaps, you want to add all income, then you should redefine your income equation:

Code: Select all

Variables
obj objective function
Income .. obj =e= sum((h,z),sum(t,(P_ppa(t,z)/1000)*SP_ppa) + sum(t,(mp(t)*(1-pvf(t))*(P_b2g(t,z)))));

Hope this helps,
-Michael
Post Reply