-
Notifications
You must be signed in to change notification settings - Fork 1
/
OPF_Lyapunov_LMP_Carbon_Feedback_Loss.m
172 lines (149 loc) · 5.7 KB
/
OPF_Lyapunov_LMP_Carbon_Feedback_Loss.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
clear
close all
tic
M = 50;
load Grid.mat
load('CCarbon.mat','CCarbon');
delta = 0.0001;
Cgen_k1 = Cgen_k+delta*CCarbon(1:Ngen,1);
kappa_carbon = 0.05;
carbon_l = [0.00;0.00];
carbon_u = [0.31;1.45];
lambda_u = [0.55;1.78]+carbon_u*kappa_carbon;
lambda_l = [0.00;0.47]+carbon_l*kappa_carbon;
% Optimal
eta = (lambda_u*eta_c*eta_d*w_h-lambda_l*w_l).*ESe./(lambda_u*eta_c*eta_d-lambda_l);
V = (eta-w_l*ESe)./lambda_u/eta_d;
psSet = zeros(Nes,Num_T);
psfSet = zeros(Nes,Num_T);
pgSet = zeros(Ngen,Num_T);
prSet = zeros(NR,Num_T);
lambdaSet = zeros(Nbus,Num_T);
qsSet = zeros(Nes,Num_T);
CPriceSet = zeros(Nbus,Num_T);
NumSet = zeros(Num_T,1);
% es0 = (w_l+w_h)*ESe/2;
es0 = w_h*ESe;
qs = es0-eta;
carbonES = carbon_l;
for t = 1:Num_T
t
PSmin = max(-ESp,(eta_c*qs+V.*lambda_l)/eta_c/eta_c/Delta_t);
PSmin(qs>=-V.*lambda_l/eta_c) = 0;
PSmax = min(ESp,(qs*eta_d+V.*lambda_u*eta_d*eta_d)/Delta_t);
PSmax(qs<=-V.*lambda_u*eta_d) = 0;
PSset = zeros(M,Nes);
for i = 1:Nes
PSset(:,i) = (linspace(PSmin(i),PSmax(i),M))';
end
fset = zeros(size(PSset));
for i = 1:Nes
fset(PSset(:,i)>0,i) = PSset(PSset(:,i)>0,i).*((PSset(PSset(:,i)>0,i)*Delta_t/2-qs(i)*eta_d)/V(i)/eta_d/eta_d-carbonES(i)*kappa_carbon);
fset(PSset(:,i)<0,i) = PSset(PSset(:,i)<0,i).*((PSset(PSset(:,i)<0,i)*eta_c*eta_c*Delta_t/2-qs(i)*eta_c)/V(i)-carbonES(i)*kappa_carbon);
end
ps = sdpvar(Nes,1); % dischange-charge
psf = sdpvar(Nes,1);
pg = sdpvar(Ngen,1);
pr = sdpvar(NR,1);
obj_opf = sum(Cgen_k1'*pg*Delta_t)+sum(psf)*Delta_t;
con1_opf = (1-losskappa)'*(Igen*pg+IR*pr+Ies*ps-PD0(:,t)) == 0;
con2_opfa = PTDF_l*(Igen*pg+IR*pr+Ies*ps-PD0(:,t)) <= Sbranch_l;
con2_opfb = -PTDF_l*(Igen*pg+IR*pr+Ies*ps-PD0(:,t)) <= Sbranch_l;
con3_opf = [PMINgen <= pg <= PMAXgen,0 <= pr <= PR(:,t)];
con4_opf = PSmin<=ps<=PSmax;
for i = 1:Nes
con4_opf = [con4_opf,psf(i)>=fset(1:M-1,i)+(fset(2:M,i)-fset(1:M-1,i))./(PSset(2:M,i)-PSset(1:M-1,i)).*(ps(i)-PSset(1:M-1,i))];
end
con_opf = [con1_opf,con2_opfa,con2_opfb,con3_opf,con4_opf];
optimize(con_opf,obj_opf,sdpsettings('verbose',0));
lambdaSet(:,t) = (-dual(con1_opf)*(1-losskappa)-PTDF_l'*dual(con2_opfa)+PTDF_l'*dual(con2_opfb))/Delta_t;
psSet(:,t) = value(ps);
psfSet(:,t) = value(psf);
pgSet(:,t) = value(pg);
prSet(:,t) = value(pr);
qs = qs-eta_c*min(psSet(:,t),0)*Delta_t-max(psSet(:,t),0)*Delta_t/eta_d;
qsSet(:,t) = qs;
[CPriceSet(:,t),NumSet(t)] = calCPrice_PTDF_num(PD0(:,t)-Ies*psSet(:,t),PR(:,t));
carbonES = CPriceSet(Ines,t);
end
toc
esSet = qsSet+eta*ones(1,Num_T);
figure;
plot(1:Num_T,lambdaSet(Ines(1),:),'LineWidth',2);
xlabel('Time (h)');
ylabel('LMP at Bus 15 ($/kWh)');
set(gca,'FontName','Times New Roman','FontSize',14);
figure;
plot(1:Num_T,lambdaSet(Ines(2),:),'LineWidth',2);
xlabel('Time (h)');
ylabel('LMP at Bus 18 ($/kWh)');
set(gca,'FontName','Times New Roman','FontSize',14);
figure;
plot(1:Num_T,CPriceSet(Ines(1),:),'LineWidth',2);
xlabel('Time (h)');
ylabel('Emission price at Bus 15 (kgCO_2/kWh)');
set(gca,'FontName','Times New Roman','FontSize',14);
figure;
plot(1:Num_T,CPriceSet(Ines(2),:),'LineWidth',2);
xlabel('Time (h)');
ylabel('Emission price at Bus 18 (kgCO_2/kWh)');
set(gca,'FontName','Times New Roman','FontSize',14);
figure;
plot(1:Nbus,CPriceSet(:,50),'LineWidth',2);
xlabel('Bus');
ylabel('Emission price (kgCO_2/kWh)');
set(gca,'FontName','Times New Roman','FontSize',14);
income = zeros(Num_T,2);
income(1,1) = (lambdaSet(Ines(1),1)+kappa_carbon*CPriceSet(Ines(1),1))*psSet(1,1);
for t = 2:Num_T
income(t,1) = income(t-1,1)+(lambdaSet(Ines(1),t)+kappa_carbon*CPriceSet(Ines(1),t))*psSet(1,t);
end
income(1,2) = (lambdaSet(Ines(2),1)+kappa_carbon*CPriceSet(Ines(2),1))*psSet(2,1);
for t = 2:Num_T
income(t,2) = income(t-1,2)+(lambdaSet(Ines(2),t)+kappa_carbon*CPriceSet(Ines(2),t))*psSet(2,t);
end
ab1 = polyfit((1:Num_T)',income(:,1),1);
ab2 = polyfit((1:Num_T)',income(:,2),1);
figure;
plot(1:Num_T,income(:,1),'LineWidth',2);
xlabel('Time (h)');
ylabel('Revenue of ES at bus 15 (10^4 $)');
set(gca,'FontName','Times New Roman','FontSize',14);
figure;
plot(1:Num_T,income(:,2),'LineWidth',2);
xlabel('Time (h)');
ylabel('Revenue of ES at bus 18 (10^4 $)');
set(gca,'FontName','Times New Roman','FontSize',14);
CCostSet_PD = CPriceSet.*PD0(:,1:Num_T);
CCostSet_ES = -psSet.*((Ies')*CPriceSet);
CCostAccum = zeros(Num_T+1,2);
for t = 1:Num_T
CCostAccum(t+1,1) = CCostAccum(t,1)+CCostSet_ES(1,t);
end
for t = 1:Num_T
CCostAccum(t+1,2) = CCostAccum(t,2)+CCostSet_ES(2,t);
end
ab1 = polyfit((1:Num_T+1)',CCostAccum(:,1),1);
ab2 = polyfit((1:Num_T+1)',CCostAccum(:,2),1);
figure;
plot(0:Num_T,CCostAccum(:,1),'LineWidth',2);
xlabel('Time (h)');
ylabel('Cumulative emission of ES at bus 15 (10^5 kgCO_2');
set(gca,'FontName','Times New Roman','FontSize',14);
figure;
plot(0:Num_T,CCostAccum(:,2),'LineWidth',2);
xlabel('Time (h)');
ylabel('Cumulative emission of ES at bus 18 (10^5 kgCO_2');
set(gca,'FontName','Times New Roman','FontSize',14);
CCostAccumSys = zeros(Num_T+1,1);
for t = 1:Num_T
CCostAccumSys(t+1) = CCostAccumSys(t)+2*sum(CCostSet_PD(:,t))+2*sum(CCostSet_ES(:,t));
end
ab1 = polyfit((1:Num_T+1)',CCostAccumSys(:,1),1);
figure;
plot(0:Num_T,CCostAccumSys,'LineWidth',2);
xlabel('Time (h)');
ylabel('Cumulative system emission (10^5 kgCO_2');
set(gca,'FontName','Times New Roman','FontSize',14);
sum(CCarbon'*pgSet*Delta_t)
save('Result_Lyapunov_ES_Feedback_Loss.mat','PD0','psSet','pgSet','lambdaSet','PR','Num_T','Delta_t','kappa_carbon','CPriceSet','income','CCostAccum','CCostAccumSys');