Error in mutation part of artificial immune system code
Show older comments
This is my project based on Artificial Immune System (AIS). I don't know how to fix the error.
clear
clc
%varyQ_all;
tic
SLT=0;
%%%%%%%%%%%%%%%%%%%%%%%%initialization%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
pop=0;
num=26;
num2=num*2;
tot_vary=8.2;
crtcl_bus=26;
max_load=18.3;
location=6;
for j=1:40000
x02=rand*90-40;
x05=rand*80-40;
x08=rand*50-10;
x011=rand*30-6;
x013=rand*30-6;
x110=rand*50;
x124=rand*50;
nu02=rand*5;
nu05=rand*5;
nu08=rand*5;
nu011=rand*5;
nu013=rand*5;
nu110=rand*5;
nu124=rand*5;
[basemva,accuracy,maxiter,busdata,linedata]=IEEE30BUSDATA;
busdata(2,6)=busdata(2,6)-x02;
busdata(5,6)=busdata(5,6)-x05;
busdata(8,6)=busdata(8,6)-x08;
busdata(11,6)=busdata(11,6)-x011;
busdata(13,6)=busdata(13,6)-x013;
busdata(10,7)=x110;
busdata(24,7)=x124;
lfybus
lfnewton
busout
lineflow
SLT=0;
pp=(Vm)';
loss=real(SLT);
Pg1=Pg(1);
if pp>=0.95 & pp<=1.10 & loss<=15.0 & Pg(1)<=500 & Pg(1)>=100
loop2=0;
for increment2=[1.0:0.05:1000.0]
loop2=loop2+1;
[basemva,accuracy,maxiter,busdata,linedata]=IEEE30BUSDATA;
busdata(crtcl_bus,location)=busdata(crtcl_bus,location)*tot_vary;
busdata(crtcl_bus,location)=busdata(crtcl_bus,location)*increment2;
busdata(2,6)=busdata(2,6)-x02;
busdata(5,6)=busdata(5,6)-x05;
busdata(8,6)=busdata(8,6)-x08;
busdata(11,6)=busdata(11,6)-x011;
busdata(13,6)=busdata(13,6)-x013;
busdata(10,7)=x110;
busdata(24,7)=x124;
lfybus
lfnewton
busout
lineflow
SLT=0;
a=min(Vm);
b=busdata(crtcl_bus,location);
if a<0.85
break
end
load2=busdata(crtcl_bus,location);
Ploss2=real(SLT);
Vmin2=min(Vm);
Vmax2=max(Vm);
Load2a(loop2,:)=busdata(crtcl_bus,location);
Ploss2a(loop2,:)=real(SLT);
Vmin2a(loop2,:)=min(Vm);
Vmax2a(loop2,:)=max(Vm);
end
if b>=20.13
pop=pop+1;
parents(pop,:)=[x02 x05 x08 x011 x013 x110 x124...
nu02 nu05 nu08 nu011 nu013 nu110 nu124...
Ploss2 Vmin2 Vmax2]
if pop==num
break
end
end
end
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%CLONE%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
x02=parents(:,1);
x05=parents(:,2);
x08=parents(:,3);
x011=parents(:,4);
x013=parents(:,5);
x110=parents(:,6);
x124=parents(:,7);
nu02=parents(:,8);
nu05=parents(:,9);
nu08=parents(:,10);
nu011=parents(:,11);
nu013=parents(:,12);
nu110=parents(:,13);
nu124=parents(:,14);
load2=parents(:,15);
Ploss2=parents(:,16);
Vmin2=parents(:,17);
Vmax2=parents(:,17);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%MUTATION%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
mutatn_iter=0;
for big_loop=1:40000
mutatn_iter=mutatn_iter+1;
tau=1/(sqrt(2*sqrt(10)));
taum=1/(sqrt(2*10));
for loop3=1:num;
for j2=1:40000 %loop j2 is to make sure that the mutated value comply to the constraint
gauss1
x02_m;
x05_m;
x08_m;
x011_m;
x013_m;
x110_m;
x124_m;
[basemva,accuracy,maxiter,busdata,linedata]=IEEE30BUSDATA;
busdata(2,6)=busdata(2,6)-x02_mutate;
busdata(5,6)=busdata(5,6)-x05_mutate;
busdata(8,6)=busdata(8,6)-x08_mutate;
busdata(11,6)=busdata(11,6)-x011_mutate;
busdata(13,6)=busdata(13,6)-x013_mutate;
busdata(10,7)=x110_mutate;
busdata(24,7)=x124_mutate;
lfybus
lfnewton
busout
lineflow
SLT=0;
qq=(Vm)';
loss2=real(SLT);
Pg1a=Pg(1);
if qq>=0.95 & qq<=1.10 & loss2<=15.0 & Pg(1)<=500 & Pg(1)>=100
loop4=0;
for increment4=[1.0:0.05:1000.0]
loop4=loop4+1;
[basemva,accuracy,maxiter,busdata,linedata]=IEEE30BUSDATA;
busdata(crtcl_bus,location)=busdata(crtcl_bus,location)*tot_vary;
busdata(crtcl_bus,location)=busdata(crtcl_bus,location)*increment4;
busdata(2,6)=busdata(2,6)-x02_mutate;
busdata(5,6)=busdata(5,6)-x05_mutate;
busdata(8,6)=busdata(8,6)-x08_mutate;
busdata(11,6)=busdata(11,6)-x011_mutate;
busdata(13,6)=busdata(13,6)-x013_mutate;
busdata(10,7)=x110_mutate;
busdata(24,7)=x124_mutate;
lfybus
lfnewton
busout
lineflow
fvsi
maxloadability
c=min(Vm);
d=busdata(crtcl_bus,location);
if c<0.85
break
end
Ploss4=real(SLT);
Vmin4=min(Vm);
Vmax4=max(Vm);
load4=busdata(crtcl_bus,loacation);
load4a(loop4,:)=busdata(crtcl_bus,loacation);
Ploss4a(loop4,:)=real(SLT);
Vmin4a(loop4,:)=min(Vm);
Vmax4a(loop4,:)=max(Vm);
end
if d>=20.13
offspring(loop3,:)=[x02_mutate x05_mutate x08_mutate...
x011_mutate x013_mutate x110_mutate x124_mutate...
nu02_mutate nu05_mutate nu08_mutate nu011_mutate...
nu013_mutate nu110_mutate nu124_mutate load4...
Ploss4 Vmin4 Vmax4]
break
end
end
end
end
x02_mutate=offspring(:,1);
x05_mutate=offspring(:,2);
x08_mutate=offspring(:,3);
x011_mutate=offspring(:,4);
x013_mutate=offspring(:,5);
x110_mutate=offspring(:,6);
x124_mutate=offspring(:,7);
nu02_mutate=offspring(:,8);
nu05_mutate=offspring(:,9);
nu08_mutate=offspring(:,10);
nu011_mutate=offspring(:,11);
nu013_mutate=offspring(:,12);
nu110_mutate=offspring(:,13);
nu124_mutate=offspring(:,14);
load4=offspring(:,15);
Ploss4=offspring(:,16);
Vmin4=offspring(:,17);
Vmax4=offspring(:,18);;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%SELECTION%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
population=[x02 x05 x08 x011 x013 x110 x124 nu02 nu05 nu08 nu011 nu013...
nu110 nu124 load2 Ploss2 Vmin2 Vmax2;x02_mutate x05_mutate...
x08_mutate x011_mutate x013_mutate x110_mutate x124_mutate...
nu02_mutate nu05_mutate nu08_mutate nu011_mutate...
nu013_mutate nu110_mutate nu124_mutate...
load4 Ploss4 Vmin4 Vmax4];
rank1=sortrows(population,15);
rank2=flipud(rank1);
nxt_genrtn=rank2(1:num,:)
x02=nxt_genrtn(:,1);
x05=nxt_genrtn(:,2);
x08=nxt_genrtn(:,3);
x011=nxt_genrtn(:,4);
x013=nxt_genrtn(:,5);
x110=nxt_genrtn(:,6);
x124=nxt_genrtn(:,7);
nu02=nxt_genrtn(:,8);
nu05=nxt_genrtn(:,9);
nu08=nxt_genrtn(:,10);
nu011=nxt_genrtn(:,11);
nu013=nxt_genrtn(:,12);
nu110=nxt_genrtn(:,13);
nu124=nxt_genrtn(:,14);
load2=nxt_genrtn(:,15);
Ploss2=nxt_genrtn(:,16);
Vmin2=nxt_genrtn(:,17);
Vmax2=nxt_genrtn(:,18);
mx_load=max(load2);
mn_load=min(load2);
diff=mx_load-mn_load
pause(3)
if diff<0.0001
break
end
end
toc
result1=[x02 x05 x08 x011 x013 x110 x124 nu02 nu05 nu08 nu011 nu013...
nu110 nu124 load2 Ploss2 Vmin2 Vmax2]
result=sortrows(result1,15)
best_reading=result(1,:)
parents1=parents
mutatn_iter1=mutatn_iter
Accepted Answer
More Answers (0)
Categories
Find more on Large Files and Big Data 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!