about single point crossover??
조회 수: 5 (최근 30일)
이전 댓글 표시
i'm writing aprog, convert word to numbers then binary then want to make crossover with random chromosome,the problem face me when the word is 3 letters output 4..and when 2 letters return error..can anyone help me plz
%convert the word 'THIS' to numbers according to the alphabetic sequence
prompt = 'Enter your text: ';
text= input(prompt,'s');
alphabet='ABCDEFGHIJKLMNOPQRSTUVWXYZ';
[~,pos] = ismember(text,alphabet)
%convert each letter of the word to binary value
step3=de2bi(pos,'left-msb')
n = size(step3, 1);
l = size(step3, 2);
%generate the default chromosome (second parent)
Step4= randi([0, 1], 1,l)
Step4=[Step4;Step4;Step4;Step4];
%Choose a crossover point
cp = randperm(l-1, 1)
for i=1:n
breeders = [step3(i,:);Step4];
b1(i,:) = [breeders(1, 1:cp), breeders(2, cp+1:end)];
b2(i,:) = [breeders(2, 1:cp), breeders(1, cp+1:end)];
i=i+1;
end
b1=b1
b2=b2
댓글 수: 0
답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Encryption / Cryptography에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!