Transporting Perishable Goods (ANEB-TSP) The Art of Implementing an EA Assignment 1 CS 348 Fall 2008
Asymmetric Non-Euclidean Bottleneck TSP Travel Time (hours)
Dataset File Format Number of vertices v e s1 d1 w1 s2 d2 w2 … s d w Number of edges Edge info: Source vertex Destination vertex Edge weight Example: …
Individual Genotype Representation Permutations Possible Permutations Cycle 1 Cycle 2
Permutation Creation 1.Create array 2.Number in-order 3.Loop i ← 1 to N 1.j ← random ≥ i 2.Swap(A[i], A[j])
Individual Datastructure A standard EA solution will usually have 2 data members –Genotype –Fitness Fitness is stored to avoid recalculation –For static problem environments
Fitness Calculation Find the edge with the largest weight in the trial solution (the permutation) –weights are given in the datafile Fitness should be inversely proportional to the largest weight –Objective function vs. Fitness function –Ideas Fitness = - largest weight Fitness = 1 / largest weight – Highest fitness value will be the best individual
Program Requirements Read from a configuration file Complete 1+ runs of the EA Write information to a log file
Required Parameters in Configuration File ( datafile ) Dataset file ( logfile ) Log file ( popsize ) Population size ( offsize ) Offspring per generation ( tournsize ) Tournament size ( maxeval ) Maximum evaluations ( runs ) Number of runs ( seed ) Random seed
Initial Setup Open configuration file Parse values into variables Read datafile describing the TSP dataset Seed random number generator
Random Number Generator Is a datastructure Updates internal variables every time a random number is requested Seed only once Use quality RNG –the Mersenne Twister personal.engin.umich.edu/~wagnerr/MersenneTwister.htmlhttp://www- personal.engin.umich.edu/~wagnerr/MersenneTwister.html
EA Run –Pass in all configuration data Create data structures for population/offspring – population [ popsize ] – offspring [ offsize ] Initialize population with random individuals – evalcount = popsize While( evalcount < maxevals ) –For # of children (offsize) Select two parents by two n-ary tournaments Recombine using cut-and-crossfill Mutate offspring Evaluate child’s fitness ( evalcount++ ) –Sort and elitist survival selection
Parent Selection Create tournsize random numbers for each parent to be selected ( r1 … rn ) Parent 1 –max_fitness(population[ r1 ]... population[ rn ]) Parent 2 –generate new random numbers ( t1 … tn ) –max_fitness(population[ t1 ]... population[ tn ])
Recombination (“cut-and-crossfill”) Child
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 ← j Child[i] ← ParentB[j]
Bonus – Implementing Another Recombination Method Many ways to implement crossover for a permutation –Affects performance of the EA Examples – Chapter 3 –Partially Mapped Crossover (PMC) –Edge Crossover –Order Crossover –Cycle Crossover
Mutation 1.i ← random from 1 to N 2.j ← random from 1 to N 3.Swap(Child[i], Child[j])
Truncation Survival Selection Combine population and offspring into one group Sort by fitness Keep the best popsize individuals in the population
Bonus – Compare to a Heuristic Implement or test a good existing heuristic for the ANEB-TSP Statistically compare to the EA Code for the heuristic is due along with the report