⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 elitist.asv

📁 遗传算法的代码,可以仿照这个学习一下,希望有所帮助
💻 ASV
字号:
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%           最优保存策略           %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

function [new_gen,curbest_indiv,curmax_fitness] = elitist(new_gen,tempbest_indiv,tempmax_fitness,fitness,popsize)

% 找出当前群体中适应度最高和最低的个体
[max_fitness,index1] = max(fitness);
[min_fitness,index2] = min(fitness);
best_indiv = new_gen(index1,:);
worst_indiv = new_gen(index2,:);

% 若当前群体中最佳个体的适应度比总的迄今为止最好个体的适应度高,则以当前群体中的
% 最佳个体作为新的迄今为止的最好个体
if max_fitness > tempmax_fitness
    curmax_fitness = max_fitness;
    curbest_indiv = best_indiv;
else
    curmax_fitness = tempmax_fitness;
    curbest_indiv = tempbest_indiv;
end

% 用迄今为止的最好个体替换当前群体
new_gen(index2,:) = curbest_indiv;


    

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -