fitv=ranking(objv,[2,1],subpop);%分配适度值
selch=selet(selfun,chorn,fitv,ggap,subpop);%选择
recch=recombin(xovfun,selch,xovr,subpop);%重组
mutch=mutate(mutfun,recch,fieldDD,mutr,subpop);%变异
objvoff=objfun(mutch);%计算目标函数值
[chorm,objv]=reins(chorm,mutch,subpop,[1 indr],objv,objvoff);%替代
gen=gen+1;
trace(gen,1) =min(objv);
trace(gen,2)=mean(objv);
%在子种群中迁移个体
if (rem(gen,miggen)==0)
[chorm,objv]=migrate(chor,subpop,[migr,1,1],objv);
end
end
[yy,ii]=min(objv);%输出最有解及序号
figure(1)
plot(chorm(ii,:),’-ro’);
figure(2);%遗传算法性能跟踪图
plot(trace(:,1));
hold on
plot(trace(:,2),’-.r’);
legend('解的变化','种群均值的变化');
2022-03-08 11:04:14
1.91MB
遗传算法
1