function [bestsole,bestpop]=ga_scomplex(num,bounds,ps,pc,pm,b,dtc)
% GA_scomple 是基于浮点编码的单纯形遗传算法主程序
% num 定义种群数量
% bounds 定义参数取值范围,格式为[Var1min,Var1max;Var2min,Var2max;…….];
%ps 选择概率
%pc 交叉概率
%pm 变异概率
%b 变异程度系数
%dtc 迭代次数
% $Date: 2005/5/25 $
%
%email:[email protected]
numvars=size(bounds,1);
xzomelength=numvars+1;
flag=1;
n=1;
[pop]=initializega(num,bounds);
while (n<=dtc&flag>0.00001)
[newpop]=select(pop,ps);
[crosspop]=crossover(bounds,newpop,pc);
[mupop]=mutation(crosspop,bounds,pm,[b,n,dtc]);
spop=[newpop;crosspop;mupop];
[y,x]=sort(spop(:,xzomelength));
spop=spop(x,:);
n_spop=size(spop,1);
bestpop=spop(n_spop:-1:n_spop-num+1,:);
[scopop]=scomplex(bounds,bestpop(1,1:numvars), 100); % 加入单纯形算法
bestpop(num,:)=scopop;
bestpop(num,xzomelength)=-scopop(xzomelength);
trace1(n)=mean(bestpop(:,xzomelength));
bestsole=bestpop(1,1:numvars);
trace2(n)=bestpop(1,xzomelength);
flag=abs(trace2(n)-trace1(n));
bmax=max(bestpop(:,1:numvars));
bmin=min(bestpop(:,1:numvars));
bounds=[bmin',bmax'];
pop=bestpop;
n=n+1;
end
t=1:n-1;
plot(t,trace1,'r-',t,trace2,'g-');
legend('均值','最优解');
toc
%%初始种群值生成子程序%%%%%%%%%%%%%%%%%%%%%%%%%
function [pop]=initializega(num,bounds)
numvars=size(bounds,1);
rng=(bounds(:,2)-bounds(:,1))';
xzomelength=numvars+1;
pop=zeros(num,xzomelength);
pop(:,1:numvars)=(ones(num,1)*rng).*(rand(num,numvars))+(ones(num,1)*bounds(:,1)');
pop(:,xzomelength)=fitness(pop(:,1:numvars));
%%选择子程序%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%5