genetic algorithm

10 次查看(过去 30 天)
Kugen Raj
Kugen Raj 2012-3-29
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.

回答(1 个)

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

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Genetic Algorithm 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by