about single point crossover??
4 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaires
Réponses (0)
Voir également
Catégories
En savoir plus sur Encryption / Cryptography dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!