📄 selecttest.m
字号:
function [lowest1,spop,publicmem,submem]=selecttest(N,spop,publicmem,submem);
%function [outspop,publicmem,submem]=select(spop,publicmem,submem]
%the function is that selecting the excellent as the propostion of 60percent
%and record information
%the following should define the main,because they will be used in every generation
%N=10; %THE NUMBER OF CITY
%publicmem=zeros(N,N); %record the information of allspop
%submem=zeros(10,N,N); %record the information of subgrooup's the top six
%submem=submem*0.9;
publicmem=publicmem*0.9+0.01;
submem=submem*0.9+0.01;
groupnum=size(spop,1);
for i=1:groupnum
tempsumeval=spop(i,1,N+1);
for j=2:10
tempsumeval=tempsumeval+spop(i,j,N+1);
end
spop(i,1,N+3)=spop(i,1,N+1)/tempsumeval;
for j=2:10
spop(i,j,N+3)=spop(i,j,N+1)/tempsumeval+spop(i,j-1,N+3);
end
end
for i=1:groupnum %according to eval,selecting the six seed every subgroup,set flag -2
count=6;
while count>0
temp=rand(1);
if spop(i,1,N+3)>=temp & spop(i,1,N+2)==0
spop(i,1,N+2)=-2;
count=count-1;
end
for j=2:10
if spop(i,j,N+3)>=temp & spop(i,j-1,N+3)<temp & spop(i,j,N+2)==0
spop(i,j,N+2)=-2;
count=count-1;
end
end
end
end
for i=1:groupnum %save the best seed every subgroup,if possible,you may get rid of the worst one of selected seed
tempmax=max(spop(i,:,N+1)); %set flag -1
tempmin=2;
for j=1:10
if spop(i,j,N+2)==-2
if tempmin>spop(i,j,N+3)
tempmin=spop(i,j,N+3);
tempflag=j;
end
end
end
for j=1:10
if spop(i,j,N+1)==tempmax
if spop(i,j,N+2)==-2
spop(i,j,N+2)=-1;
else
spop(i,j,N+2)=-1;
spop(i,tempflag,N+2)=0;
end
end
end
end
for i=1:groupnum
for k=1:10 %useing submem record subgroup's excellent gene of individual
if spop(i,k,1)>0
for m=1:N-1
temp1=spop(i,k,m);
temp2=spop(i,k,m+1);
submem(i,temp1,temp2)=submem(i,temp1,temp2)+1;
end
temp1=spop(i,k,N);
temp2=spop(i,k,1);
submem(i,temp1,temp2)=submem(i,temp1,temp2)+1;
end
end
for k=1:10 %useing publicmem record allgroup's excellent gene of individual
if spop(i,k,N+2)==-1
for m=1:N-1 %record publicmem
temp1=spop(i,k,m);
temp2=spop(i,k,m+1);
publicmem(temp1,temp2)=publicmem(temp1,temp2)+1;
end
temp1=spop(i,k,N);
temp2=spop(i,k,1);
publicmem(temp1,temp2)=publicmem(temp1,temp2)+1;
end
end
end
lowest1=1;
lowest=10000;
for i=1:groupnum
for j=1:10
if spop(i,j,N+2)==-1 & lowest>spop(i,j,N+1); %record the lowest for delete the lowest subgroup
lowest1=i;
lowest=spop(i,j,N+1);
end
end
end
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -