├── PSO.m ├── README.md ├── busdatas.m ├── limitchk.m ├── linedatas.m ├── loadflow.m ├── main.m ├── nrloadflow.m ├── objf.m ├── pol2rect.m ├── resultcalc.m └── ybusppg.m /PSO.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ratana103/Power-system-calculation-using-PSO-optimization/b1ea44669e82955366c0b457a4e3a3f3234f63c6/PSO.m -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Power-system-calculation-using-PSO-optimization -------------------------------------------------------------------------------- /busdatas.m: -------------------------------------------------------------------------------- 1 | % Returns Initial Bus datas of the system... 2 | % Author: Ratana Lim 3 | % Created date: 25/04/2018 4 | 5 | function busdt = busdatas(num) 6 | 7 | % Type.... 8 | % 1 - Slack Bus.. 9 | % 2 - PV Bus.. 10 | % 3 - PQ Bus.. 11 | 12 | % |Bus | Type | Vsp | theta | PGi | QGi | PLi | QLi | Qmin | Qmax | 13 | busdat30 = [1 1 1.04 0 0 0 0 0 0 0; 14 | 2 2 1.023 0 50 40.0 27.7 52.7 -40 50; 15 | 3 3 1.09 0 0 0 2.2 1.6 0 0; 16 | 4 2 1.06 0 0 0 7.6 1.6 0 0; 17 | 5 2 1.01 0 0 37.0 94.2 19.0 -40 40; 18 | 6 3 1.0 0 0 0 0.0 0.0 0 0; 19 | 7 2 1.0 0 0 0 22.8 10.9 0 0; 20 | 8 2 1.06 0 0 37.3 30.0 30.0 -10 40; 21 | 9 3 1.05 0 0 0 0.0 0.0 0 0; 22 | 10 3 1.0 0 0 19.0 5.8 2.0 0 0; 23 | 11 2 1.082 0 0 16.2 0.0 0.0 -6 24; 24 | 12 3 1.09 0 0 0 11.2 7.5 0 0; 25 | 13 2 1.071 0 0 10.6 0.0 0.0 -6 24; 26 | 14 3 1.0 0 0 0 6.2 1.6 0 0; 27 | 15 3 1.053 0 0 0 8.2 2.5 0 0; 28 | 16 3 1.0 0 0 3.2 3.5 1.8 0 0; 29 | 17 2 1.02 0 0 0 9.0 5.8 0 0; 30 | 18 3 1.0 0 0 2.2 3.2 0.9 0 0; 31 | 19 3 1.0 0 0 0 9.5 3.4 0 0; 32 | 20 3 1.01 0 0 0 2.2 0.7 0 0; 33 | 21 3 1.0 0 0 0 17.5 11.2 0 0; 34 | 22 3 1.05 0 0 2.2 0.0 0.0 0 0; 35 | 23 3 1.02 0 0 0 3.2 1.6 0 0; 36 | 24 3 1.03 0 0 4.3 8.7 6.7 0 0; 37 | 25 3 1.0 0 0 0 0.0 0.0 0 0; 38 | 26 3 1.0 0 0 0 3.5 2.3 0 0; 39 | 27 3 1.09 0 0 0 0.0 0.0 0 0; 40 | 28 3 1.08 0 0 0 0.0 0.0 0 0; 41 | 29 3 1.0 0 0 0 2.4 0.9 0 0; 42 | 30 3 1.04 0 0 0 10.6 1.9 0 0 ]; 43 | 44 | busdt = busdat30; 45 | end -------------------------------------------------------------------------------- /limitchk.m: -------------------------------------------------------------------------------- 1 | % Author: Ratana Lim 2 | % Created date: 25/04/2018 3 | 4 | function x=limitchk(x,up,low,nbus,loadbusLocation) 5 | for ii=1:numel(x) 6 | if x(ii)up 9 | x(ii)=up; 10 | end 11 | end 12 | %% volateg constraint check 13 | 14 | % busdata = busdatas(nbus); % load the bus data 15 | % linedata=linedatas(nbus); % load the line data 16 | % % DG locations 17 | % busdata(loadbusLocation,7)=-x+busdata(loadbusLocation,7);% add the DG power to active load 18 | % resultwithDG=nrloadflow(nbus,busdata,linedata); 19 | % V=resultwithDG.V; 20 | % Vmax=1.1; Vmin=0.95; 21 | % cond=numel(unique((Vmin<=V&V<=Vmax))); 22 | % dim=numel(x); 23 | % while cond==2 24 | % x=(up-low).*rand(dim,1)+low; 25 | % busdata = busdatas(nbus); 26 | % busdata(loadbusLocation,7)=-x+busdata(loadbusLocation,7);% add the DG power to active load 27 | % resultwithDG=nrloadflow(nbus,busdata,linedata); 28 | % V=resultwithDG.V; 29 | % cond=numel(unique((Vmin<=V&V<=Vmax))); 30 | % display('asnfhasdfhfo') 31 | % end 32 | -------------------------------------------------------------------------------- /linedatas.m: -------------------------------------------------------------------------------- 1 | % Returns Line datas of the system... 2 | % Author: Ratana Lim 3 | % Created date: 25/04/2018 4 | 5 | function linedt = linedatas(num) 6 | 7 | % | From | To | R | X | B/2 | X'mer | 8 | % | Bus | Bus | pu | pu | pu | TAP (a) | 9 | linedat30 = [1 2 0.0472 0.0379 0.0045 1 10 | 1 3 0.0119 0.2560 0.0042 1 11 | 2 4 0.0460 0.2559 0.0085 1 12 | 3 4 0.0120 0.0379 0.0102 1 13 | 2 5 0.0472 0.1983 0.0209 1 14 | 2 6 0.0472 0.1304 0.0187 1 15 | 4 6 0.0119 0.2090 0.0045 1 16 | 5 7 0.0460 0.1160 0.0102 1 17 | 6 7 0.0267 0.0820 0.0085 1 18 | 6 8 0.0120 0.0420 0.0045 1 19 | 6 9 0.0 0.2080 0.0 0.978 20 | 6 10 0.0 0.5560 0.0 0.969 21 | 9 11 0.0 0.2080 0.0 1 22 | 9 10 0.0 0.1100 0.0 1 23 | 4 12 0.0 0.2560 0.0 0.932 24 | 12 13 0.0 0.1400 0.0 1 25 | 12 14 0.0636 0.2559 0.0 1 26 | 12 15 0.0662 0.1304 0.0 1 27 | 12 16 0.0945 0.1987 0.0 1 28 | 14 15 0.2210 0.1997 0.0 1 29 | 16 17 0.0824 0.1923 0.0 1 30 | 15 18 0.1073 0.2185 0.0 1 31 | 18 19 0.0639 0.1292 0.0 1 32 | 19 20 0.0340 0.0680 0.0 1 33 | 10 20 0.0936 0.2090 0.0 1 34 | 10 17 0.0324 0.0845 0.0 1 35 | 10 21 0.0348 0.0749 0.0 1 36 | 10 22 0.0727 0.1499 0.0 1 37 | 21 23 0.0116 0.0236 0.0 1 38 | 15 23 0.1000 0.2020 0.0 1 39 | 22 24 0.1150 0.1790 0.0 1 40 | 23 24 0.1320 0.2700 0.0 1 41 | 24 25 0.1885 0.3292 0.0 1 42 | 25 26 0.2544 0.3800 0.0 1 43 | 25 27 0.1093 0.2087 0.0 1 44 | 28 27 0.0169 0.3960 0.0 0.968 45 | 27 29 0.2198 0.4153 0.0 1 46 | 27 30 0.3202 0.6027 0.0 1 47 | 29 30 0.2399 0.4533 0.0 1 48 | 8 28 0.0636 0.2000 0.0214 1 49 | 6 28 0.0169 0.0599 0.065 1 ]; 50 | 51 | linedt = linedat30; 52 | end -------------------------------------------------------------------------------- /loadflow.m: -------------------------------------------------------------------------------- 1 | % Author: Ratana Lim 2 | % Created date: 25/04/2018 3 | 4 | function [Pi Qi Pg Qg Pl Ql Lpij Lqij V Iijm] = loadflow(nb,V,del,BMva,busd,lined) 5 | %--------------------------- 6 | Y = ybusppg(lined); 7 | xc=0; 8 | %--------------------------- 9 | Vm = pol2rect(V,del); 10 | Del = 180/pi*del; 11 | fb = lined(:,1); 12 | tb = lined(:,2); 13 | nl = length(fb); 14 | Pl = busd(:,7); 15 | Ql = busd(:,8); 16 | Iij = zeros(nb,nb); 17 | Sij = zeros(nb,nb); 18 | Si = zeros(nb,1); 19 | %--------------------------- 20 | I = Y*Vm; 21 | Im = abs(I); 22 | Ia = angle(I); 23 | %--------------------------- 24 | for m = 1:nl 25 | p = fb(m); q = tb(m); 26 | Iij(p,q) = -(Vm(p) - Vm(q))*Y(p,q); % Y(m,n) = -y(m,n).. 27 | Iij(q,p) = -Iij(p,q); 28 | end 29 | %--------- DG6------------------ 30 | Iij = sparse(Iij); 31 | Iijm = abs(Iij); 32 | Iija = angle(Iij); 33 | %------------------------------- 34 | for m = 1:nb 35 | for n = 1:nb 36 | if m ~= n 37 | Sij(m,n) = Vm(m)*conj(Iij(m,n))*BMva; 38 | end 39 | end 40 | end 41 | %------------------------------- 42 | Pij = real(Sij); 43 | Qij = imag(Sij); 44 | Lij = zeros(nl,1); 45 | %------------------------------- 46 | for m = 1:nl 47 | p = fb(m); q = tb(m); 48 | Lij(m) = Sij(p,q) + Sij(q,p); 49 | end 50 | %------------------------------- 51 | Lpij = real(Lij); 52 | Lqij = imag(Lij); 53 | %------------------------------- 54 | for i = 1:nb 55 | for k = 1:nb 56 | Si(i) = Si(i) + conj(Vm(i))* Vm(k)*Y(i,k)*BMva; 57 | end 58 | end 59 | %------------------------------- 60 | Pi = real(Si); 61 | Qi = -imag(Si); 62 | Pg = Pi+Pl; 63 | Qg = Qi+Ql; 64 | disp('========================================================================================='); 65 | disp('/////////////////////////////////////////////////////////////////////////////////////////'); 66 | disp(' Newton Raphson Loadflow Analysis '); 67 | disp('/////////////////////////////////////////////////////////////////////////////////////////'); 68 | disp('| Bus | V | Angle | Injection | Generation | Load |'); 69 | disp('| No | pu | Degree | MW | MVar | MW | Mvar | MW | MVar | '); 70 | for m = 1:nb 71 | disp('......................................................................................'); 72 | fprintf('%3g', m); fprintf(' %8.4f', V(m)); fprintf(' %8.4f', Del(m)); 73 | fprintf(' %8.3f', Pi(m)); fprintf(' %8.3f', Qi(m)); 74 | fprintf(' %8.3f', Pg(m)); fprintf(' %8.3f', Qg(m)); 75 | fprintf(' %8.3f', Pl(m)); fprintf(' %8.3f', Ql(m)); fprintf('\n'); 76 | end 77 | disp('////////////////////////////////////////////////////////////////////////////////////////'); 78 | fprintf(' Total ');fprintf(' %8.3f', sum(Pi)); fprintf(' %8.3f', sum(Qi)); 79 | fprintf(' %8.3f', sum(Pi+Pl)); fprintf(' %8.3f', sum(Qi+Ql)); 80 | fprintf(' %8.3f', sum(Pl)); fprintf(' %8.3f', sum(Ql)); fprintf('\n'); 81 | disp('////////////////////////////////////////////////////////////////////////////////////////'); 82 | fprintf('\n\n'); 83 | disp('========================================================================================'); 84 | disp('////////////////////////////////////////////////////////////////////////////////////////'); 85 | disp(' Line FLow and Losses '); 86 | disp('////////////////////////////////////////////////////////////////////////////////////////'); 87 | disp('|From|To | P | Q | From| To | P | Q | Line Loss |'); 88 | disp('|Bus |Bus| MW | MVar | Bus | Bus| MW | MVar | MW | MVar |'); 89 | for m = 1:nl 90 | p = fb(m); q = tb(m); 91 | disp('-------------------------------------------------------------------------------------'); 92 | fprintf('%4g', p); fprintf('%4g', q); fprintf(' %8.3f', Pij(p,q)); fprintf(' %8.3f', Qij(p,q)); 93 | fprintf(' %4g', q); fprintf('%4g', p); fprintf(' %8.3f', Pij(q,p)); fprintf(' %8.3f', Qij(q,p)); 94 | fprintf(' %8.3f', Lpij(m)); fprintf(' %8.3f', Lqij(m)); 95 | fprintf('\n'); 96 | end 97 | disp('//////////////////////////////////////////////////////////////////////////////////////'); 98 | fprintf(' Total Loss '); 99 | fprintf(' %8.3f', sum(Lpij)); fprintf(' %8.3f', sum(Lqij)); fprintf('\n'); 100 | disp('//////////////////////////////////////////////////////////////////////////////////////'); 101 | fprintf('\n\n'); 102 | disp('======================================================================================'); -------------------------------------------------------------------------------- /main.m: -------------------------------------------------------------------------------- 1 | % Author: Ratana Lim 2 | % Created date: 25/04/2018 3 | 4 | %% Calculation of Power System 5 | clc 6 | clear 7 | close all 8 | %% NR load flow analysis 9 | nbus = 30; 10 | busdata = busdatas(nbus); 11 | linedata = linedatas(nbus); 12 | resultWithoutDG = nrloadflow(nbus,busdata,linedata); 13 | dim = 10; 14 | Pmin=3; %minimum power of solar DG unit 15 | if nbus==30 16 | Pmax=30; %maximum power of solar DG unit in MW 17 | else 18 | Pmax=100; 19 | end 20 | %% potential bus selection 21 | R=linedata(:,3); 22 | sourcbus=linedata(:,1); 23 | destintnbus=linedata(:,2); 24 | % del=180/pi*del; 25 | for ii=1:size(linedata,1) 26 | alpha(ii)=(R(ii)/(abs(resultWithoutDG.V(sourcbus(ii)))... 27 | *abs(resultWithoutDG.V(sourcbus(ii)))))... 28 | *cos(resultWithoutDG.del(sourcbus(ii))... 29 | -resultWithoutDG.del(destintnbus(ii))); 30 | beta(ii)=(R(ii)/(abs(resultWithoutDG.V(sourcbus(ii)))... 31 | *abs(resultWithoutDG.V(sourcbus(ii)))))... 32 | *sin(resultWithoutDG.del(sourcbus(ii))... 33 | -resultWithoutDG.del(destintnbus(ii))); 34 | SV(ii)=alpha(ii).*resultWithoutDG.Pi(destintnbus(ii))... 35 | -beta(ii).*resultWithoutDG.Qi(destintnbus(ii)); 36 | end 37 | 38 | [sv,ind]=sort(SV,'descend'); 39 | po=destintnbus(ind); 40 | [poo,ia,ic]=unique(po); 41 | temp=po(sort(ia)); 42 | loadBusLocation = temp(1:dim); 43 | %% GA optimisation 44 | fitness= @(x) objf(x,loadBusLocation,resultWithoutDG,nbus); 45 | options = gaoptimset('MutationFcn',@mutationadaptfeasible,'PopulationSize',20); 46 | options = gaoptimset(options,'PlotFcns',{@gaplotbestf}, ... 47 | 'Display','iter','Generations',80); 48 | [GAx,fval] = ga(fitness,dim,[],[],[],[],Pmin.*ones(1,dim)... 49 | ,Pmax.*ones(1,dim),[],options); 50 | finalGAresults= resultcalc(GAx,loadBusLocation,resultWithoutDG,nbus); 51 | %% PSO optimisation 52 | [PSOx,objval]=PSO(loadBusLocation,resultWithoutDG,nbus,dim,Pmax,Pmin); 53 | finalPSOresults= resultcalc(PSOx',loadBusLocation,resultWithoutDG,nbus); 54 | FIG1 = figure('Name', 'PSO Optimization','NumberTitle','off'); 55 | figure(FIG1) 56 | plot(1./objval) 57 | grid on; 58 | ylabel('VL (pu)'); 59 | xlabel('time (sec)'); 60 | title('PSO optimisation') 61 | %% Result plotting 62 | % volatge magnitude plot 63 | FIG2 = figure('Name', 'BUS VOLTAGE','NumberTitle','off'); 64 | figure(FIG2) 65 | bar([finalPSOresults.V,finalGAresults.V,resultWithoutDG.V],'group') 66 | xlim([0 nbus+1]) 67 | ylim([0.95,1.1]) 68 | grid on; 69 | legend('PSO optimised','GA optimised','Without DG') 70 | xlabel('Bus number') 71 | ylabel('Volatge Magnitude in p.u.') 72 | title('Bus Voltage') 73 | % power loss comparison 74 | FIG3 = figure('Name', 'Total Active Power loss','NumberTitle','off'); 75 | figure(FIG3) 76 | bar([sum(finalPSOresults.Lpij);sum(finalGAresults.Lpij);sum(resultWithoutDG.Lpij)]) 77 | grid on; 78 | title('Total Active Power loss in MW') 79 | ylabel('Active Power loss(MW)') 80 | set(gca,'Xtick',0) 81 | text(0.8,-0.2,'PSO tuned') 82 | text(1.8,-0.2,'GA tuned') 83 | text(2.8,-0.2,'Without Optimisation') 84 | % printresult 85 | 86 | 87 | -------------------------------------------------------------------------------- /nrloadflow.m: -------------------------------------------------------------------------------- 1 | % Author: Ratana Lim 2 | % Created date: 25/04/2018 3 | 4 | function result= nrloadflow(nbus,busd,linedata) 5 | Y = ybusppg(linedata); % Calling ybusppg.m to get Y-Bus Matrix.. 6 | % busd = busdatas(nbus); % Calling busdatas.. 7 | BMva = 100; % Base MVA.. 8 | bus = busd(:,1); % Bus Number.. 9 | type = busd(:,2); % Type of Bus 1-Slack, 2-PV, 3-PQ.. 10 | V = busd(:,3); % Specified Voltage.. 11 | del = busd(:,4); % Voltage Angle.. 12 | Pg = busd(:,5)/BMva; % PGi.. 13 | Qg = busd(:,6)/BMva; % QGi.. 14 | Pl = busd(:,7)/BMva; % PLi.. 15 | Ql = busd(:,8)/BMva; % QLi.. 16 | Qmin = busd(:,9)/BMva; % Minimum Reactive Power Limit.. 17 | Qmax = busd(:,10)/BMva; % Maximum Reactive Power Limit.. 18 | P = Pg - Pl; % Pi = PGi - PLi.. 19 | Q = Qg - Ql; % Qi = QGi - QLi.. 20 | Psp = P; % P Specified.. 21 | Qsp = Q; % Q Specified.. 22 | G = real(Y); % Conductance matrix.. 23 | B = imag(Y); % Susceptance matrix.. 24 | 25 | pv = find(type == 2 | type == 1); % PV Buses.. 26 | pq = find(type == 3); % PQ Buses.. 27 | npv = length(pv); % No. of PV buses.. 28 | npq = length(pq); % No. of PQ buses.. 29 | 30 | Tol = 1; 31 | Iter = 1; 32 | while (Tol > 1e-5) % Iteration starting.. 33 | 34 | P = zeros(nbus,1); 35 | Q = zeros(nbus,1); 36 | % Calculate P and Q 37 | for i = 1:nbus 38 | for k = 1:nbus 39 | P(i) = P(i) + V(i)* V(k)*(G(i,k)*cos(del(i)-del(k)) + B(i,k)*sin(del(i)-del(k))); 40 | Q(i) = Q(i) + V(i)* V(k)*(G(i,k)*sin(del(i)-del(k)) - B(i,k)*cos(del(i)-del(k))); 41 | end 42 | end 43 | 44 | % Checking Q-limit violations.. 45 | if Iter <= 7 && Iter > 2 % Only checked up to 7th iterations.. 46 | for n = 2:nbus 47 | if type(n) == 2 48 | QG = Q(n)+Ql(n); 49 | if QG < Qmin(n) 50 | V(n) = V(n) + 0.01; 51 | elseif QG > Qmax(n) 52 | V(n) = V(n) - 0.01; 53 | end 54 | end 55 | end 56 | end 57 | 58 | % Calculate change from specified value 59 | dPa = Psp-P; 60 | dQa = Qsp-Q; 61 | k = 1; 62 | dQ = zeros(npq,1); 63 | for i = 1:nbus 64 | if type(i) == 3 65 | dQ(k,1) = dQa(i); 66 | k = k+1; 67 | end 68 | end 69 | dP = dPa(2:nbus); 70 | M = [dP; dQ]; % Mismatch Vector 71 | 72 | % Jacobian 73 | % J1 - Derivative of Real Power Injections with Angles.. 74 | J1 = zeros(nbus-1,nbus-1); 75 | for i = 1:(nbus-1) 76 | m = i+1; 77 | for k = 1:(nbus-1) 78 | n = k+1; 79 | if n == m 80 | for n = 1:nbus 81 | J1(i,k) = J1(i,k) + V(m)* V(n)*(-G(m,n)*sin(del(m)-del(n)) + B(m,n)*cos(del(m)-del(n))); 82 | end 83 | J1(i,k) = J1(i,k) - V(m)^2*B(m,m); 84 | else 85 | J1(i,k) = V(m)* V(n)*(G(m,n)*sin(del(m)-del(n)) - B(m,n)*cos(del(m)-del(n))); 86 | end 87 | end 88 | end 89 | 90 | % J2 - Derivative of Real Power Injections with V.. 91 | J2 = zeros(nbus-1,npq); 92 | for i = 1:(nbus-1) 93 | m = i+1; 94 | for k = 1:npq 95 | n = pq(k); 96 | if n == m 97 | for n = 1:nbus 98 | J2(i,k) = J2(i,k) + V(n)*(G(m,n)*cos(del(m)-del(n)) + B(m,n)*sin(del(m)-del(n))); 99 | end 100 | J2(i,k) = J2(i,k) + V(m)*G(m,m); 101 | else 102 | J2(i,k) = V(m)*(G(m,n)*cos(del(m)-del(n)) + B(m,n)*sin(del(m)-del(n))); 103 | end 104 | end 105 | end 106 | 107 | % J3 - Derivative of Reactive Power Injections with Angles.. 108 | J3 = zeros(npq,nbus-1); 109 | for i = 1:npq 110 | m = pq(i); 111 | for k = 1:(nbus-1) 112 | n = k+1; 113 | if n == m 114 | for n = 1:nbus 115 | J3(i,k) = J3(i,k) + V(m)* V(n)*(G(m,n)*cos(del(m)-del(n)) + B(m,n)*sin(del(m)-del(n))); 116 | end 117 | J3(i,k) = J3(i,k) - V(m)^2*G(m,m); 118 | else 119 | J3(i,k) = V(m)* V(n)*(-G(m,n)*cos(del(m)-del(n)) - B(m,n)*sin(del(m)-del(n))); 120 | end 121 | end 122 | end 123 | 124 | % J4 - Derivative of Reactive Power Injections with V.. 125 | J4 = zeros(npq,npq); 126 | for i = 1:npq 127 | m = pq(i); 128 | for k = 1:npq 129 | n = pq(k); 130 | if n == m 131 | for n = 1:nbus 132 | J4(i,k) = J4(i,k) + V(n)*(G(m,n)*sin(del(m)-del(n)) - B(m,n)*cos(del(m)-del(n))); 133 | end 134 | J4(i,k) = J4(i,k) - V(m)*B(m,m); 135 | else 136 | J4(i,k) = V(m)*(G(m,n)*sin(del(m)-del(n)) - B(m,n)*cos(del(m)-del(n))); 137 | end 138 | end 139 | end 140 | 141 | J = [J1 J2; J3 J4]; % Jacobian Matrix.. 142 | 143 | X = inv(J)*M; % Correction Vector 144 | dTh = X(1:nbus-1); % Change in Voltage Angle.. 145 | dV = X(nbus:end); % Change in Voltage Magnitude.. 146 | 147 | % Updating State Vectors.. 148 | del(2:nbus) = dTh + del(2:nbus); % Voltage Angle.. 149 | k = 1; 150 | for i = 2:nbus 151 | if type(i) == 3 152 | V(i) = dV(k) + V(i); % Voltage Magnitude.. 153 | k = k+1; 154 | end 155 | end 156 | 157 | Iter = Iter + 1; 158 | Tol = max(abs(M)); % Tolerance.. 159 | 160 | end 161 | result.del=del; 162 | [result.Pi, result.Qi, result.Pg, result.Qg, result.Pl, result.Ql,... 163 | result.Lpij, result.Lqij, result.V,result.I] =loadflow(nbus,V,del,BMva,busd,linedata); % Calling Loadflow.m.. 164 | 165 | power=[result.Pi result.Qi result.Pg result.Qg result.Pl result.Ql]'./BMva; 166 | % result.Pi =result.Pi /BMva 167 | % result.Qi=result.Qi/BMva 168 | % result.Pg=result.Pg/BMva 169 | % result.Qg=result.Qg/BMva 170 | % result.Pl=result.Pl/BMva 171 | % result.Ql=result.Ql/BMva -------------------------------------------------------------------------------- /objf.m: -------------------------------------------------------------------------------- 1 | % Author: Ratana Lim 2 | % Created date: 25/04/2018 3 | 4 | function fitval=objf(x,loadbusLocation,resultwithoutDG,nbus) 5 | 6 | busdata = busdatas(nbus); % load the bus data 7 | linedata=linedatas(nbus); % load the line data 8 | % DG locations 9 | busdata(loadbusLocation,7)=-x'+busdata(loadbusLocation,7);% add the DG power to active load 10 | resultwithDG=nrloadflow(nbus,busdata,linedata); 11 | %% real power loss index calculation 12 | PLRI=(sum(resultwithoutDG.Lpij)-sum(resultwithDG.Lpij))/sum(resultwithoutDG.Lpij); 13 | %% reactive power loss index calculation 14 | QLRI=(sum(resultwithoutDG.Lqij)-sum(resultwithDG.Lqij))/sum(resultwithoutDG.Lqij); 15 | %% voltage deviation index calculation 16 | Vref=1; 17 | VDI= max((Vref-resultwithDG.V)./Vref); 18 | %% Line Loading Capacity Index calculation 19 | LLI=max(round(resultwithDG.Pi,2)./round(resultwithoutDG.Pi,2)); 20 | %% Short Circuit Index calculation 21 | % IfaultwithoutDG= 22 | %% fitness value calculation 23 | % fitval=0.35*PLRI + 0.15*QLRI + 0.30*VDI + 0.10*LLI + 0.10*SCI; 24 | fitval=0.50*PLRI + 0.35*QLRI + 0.15*VDI ; -------------------------------------------------------------------------------- /pol2rect.m: -------------------------------------------------------------------------------- 1 | % Author: Ratana Lim 2 | % Created date: 25/04/2018 3 | 4 | function rect = pol2rect(rho,theta) 5 | rect = rho.*cos(theta) + j*rho.*sin(theta); -------------------------------------------------------------------------------- /resultcalc.m: -------------------------------------------------------------------------------- 1 | % Author: Ratana Lim 2 | % Created date: 25/04/2018 3 | 4 | function resultwithDG= resultcalc(x,loadbusLocation,resultwithoutDG,nbus) 5 | busdata = busdatas(nbus); % load the bus data 6 | linedata=linedatas(nbus); % load the line data 7 | % DG locations 8 | busdata(loadbusLocation,7)=-x'+busdata(loadbusLocation,7);% add the DG power to active load 9 | resultwithDG=nrloadflow(nbus,busdata,linedata); 10 | end -------------------------------------------------------------------------------- /ybusppg.m: -------------------------------------------------------------------------------- 1 | %% Program to for Admittance And Impedance Bus Formation.... 2 | % Author: Ratana Lim 3 | % Created date: 25/04/2018 4 | 5 | function Y = ybusppg(linedata) % Returns Y 6 | xc=0; 7 | % linedata=linedatas(nbus); 8 | 9 | 10 | fb = linedata(:,1); % From bus number... 11 | tb = linedata(:,2); % To bus number... 12 | r = linedata(:,3); % Resistance, R... 13 | x = linedata(:,4); % Reactance, X... 14 | b = linedata(:,5); % Ground Admittance, B/2... 15 | a = linedata(:,6); % Tap setting value.. 16 | z = r + i*x; % z matrix... 17 | y = 1./z; % To get inverse of each element... 18 | b = i*b; % Make B imaginary... 19 | 20 | nb = max(max(fb),max(tb)); % No. of buses... 21 | nl = length(fb); % No. of branches... 22 | Y = zeros(nb,nb); % Initialise YBus... 23 | 24 | % Formation of the Off Diagonal Elements... 25 | for k = 1:nl 26 | Y(fb(k),tb(k)) = Y(fb(k),tb(k)) - y(k)/a(k); 27 | Y(tb(k),fb(k)) = Y(fb(k),tb(k)); 28 | end 29 | 30 | % Formation of Diagonal Elements.... 31 | for m = 1:nb 32 | for n = 1:nl 33 | if fb(n) == m 34 | Y(m,m) = Y(m,m) + y(n)/(a(n)^2) + b(n); 35 | elseif tb(n) == m 36 | Y(m,m) = Y(m,m) + y(n) + b(n); 37 | end 38 | end 39 | end 40 | %Y; % Bus Admittance Matrix 41 | %Z = inv(Y); % Bus Impedance Matrix --------------------------------------------------------------------------------