Error in Optimization Problem Topic is solved

Solver related questions
Post Reply
mjavadm
User
User
Posts: 6
Joined: 3 years ago

Error in Optimization Problem

Post by mjavadm »

Hello everyone...
I have a problem with the solution of the GAMS. In fact, it shows me an error which states "division by zero" as the following picture. I recheck the code several times but I could not understand what is the problem. Also, I have to add this is the first time that I am using GAMS in order to find the solution of an optimization problem. The code and the error are coming in continue...I would be so appreciative if you guide me :)
---------------------------------------------------------------------------------------------
SETS
i one year simulation time frame consists of each quarter hour /1*96/

VARIABLES
Ctot 'total cost'
Cbuyenergy 'cost of energy purchase from grid'
Csubstorage 'storage investment cost'
Cbatt 'cost of sole energy storage without inverter'
Cinverter 'cost of inverter'
Cstorage 'total cost of energy storage system'
Csubstoragedeg 'cost caused by battery degradation'

Pbatt(i) 'bidirectional power flow from/to the battery'
Ppvload(i) 'PV power fed to the load'
Ppvbatt(i) 'PV power stored in the battry'
Pbattload(i) 'power from battery to load'
Pgridload(i) 'power from grid to load'
Pcurtail(i) 'surplus power curtailed according to regulatio'
Pfeedmax 'maximum feed-in power'

SOH(i) 'state of health'
SOHdelta 'SOHdelta'
Ebatt(i) 'battery energy contentat at time i'
SOC(i) 'state of charge at time i'
SOHvar(i) 'Arbitrariness variable to obtain the difference between SOH(i-1) and SOH(i)'

Enombatt 'Nominal battery capacity'
Pnominv 'nominal power of battery invertor'

Euseablebatt 'fraction of the total energy content of the battery installed'
agingcal(i) 'calendric aging of battery'
agingcyc(i) 'cycle aging of battery'
agingtot(i) 'totla aging'

SCALAR
nbatt 'battery round-trip efficiency' /0.85/
SDbatt 'self-discharge per day' /0.0017/
SOCmin 'minimum state of charge' /0.5/
SOCmax 'maximum state of charge' /1/
lifecal 'calendric life indicator in year' /10/
lifecyc 'cycle life indicator in FEC' /1500/
Cvarbatt 'variable battery pric' /271/
Cfix 'fixed price for storage' /1182/
ninv 'average one way inverter efficiency' /0.975/
Tinv 'assumed inverter life time in year' /20/
Cvarinv 'cost of inverter per nominal power' /155/
Cbuy 'retail energy price' /28.69/
Csell 'feed-in energy reinbursement tariff' /12.31/
fnoESS 'maximum feed-in ratio without ESS' /0.7/
fESS 'maximum feed-in ratio with ESS' /0.5/
rsubsidy 'government subsidy rate for storage system' /0.22/
PpeakPV 'peak value of PV' /835 /
d 'number of time steps per day' /96/
areplace 'precentage value to link SOH to EOL' /0.6/
Dt 'timespan covered with simulation (here 1 year)' /1/


PARAMETERS
Pload(i) 'load demand at time i'
/
1 99
2 168
3 446
4 29
5 331
6 54
7 150
8 727
9 1530
10 41
11 368
12 37
13 453
14 731
15 346
16 224
17 100
18 60
19 49
20 223
21 17
22 110
23 208
24 186
25 122
26 216
27 183
28 102
29 30
30 158
31 14
32 100
33 9
34 9
35 158
36 12
37 101
38 79
39 466
40 208
41 118
42 300
43 134
44 25
45 20
46 125
47 22
48 55
49 46
50 94
51 78
52 35
53 63
54 345
55 83
56 203
57 336
58 141
59 40
60 86
61 46
62 192
63 165
64 42
65 448
66 102
67 58
68 109
69 218
70 19
71 317
72 106
73 225
74 218
75 300
76 338
77 535
78 46
79 319
80 239
81 43
82 241
83 87
84 192
85 82
86 42
87 69
88 509
89 93
90 281
91 0
92 958
93 382
94 829
95 43
96 8
/


Ppv(i) 'PV power at time i'
/
1 0
2 0
3 0
4 0
5 0
6 0
7 0
8 0
9 0
10 0
11 0
12 0
13 0
14 0
15 0
16 0
17 0
18 0
19 0
20 48
21 78
22 113
23 152
24 193
25 235
26 279
27 323
28 367
29 410
30 453
31 494
32 534
33 571
34 607
35 641
36 672
37 701
38 728
39 751
40 772
41 790
42 805
43 817
44 826
45 832
46 835
47 835
48 832
49 826
50 817
51 805
52 790
53 772
54 751
55 728
56 701
57 672
58 641
59 607
60 571
61 534
62 494
63 453
64 410
65 367
66 323
67 279
68 235
69 193
70 152
71 113
72 78
73 48
74 22
75 0
76 0
77 0
78 0
79 0
80 0
81 0
82 0
83 0
84 0
85 0
86 0
87 0
88 0
89 0
90 0
91 0
92 0
93 0
94 0
95 0
96 0
/


EQUATIONS

P1 'all power flows from the PV generator'
P2 'maximum feed-in power'
P3 'total demand of system'
P4 'bidirectional power flow from/to the battery'
P5 'lower band of charge power (Ppvbatt(i))'
P6 'upper band of charge power (Ppvbatt(i))'
P7 'lower band of discharge power (Pbattload(i))'
P8 'upper band of discharge power (Pbattload(i))'

E1 'battery energy contentat at time i'
E2 'fraction of the total energy content of the battery installed'
E3 'upper band of battery energy content'

O1 'calendric aging of battery'
O2 'cycle aging of battery'
O5 'total aging'
O3 'state of health'
O4 'state of charge at time i'
O6 'difference between SOH(i-1) and SOH(i)'
O7 'SOHdelta'

cost 'total cost'
C1 'cost of energy purchase from grid'
C2 'storage investment cost'
C3 'cost of sole energy storage without inverter'
C4 'cost of energy storage system with invertere'
C5 'total cost of energy storage system'
C6 'cost caused by battery degradation'


;

P1(i) .. Ppv(i)=e=Ppvload(i)+Ppvbatt(i)+Pcurtail(i);
P2 .. Pfeedmax=e=fnoESS*PpeakPV;
P3(i) .. Pload(i)=e=Ppvload(i)+Pbattload(i)+Pgridload(i);
P4(i) .. Pbatt(i)=e=(ninv*Ppvbatt(i))-(1/ninv)*(Pbattload(i));
P5(i) .. Ppvbatt(i)=g=0;
P6(i) .. Ppvbatt(i)=l=Pnominv;
P7(i) .. Pbattload(i)=g=0;
P8(i) .. Pbattload(i)=l=Pnominv;

E1(i) .. Ebatt(i)=e=(Ebatt(i-1)*(SDbatt/d))+(nbatt*Pbatt(i)*(1/15));
E2 .. Euseablebatt=e=Enombatt*(SOCmax-SOCmin);
E3(i) .. Ebatt(i)=l=Euseablebatt*SOH(i);

O1(i) .. agingcal(i)=e=ord(i)*(15/lifecal);
O2(i) .. agingcyc(i)=e=agingcyc(i-1)+(0.5*(abs((Pbatt(i)*15))/Ebatt(i))*(1/lifecyc));
O5(i) .. agingtot(i)=e=agingcal(i)+agingcyc(i);
O3(i) .. SOH(i)=e=SOH(i-1)-(agingtot(i)*0.2);
O4(i) .. SOC(i)=e=Ebatt(i)/(Euseablebatt*SOH(i));
O6(i) .. SOHvar(i)=e=SOH(i-1)-SOH(i);
O7 .. SOHdelta=e=sum(i,SOHvar(i))/96;

C1 .. Cbuyenergy=e=sum(i,Cbuy*Pgridload(i));
C2 .. Csubstorage=e=Cstorage*(1-rsubsidy);
C3 .. Cbatt=e=Cfix+(Cvarbatt*Enombatt);
C4 .. Cinverter=e=Cvarinv*Pnominv;
C5 .. Cstorage=e=Cbatt+Cinverter;
C6 .. Csubstoragedeg=e=((SOHdelta*Cbatt)/(1-areplace))+((Cinverter*Dt)/Tinv);
cost .. Ctot=e=Cbuyenergy+Csubstoragedeg;

model sizingESS /all/;
* initial values for variables
SOH.l(i)=0;

solve sizingESS using DNLP minimizing Ctot;
display O1.l,SOH.l;
-----------------------------------------------------------------------------
The error:
image.png
User avatar
Renger
Posts: 639
Joined: 7 years ago

Re: Error in Optimization Problem

Post by Renger »

Hi
As a newbee it is always good to read the Rules for this forum. There it states clearly
Before sending a question to the group, please...
...start with the following documents that can be found here: if you are new to GAMS look at the GAMS tutorial, search the GAMS User's Guide, and search the Expanded GAMS User Guide.
...search this group.
As you are not the only one making this mistake, you will find quite a few hits, when you search for "Division by zero" with explanations.

Cheers
Renger

PS. If you post code, it is better to insert the code between the code symbols (just click on the </>-symbol in the editor) or attach a file.
____________________________________
Enjoy modeling even more: Read my blog on modeling at The lazy economist
mjavadm
User
User
Posts: 6
Joined: 3 years ago

Re: Error in Optimization Problem

Post by mjavadm »

Renger wrote: 3 years ago Hi
As a newbee it is always good to read the Rules for this forum. There it states clearly
Before sending a question to the group, please...
...start with the following documents that can be found here: if you are new to GAMS look at the GAMS tutorial, search the GAMS User's Guide, and search the Expanded GAMS User Guide.
...search this group.
As you are not the only one making this mistake, you will find quite a few hits, when you search for "Division by zero" with explanations.

Cheers
Renger

PS. If you post code, it is better to insert the code between the code symbols (just click on the </>-symbol in the editor) or attach a file.
Dear Mr. Renger
Your right... I am so sorry for my mistake. In fact, at that time I was trying to find the solution, however, I could not see any similar case. I am so thankful to tell me my mistake and the proper and correct way to ask my questions into the Forums. Again sorry for mistake...
Post Reply