ARTIFICIAL INTELLIGENCE (CSCU9YE ) LECTURE 5: EVOLUTIONARY ALGORITHMS Gabriela Ochoa http://www.cs.stir.ac.uk/~goc/ OUTLINE Optimisation problems Optimisation & search Two Examples The knapsack problem The traveling salesman problem TSP Optimisation methods Heuristics and metaheuristcis Single point algorithms Population-based algorithms 2 1
DEMOS AND VIDEOS BBC Program (From minute 31 the TSP): The Secret Rules of Modern Living: Algorithms State-of-the-art for the TSP TSP home University of Waterloo, Canada Lin-Kernighan Helsgaun LKH World TSP images and animations Demos with HeuristicLab The evolution of a Spaceship using NEAT (NeuroEvolution of Augmenting Topologies) method for evolving increasingly complex neural networks. 3 TRAVELLING SALESMAN PROBLEM (TSP) A salesman must visit number of cities while minimising the total cost of traveling Configurations: permutation (ordering) of cities. s1= (A B C D), f(s1)= 20+30+12+35= 97 s2= (A B D C), f(s2)= 20+34+12+42=108 s3= (A C B D), f(s3)= 42+30+34+35= 141 Local change (move): swap two cities s1 = (A B C D) s1 = (A D C B) 4 2
IMPORTANCE OF TSP Many real-world problems can be formulated as instances of the TSP Computer wiring Vehicle routing Crystallography Robot control Drilling of printed circuit boards Chronological sequencing. Theoretical and practical insight achieved in the study of TSP can often be useful in the solution of other problems in this area Branch and bound Development of the computational complexity theory 5 OPTIMISATION PROBLEMS General constrained optimisation problem: x Min/Max f( ) Subject to: g i h j ( x) 0 ( x) 0 i = 1,,p j = 1,,n Search Space: set of candidate solutions. All possible combinations of the decision variables. Optimisation through search Iteratively generate and evaluate candidate solutions. Systematic search (Stochastic) local search 6 3
WHAT IS A HEURISTIC? An optimisation method that tries to exploit problem-specific knowledge, for which we have no guarantee to find the optimal solution Construction Search space: partial candidate solutions Search step: extension with one or more solution components Example in TSP: nearest neighbour Improvement Search space: complete candidate solutions Search step: modification of one or more solution components Example in TSP: 2-opt 7 THE NOTION OF NEIGHBOURHOOD Region of the search space that is near to some particular point in that space Solutions that can be reached after a small step Move operator Example in the TSP (2-opt move) x N(x) S A search space S, a potential solution x, and its neighbourhood N(x) 8 4
DEFINING NEIGHBOURHOODS Binary 1-flip: Solutions generated by flipping a single bit in the given bit string Every solution has n neighbours Example: 1 1 0 0 1 0 1 0 0 1 Permutation 2-swap: Solutions generated by swapping two cities from a given tour Every solution has n(n-1)/2 neighbours Example: 2 4 5 3 1 2 3 5 4 1, 9 NEAREST NEIGHBOUR HEURISTIC The salesman starts at a random city and repeatedly visits the nearest city until all have been visited It quickly yields a short tour, but usually not the optimal one Algorithm 1. start on an arbitrary city as current city 2. find out the shortest distance connecting the current city and an unvisited city V. 3. set current city to V. 4. mark V as visited. 5. if all the cities (vertices) in domain are visited, then terminate. 6. Go to step 2. 10 5
EVOLUTION BY NATURAL SELECTION Natural Selection 1. Variation 2. Hereditary transmission 3. High rate of population growth 4. Differential survival and reproduction Charles Darwin and Alfred Wallace: Theory of evolution by means of Natural Selection. 1859: On the Origin of Species by Means of Natural Selection: Or, The Preservation of Favoured Races in the Struggle for Life 11 EXAMPLES OF APPARENT DESIGN IN NATURE 12 6
EVOLUTIONARY COMPUTING: THE ANALOGY Nature Individual Population Fitness Chromosome Gene Crossover and Mutation Natural Selection Computer Solution to a problem Set of solutions Quality of a solution Encoding for a solution Part of the encoding of a solution Search operators Reuse of good (sub-) solutions 13 OUTLINE OF AN EVOLUTIONARY ALGORITHM Generate [P(0)] t 0 WHILE NOT Termination_Criterion [P(t)] DO Evaluate [P(t)] P' (t) Select [P(t)] P''(t) Apply_Variation_Operators [P'(t)] P(t+1) Replace [P(t), P''(t)] t t + 1 END RETURN Best_Solution Important Components Representation: Genetic material Fitness Function: Task to perform Select Survivors Fitness Evaluation Initial Population Select Parents Recombination Mutation 14 7
GENETIC ALGORITHMS Procedure GA Generate [P(0)] t = 0 while NOT Termination_Criterion { Evaluate [P(t)] P' (t) = Select [P(t)] P''(t) = Apply_Operators [P'(t)] P(t+1) = Replace [P(t), P''(t)] t = t + 1 } Parent selection: Better individuals get higher chance (proportional to fitness). Proportional selection (roulette wheel, stochastic universal sampling) Scaling methods Rank selection Tournament selection (μ + λ)- and (μ, λ) selection Replacement (population models) Generational: each generation set of parents replaced by the offspring Steady-state: one offspring is generated per generation. One member is replaced Generation gap: a proportion of the population is replaced Tournament selection 15 Search operators for binary representation Mutation: Alter each gene independently with a probability P m (mutation rate) Typically: 1/chromosome_length Recombination: One-point N-point Uniform P c typically in range (0.6, 0.9) 16 8
Search operators for permutation representation Mutation: Small variation in one permutation, e.g.: swapping values of two randomly chosen positions, 1 3 5 2 6 4 7 8 1 3 7 2 6 4 5 8 Recombination: Combining two permutations into two new permutations: choose random crossover point copy first parts into children create second part by inserting values from other parent: in the order they appear there beginning after crossover point skipping values already in child 1 3 5 2 6 4 7 8 8 7 6 5 4 3 2 1 1 3 5 4 2 8 7 6 8 7 6 2 4 1 3 5 17 OTHER POPULATION-BASED ALGORITHMS: THE SOCIAL BEHAVIOUR METAPHOR Ant colony optimisation (ACO) Dorigo, Di Caro & Gambardella (1991). Inspired by the behaviour of real ant colonies A set of software agents artificial ants search for good solutions Problem transformed to finding the best path on a weighted graph. Ants build solutions incrementally by moving on the graph http://www.aco-metaheuristic.org/ http://www.scholarpedia.org/article/ant_colo ny_optimization Particle Swarm Optimization (PSO) Eberhart & Kennedy, 1995 Inspired by social behaviour of bird flocking or fish schooling Solutions (called particles) fly through the search space by following the current optimum particles At each iteration they accelerate towards the best locations http://www.swarmintelligence.org/ http://www.scholarpedia.org/article/pa rticle_swarm_optimization 18 9
CONCLUSIONS This is our last lecture related to search! There more algorithms and research topics related to computational search. We covered the basics Types of search methods Tree-based, exhaustive methods: search for a sequence of actions to reach a goal: BFS, DFS, Greedy, A* Local search: search for a complete solution Constructive heuristics: nearest neighbour Improvement heuristics Single-point: hill-climbing, iterated local search, simulated annealing Population-based: Evolutionary Algorithms, GAs, ACO, PSO Next topic: Machine Learning 19 10