Drexel dragonThe Math ForumDonate to the Math Forum



Search All of the Math Forum:

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


Math Forum » Discussions » Software » comp.soft-sys.matlab

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

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   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
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

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



Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© Drexel University 1994-2014. All Rights Reserved.
The Math Forum is a research and educational enterprise of the Drexel University School of Education.