$if not set HOUR $abort --HOUR needs to be set $eval STARTHR (%HOUR%-2)*900+1 $eval ENDHR (%HOUR%-1)*900 sets T total number of time intervals /%STARTHR%*%ENDHR%/ h number of hours/%HOUR%*24/ N sources/1*100/ r /1/; Scalar Ef Efficiency/0.9/, Beta /0.05 /, N_N Total Number of sources/100/, phi coefficient /0.01/, si coefficient /0.9/, eta coefficient /0.3/, TR /900/; alias(i,h); alias(y,T); Parameter DEP(N,h) Probability, Adep(N,h) Accumulated Probability, En(N,h) Energy consumed, SOI(N,r), MP(N,r), Mci(N,r), Mt(N,r), Et(N,r), FP(h,r), Pup(h,r), Pdw(h,r), ExU(h,r), ExD(h,r), Av(N,h) Availability Coefficient, EPer(r,h), RegPerc(T,r), Comp(N,h), SOR(N,T); $GDXIN OneDay.gdx $LOAD FP Pup Pdw MP Mci Mt Et En Av ExD ExU RegPerc DEP $GDXIN $eval HOURM1 %HOUR%-1 $GDXIN inopt%HOURM1%.gdx $LOAD SOR $GDXIN Variables SO(N,h), Income(h,r) daily income, Cost(h,r) daily cost, Daily_profit; Positive Variables PP(N,h), Mx(N,h), Mn(N,h); Equations Income_e,Cost_e,Daily_profit_e,C_0,C_1,C_2,C_3,C_4,C_5,C_6,C_7,C_8a,C_8b,C_9,C_10,C_11; Comp(N,h)=1/(1-DEP(N,h)); Adep(N,h)$(ord(h)< Mt(N,'1'))=sum(i$[ord(i)<= ord(h)],DEP(N,i)); Adep(N,h)$(ord(h)>= Et(N,'1'))=sum(i$[Et(N,'1') <= ord(h) and ord(i)<= ord(h)],DEP(N,i)) ; Adep(N,h)$(ord(h)>= Mt(N,'1') and ord(h) < Et(N,'1') )=sum(i$[Mt(N,'1') <= ord(h) and ord(i)<= ord(h)],DEP(N,i)); EPer('1',h)=1-((1/N_N)*sum(N,Adep(N,h))); EPer('1','22')=1; EPer('1','23')=1; EPer('1','24')=1; *to assign the last value of SOR output variable (T=900) from the previous dispatching problem as initial value of the state of charge of the battery at the begining of the second hour loop((N,T,h),SOI(N,'1')=SOR(N,T)$(ord(T)=TR)); Income_e(h,r).. Income(h,r)=E=EPer(r,h)*((Pup(h,r)*0.001*sum(N,Mn(N,h))+Pdw(h,r)*0.001*sum(N,Mx(N,h))) + Beta*sum(N,(Av(N,h)*((Mx(N,h)*ExD(h,r) + PP(N,h) - Mn(N,h)*ExU(h,r)))))); Cost_e(h,r).. Cost(h,r)=E=EPer(r,h)*0.001*FP(h,r)*(sum(N,Av(N,h)*(Mx(N,h)*ExD(h,r)+PP(N,h)- Mn(N,h)*ExU(h,r)))); Daily_profit_e.. Daily_profit=E=sum(h,Income(h,'1')-Cost(h,'1')); C_0(N,h).. SO(N,h)=E=SOI(N,'1')$(ord(h)=1)+SO(N,h-1)$(ord(h)>1)+(Av(N,h)*(Mx(N,h)*ExD(h,'1') + PP(N,h) - Mn(N,h)*ExU(h,'1'))*Comp(N,h)*Ef)-En(N,h); C_1(N,h).. SO(N,h)=L=Mci(N,'1'); C_2(N,h)$(ord(h)<24).. SO(N,h)=G=phi*Mci(N,'1') ; C_3(N,h)$(ord(h)=24).. SO(N,h)=G=si*Mci(N,'1') ; C_4(N,h).. (PP(N,h)+Mx(N,h))*Comp(N,h)*Ef=L=Mci(N,'1')-(SO(N,h-1)$(ord(h)>1))-(SOI(N,'1')$(ord(h)=1)); C_5(N,h).. (PP(N,h)-Mn(N,h))*Comp(N,h)*Ef+(SO(N,h-1)$(ord(h)>1))+(SOI(N,'1')$(ord(h)=1))=G=En(N,h); C_6(N,h).. (PP(N,h)+Mx(N,h))*Comp(N,h)=L=Av(N,h)*MP(N,'1'); C_7(N,h).. PP(N,h)-Mn(N,h)=G=0; C_8a(N,h).. Mx(N,h)=G=0; C_8b(N,h).. Mn(N,h)=G=0; C_9(N,h).. PP(N,h)=G=0; C_10(N,h)$(Av(N,h)=1).. (SO(N,h)-(SO(N,h-1)$(ord(h)>1))-(SOI(N,'1')$(ord(h)=1)))=L=Av(N,h)*MP(N,'1')*Ef; C_11(N,h)$(Av(N,h)=1).. (SO(N,h)-(SO(N,h-1)$(ord(h)>1))-(SOI(N,'1')$(ord(h)=1)))=G=-Av(N,h)*MP(N,'1')*Ef; Model optimization /all/ ; Solve optimization using lp maximizing Daily_profit; Parameter PPPar(N,h), MnPar(N,h), MxPar(N,h); PPPar(N,h) = PP.l(N,h); MnPar(N,h) = Mn.l(N,h); MxPar(N,h) = Mx.l(N,h); execute_unload 'outopt%HOUR%h.gdx',PPPar=PP, MnPar=Mn, MxPar=Mx, MP, Mci, En, Av, RegPerc, SOI;