Sei sulla pagina 1di 10

• traveling salesman problem

• traveling salesman problem cons ists of a salesman and a set of


cities. The sales man has to vis it each one of the cities starting
from a certain one (e.g. the hometown) and ret urning to the same
city.The challenge of the problem is that the
traveling salesman want s to minimize t he total length of the
trip. ·,....,.,,
Cons1d« bc folk.l'A'1.ngS<" ofcrt1rs:
Method Used
• We have a set of cities (points) in 2d plane. Each city has road
to each city. We need to find loop-path that will be in each
city only one time and path length is minimal.

• The genetic a lgorithm is sequence of following operations


that repeated in generations loop:
1) Generate random population a nd finding path length.
2) find probabilities for selection.
3) prepare to crossover according proba bilities.
4) crossov er,parents replaced with children.
5) mutations.
STE P 1: Create Random Population
• So we have a lot of paths with different lengths. A path can have
crossover with another path and mutate. After crossover it will be
replaced by its children . pa hs recorded in matr ix G •
Al t3 4 < Wthll<.o I
l - p11l!l (Jo i
1 2 3 4
4 3 2 1 - plhUo

3 4 2 1 < (1-'1'1 N 4

3 2 1 4 - i:.i<1n't o

1 2 3 4 - 081fl f',jO 8

• here we have population with 6 paths (population size ps=6), and it is


for 4 cities.
• In the code to generate initial population of random paths randper m
matlab function was used. It return randomly per mutated numbers,for
example:
>> randperm(4) ans
=
3 4 2 1
STE P 2: Fitness eva luation
• To have fast calculation of pat hs length before start iterat ion, it
is calculated in a matrix of distancies dsm.lt is a n x n mat rix
where n is number of c it ies,ds m(il,i2) is distance between city
iland city i2.
• The logic used is that if we want to minimize d istance then we
want to maximize inverse distance.
• Thus the fitness function we want to maximize is the inverse of
distance
f(x)= 1/d
STE P 3 :SELECTI O N FOR CROSSOVE
R
• For this case roulette_wheel_ indexes.m function was made.First calculate probabilities as
inverse distances divided by sum of inverse distances :
1
d1
Pt = --y
l.1 ([i
• Here p1 is probability of i path to be put to crossover,d 1 is i path length.
• for example we have 6 paths with numbers
1234 5 6
• and let it have probabilities
• 0.05 0.5 0.05 0.05 0.05 0.3
• then by using roulette_wheel_ indexes.m function we willput for the crossover for example
• 1 2 6 2 6 2
• You can see that 2 most frequent and 6 also frequent,rest ELIMINATED.But all this is
random.
• So after that we have pair wise crossover :
1and 2 (gives 2 children)
6 and 2 (gives 2 children)
6 and 2 (gives 2 children)
STE P 4: CROSSOV ER
• The different crossover techniques used for solving the travelling
salesman problem are listed below:
l"nrlinJly - l1kJ>J><'CI C'rek.M>V<'r (1-,IX) Gul<il>crg l\lt<I Lingle ( I V85) [6]
Order·Cro..ovcr (OXl) Davi• (108ti) (2)
Or(lt•r 1.li\M'<I C.'ro:;ttl>\'t'I' Sy•wl'nln ( I !)J' I ) I1 7]
(C>X2) PoKit ion OnK<'fl
Syswcr<ln ( L()() I ) IJ 7]
CrOAAOvcr (1 0$) IIC\trislic C:1·crcnst('l,I<' ( IOl!7)
C'rosO\'CI' (11X) l5J
Edge R<'COmbination CrO<lsovcr ( ER) \Vbit lcy ct al. ( 1989) ( 18)
Sol'tccl latch Crossover (SIX) Brady {1985) (1)
f\ lax. imal Preservative Cr08sovcr Miihlcnbein et al. (1988) 113)
(MPX) Voti11g Rccombi11atio11 ltihlcnbcin {1989) 114]
Crossover (VR) A ltcr1liLi11g - Lannongn cl nl . (1996) (9)
Poi:;:ition Croi.;-. ;ovt•r (A P)

• Among these PMX, ER a nd POS are quoted to be the fastest


o perators as far as the number of necessary iterations to reach
convergence is concerned . The convergence rates of these three o perators
are observed to be similar.
Example of PMX
Civ<'Jl l\\'O p1'r<'111 .ii' u11cl t .J > I X r1111tlo111ly 1->ic.-k '' crosso\.<.•r 1>0i11L like l-poi11t
cr<JbhO\l'r Tho ehild is thon ro1i.1n1rtod in 1.Jw following wny. Srnrting with n ropy or s,
tho Jl(ltiition.' l><'t\\ N'lt tll<' o,rr r J)()ii1ts nr<', 011<"
l)y 011r, Sl't to [)1c \ritl,1r of t i11 tfl('S(' }>Ofi:ition . To keep the string I\ vnlid
ehromosomo the ei ties in these positions nre not just o,erwritten . Th set positio11 p to
city c, t11c city 111 position p Md city c S\\'RP positions. Belo\\·)'Ott sec an e.x. arnple of
Lllis t-odi11g and special crossover tcclu1iquc for t\vo sa.u1ple pem1utations: 5,7,J.3,6,4.2
nnd 4,6,2,7,3,J,5

First ofT•1>rl ng: I4 I61 213 I7 I5 It I

]7) 1I3 I6 I 4 I 2 1
14 1 61 2171 31115 1 l51 1l 2 lslsl 11 5I
t t t t
Second offspling: I5 I7 I l I6I3
I2I5 I
STE P 5: MUTATION

• Ther e a re 3 types of mutations used:


1) Chose 2 random cities
! L
I 2 I 1 1 3 I4 I
a nd swa p them,
Result:
STE P 5: MUTATION (CONT.)

2) mutation by exchange of 2 pieces of path :


• First randomly chose point of spit, for exa mple
between 2 a nd 3 positions:
I 2 I 1 13 I 4I
• now swap two pieces:
I 3 I 4 12 I 1 I
STE P 5 :MUTATION (CONT)

3) mutation of flip random piece of path


• first choose some random piece of path:
3 4 21
• now flip it left-right:

3 4 21
• Elitism means that we save best path and put it
manually to next generation without changes.
• G( ,:)=Gb;% elitism

Potrebbero piacerti anche