1 / 19

Euclidean TSP EA

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

ecollazo
Télécharger la présentation

Euclidean TSP EA

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Euclidean TSP EA Pseudo Code

  2. 1 2 4 3 5 What is a Euclidean TSP? • cij2 = (xi – xj)2 + (yi – yj)2

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

  4. 4 1 4 3 2 2 6 3 3 1 1 4 5 5 2 5 6 6 Permutation Creation • Create array • Number in-order • Loop i = 1 to N • j = random ≥ i • Swap(A[i], A[j]) [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

  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. 4 3 6 2 1 5 4 2 4 3 6 3 1 1 2 5 6 5 Recombination (“cut-and-crossfill”) Child [Eiben2003], p26

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

  16. Mutation • i = random from 1 to N • j = random from 1 to N • Swap(Child[i], Child[j]) 4 3 6 2 1 5 Child [Eiben2003], p26

  17. Survival Selection • Combine populations • Sort • Crop

  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/

More Related