遗传算法源代码我要分享

Genetic algorithm with source code

matlab 算法 源代码 遗传

关注次数: 265

下载次数: 0

文件大小: 28.94 kB

代码分类: 其他

开发平台: matlab

下载需要积分: 2积分

版权声明:如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

代码描述

中文说明: %P199_8  GA clc; clear; pop_size=100;%种群大小 m=42;%每个个体的基因数目 m1=21;%每个个体中x1占的位数 m2=21;%每个个体中x2占的位数 %产生初始种群 for j=1:pop_size     for i=1:m         num=randperm(2)-1;         str_num(j,i)=dec2bin(num(1));%随机产生的二进制数,pop_size个,每个m位            end   end delta=10; cc=0;%迭代次数 while delta>0.01%for qq=1:500%大循环 for j=1:pop_size for i=1:m     if i<=m1             str_num1(j,i)=str_num(j,i);         else             str_num2(j,i)=str_num(j,i);         end     end


English Description:

%P199_8 GA clc; clear; Pop_size=100;% population size M=42;% number of genes in each individual M1=21;% number of X1 bits in each individual M2=21;% number of X2 bits in each individual % Of initial population for j=1:pop_size for i=1:m num=randperm(2)-1; Str_num (j,i) =DEC2BIN (num (1));% of random binary number, pop_size a, m end end delta=10; CC=0;% number of iterations While Delta>0.01%for QQ=1:500% circulation for j=1:pop_size for i=1:m if i<=m1 str_num1(j,i)=str_num(j,i); else str_num2(j,i)=str_num(j,i); end end end F1=BIN2DEC (str_num1),%X1 fitness F2=BIN2DEC (str_num2),%X2 fitness x1=-100+f1*(100-(-100))/(2^m1-1);%-3.0+f1*(12.1-(-3.0))/(2^m1-1); x2=-100+f2*(100-(-100))/(2^m2-1);%4.1+f2*(5.8-4.1)/(2^m2-1); F=fun_value (X1,X2);% fitness delta=abs(


代码预览