Presentation is loading. Please wait.

Presentation is loading. Please wait.

Euclidean TSP EA Pseudo Code. What is a Euclidean TSP? 1 2 4 5 3 c ij 2 = (x i – x j ) 2 + (y i – y j ) 2.

Similar presentations


Presentation on theme: "Euclidean TSP EA Pseudo Code. What is a Euclidean TSP? 1 2 4 5 3 c ij 2 = (x i – x j ) 2 + (y i – y j ) 2."— Presentation transcript:

1 Euclidean TSP EA Pseudo Code

2 What is a Euclidean TSP? 1 2 4 5 3 c ij 2 = (x i – x j ) 2 + (y i – y j ) 2

3 Individual Representation Permutation of the cities What permutation represents this tour? Solutions? 1 2 4 5 3 143523521412534

4 Permutation Creation 1. Create 1. Create array 2. Number 2. Number in-order 3. Loop 3. Loop i = 1 to N 1.j 1.j = random ≥ i 2.Swap(A[i], 2.Swap(A[i], A[j]) 123456423156436125 [Skiena1997], Generating Permutations

5 Individual Datastructure Generic solution is usually to have two data members –Genotype –Fitness This way fitness is stored once calculated

6 Fitness Calculation Sum up all the edge lengths Requires many slow sqrt() calls

7 Program Requirements Read from a parameter file Execute one or more runs Create a log file

8 Required Parameters (world) TSP world (logfile) Log file (popsize) Population size (offsize) Offspring per generation (maxeval) Maximum evaluations (runs) Number of runs (seed) Random seed

9 Setup Open configuration file Parse values into variables Read world file describing TSP world Seed random number generator

10 Random Number Generator Is a datastructure Updates internal variables every time a random number is requested Needs to be passed around by reference Seed only once Use the Mersenne Twister –http://www-personal.engin.umich.edu/~wagnerr/MersenneTwister.html http://www-personal.engin.umich.edu/~wagnerr/MersenneTwister.html

11 TSP World File Format Line 1: “TSP” Line 2: Number of cities Lines 3+: x-coordinate y-coordinate –Two ascii integers per line separated by a space

12 EA Run –Pass in all configuration data –Make sure the random number generator is passed by reference Allocate your data structures –population[popcount] –offspring[offcount] Initialize population with random individuals evalcount = popsize While(evalcount < maxevals) –For # of children Select two parents by two binary tournaments Recombine using cut-and-crossfill Mutate offspring Evaluate child’s fitness (evalcount++) –Sort and elitist survival selection

13 Parent Selection Create four random numbers a, b, c, d Parent 1 –max_fitness(population[a], population[b]) Parent 2 –max_fitness(population[c], population[d])

14 Recombination (“cut-and-crossfill”) 436125243156 Child 436215 [Eiben2003], p26

15 Recombination (“cut-and-crossfill”) 1. Used = boolean array of all false’s 2. XPoint = random from 1 to N 3. For (i = 1 to XPoint) 1.Child[i] = ParentA[i] 2.Used[Child[i]] = true 4. j = 0 5. For (i = XPoint to N) 1.While(Used[ParentB[j]]) 1. j++ 2.Child[i] = ParentB[j]

16 Mutation i = random from 1 to N j = random from 1 to N Swap(Child[i], Child[j]) Child 436215 [Eiben2003], p26

17 Survival Selection Combine populations SortCrop

18 TSPView Demo

19 References [Eiben2003] A.E. Eiben and J.E. Smith. Introduction to Evolutionary Computing. Spring-Verlag, Berlin Heidelberg, 2003, ISBN 3-540-40184-9. [Skiena1997] Steven S. Skiena. The Algorithm Design Manual. Springer-Verlag, New York, 1997. http://www2.toki.or.id/book/AlgDesignManual/ http://www2.toki.or.id/book/AlgDesignManual/


Download ppt "Euclidean TSP EA Pseudo Code. What is a Euclidean TSP? 1 2 4 5 3 c ij 2 = (x i – x j ) 2 + (y i – y j ) 2."

Similar presentations


Ads by Google