资 源 简 介
%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