clc
clear all
target="hello,world!";
function fitval = fitness(source, target)%def calc_fitness;
fitval = 0;
for i = 1 : length(source)
fitval = fitval + (double(target(i)) - double(source(i))) ^ 2;
end
end
function [child_dna,child_fitness]=mutate(parent1,parent2)%def mutate(parent1,
parent2):
child_dna=parent1(1,:);
start=randi(size(parent2(1,:)),1,1);
stop=randi(size(parent2(1,:)),1,1);
if(start>stop) tmp=start; start=stop; stop=start; end
child_dna(start:stop)=parent2(1,start:stop);
charpos=randi(size(child_dna),1,1);
child_dna(charpos)=char(uint8(child_dna(charpos))+randi(3,1,1)-2);
%child_fitness=calc_fitness(child_dna,target);
child_fitness=0;
end
function [x] = random_parent(genepool , GENSIZE)
wRndNr = rand() * rand() * ( GENSIZE - 1 )
wRndNr = int32(wRndNr); x = genepool(wRndNr);