Sie sind auf Seite 1von 10

November

MT 461 PATH PLANNING IN MOBILE ROBOTS


24, 2019

Genetic Algorithms:

Introduction:

A genetic algorithm (GA) is a method for solving both constrained and


unconstrained optimization problems based on a natural selection process that mimics biological
evolution. The algorithm repeatedly modifies a population of individual solution.
Stochastic method:

GA uses the stochastic method to solve the problems. Stochastic programs work by using
probabilistic methods to solve problems.

Techniques used in GA:

The process of natural selection starts with the selection of fittest individuals from a population.
They produce offspring which inherit the characteristics of the parents and will be added to the
next generation. If parents have better fitness, their offspring will be better than parents and have
a better chance at surviving. This process keeps on iterating and at the end, a generation with the
fittest individuals will be found. This notion can be applied for a search problem. We consider a
set of solutions for a problem and select the set of best ones out of them.
Five phases are considered in a genetic algorithm.

1. Coding.
2. Fitness function.
3. Selection.
4. Crossover.
5. Mutation.

Coding:

 First, we have to code a string structure into a variable. We use binary structures so that
the values are understand-able for the computer.
 The length of the binary number is related with the accuracy.
November
MT 461 PATH PLANNING IN MOBILE ROBOTS
24, 2019

 To decode the value we are supposed to use following formula:

Fitness function:

The fitness function determines how fit an individual is (the ability of an individual to compete
with other individuals). It gives a fitness score to each individual. The probability that an
individual will be selected for reproduction is based on its fitness score.

The fitness function can be defined for maximization as well as minimization accordingly.

Selection:

The idea of selection phase is to select the fittest individuals and let them pass their genes to the
next generation.

Two pairs of individuals (parents) are selected based on their fitness scores. Individuals with high
fitness have more chance to be selected for reproduction.

Crossover:

Crossover is the most significant phase in a genetic algorithm. For each pair of parents to be
mated, a crossover point is chosen at random from with-in the genes.
November
MT 461 PATH PLANNING IN MOBILE ROBOTS
24, 2019

For example, consider the crossover point to be 3 as shown below.

Offspring are created by exchanging the genes of parents among themselves until the crossover
point is reached.

Exchanging genes among parents

The new offspring are added to the population.

New offspring
November
MT 461 PATH PLANNING IN MOBILE ROBOTS
24, 2019

Mutation

In certain new offspring formed, some of their genes can be subjected to a mutation with a low
random probability. This implies that some of the bits in the bit string can be flipped.

Mutation: Before and After

Mutation occurs to maintain diversity within the population and prevent premature convergence.

Implementation:
November
MT 461 PATH PLANNING IN MOBILE ROBOTS
24, 2019

Code:

% Binary Genetic Algorithm


%
% minimizes the objective function designated in ff
% Before beginning, set all the parameters in parts
%I, II, and III
% Haupt & Haupt
% 2003
clear
clc
tic
%_______________________________________________________
% I. Setup the GA
ff='function'; % objective function
npar=1; % number of optimization variables
%_______________________________________________________
% II. Stopping criteria
maxit=10; % max number of iterations
November
MT 461 PATH PLANNING IN MOBILE ROBOTS
24, 2019

mincost=-9999999; % minimum cost

%_______________________________________________________
% III. GA parameters
popsize=100; % set population size
mutrate=.15; % set mutation rate
selection=0.5; % fraction of population
% kept
nbits=8; % number of bits in each
% parameter
Nt=nbits*npar; % total number of bits
% in a chormosome
keep=floor(selection*popsize); % #population members
% that survive
%_______________________________________________________
% Create the initial population
iga=0; % generation counter
% initialized
pop=round(rand(popsize,Nt)); % random population of
% 1s and 0s
par=gadecode(pop,0,10,nbits); % convert binary to
% continuous values
cost=feval(ff,par); % calculates population
% cost using ff
[cost,ind]=sort(cost); % min cost in element 1
par=par(ind,:);pop=pop(ind,:); % sorts population with
% lowest cost first
minc(1)=min(cost); % minc contains min of
% population
meanc(1)=mean(cost); % meanc contains mean
% of population
November
MT 461 PATH PLANNING IN MOBILE ROBOTS
24, 2019

%_______________________________________________________
% 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
%PROGRAM I: BINARY GENETIC ALGORTHIM 213
pick1=rand(1,M); % mate #1
pick2=rand(1,M); % mate #2
% ma and pa contain the indicies of the chromosomes
% that will mate
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
%_______________________________________________________
November
MT 461 PATH PLANNING IN MOBILE ROBOTS
24, 2019

% 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
%_______________________________________________________
% 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);
%_______________________________________________________
November
MT 461 PATH PLANNING IN MOBILE ROBOTS
24, 2019

% Stopping criteria
if iga>maxit | cost(1)<mincost
break
end
[iga cost(1)]
end %iga
%_______________________________________________________
% 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)' nbits'])
figure(24)
iters=0:length(minc)-1;
plot(iters,minc,iters,meanc);
xlabel('generation');ylabel('cost');
text(0,minc(1),'best');text(1,minc(2),'population average')
toc

Applications:

Robotics:

GAs can be programmed to search for a range of optimal designs and components for each
specific use, or to return results for entirely new types of robots that can perform multiple tasks
and have more general application.
November
MT 461 PATH PLANNING IN MOBILE ROBOTS
24, 2019

Engineering Design

Getting the most out of a range of materials to optimize the structural and operational design of
buildings, factories, machines, etc. is a rapidly expanding application of GAs. These are being
created for such uses as optimizing the design of heat exchangers, robot gripping arms, satellite
booms, building trusses, flywheels, turbines, and just about any other computer-assisted
engineering design application.

Computer Gaming

Those who spend some of their time playing computer Sims games (creating their own
civilizations and evolving them) will often find themselves playing against sophisticated
artificial intelligence GAs instead of against other human players online. These GAs have been
programmed to incorporate the most successful strategies from previous games – the programs
‘learn’ – and usually incorporate data derived from game theory in their design. Game theory is
useful in most all GA applications for seeking solutions to whatever problems they are applied
to, even if the application really is a game.

Conclusion:

To conclude the discussion, I’ll say that genetic algorithm is a very useful technique to get the
best possible generation out of the given parent generations. As it uses stochastic approach to get
the results one can get more than one possibly best solution to a problem.

Das könnte Ihnen auch gefallen