901470_genetic22
TRANSCRIPT
-
8/10/2019 901470_genetic22
1/83
Genetic AlgorithmsGenetic Algorithms
AnAn algorithmalgorithmis a set of instructions thatis a set of instructions thatis repeated to solve a problem.is repeated to solve a problem.
AA genetic algorithmgenetic algorithmconceptually followsconceptually followssteps inspired by the biologicalsteps inspired by the biologicalprocesses of evolution.processes of evolution.
Genetic Algorithms follow the idea ofGenetic Algorithms follow the idea of
SURVIVAL OF THE FITTESTSURVIVAL OF THE FITTEST- Better- Betterand better solutions evolve fromand better solutions evolve fromprevious generations until a near optimalprevious generations until a near optimalsolution is obtained.solution is obtained.
-
8/10/2019 901470_genetic22
2/83
Genetic AlgorithmsGenetic Algorithms
Also known asAlso known as evolutionary algorithmsevolutionary algorithms,,genetic algorithms demonstrate selfgenetic algorithms demonstrate selforganization and adaptation similar to theorganization and adaptation similar to the
way that the ttest biological organismway that the ttest biological organismsurvive and reproduce.survive and reproduce. A genetic algorithm is an iterative procedureA genetic algorithm is an iterative procedure
that represents its candidate solutions asthat represents its candidate solutions asstrings of genes called chromosomes.strings of genes called chromosomes.
Generally applied to spaces which aretoo large
-
8/10/2019 901470_genetic22
3/83
Genetic AlgorithmsGenetic Algorithms
Genetic Algorithms are often used toGenetic Algorithms are often used toimprove the performance of other Aimprove the performance of other A
methods such as e!pert systems ormethods such as e!pert systems orneural networks.neural networks.
"he method learns by producing"he method learns by producingo#spring that are better and better aso#spring that are better and better as
measured by a tness function, which ismeasured by a tness function, which isa measure of the ob$ective to bea measure of the ob$ective to be
obtained %ma!imum or minimum&.obtained %ma!imum or minimum&.
-
8/10/2019 901470_genetic22
4/83
Simple GASimple GA initiali!e pop"lation#
e$al"ate pop"lation#
while Termination%riteria&otSatis'ed
select parents (or reprod"ction#
per(orm crosso$er and m"tation#
repair)*#
e$al"ate pop"lation# +
+
Every loop called
generation
-
8/10/2019 901470_genetic22
5/83
'oncepts'oncepts
Population(set of individuals eachrepresenting a possible solution to a givenproblem.
Gene(a solution to problem represented as
a set of parameters ,these parametersknown as genes.
Chromosome(genes $oined together toform a string of values called chromosome.
Fitness score(value)(every chromosomehas tness score can be inferred from thechromosome itself by using tness function.
-
8/10/2019 901470_genetic22
6/83
Recombination
)tochastic operators)tochastic operators
SelectionSelectionreplicates the most successfulreplicates the most successfulsolutions found in a population at a ratesolutions found in a population at a rate
proportional to their relative *ualityproportional to their relative *uality RecombinationRecombination)%rosso$er*)%rosso$er*
decomposes two distinct solutions anddecomposes two distinct solutions andthen randomly mi!es their parts to formthen randomly mi!es their parts to form
novel solutionsnovel solutions MutationMutationrandomly perturbs a candidaterandomly perturbs a candidate
solutionsolution
-
8/10/2019 901470_genetic22
7/83
)imulated +volution)imulated +volution
e need the followinge need the following epresentation of an individualepresentation of an individual
itness unctionitness unction eproduction /ethodeproduction /ethod
)election 'riteria)election 'riteria
-
8/10/2019 901470_genetic22
8/83
epresenting an ndividualepresenting an ndividual
An individual is data structureAn individual is data structure
representing the 0geneticrepresenting the 0genetic
structure1 of a possible solution.structure1 of a possible solution. Genetic structure consists of anGenetic structure consists of an
alphabet %usually 2,3&alphabet %usually 2,3&
-
8/10/2019 901470_genetic22
9/83
Binary +ncodingBinary +ncoding
/ost 'ommon 4 string of bits, 2 or 3./ost 'ommon 4 string of bits, 2 or 3.
'hrom( A 5 3 2 33 2 2 3 2 3 3'hrom( A 5 3 2 33 2 2 3 2 3 3
'hrom( B 5 3 3 3 3 3 3 2 2 2 2'hrom( B 5 3 3 3 3 3 3 2 2 2 2
Gives you many possibilitiesGives you many possibilities +!ample 6roblem( 7napsack problem+!ample 6roblem( 7napsack problem "he problem( there are things with given value"he problem( there are things with given value
and size. "he knapsack has given capacity.and size. "he knapsack has given capacity.)elect things to ma!imize the values.)elect things to ma!imize the values.
+ncoding( +ach bit says, if the corresponding+ncoding( +ach bit says, if the correspondingthing is in the knapsackthing is in the knapsack
-
8/10/2019 901470_genetic22
10/83
6ermutation +ncoding6ermutation +ncoding
8sed in 0ordering problems18sed in 0ordering problems1 +very chromosome is a string of numbers,+very chromosome is a string of numbers,
which represents number is a se*uence.which represents number is a se*uence.'hrom A( 3 9 : ; < = > ? @'hrom A( 3 9 : ; < = > ? @'hrom B( @ 9 > > ; : 3 = ?'hrom B( @ 9 > > ; : 3 = ?
+!ample( "ravelling salesman problem+!ample( "ravelling salesman problem
"he problem( cities that must be visited."he problem( cities that must be visited. +ncoding says order of cities in which+ncoding says order of cities in which
salesman willl visit.salesman willl visit.
-
8/10/2019 901470_genetic22
11/83
Another +!ampleAnother +!ample
"o nd optimal *uantity of three"o nd optimal *uantity of three
ma$or ingredients %sugar, milk,ma$or ingredients %sugar, milk,
sesame oil& denoting ounces.sesame oil& denoting ounces. 8se an alphabet of 3-? denoting8se an alphabet of 3-? denoting
ounces..ounces..
)olutions might be 3-3-3, ;-3-=, :-:-3.)olutions might be 3-3-3, ;-3-=, :-:-3.
-
8/10/2019 901470_genetic22
12/83
alue +ncodingalue +ncoding
8sed for complicated values %real numbers&8sed for complicated values %real numbers&and when binary coding would be dicultand when binary coding would be dicult
+ach chromosome is a string of some values.+ach chromosome is a string of some values.'hrom A( 3.;:;: 9.:;=: 2.=99
-
8/10/2019 901470_genetic22
13/83
ule base systemule base system
Given a rule %if color5red and size5smallGiven a rule %if color5red and size5smalland shape5round then ob$ect5apple.and shape5round then ob$ect5apple.
Assume that each feature has nite set ofAssume that each feature has nite set ofvalues %e.g., size 5 small,large&values %e.g., size 5 small,large&
epresent the value as a substring of lengthepresent the value as a substring of lengthe*ul to the number of possible values. ore*ul to the number of possible values. ore!ample, small 5 32, large 5 23.e!ample, small 5 32, large 5 23.
"he entire rule would be 322 32 23 2322 4"he entire rule would be 322 32 23 2322 4set of rules concatenating the valuesset of rules concatenating the valuestogether.together.
-
8/10/2019 901470_genetic22
14/83
How o,spring areHow o,spring are
prod"ced -prod"ced -Reprod"ctionReprod"ction -eproduction-eproduction- "hrough- "hrough
reprod"ctionreprod"ction, genetic algorithms, genetic algorithms
produce new generations ofproduce new generations ofimproved solutions by selectingimproved solutions by selectingparents with higher tness ratingsparents with higher tness ratings
or by giving such parents a greateror by giving such parents a greaterprobability of being contributorsprobability of being contributorsand by using random selectionand by using random selection
-
8/10/2019 901470_genetic22
15/83
How o,spring areHow o,spring are
prod"cedprod"ced (Recombination)(Recombination)'rossover'rossover- /any- /any
genetic algorithms use strings of binarygenetic algorithms use strings of binary
symbols for chromosomes, as in oursymbols for chromosomes, as in our7napsack e!ample, to represent solutions.7napsack e!ample, to represent solutions.%rosso$er%rosso$ermeans choosing a randommeans choosing a randomposition in the string %say, after ; digits&position in the string %say, after ; digits&
and e!changing the segments either toand e!changing the segments either tothe right or to the left of this point withthe right or to the left of this point withanother string partitioned similarly toanother string partitioned similarly toproduce two new o# spring.produce two new o# spring.
-
8/10/2019 901470_genetic22
16/83
%rosso$er E.ample%rosso$er E.ample
6arent A 2332336arent A 233233
6arent B 3233226arent B 323322
00/ate the parents by splitting each/ate the parents by splitting eachnumber as shown between the secondnumber as shown between the secondand third digits %position is randomlyand third digits %position is randomly
selected&selected&
23C323323C3233 32C332232C3322
-
8/10/2019 901470_genetic22
17/83
'rossover +!ample'rossover +!ample
Dow combine the rst digits of A with the lastDow combine the rst digits of A with the lastdigits of B, and the rst digits of B with the lastdigits of B, and the rst digits of B with the lastdigits of Adigits of A
"his gives you two new o#spring"his gives you two new o#spring 233322233322 323233323233
f these new solutions, or o#spring, are betterf these new solutions, or o#spring, are better
solutions than the parent solutions, the system willsolutions than the parent solutions, the system willkeep these as more optimal solutions and they willkeep these as more optimal solutions and they willbecome parents. "his is repeated until somebecome parents. "his is repeated until somecondition %for e!ample number of populations orcondition %for e!ample number of populations orimprovement of the best solution& is satised.improvement of the best solution& is satised.
-
8/10/2019 901470_genetic22
18/83
How o,spring areHow o,spring are
prod"cedprod"ced /utation/utation-- /"tation/"tationis an arbitraryis an arbitrary
change in a situation. )ometimes itchange in a situation. )ometimes it
is used to prevent the algorithmis used to prevent the algorithmfrom getting stuck. "he procedurefrom getting stuck. "he procedurechanges a 3 to a 2 to a 3 instead ofchanges a 3 to a 2 to a 3 instead of
duplicating them. "his changeduplicating them. "his changeoccurs with a very low probabilityoccurs with a very low probability%say 3 in 3222&%say 3 in 3222&
-
8/10/2019 901470_genetic22
19/83
1 0 1 0 1 1 1
1 1 0 0 0 1 1
Parent 1
Parent 2
1 0 1 0 0 1 1
1 1 0 0 1 1 0
Child 1
Child 2 Mutation
Genetic AlgorithmGenetic AlgorithmOperatorsOperators
/"tation and %rosso$er/"tation and %rosso$er
-
8/10/2019 901470_genetic22
20/83
'rossover Eperators'rossover Eperators )inglepoint crossover()inglepoint crossover( 6arent A(6arent A( 0 1 1 0 12 0 0 0 1 00 1 1 0 12 0 0 0 1 0 6arent B( 2 3 2 3 3 F3 2 3 3 26arent B( 2 3 2 3 3 F3 2 3 3 2
'hild AB('hild AB( 0 1 1 0 10 1 1 0 13 2 3 3 23 2 3 3 2 'hild BA( 2 3 2 3 3'hild BA( 2 3 2 3 3 0 0 0 1 00 0 0 1 0
"wopoint crossover("wopoint crossover( 6arent A(6arent A( 0 1 120 1 0 02 0 1 00 1 120 1 0 02 0 1 0
6arent B( 2 3 26arent B( 2 3 2CC3 3 3 23 3 3 2CC3 3 23 3 2
'hild AB('hild AB( 0 1 1 00 1 1 03 3 23 3 2 0 1 00 1 0 'hild BA( 2 3 2 3'hild BA( 2 3 2 3 1 0 01 0 03 3 23 3 2
-
8/10/2019 901470_genetic22
21/83
8niform 'rossover and8niform 'rossover and- A random mask is generated- A random mask is generated
- "he mask determines which bits are copied from- "he mask determines which bits are copied fromone parent and which from the other parentone parent and which from the other parent
- Bit density in mask determines how much material- Bit density in mask determines how much materialis taken from the other parent.is taken from the other parent.
-
8/10/2019 901470_genetic22
22/83
+!amples+!amples
/utation(/utation(
"he recipe e!ample("he recipe e!ample(
3-;-: may be changed to 3-:-: or :-;-3-;-: may be changed to 3-:-: or :-;-:, giving two new o#spring. ow:, giving two new o#spring. owoftenH ow many digits changeH owoftenH ow many digits changeH ow
bigH %parameters to ad$ust&bigH %parameters to ad$ust&
-
8/10/2019 901470_genetic22
23/83
/ore e!amples(/ore e!amples(
'rossover'rossover
ecipe (ecipe (
6arents 3-:-: I :-;-:. 'rossover6arents 3-:-: I :-;-:. 'rossoverpoint after the rst digit. Generatepoint after the rst digit. Generatetwo o#spring( :-:-: and 3-;-:.two o#spring( :-:-: and 3-;-:.
'an have one or two point crossover.'an have one or two point crossover.
-
8/10/2019 901470_genetic22
24/83
'rossover 4 6ermutation'rossover 4 6ermutation
+ncoding+ncodingSingle point crosso$erSingle point crosso$er- one crossover point is selected,- one crossover point is selected,
till this point the permutation is copied from the rsttill this point the permutation is copied from the rstparent, then the second parent is scanned and if theparent, then the second parent is scanned and if thenumber is not yet in the o#spring it is addednumber is not yet in the o#spring it is added
%%0 3 4 5 620 3 4 5 62< > @ ?& J %< > @ ?& J %5 6 4 7 825 6 4 7 82? > ; 3& 5 %? > ; 3& 5 %0 3 4 5 60 3 4 5 6< @ ? >&< @ ? >&
/"tation/"tation
Order changingOrder changing- two numbers are selected and- two numbers are selected ande!changede!changed
%3%3 33: = 9 & 5K %3? >& 5K %3 88: = 9 &>&
-
8/10/2019 901470_genetic22
25/83
'rossover 4 alue'rossover 4 alue
+ncoding+ncoding%rosso$er%rosso$er
All crossovers fromAll crossovers from 9inary encoding9inary encodingcancan
be usedbe used
/"tation/"tationAddingAddinga small number %for real value encoding&a small number %for real value encoding&
- to selected values is added %or subtracted& a- to selected values is added %or subtracted& asmall numbersmall number
%%3.;? 9.
-
8/10/2019 901470_genetic22
26/83
)election 'riteria)election 'riteria
itness proportionate selection, rankitness proportionate selection, rankselection methods.selection methods. itness proportionate 4 each individual,itness proportionate 4 each individual, ,,hashas
thethe probabilityprobabilitytness%&MsumNoverNallNindividualN$ itness%$tness%&MsumNoverNallNindividualN$ itness%$&,&,wherewhere itness%&itness%&is the tness function value foris the tness function value for
individualindividual ..
ank selection 4 sorts individual by tness andank selection 4 sorts individual by tness andthe probability that an individual will bethe probability that an individual will beselected is proportional to its rank in this sortedselected is proportional to its rank in this sorted
list.list.
-
8/10/2019 901470_genetic22
27/83
itness unctionitness unction
epresents a rank of the 0representation1epresents a rank of the 0representation1 t is usually a real number.t is usually a real number.
"he function usually has a value between 2"he function usually has a value between 2and 3 and is monotonically increasing.and 3 and is monotonically increasing. Ene can have a sub$ective $udgment %e.g.Ene can have a sub$ective $udgment %e.g.
3-9 for recipe ;-3-=.&3-9 for recipe ;-3-=.&
)imilarly the length of the route in the)imilarly the length of the route in thetraveling salesperson problem is a goodtraveling salesperson problem is a goodmeasure, because the shorter the route,measure, because the shorter the route,the better the solution.the better the solution.
-
8/10/2019 901470_genetic22
28/83
O"tline o( the =&ew pop"lation> 'reate a new'reate a newpopulation by repeating followingpopulation by repeating followingsteps until the new population issteps until the new population iscompletecomplete
-
8/10/2019 901470_genetic22
29/83
O"tline o( the =/"tation>ith a mutation probability mutateith a mutation probability mutate
new o#spring at each locus %position innew o#spring at each locus %position inchromosome&.chromosome&.
-
8/10/2019 901470_genetic22
30/83
O"tline o( the
-
8/10/2019 901470_genetic22
31/83
Flow @iagram o( theFlow @iagram o( theGenetic AlgorithmGenetic Algorithm
rocessrocessDescribe
Problem
Generate
Initial
Solutions
Test: is initial
solution good enough?Stop
Select parentsto reproduce
ppl! crosso"er process
and create a set o# o##spring
ppl! random mutation
Step 1
Step 2
Step $
Step %
Step &
'es
(o
-
8/10/2019 901470_genetic22
32/83
'omponents of a GA'omponents of a GA
A problem denition as input, andA problem denition as input, and
+ncoding principles %gene, chromosome&+ncoding principles %gene, chromosome&
nitialization procedure %creation&nitialization procedure %creation& )election of parents %reproduction&)election of parents %reproduction&
Genetic operators %mutation, recombination&Genetic operators %mutation, recombination&
+valuation function %environment&+valuation function %environment&
"ermination condition"ermination condition
-
8/10/2019 901470_genetic22
33/83
epresentation %encoding&epresentation %encoding&
6ossible individualOs encoding6ossible individualOs encoding Bit strings %2323 ...Bit strings %2323 ...
3322&3322&
eal numbers %=:.; -::.3 ... 2.2eal numbers %=:.; -::.3 ... 2.2@?.;&@?.;&
6ermutations of element %+33 +: +> ... +3 +39&6ermutations of element %+33 +: +> ... +3 +39&
Pists of rules %3 ; : ... ;; ;:&Pists of rules %3 ; : ... ;; ;:&
6rogram elements %genetic6rogram elements %genetic
programming&programming&
... any data structure ...... any data structure ...
-
8/10/2019 901470_genetic22
34/83
epresentation %cont&epresentation %cont&
When choosing an encoding method rely on thefollowing key ideas
8se a data structure as close as possible to8se a data structure as close as possible tothe natural representationthe natural representation
rite appropriate genetic operators as neededrite appropriate genetic operators as needed f possible, ensure that all genotypesf possible, ensure that all genotypes
correspond to feasible solutionscorrespond to feasible solutions f possible, ensure that genetic operatorsf possible, ensure that genetic operators
preserve feasibilitypreserve feasibility
-
8/10/2019 901470_genetic22
35/83
nitializationnitialization
Start with a population of randomly
generated individuals, or use
- A previously saved population
- A set of solutions provided by
a human expert
- A set of solutions provided by
another heuristic algorithm
-
8/10/2019 901470_genetic22
36/83
)election)election
-
8/10/2019 901470_genetic22
37/83
itness 6roportionate )electionitness 6roportionate )election
Qerived by olland as the optimal trade-Qerived by olland as the optimal trade-
o# between e!ploration and e!ploitationo# between e!ploration and e!ploitation
QrawbacksQrawbacks Qi#erent selection forQi#erent selection for ff11(x)(x) andand ff22(x) = f(x) = f11(x) + c(x) + c
SuperindividualsSuperindividualscause convergence %thatcause convergence %that
may be premature&may be premature&
-
8/10/2019 901470_genetic22
38/83
Pinear anking )electionPinear anking )election
Based on sorting of individuals by decreasing fitness
The probability to be extracted for the ithindividual
in the ranking is defined as
21,1
1)1(2
1)(
=
n
i
nip
wherecan be interpreted as
the expected sampling rate ofthe best individual
-
8/10/2019 901470_genetic22
39/83
"ournament )election"ournament )election
Tournament Selection:
randomly select two individuals and the one
with the highest rank goes on and reproduces
cares only about the one with the higher rank,not the spread between the two fitness scores
puts an upper and lower bound on the chances
that any individual to reproduce for the next
generation equal to )2s 2r + 1*/ s2
! s is the si"e of the population
! r is the rank of the #winning# individual
can be generali"ed to select best of n individuals
-
8/10/2019 901470_genetic22
40/83
-
8/10/2019 901470_genetic22
41/83
ecombination %'rossover&ecombination %'rossover&
!nables the evolutionary process
to move toward promising
regions of the search space "atches good parents# sub-solutions
to construct better offspring
-
8/10/2019 901470_genetic22
42/83
/utation/utation
"rposeB"rposeBto simulate the e#ect of errors thatto simulate the e#ect of errors thathappen with low probability during duplicationhappen with low probability during duplication
Res"ltsBRes"ltsB
- /ovement in the search space- /ovement in the search space
- estoration of lost information to the- estoration of lost information to the
populationpopulation
-
8/10/2019 901470_genetic22
43/83
+valuation %tness function&+valuation %tness function&
)olution is only as good as the)olution is only as good as the
evaluation functionR choosing a goodevaluation functionR choosing a good
one is often the hardest partone is often the hardest part )imilar-encoded solutions should have a)imilar-encoded solutions should have a
similar tnesssimilar tness
-
8/10/2019 901470_genetic22
44/83
"ermination condition"ermination condition
+!amples(+!amples(
A pre-determined number of generations or timeA pre-determined number of generations or time
has elapsedhas elapsed A satisfactory solution has been achievedA satisfactory solution has been achieved
Do improvement in solution *uality has takenDo improvement in solution *uality has taken
place for a pre-determined number ofplace for a pre-determined number of
generationsgenerations
-
8/10/2019 901470_genetic22
45/83
+!ample(+!ample(the /ASED+ problemthe /ASED+ problem
Suppose we want to maximi$e the number of
ones in a string of lbinary digits
%s it a trivial problem&
%t may seem so because we know the answer in
advance
'owever, we can think of it as maximi$ing the
number of correct answers, each encoded by (,
to l yes)no difficult *uestions+
-
8/10/2019 901470_genetic22
46/83
+!ample %cont&+!ample %cont&
An individual is encoded %naturally& as aAn individual is encoded %naturally& as astring ofstring of llbinary digitsbinary digits
"he tness"he tness ffof a candidate solution toof a candidate solution tothe /ASED+ problem is the number ofthe /ASED+ problem is the number ofones in its genetic codeones in its genetic code
e start with a population ofe start with a population of nnrandomrandom
strings. )uppose thatstrings. )uppose that ll5 32 and5 32 and nn5
-
8/10/2019 901470_genetic22
47/83
+!ample %initialization&+!ample %initialization&
We toss a fair coin times and get the
following initial population.
s1$ 1111%1%1%1 f (s1) $ &
s2$ %111%%%1%1 f (s2) $ '
s$ 111%11%1%1 f (s) $ &
s$ %1%%%1%%11 f (s) $
s'$ 111%1111%1 f (s') $ *
s+$ %1%%11%%%% f (s+) $
-
8/10/2019 901470_genetic22
48/83
+!ample %selection3&+!ample %selection3&
/ext we apply fitness proportionate selection with the
roulette wheel method.
21n
rea is
-roportional
to fitness
value
%ndividual iwill have a
probability to be chosen
i
if
if
)(
)(
4
We repeat the extraction
as many times as the
number of individuals we
need to have the sameparent population si$e
0 in our case1
-
8/10/2019 901470_genetic22
49/83
+!ample %selection;&+!ample %selection;&
Suppose that, after performing selection, we get
the following population.
s1. $ 1111%1%1%1 (s1)
s2. $ 111%11%1%1 (s)
s. $ 111%1111%1 (s')
s
. $ %111%%%1%1 (s2
)
s'. $ %1%%%1%%11 (s)
s+. $ 111%1111%1 (s')
-
8/10/2019 901470_genetic22
50/83
+!ample %crossover3&+!ample %crossover3&
/ext we mate strings for crossover2 3or each
couple we decide according to crossover
probability 0for instance 21 whether to actually
perform crossover or notSuppose that we decide to actually perform
crossover only for couples 0s(+, s4+1 and 0s5+, s+12
3or each couple, we randomly extract a
crossover point, for instance 4 for the first and 5
for the second
-
8/10/2019 901470_genetic22
51/83
+!ample %crossover;&+!ample %crossover;&
s1. $ 1111%1%1%1
s2. $ 111%11%1%1
s'. $ %1%%%1%%11
s+. $ 111%1111%1
Before crossover.
After crossover.
s1.. $ 111%11%1%1
s2.. $ 1111%1%1%1
s'.. $ %1%%%111%1
s+.. $ 111%11%%11
-
8/10/2019 901470_genetic22
52/83
+!ample %mutation3&+!ample %mutation3&
The final step is to apply random mutation. for each bit that
we are to copy to the new population we allow a smallprobability of error 0for instance 2(1
Before applying mutation.
s1.. $ 111%11%1%1
s2.. $ 1111%1%1%1
s.. $ 111%1111%1
s.. $ %111%%%1%1
s'.. $ %1%%%111%1
s+.. $ 111%11%%11
-
8/10/2019 901470_genetic22
53/83
+!ample %mutation;&+!ample %mutation;&
After applying mutation.
s1... $ 111%1%%1%1 f(s1... ) $ +
s2... $ 111111%1%% f(s2... ) $ &
s... $ 111%1%1111 f(s... ) $ *
s... $ %111%%%1%1 f(s... ) $ '
s'... $ %1%%%111%1 f(s'... ) $ '
s+... $ 111%11%%%1 f(s+... ) $ +
-
8/10/2019 901470_genetic22
54/83
+!ample %end&+!ample %end&
%n one generation, the total population fitness
changed from 67 to 68, thus improved by 9:;
At this point, we go through the same process
all over again, until a stopping criterion is met
-
8/10/2019 901470_genetic22
55/83
E.ample BE.ample B S"ppose a Genetic Algorithm "ses chromosomes o( the (ormS"ppose a Genetic Algorithm "ses chromosomes o( the (orm
.Ca9cde(gh with a '.ed length o( eight genes : Each gene.Ca9cde(gh with a '.ed length o( eight genes : Each genecan 9e any digit 9etween 1 and ? : Let the 'tness o(can 9e any digit 9etween 1 and ? : Let the 'tness o(indi$id"al . 9e calc"lated as Bindi$id"al . 9e calc"lated as B
().* C)aD9*-)cDd*D)eD(*- ) gDh*().* C)aD9*-)cDd*D)eD(*- ) gDh*And let the initial pop"lation consist o( (o"r indi$id"als .0 :::And let the initial pop"lation consist o( (o"r indi$id"als .0 :::
.5 with the (ollowing chromosomes B.5 with the (ollowing chromosomes B0 C 7 6 5 0 4 6 4 30 C 7 6 5 0 4 6 4 3F).0* C)7D6*-)5D0*D)4D6*-)4D3* C ?F).0* C)7D6*-)5D0*D)4D6*-)4D3* C ?3 C 8 ; 0 3 7 7 1 03 C 8 ; 0 3 7 7 1 0F).3* C )8D;*-)0D3*D)7D7*-)1D0* C 34F).3* C )8D;*-)0D3*D)7D7*-)1D0* C 34
4 C 3 4 ? 3 0 3 8 64 C 3 4 ? 3 0 3 8 6F).4* C )3D4*-)?D3*D)0D3*-)8D6* C -07F).4* C )3D4*-)?D3*D)0D3*-)8D6* C -075C 5 0 8 6 3 1 ? 55C 5 0 8 6 3 1 ? 5F).5* C )5D0*-)8D6*D)3D1*-)?D5* C -0?F).5* C )5D0*-)8D6*D)3D1*-)?D5* C -0?The arrangement is ) ass"me ma.imi!ation *The arrangement is ) ass"me ma.imi!ation *33 .0.0 .4.4 .5.5) the 'ttest indi$id"al *) the 'ttest indi$id"al * ) least 't indi$id"al *) least 't indi$id"al *
-
8/10/2019 901470_genetic22
56/83
6ut the calculations in6ut the calculations in
table for simplicitytable for simplicityIndi$id"alIndi$id"al
ss
StringStringRepresentatioRepresentatio
nn
FitnesFitnesss
Arrangement Ass"meArrangement Ass"mema.imi!ationma.imi!ation
S3S3
-
8/10/2019 901470_genetic22
57/83
3 C 83 C 8 ;; 00 33 77 77 11 000 C 70 C 7 66 55 00 44 66 44 33
O,spring 0 C 8O,spring 0 C 8 ;; 00 33 44 66 44 33
O,spring 3 C 7O,spring 3 C 7 66 55 00 77 77 11 00
0 C 70 C 7 66 55 00 44 66 44 334 C 34 C 3 44 ?? 33 00 33 88 66
O,spring 4 C 7O,spring 4 C 7 66 ?? 33 00 33 44 33O,spring 5 C 3O,spring 5 C 3 44 55 00 44 66 88 66
Middlecrossover
crossover crossover
-
8/10/2019 901470_genetic22
58/83
S; 5 @S; 5 @ >> 33 ;;
-
8/10/2019 901470_genetic22
59/83
E#spring 3 5 @E#spring 3 5 @ >> 33 ;; :: 99 :: ;;
F )O,spring 0* C)8D;*-)0D3*D)4D6*-)4D3* C 06F )O,spring 0* C)8D;*-)0D3*D)4D6*-)4D3* C 06
E#spring ; 5
-
8/10/2019 901470_genetic22
60/83
Indi$id"alsIndi$id"als String RepresentationString Representation FitnessFitness
E#spring 3E#spring 3 @>3;:9:;@>3;:9:; 3939
E#springE#spring;;
-
8/10/2019 901470_genetic22
61/83
+!ample( "he 7napsack+!ample( "he 7napsack
6roblem6roblemTou are going on an overnight hike andTou are going on an overnight hike and
have a number of items that you could takehave a number of items that you could takealong. +ach item has a weight %in pounds&along. +ach item has a weight %in pounds&
and a benet or value to you on the hike%forand a benet or value to you on the hike%formeasurements sake letOs say, in 8) dollars&,measurements sake letOs say, in 8) dollars&,and you can take one of each item at most.and you can take one of each item at most."here is a capacity limit on the weight you"here is a capacity limit on the weight youcan carry %constraint&. "his problem onlycan carry %constraint&. "his problem onlyillustrates one constraint, but in realityillustrates one constraint, but in realitythere could be many constraints includingthere could be many constraints includingvolume, time, etc.volume, time, etc.
-
8/10/2019 901470_genetic22
62/83
Item:Item: 1 2 $ % & + ,1 2 $ % & + ,
-ene#it:-ene#it: & . $ 2 , / %& . $ 2 , / %
eight:eight: , . %, . % 10 % + %10 % + %
napsac holds a ma3imum o# 22 poundsnapsac holds a ma3imum o# 22 pounds 4ill it to get the ma3imum bene#it4ill it to get the ma3imum bene#it
Solutions tae the #orm o# a string o# 15s and 05sSolutions tae the #orm o# a string o# 15s and 05s
Solutions: lso no6n as strings o# genes called ChromosomesSolutions: lso no6n as strings o# genes called Chromosomes
3. 23232323. 2323232 ;. 3322322;. 3322322 :. 2322333:. 2322333
GA E.ampleB The napsacJGA E.ampleB The napsacJro9lemro9lem
-
8/10/2019 901470_genetic22
63/83
-
8/10/2019 901470_genetic22
64/83
7napsack +!ample7napsack +!ample
"ypically, a string of 3s and 2s can"ypically, a string of 3s and 2s canrepresent a solution.represent a solution.
6ossible solutions generated by the6ossible solutions generated by thesystem usingsystem using -eproduction,-eproduction,'rossover'rossover, or, or /utations/utations 3. 23232323. 2323232 ;. 3322322;. 3322322 :. 2322333:. 2322333
-
8/10/2019 901470_genetic22
65/83
7napsack +!ample7napsack +!ample
)olution 3)olution 3
Benet @ J ; J ? 5 3?Benet @ J ; J ? 5 3? eight @ J 32 J < 5 ;=eight @ J 32 J < 5 ;=
temtem 33 ;; :: == 99 >
Sol"tioSol"tionn 11 00 11 00 11 00 11
BenetBenet 99 @@ :: ;; >> ?? ==
eighteight >> @@ == 3232 ==
-
8/10/2019 901470_genetic22
66/83
7napsack +!ample7napsack +!ample
)olution ;)olution ;
Benet 9 J @ J > 5 ;2Benet 9 J @ J > 5 ;2
eight > J @ J = 5 3?eight > J @ J = 5 3?
temtem 33 ;; :: == 99 >
Sol"tioSol"tio
nn
00 00 11 11 00 11 11
BenetBenet 99 @@ :: ;; >> ?? ==
eighteight >> @@ == 3232 ==
-
8/10/2019 901470_genetic22
67/83
7napsack +!ample7napsack +!ample
)olution :)olution :
Benet @ J > J ? J = 5 ;@Benet @ J > J ? J = 5 ;@
eight @ J = J < J = 5 ;;eight @ J = J < J = 5 ;;
temtem 33 ;; :: == 99 >
Sol"tioSol"tio
nn
11 00 11 11 00 00 00
BenetBenet 99 @@ :: ;; >> ?? ==
eighteight >> @@ == 3232 ==
-
8/10/2019 901470_genetic22
68/83
7napsack +!ample7napsack +!ample
)olution : is clearly the best solution)olution : is clearly the best solutionand has met our conditions, therefore,and has met our conditions, therefore,item number ;, 9, will be takenitem number ;, 9, will be takenon the hiking trip. e will be able to geton the hiking trip. e will be able to getthe most benet out of these itemsthe most benet out of these itemswhile still having weight e*ual to ;;while still having weight e*ual to ;;
pounds.pounds."his is a simple e!ample illustrating a"his is a simple e!ample illustrating a
genetic algorithm approach.genetic algorithm approach.
-
8/10/2019 901470_genetic22
69/83
7napsack 6roblem7napsack 6roblem"o understand GA must work with the following
problem((Knap Sack Problem) "hief wants to steal gold store.
"hief has a bag%the bag can hold a specicweight&. +very piece of gold has a specic weight and price. "hief wants to steal gold with high price but the
weight must e*ual or less than the weight that bagcan hold it.
f we gave every gold piece a specic number3,;,:,U,n%suggest n5@ in this e!ample&.
1 2 3 4 5 6 7 8
weight 5 3 10 6 5 5 4 4
price 100 30 250 150 50 75 50 50
0-Encoding )representation*
-
8/10/2019 901470_genetic22
70/83
0-Encoding )representation*)genechromosome*
%hromosome co"ld 9eB Bit strings %323323232322&. eal numbers %=:.3,=9.;,
-
8/10/2019 901470_genetic22
71/83
3-Initiali!e pop"lation
Implementers speci(y pop"lation si!e : To initiali!e pop"lation create
chromosomes randomly and store them in
list o( length the pop"lation si!e: In o"r pro9lem lets taJe pop"lation si!e 7
chromosomes: e can initiali!e pop"lation a (ollowingB
1 "10100001"
2 "01110011"
3 "11110000"
4 "00110011"
5 "01010101"
6 "00001111"
-
8/10/2019 901470_genetic22
72/83
4-E$al"ation o( pop"lation:
Giving every chromosome in population
'tness $al"eby using 'tness ("nction. Fitness ("nctionswill di#er according to the
problem and encoding techni*ue. Fitness ("nctionreturns a single
numerical%'tness& which reVe! the "tilityorthe a9ilityof the individual which thatchromosome represents.
itness function can calculate ( strength,weight, width, ma!imum load,cost,construction
time or combination of all these. itness value well be stored with chromosome.
chromosome /itness function /itness value
-
8/10/2019 901470_genetic22
73/83
-
n our e!ample we will make tness function as
1 "10100001" 225
2 "01110011" 305
3 "11110000" 225
4 "00110011" 225
5 "01010101" 450
6 "00001111" 530
Chromosome #itness "alue
5-Selection o( new
-
8/10/2019 901470_genetic22
74/83
5 Selection o( newparents)reproduction*
ndividuals are selected from population randomly orby using any selection method to improve thepopulation itself.
Good individuals will probably be selected severaltimes in a generation ,poor ones may not be at all.
Methods of selectionRandom ,est, !ournament, Roulette "heel,
!runcation, Rank, #$ponential, olt%man,Stead& state, 'nteractive and binar&tournament selection
n our e!ample we will use Tr"ncationselectionwith parameter :.
search best : chromosomes and then select