210 likes | 445 Views
Transporting Perishable Goods (ANEB-TSP). The Art of Implementing an EA Assignment 1 CS 348 Fall 2008. 1. 7. 10. 12. 14. 8. 2. 4. 6. 12. 3. 15. 11. Travel Time (hours). 5. Asymmetric Non-Euclidean Bottleneck TSP. 1. 7. 10. 2. 4. 12. 14. 3. 8. 6. 12. 15. 11. 5.
E N D
Transporting Perishable Goods (ANEB-TSP) The Art of Implementing an EA Assignment 1 CS 348 Fall 2008
1 7 10 12 14 8 2 4 6 12 3 15 11 Travel Time (hours) 5 Asymmetric Non-Euclidean Bottleneck TSP
1 7 10 2 4 12 14 3 8 6 12 15 11 5 Dataset File Format Number of vertices v e s1 d1 w1 s2 d2 w2 … s<e> d<e> w<e> Number of edges Edge info: Source vertex Destination vertex Edge weight Example: 5 10 1 4 10 4 1 14 4 3 6 3 4 8 3 5 11 5 3 11 …
1 7 10 2 4 12 14 3 8 6 12 15 11 5 Individual Genotype Representation • Permutations Possible Permutations 1 4 3 5 2 Cycle 1 5 2 1 4 3 Cycle 1 2 5 3 4 1 Cycle 2
1 4 4 2 2 3 3 5 3 1 1 4 5 6 5 2 6 6 Permutation Creation • Create array • Number in-order • Loop i ← 1 to N • j ← random ≥ i • 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 • http://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])
4 3 6 2 1 5 4 2 4 3 3 6 1 1 5 2 6 5 Recombination (“cut-and-crossfill”) Child
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 ← j + 1 • 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 • i ← random from 1 to N • j ← random from 1 to N • Swap(Child[i], Child[j]) 4 3 6 2 1 5
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