genetic algorithm
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
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.
0 Commenti
Risposte (1)
Vedere anche
Categorie
Scopri di più su Genetic Algorithm in Help Center e File Exchange
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!