this is code which i am trying to run , when i run this program it gives 168 variables but does not fulfill constraints criteria can any one tell what is problem in code

1 view (last 30 days)
%MAIN FUNCTION
% nvars = 240;
nvars = 168;
LB=[0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...
-8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 ...
-8 -8 -8 -8 -8 -8];
UB=[1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...
8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 ...
8 8 8 8 8 8
];
ObjectiveFunction = @fitness1;
ConstraintFunction = @constraints;
opts = gaoptimset(...
'PopulationSize', 300, ...
'Generations', 600, ...
'EliteCount', 20, ...
'StallGenLimit' ,400,...
'TolFun', 1e-8, ...
'PlotFcns',@gaplotbestf);
[x, fbest, exitflag] = ga(ObjectiveFunction, nvars, [], [], [], [], LB, UB, ConstraintFunction,1:168, opts);
display(x)
CONSTRAINTS:
%%CONSTRAINTS FUNCTION
function [c, ceq]=constraints(x)
global Simu_Hour;
tap_num=0;c1_tap=0;c2_tap=0;c3_tap=0;c4_tap=0;c5_tap=0;c6_tap=0;
for j = 1:Simu_Hour
if x(144+j)~=x(145+j)
tap_num=tap_num+1 ;
else
end
if (x(j)~=x(j+1))
c1_tap= c1_tap+1;
else
end
if (x(24+j)~=x(25+j))
c2_tap= c2_tap+1;
else
end
if (x(48+j)~=x(49+j))
c3_tap= c3_tap+1;
else
end
if (x(72+j)~=x(73+j))
c4_tap= c4_tap+1;
else
end
if (x(96+j)~=x(97+j))
c5_tap= c5_tap+1;
else
end
if (x(120+j)~=x(121+j))
c6_tap= c6_tap+1;
else
end
end % for loop end
V_day=zeros(1,24);
Vmax=zeros(1,24);
Vmin=zeros(1,24);
for j = 1:Simu_Hour
tap=1+0.0125*x(144+j);
temp=case30(x(j),x(24+j),x(48+j),x(72+j),x(96+j),x(120+j),tap);
T=runpf(temp);
for b=1:29
V_day(b)=T.bus(b,8);
end
Vmax(j)=max(V_day);
Vmin(j)=min(V_day);
end
vol=[-1*Vmin(1)-(-0.95); Vmax(1)-1.05;...
-1*Vmin(2)-(-0.95); Vmax(2)-1.05;...
-1*Vmin(3)-(-0.95); Vmax(3)-1.05;...
-1*Vmin(4)-(-0.95); Vmax(4)-1.05;...
-1*Vmin(5)-(-0.95); Vmax(5)-1.05;...
-1*Vmin(6)-(-0.95); Vmax(6)-1.05;...
-1*Vmin(7)-(-0.95); Vmax(7)-1.05;...
-1*Vmin(8)-(-0.95); Vmax(8)-1.05;...
-1*Vmin(9)-(-0.95); Vmax(9)-1.05;...
-1*Vmin(10)-(-0.95); Vmax(10)-1.05;...
-1*Vmin(11)-(-0.95); Vmax(11)-1.05;...
-1*Vmin(12)-(-0.95); Vmax(12)-1.05;...
-1*Vmin(13)-(-0.95); Vmax(13)-1.05;...
-1*Vmin(14)-(-0.95); Vmax(14)-1.05;...
-1*Vmin(15)-(-0.95); Vmax(15)-1.05;...
-1*Vmin(16)-(-0.95); Vmax(16)-1.05;...
-1*Vmin(17)-(-0.95); Vmax(17)-1.05;...
-1*Vmin(18)-(-0.95); Vmax(18)-1.05;...
-1*Vmin(19)-(-0.95); Vmax(19)-1.05;...
-1*Vmin(20)-(-0.95); Vmax(20)-1.05;...
-1*Vmin(21)-(-0.95); Vmax(21)-1.05;...
-1*Vmin(22)-(-0.95); Vmax(22)-1.05;...
-1*Vmin(23)-(-0.95); Vmax(23)-1.05;...
-1*Vmin(24)-(-0.95); Vmax(24)-1.05];
capacitor_swtching = [
c1_tap - 7;...
c2_tap - 7;...
c3_tap - 7;...
c4_tap - 7;...
c5_tap - 7;...
c6_tap - 7
tap_num-12];
% All nonlinear constraints
c = [vol;capacitor_swtching];
% No equality constraints
ceq = [];
FITNESS FUNCTION:
function y=fitness1(x)
p = 0;
global Simu_Hour;
for j = 1:Simu_Hour
tap=1+0.0125*x(144+j);
temp=case30(x(j),x(24+j),x(48+j),x(72+j),x(96+j),x(120+j),tap);
T=runpf(temp);
for b=1:29
p=p+T.branch(b,14)+T.branch(b,16);
end
end
y=p;
%%SYSTEM DATA
%%SYSTEM DATA
function mpc =case30(cap1,cap2,cap3,cap4,cap5,cap6,tap);
if cap1==1
c1=0.6
else c1=0
end
if cap2==1
c3=0.6
else c3=0
end
if cap3==1
c4=0.6
else c4=0
end
if cap4==1
c5=0.3
else c5=0
end
if cap5==1
c6=0.9
else c6=0
end
if cap6==1
c7=0.9
else c7=0
end
mpc.version = '2';
%%----- Power Flow Data -----%%
%%system MVA base
mpc.baseMVA = 100;
%%bus data
% bus_i type Pd Qd Gs Bs area Vm Va baseKV zone Vmax Vmin
mpc.bus = [1 3 0 0 0 0 1 1.06 0 132 1 1.06 0.94;
2 2 21.7 12.7-c1 0 0 1 1.043 -5.48 132 1 1.06 0.94;
3 1 2.4 1.2 0 0 1 1.021 -7.96 132 1 1.06 0.94;
4 1 7.6 1.6 0 0 1 1.012 -9.62 132 1 1.06 0.94;
5 2 89.482 19 0 0 1 1.01 -14.37 132 1 1.06 0.94;
6 1 -4.9867 0 0 0 1 1.01 -11.34 132 1 1.06 0.94;
7 1 22.8 10.9 0 0 1 1.002 -13.12 132 1 1.06 0.94;
8 2 30 30 0 0 1 1.01 -12.1 132 1 1.06 0.94;
9 1 -4.9674 0 0 0 1 1.051 -14.38 1 1 1.06 0.94;
10 1 5.8 2 0 19 1 1.045 -15.97 33 1 1.06 0.94;
11 2 -4.7298 0 0 0 1 1.082 -14.39 11 1 1.06 0.94;
12 1 11.2 7.5 0 0 1 1.057 -15.24 33 1 1.06 0.94;
13 2 0 0 -c3 0 1 1.071 -15.24 11 1 1.06 0.94;
14 1 6.2 1.6 0 0 1 1.042 -16.13 33 1 1.06 0.94;
15 1 3.7564 2.5-c4 0 0 1 1.038 -16.22 33 1 1.06 0.94;
16 1 3.5 1.8 0 0 1 1.045 -15.83 33 1 1.06 0.94;
17 1 9 5.8 0 0 1 1.04 -16.14 33 1 1.06 0.94;
18 1 3.2 0.9 0 0 1 1.028 -16.82 33 1 1.06 0.94;
19 1 9.5 3.4-c5 0 0 1 1.026 -17 33 1 1.06 0.94;
20 1 2.2 0.7 0 0 1 1.03 -16.8 33 1 1.06 0.94;
21 1 17.5 11.2 0 0 1 1.033 -16.42 33 1 1.06 0.94;
22 1 0 0 0 0 1 1.033 -16.41 33 1 1.06 0.94;
23 1 3.2 1.6-c6 0 0 1 1.027 -16.61 33 1 1.06 0.94;
24 1 8.7 6.7 0 4.3 1 1.021 -16.78 33 1 1.06 0.94;
25 1 0 -c5 0 0 1 1.017 -16.35 33 1 1.06 0.94;
26 1 3.5 2.3 0 0 1 1 -16.77 33 1 1.06 0.94;
27 1 0 0 0 0 1 1.023 -15.82 33 1 1.06 0.94;
28 1 -4.9887 0 0 0 1 1.007 -11.97 132 1 1.06 0.94;
29 1 2.4 0.9 0 0 1 1.003 -17.06 33 1 1.06 0.94;
30 1 10.6 1.9 0 0 1 0.992 -17.94 33 1 1.06 0.94;
];
%%generator data
% bus Pg Qg Qmax Qmin Vg mBase status Pmax Pmin Pc1 Pc2 Qc1min Qc1max Qc2min Qc2max ramp_agc ramp_10 ramp_30 ramp_q apf
mpc.gen = [
1 260.2 -16.1 10 0 1.06 100 1 360.2 0 0 0 0 0 0 0 0 0 0 0 0;
2 40 50 50 -40 1.045 100 1 140 0 0 0 0 0 0 0 0 0 0 0 0;
5 0 37 40 -40 1.01 100 1 100 0 0 0 0 0 0 0 0 0 0 0 0;
8 0 37.3 40 -10 1.01 100 1 100 0 0 0 0 0 0 0 0 0 0 0 0;
11 0 16.2 24 -6 1.082 100 1 100 0 0 0 0 0 0 0 0 0 0 0 0;
13 0 10.6 24 -6 1.071 100 1 100 0 0 0 0 0 0 0 0 0 0 0 0;
];
%%branch data
% fbus tbus r x b rateA rateB rateC ratio angle status angmin angmax
mpc.branch = [
1 2 0.0192 0.0575 0.0528 0 0 0 tap 0 1 -360 360;
1 3 0.0452 0.1652 0.0408 0 0 0 0 0 1 -360 360;
2 4 0.057 0.1737 0.0368 0 0 0 0 0 1 -360 360;
3 4 0.0132 0.0379 0.0084 0 0 0 0 0 1 -360 360;
2 5 0.0472 0.1983 0.0418 0 0 0 0 0 1 -360 360;
2 6 0.0581 0.1763 0.0374 0 0 0 0 0 1 -360 360;
4 6 0.0119 0.0414 0.009 0 0 0 0 0 1 -360 360;
5 7 0.046 0.116 0.0204 0 0 0 0 0 1 -360 360;
6 7 0.0267 0.082 0.017 0 0 0 0 0 1 -360 360;
6 8 0.012 0.042 0.009 0 0 0 0 0 1 -360 360;
6 9 0 0.208 0 0 0 0 0.978 0 1 -360 360;
6 10 0 0.556 0 0 0 0 0.969 0 1 -360 360;
9 11 0 0.208 0 0 0 0 0 0 1 -360 360;
9 10 0 0.11 0 0 0 0 0 0 1 -360 360;
4 12 0 0.256 0 0 0 0 0.932 0 1 -360 360;
12 13 0 0.14 0 0 0 0 0 0 1 -360 360;
12 14 0.1231 0.2559 0 0 0 0 0 0 1 -360 360;
12 15 0.0662 0.1304 0 0 0 0 0 0 1 -360 360;
12 16 0.0945 0.1987 0 0 0 0 0 0 1 -360 360;
14 15 0.221 0.1997 0 0 0 0 0 0 1 -360 360;
16 17 0.0524 0.1923 0 0 0 0 0 0 1 -360 360;
15 18 0.1073 0.2185 0 0 0 0 0 0 1 -360 360;
18 19 0.0639 0.1292 0 0 0 0 0 0 1 -360 360;
19 20 0.034 0.068 0 0 0 0 0 0 1 -360 360;
10 20 0.0936 0.209 0 0 0 0 0 0 1 -360 360;
10 17 0.0324 0.0845 0 0 0 0 0 0 1 -360 360;
10 21 0.0348 0.0749 0 0 0 0 0 0 1 -360 360;
10 22 0.0727 0.1499 0 0 0 0 0 0 1 -360 360;
21 22 0.0116 0.0236 0 0 0 0 0 0 1 -360 360;
15 23 0.1 0.202 0 0 0 0 0 0 1 -360 360;
22 24 0.115 0.179 0 0 0 0 0 0 1 -360 360;
23 24 0.132 0.27 0 0 0 0 0 0 1 -360 360;
24 25 0.1885 0.3292 0 0 0 0 0 0 1 -360 360;
25 26 0.2544 0.38 0 0 0 0 0 0 1 -360 360;
25 27 0.1093 0.2087 0 0 0 0 0 0 1 -360 360;
28 27 0 0.396 0 0 0 0 0.968 0 1 -360 360;
27 29 0.2198 0.4153 0 0 0 0 0 0 1 -360 360;
27 30 0.3202 0.6027 0 0 0 0 0 0 1 -360 360;
29 30 0.2399 0.4533 0 0 0 0 0 0 1 -360 360;
8 28 0.0636 0.2 0.0428 0 0 0 0 0 1 -360 360;
6 28 0.0169 0.0599 0.013 0 0 0 0 0 1 -360 360;
];

Answers (0)

Categories

Find more on Programming in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!