Search All of the Math Forum:

Views expressed in these public forums are not endorsed by NCTM or The Math Forum.

Notice: We are no longer accepting new posts, but the forums will continue to be readable.

Topic: Easily Implementation of a Genetic Algorithm Mutation function
Replies: 2   Last Post: Dec 28, 2012 11:32 AM

 Messages: [ Previous | Next ]
 Michael Doukas Posts: 12 Registered: 12/26/12
Re: Easily Implementation of a Genetic Algorithm Mutation function
Posted: Dec 28, 2012 11:32 AM

I have found a very dumb way to work around my issue:

function MutChrom = mut(OldChrom,Pm)

echo on

% get population size (Nind) and chromosome length (Lind)
[Nind, Lind] = size(OldChrom) ;

% definition of probality for mutation to happen
Pm = 0.7/Lind;

% creation of matrix of random numbers
RandMat=rand(Nind,Lind);

MutChrom=OldChrom;

for n=1:Nind
for m=1:Lind

%check probability
if Pm>=RandMat(n,m)

% perform mutation on chromosome structure
if m==1
MutChrom(n,m)=randi([1,3],1);
elseif m==2
MutChrom(n,m)=randi([4,5],1);
elseif m==3
MutChrom(n,m)=randi([6,8],1);
elseif m==4
MutChrom(n,m)=randi([9,12],1);
elseif m==5
MutChrom(n,m)=randi([13,23],1);
elseif m==6
MutChrom(n,m)=randi([24,26],1);
elseif m==7
MutChrom(n,m)=randi([27,28],1);
elseif m==8
MutChrom(n,m)=randi([29,40],1);
else
MutChrom(n,m)=randi([41,53],1);
end

end

end
end

In case anyone comes up with something better i would be happy to throw it away..

Thanks,
Mike

Date Subject Author
12/28/12 Michael Doukas
12/28/12 Michael Doukas
12/28/12 Michael Doukas