Design & Analysis of Algorithms Combinatorial optimization SCHOOL OF COMPUTING Design & Analysis of Algorithms Combinatorial optimization Pasi Fränti 27.4.2016
Optimization techniques Local search Stochastic variations of local search Genetic algorithms Swarm Intelligence
Knapsack problem Simplified Input: Weight of N items {w1, w2, ..., wn} Knapsack limit S Output: Selection for knapsack: {x1,x2,…xn} where xi {0,1}. 5 3 7 Sample input: wi={2,3,5,7,11} S=15 Max 15 2 11
Knapsack as decision tree Yes No Chooce 2 2 - Yes No Yes No Chooce 3 5 2 3 - Yes No Yes No Yes No Yes No Chooce 5 10 5 7 2 8 3 5 - Yes No Yes Chooce 7 17 10 12 5 5 14 9 2 15 8 10 3 12 5 7 - … … … … No 28 12 14 13 26 15 12 -
In context of search tree Brute force: search full tree 2 - 5 2 3 - Heuristics Greedy 10 5 7 2 8 3 5 - 17 10 12 5 5 14 9 2 15 8 10 3 12 5 7 - … … … 28 10 12 14 13 26 15 12 - Local search
Local search
Main principle of local search Select one and move
Structure of local search Generate initial solution REPEAT Generate a set of new solutions Evaluate the new solutions Select the best solution UNTIL stopping criterion met best 13 15 9 12 11 7 13 21 9 12 14 17 best
Components of local search Representation of solution Bit string (0010111010001…) Problem-domain data structure {1, 3, 5, 2…} Neighborhood function (move) Bits: (0010111010001…) (0010011010001…) Application domain: {1, 3, 5, 2…} {1, 5, 3, 2…} Search strategy Best-improvement: try all, select best First-improvement: select first that improves. TSP
Movement in neighborhood Study neighbor solutions
Search strategy Best improvement: First improvement: first best 13 21 9 12 14 17 12 first best 21 13 Hill-climbing (max!) / Descendent (min! 15 13 21 9 12 14 17 8 dead end 7 6 8 11 10 9 5 4 8 7
Accept only better solutions Hill climbing Accept only better solutions
Local and global maxima
Combining local search and hill-climbing
Local search for Knapsack
Representation of knapsack Represent solution as bit string (x1x2,…xn), where xi {0,1}. Problem instance: wi= (2,3,5,7,11), S=15. Solution with elements 2,3 and 7 is represented as 11010.
Move in knapsack S=15 W=[2, 3, 5, 7, 11] Single bit change: 01 or 10
Extended neighborhood S=15 W=[2, 3, 5, 7, 11] Two operations: 01 or 10 Swap bit location 10011
Local maximum S=15 W=[2, 3, 5, 7, 11]
Tabu search S=15 W=[2, 3, 5, 7, 11] Prevents search to return previously visited solutions Tabu! Select the next best
Tabu search (2nd iteration) S=15 W=[2, 3, 5, 7, 11]
Traveling salesman problem Permute local changes in given route ... pi-1 pi pi+1 ... ... pi-1 pi+1 pi ... ... pi pi-1 pi+1 ... ... pi pi+1 pi-1 ... ... pi+1 pi pi-1 ... ... pi+1 pi-1 pi ...
Local search for TSP
TSP example E F G H A 4 + + 2 + = 2 + 6 E F H G A 4 + 3 + 2 + 2 = 11 min! E G F H A + + 3 + = 3 + 3 E G H F A + 2 + 3 + = 2 + 5 E H G F A 3 + 2 + + = 2 + 5 E H F G A 3 + 3 + + 2 = 1 + 6
Genetic algorithm
Genetic algorithm (GA) Needs more material!
Main structure of GA Generate a set of initial solutions. REPEAT Generate new solutions by crossover. Mutate the new solutions (optional). Evaluate the candidate solutions. Retain best candidates and delete the rest. UNTIL stopping criterion met.
Permuting pairs for crossover Elitist approach using zigzag scanning among the best solutions
Chess playing
Minmax technique
Tic-tac-toe example
Optimizing chess playing Revise
Evaluation function
Minmax example Redraw 34
Minmax playing: Min’s move 35
Minmax playing: Max’s move Minimax maximizes the worst-case outcome for max 36
Chess Game tree
Beyond the horizon What value is the position?
Evaluating Chess position
Positional factors
Initial value range
Result of optimization
Swarm intelligence
Swarm intelligence (SI) Social intelligence: individual behavior maybe naive but joint effect can be intelligent. Decentralized: no central control of the individuals of the colony Self-organized: individual adapts to environment and other members of colony Robust: Task is completed even if some individuals fail
Ant colony optimization (ACO) Main principle: Emitting pheromone between nest and food Joint efforts to carry loads Solving TSP by ants: Sending ants to make randomized tours Short links chosen more often than long ones Good tracks are marked by pheromone Tracks with high pheromone chosen more often
Ant colony optimization Initialization: Generate randomized tours. Smaller links chosen more often than longer ones Simulate pheromone: Subtract cost of the links in best solution (-1) Increase the ones in the worst solution (+1) Tours are evaluated using the original graph.
Ant colony optimization 1st round
Ant colony optimization 2nd round
The end