genetic algorithm

6 views (last 30 days)
Kugen Raj
Kugen Raj on 29 Mar 2012
im new to the genetic algorithm. here is a sample code of a genetic algorithm for an antenna array.
%This is a simple genetic algorithm written in MATLAB
N=8; %number of bits in a gene
M=N; %number of genes
last=20; %number of iterations
M2=M/2;
%creates M random genes having N bits
Gene=round(rand(M,N)); %gene is an MxN matrix
for ib=1:last
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% cost=function (Gene) %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%ranks results and discards bottom 50%
[cost,ind]=sort(cost); %sorts costs from best to worst
Gene=Gene(ind(l:M2),:); %sorts Gene according to costs and discard bottom half.
%mate
cross=ceil((N-l)+rand(M2,1)); %selects random cross over points
%pairs genes and swaps binary digits to the right of the
%cross over points to form the offspring
for ic=1:2:M2
Gene (M2+ic,1:cross)= Gene (ic,1:cross) ;%offspring #1
Gene (MZ+ic,cross+l:N)=Gene (ic+l,cross+l:N) ;
Gene (M2+ic+l,1 :cross)=Gene (ic+l,1:cross) ;%offspring #2
Gene (M2+ic+l,cross+l:N)=Gene (ic,cross+l:N) ;
end
% mutate
ix=ceil (M*rand) ;% randam gene
iy=ceil (N*rand) ;% randam bit in gene
Gene(ix,iy)=l-Gene(ix,iy);% mutate bit iy in gene ix
end %for ib-1:last
how can I identify that this a binary or decimal genetic algorithm.

Answers (1)

Thomas
Thomas on 29 Mar 2012
I would guess Binary, since your gene is binary encoded..
  1 Comment
Kugen Raj
Kugen Raj on 29 Mar 2012
how cn I manipulate this into decimal encoding GA? what do I need to change.

Sign in to comment.

Products

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!