资源简介

本程序开发了基于Matlab的遗传算法,解决了优化设计问题,求得了全局最小值

资源截图

代码片段和文件信息

clear
clc
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%本程序用于Schaffer‘s Function%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
mount_person=200; %种群大小
maxgen=500; %最大遗传代数
pro_cro=0.9; %交叉概率
pro_mut=0.005; %变异概率

x_max=100; %变量x的最大值
x_min=-100; %变量x的最小值
y_max=100; %变量y的最大值
y_min=-100; %变量y的最小值

chromlength=20; %变量的二进制位数
limit=1e-3;     %结束限制

groupunitchrom=0;
new_groupunitchrom=0;
sonunitgroup=0;
numbercount=0;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%开始2进制编码
for i=1:mount_person
    for j=1:chromlength
        groupunitchrom(ij)=rand(1); %groupunitchrom记录了种群个体染色体基因为20*20的数组
        if groupunitchrom(ij)<0.5
            groupunitchrom(ij)=0;
        else
            groupunitchrom(ij)=1;
        end
    end
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

评论

共有 条评论