Genetic Algorithms CPSC 212 Spring 2004
Heuristic Stochastic optimization algorithm Used to search for good/excellent solutions to large NP-complete problems Does not guarantee optimal solution Provides good solution very quickly
Basic Algorithm Create population of solutions Evaluate each solution Sort in increasing order of quality of solution (i.e., best solution is #1) Repeat: Select and mate parents Produce and evaluate offspring Insert offspring into population
GAs Applied to Traveling Salesperson Problem Given n cities: 0, 1, …, (n-1) A solution is a permutation of the values 0 through (n-1) Randomly create an initial population of solutions (permutations) Evaluate (determine cost of each tour) Sort by increasing cost
Traveling Salesperson Problem Example: 6 cities Initial population: Adjacency Matrix: 0 1 2 3 4 5 0 0 4 5 7 4 9 1 2 0 2 21 14 5 2 3 2 0 2 12 18 3 11 6 7 0 6 15 4 5 4 9 11 0 5 5 6 3 8 3 12 0 0 1 3 4 5 2 4+21+6+5+8+3=47 1 2 5 0 3 4 32 5 0 1 3 4 2 46 1 5 2 4 3 0 51 2 1 5 4 3 0 46
Traveling Salesperson Problem Sort the population Adjacency Matrix: 0 1 2 3 4 5 0 0 4 5 7 4 9 1 2 0 2 21 14 5 2 3 2 0 2 12 18 3 11 6 7 0 6 15 4 5 4 9 11 0 5 5 6 3 8 3 12 0 1 2 5 0 3 4 32 5 0 1 3 4 2 46 2 1 5 4 3 0 46 0 1 3 4 5 2 47 1 5 2 4 3 0 51
Traveling Salesperson Problem Randomly select parents (2 and 5) 1 2 5 0 3 4 32 5 0 1 3 4 2 46 2 1 5 4 3 0 46 0 1 3 4 5 2 47 1 5 2 4 3 0 51
Traveling Salesperson Problem Mate parents (1-point crossover) randomly select crossover point cross-selection of genes 5 0 1 3 4 2 46 1 5 2 4 3 0 51 5 0 1 2 4 3 ____ 1 5 0 3 4 2 ____
Traveling Salesperson Problem Produce offspring 5 0 1 2 4 3 ____ 1 5 0 3 4 2 ____
Traveling Salesperson Problem Evaluate offspring Adjacency Matrix: 0 1 2 3 4 5 0 0 4 5 7 4 9 1 2 0 2 21 14 5 2 3 2 0 2 12 18 3 11 6 7 0 6 15 4 5 4 9 11 0 5 5 6 3 8 3 12 0 5 0 1 2 4 3 50 1 5 0 3 4 2 33
Traveling Salesperson Problem Insert offspring into population 5 0 1 2 4 3 50 1 5 0 3 4 2 33 1 2 5 0 3 4 32 1 5 0 3 4 2 33 5 0 1 3 4 2 46 2 1 5 4 3 0 46 0 1 3 4 5 2 47
Traveling Salesperson Problem Repeat mating
Traveling Salesperson Problem Mutation: Randomly select 1 parent 1 2 5 0 3 4 32 1 5 0 3 4 2 33 5 0 1 3 4 2 46 2 1 5 4 3 0 46 0 1 3 4 5 2 47
Traveling Salesperson Problem Mutation: Randomly select 2 genes 5 0 1 3 4 2 46 ^ ^
Traveling Salesperson Problem Mutation: Swap 2 genes Adjacency Matrix: 0 1 2 3 4 5 0 0 4 5 7 4 9 1 2 0 2 21 14 5 2 3 2 0 2 12 18 3 11 6 7 0 6 15 4 5 4 9 11 0 5 5 6 3 8 3 12 0 5 0 1 3 4 2 46 => 5 4 1 3 0 2 54
Traveling Salesperson Problem Mutation: Insert mutant solution into population if it is better than worst member 5 4 1 3 0 2 54 1 2 5 0 3 4 32 1 5 0 3 4 2 33 5 0 1 3 4 2 46 2 1 5 4 3 0 46 0 1 3 4 5 2 47
Traveling Salesperson Problem Perform mating 90% of time Perform mutation 10% of time Stop when time has expired