-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain_program.m
More file actions
274 lines (188 loc) · 5.7 KB
/
main_program.m
File metadata and controls
274 lines (188 loc) · 5.7 KB
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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
clc;
clear all;
%% ---Input data of 33-bus test system--- %%
[BD,LD,TL]=data33(); %%---Bus, line, and tie data---%%
Vbase=12.66; %%---Base Voltage in kV---%%
Sbase=1; %%---Base Power in MVA---%%
%% ---Input data of 69-bus test system--- %%
% [BD,LD,TL]=data69(); %%---Bus, line, and tie data---%%
% Vbase=12.66; %%---Base Voltage in kV---%%
% Sbase=1; %%---Base Power in MVA---%%
%% ---Input data of 84-bus test system--- %%
% [BD,LD,TL]=data84(); %%---Bus, line, and tie data---%%
% Vbase=11.40; %%---Base Voltage in kV---%%
% Sbase=1; %%---Base Power in MVA---%%
%% ---Input data of 136-bus test system--- %%
% [BD,LD,TL]=data136(); %%---Bus, line, and tie data---%%
% Vbase=13.8; %%---Base Voltage in kV---%%
% Sbase=1; %%---Base Power in MVA---%%
%% ---Input data of 417-bus test system--- %%
% [BD,LD,TL]=data417(); %%---Bus, line, and tie data---%%
% Vbase=10; %%---Base Voltage in kV---%%
% Sbase=100; %%---Base Power in MVA---%%
%% ---Other informations--- %%
nbr=size(LD,1);
ntl=size(TL,1);
nbus=size(BD,1);
itermax=20;
iter=1;
Loss=zeros(itermax,1);
ref=find(BD(:,2)==3,1);
[Yb, ~] = Ybus(LD,nbr,nbus);
[Vmag, ~, Pcalc, ~]= NR_method(BD,Yb,nbus);
Vmin=min(Vmag);
Vmax=max(Vmag);
Loss(iter)=sum(Pcalc);
iter=iter+1;
x=sort(TL(:,1));
fprintf('Tie switch in initial Configuration: %s \n',num2str(x'))
fprintf('The total active power loss in the initial configuration of %d bus system is %f kW. \n\n', nbus, Loss(1)*Sbase*1000)
tstart=tic;
%% ---List of switches--- %%
[LD]=Rearrange(LD,ref);
[bibc, ~]=BIBC(LD,nbus,ref);
n_1=3;
n_2=2;
sw=zeros(nbr+ntl,1);
sw(TL(:,1))=sw(TL(:,1))+ones(ntl,1);
%%---Exclusion of Type-3 switch---%%
for i=1:ntl
sw(LD(:,1))=sw(LD(:,1))+abs(bibc(:,TL(i,2))-bibc(:,TL(i,3)));
end
tempsw=sw;
%% ---Sequential Switch Opening using minimum current method--- %%
LD=[LD;TL];
t=0;
[Yb, A] = Ybus(LD,size(LD,1),nbus);
[Vmag, theta, Pcalc, ~]= NR_method(BD,Yb,nbus);
Vbus=Vmag.*(cos(theta)+1i.*sin(theta));
Vbr=Vbus(LD(:,2))-Vbus(LD(:,3));
Z=LD(:,4)+1i.*LD(:,5);
Ibr=Vbr./Z;
[~,index1]=sort((abs(Ibr)),'ascend');
index1=LD(index1,1);
t1=1;
while t<ntl
if sw(index1(t1))>0
index=find(LD(:,1)==index1(t1));
tempA=A;
tempA(index,:)=[];
if rank(tempA)==nbus-1
t=t+1;
TL(t,:)=LD(index,:);
LD(index,:)=[];
A=tempA;
t1=t1+1;
else
t1=t1+1;
end
else
t1=t1+1;
end
end
%% ---Branch exchange method using BIBC matrix--- %%
nbr=size(LD,1);
[LD]=Rearrange(LD,ref);
[bibc, bcbv]=BIBC(LD,nbus,ref);
%%---Exclusion of Type-1 switch---%%
temp=sum(bibc,1);
for i=1:nbus
if temp(i)<n_1
for j=1:nbr
if bibc(j,i)==1
sw(LD(j,1))=0;
end
end
end
end
%%---Exclusion of Type-2 switch---%%
for i=1:nbr
x=find(LD(:,2)==LD(i,3));
if size(x,1)>n_2
sw(LD(i,1))=0;
end
end
Vbus=BD(:,3).*(cos(BD(:,4))+1i.*sin(BD(:,4)));
Sinj=(BD(:,5)-BD(:,7))+1i*(BD(:,6)-BD(:,8));
[Vbus,Iinj]= dlf(ref,nbus,Sinj,Vbus,bibc,bcbv);
Ibr=-bibc*Iinj;
Vmag=abs(Vbus);
Loss(iter)=sum((abs(Ibr).^2).*LD(:,4));
iter=iter+1;
maxdPloss=inf;
iter1=0;
while iter1<1
%%---Selection of switch pair for the exchange operation---%%
maxdPloss=-inf;
for k1=1:ntl
m1=TL(k1,2);
n1=TL(k1,3);
Rk1=TL(k1,4);
loop=abs(bibc(:,m1)-bibc(:,n1));
for k2=1:nbr
if loop(k2)==1 && sw(LD(k2,1))>0
Ibrnew=Ibr+loop.*(1-2.*(bibc(:,m1).*bibc(k2,m1)+bibc(:,n1).*bibc(k2,n1))).*Ibr(k2);
dPloss=-sum((abs(Ibrnew).^2).*LD(:,4))+sum((abs(Ibr).^2).*LD(:,4))-abs(Ibr(k2)^2)*Rk1;
if maxdPloss<dPloss
maxdPloss=dPloss;
index2=k2;
index1=k1;
end
end
end
end
%%---Updating the configuration---%%
tempLD=[LD; TL(index1,:)];
temp=tempLD(index2,:);
tempLD(index2,:)=[];
[tempLD]=Rearrange(tempLD,ref);
[tempbibc, tempbcbv]=BIBC(tempLD,nbus,ref);
[tempVbus,Iinj]= dlf(ref,nbus,Sinj,Vbus,tempbibc,tempbcbv);
tempIbr=-tempbibc*Iinj;
temploss=sum((abs(tempIbr).^2).*tempLD(:,4));
tempVmag=abs(Vbus);
if temploss<Loss(iter-1) && min(tempVmag)>=Vmin && max(tempVmag)<=Vmax
LD=tempLD;
TL(index1,:)=[];
TL(ntl,:)=temp;
Vbus=tempVbus;
bibc=tempbibc;
Ibr=tempIbr;
sw=tempsw;
%%---Exclusion of Type-1 switch---%%
temp=sum(bibc,1);
for i=1:nbus
if temp(i)<n_1
for j=1:nbr
if bibc(j,i)==1
sw(LD(j,1))=0;
end
end
end
end
%%---Exclusion of Type-2 switch---%%
for i=1:nbr
x=find(LD(:,2)==LD(i,3));
if size(x,1)>n_2
sw(LD(i,1))=0;
end
end
Loss(iter)=temploss;
iter=iter+1;
else
Loss(iter)=Loss(iter-1);
iter=iter+1;
temp=TL(index1,:);
TL(index1,:)=[];
TL(ntl,:)=temp;
iter1=iter1+1;
end
end
Loss(iter:end)=[];
Loss=Loss.*Sbase*1000;
tstop=toc(tstart);
%% ---RESULTS--- %%
x=sort(TL(:,1));
fprintf('Tie switch in final Configuration: %s \n',num2str(x'))
fprintf('The total active power loss in the final configuration of %d bus system is %f kW. \n\n', nbus, Loss(end))
fprintf('The total computational time is %f sec. \n\n',tstop)