0% found this document useful (0 votes)
26 views21 pages

Lecture 4.3 Genetic Algorithms For Optimum Design

This document is a lecture on Genetic Algorithms (GA) for optimum design, specifically focusing on the implementation of a Binary GA in MATLAB. It covers various aspects of the GA process, including population initialization, mating, mutation, and evaluation of costs, along with stopping criteria and output display. Several examples are provided to illustrate the application of the GA in optimization problems.

Uploaded by

ali123456784444
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
26 views21 pages

Lecture 4.3 Genetic Algorithms For Optimum Design

This document is a lecture on Genetic Algorithms (GA) for optimum design, specifically focusing on the implementation of a Binary GA in MATLAB. It covers various aspects of the GA process, including population initialization, mating, mutation, and evaluation of costs, along with stopping criteria and output display. Several examples are provided to illustrate the application of the GA in optimization problems.

Uploaded by

ali123456784444
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 21

Iran University of Science and Technology

Automotive Engineering Department

Optimization
Lecture 7:
Genetic Algorithms
for Optimum
Design
The Binary GA in MATLAB
GA Setup

Lecture 7: Genetic Algorithms for Optimum Design Optimization 2


The Binary GA in MATLAB
Initial Population

Lecture 7: Genetic Algorithms for Optimum Design Optimization 3


The Binary GA in MATLAB
Chromosome Decoding

Lecture 7: Genetic Algorithms for Optimum Design Optimization 4


The Binary GA in MATLAB

%_______________________________________________________
% Iterate through generations
while iga<maxit
iga=iga+1; % increments generation counter

%_______________________________________________________
% Pair and mate
M=ceil((popsize-keep)/2); % number of matings
prob=flipud([1:keep]'/sum([1:keep]));% weights chromosomes based upon position in list
odds=[0 cumsum(prob(1:keep))']; % probability distribution function (Cumulative Sum)

pick1=rand(1,keep); % mate #1
pick2=rand(1,keep); % mate #2
% ma and pa contain the indicies of the chromosomes
% that will mate

Lecture 7: Genetic Algorithms for Optimum Design Optimization 5


The Binary GA in MATLAB

ic=1;
while ic<=M
for id=2:keep+1
if pick1(ic)<=odds(id) & pick1(ic)>odds(id-1)
ma(ic)=id-1;
end % if
if pick2(ic)<=odds(id) & pick2(ic)>odds(id-1)
pa(ic)=id-1;
end % if
end % id
ic=ic+1;
end % while
% picks those ma and pa that their randomly generated probabailties (i.e. pick1and2) are
% between probabailties intervals (odds)

Lecture 7: Genetic Algorithms for Optimum Design Optimization 6


The Binary GA in MATLAB
%_______________________________________________________
% Performs mating using single point crossover
ix=1:2:keep; % index of mate #1
xp=ceil(rand(1,M)*(Nt-1)); % crossover point
pop(keep+ix,:)=[pop(ma,1:xp) pop(pa,xp+1:Nt)];
% first offspring
pop(keep+ix+1,:)=[pop(pa,1:xp) pop(ma,xp+1:Nt)];
% second offspring

%_______________________________________________________
% Mutate the population
nmut=ceil((popsize-1)*Nt*mutrate); % total number
% of mutations
mrow=ceil(rand(1,nmut)*(popsize-1))+1; % row to mutate
mcol=ceil(rand(1,nmut)*Nt); % column to mutate
for ii=1:nmut
pop(mrow(ii),mcol(ii))=abs(pop(mrow(ii),mcol(ii))-1);
% toggles bits
end % ii
%_______________________________________________________
Lecture 7: Genetic Algorithms for Optimum Design Optimization 7
The Binary GA in MATLAB
% The population is re-evaluated for cost
par(2:popsize,:)=gadecode(pop(2:popsize,:),0,10,nbits);
% decode
cost(2:popsize)=feval(ff,par(2:popsize,:));

%_______________________________________________________
% Sort the costs and associated parameters
[cost,ind]=sort(cost);
par=par(ind,:);
pop=pop(ind,:);

%_______________________________________________________
% Do statistics for a single nonaveraging run
minc(iga+1)=min(cost);
meanc(iga+1)=mean(cost);

Lecture 7: Genetic Algorithms for Optimum Design Optimization 8


The Binary GA in MATLAB
%_______________________________________________________
% Stopping criteria
if iga>maxit | cost(1)<mincost
break
end
[iga cost(1)]
end %iga

Lecture 7: Genetic Algorithms for Optimum Design Optimization 9


The Binary GA in MATLAB
%_______________________________________________________
% Displays the output
day=clock;
disp(datestr(datenum(day(1),day(2),day(3),day(4),day(5),day(6)),0))
disp(['optimized function is ' ff])
format short g
disp(['popsize = ' num2str(popsize) ' mutrate = ' num2str(mutrate) ' # par = '
num2str(npar)])
disp(['#generations=' num2str(iga) ' best cost=' num2str(cost(1))])
disp(['best solution'])
disp([num2str(par(1,:))])
disp('binary genetic algorithm')
disp(['each parameter represented by ' num2str(nbits) ' bits'])
figure(24)
iters=0:length(minc)-1;
plot(iters,minc,iters,meanc,'r:');
xlabel('generation');ylabel('cost');
text(0,minc(1),'best');text(1,minc(2),'population average')

Lecture 7: Genetic Algorithms for Optimum Design Optimization 10


The Binary GA in MATLAB
Example 1

Lecture 7: Genetic Algorithms for Optimum Design Optimization 11


The Binary GA in MATLAB
Example 1

Lecture 7: Genetic Algorithms for Optimum Design Optimization 12


The Binary GA in MATLAB
Example 1

Lecture 7: Genetic Algorithms for Optimum Design Optimization 13


The Binary GA in MATLAB
Example 1

Lecture 7: Genetic Algorithms for Optimum Design Optimization 14


The Binary GA in MATLAB
Example 2

f=x(:,1).^2+x(:,2).^2;

Lecture 7: Genetic Algorithms for Optimum Design Optimization 15


The Binary GA in MATLAB
Example 3

Lecture 7: Genetic Algorithms for Optimum Design Optimization 16


The Binary GA in MATLAB
Example 4

Lecture 7: Genetic Algorithms for Optimum Design Optimization 17


The Binary GA in MATLAB
Example 5

Lecture 7: Genetic Algorithms for Optimum Design Optimization 18


The Binary GA in MATLAB
Example 6

Lecture 7: Genetic Algorithms for Optimum Design Optimization 19


The Binary GA in MATLAB
Example 7

Lecture 7: Genetic Algorithms for Optimum Design Optimization 20


The Binary GA in MATLAB
Example 8

Lecture 7: Genetic Algorithms for Optimum Design Optimization 21

You might also like