Genetic Algorithms: A Tutorial “Genetic Algorithms are good at taking large, potentially huge search spaces and navigating them, looking for optimal combinations of things, solutions you might not otherwise find in a lifetime.” - Salvatore Mangano Computer Design, May 1995 Wendy Williams Metaheuristic Algorithms 1 Genetic Algorithms: A Tutorial A Simple Example The Traveling Salesman Problem: Find a tour of a given set of cities so that each city is visited only once the total distance traveled is minimized Wendy Williams Metaheuristic Algorithms 2 Genetic Algorithms: A Tutorial Classes of Search Techniques Search techniques C alculus-based techniques D irect m ethods F inonacci G uided random search techniques Indirect m ethods N ew ton Evolutionary algorithm s Evolutionary strategies Wendy Williams Metaheuristic Algorithms D ynam ic program m ing G enetic algorithm s Parallel C entralized Sim ulated annealing Enum erative techniques D istributed 3 Sequential Steady-state G enerational Genetic Algorithms: A Tutorial Components of a GA A problem to solve, and ... Encoding technique (gene, chromosome) Initialization procedure (creation) Evaluation function (environment) Selection of parents (reproduction) Genetic operators (mutation, recombination) Parameter settings (practice and art) Wendy Williams Metaheuristic Algorithms 4 Genetic Algorithms: A Tutorial Simple Genetic Algorithm { initialize population; evaluate population; while TerminationCriteriaNotSatisfied { select parents for reproduction; perform recombination and mutation; evaluate population; } } Wendy Williams Metaheuristic Algorithms 5 Genetic Algorithms: A Tutorial The GA Cycle of Reproduction reproduction children modification modified children parents population evaluation evaluated children deleted members discard Wendy Williams Metaheuristic Algorithms 6 Genetic Algorithms: A Tutorial Population population Chromosomes could be: Bit strings Real numbers Permutations of element Lists of rules Program elements ... any data structure ... Wendy Williams Metaheuristic Algorithms 7 (0101 ... 1100) (43.2 -33.1 ... 0.0 89.2) (E11 E3 E7 ... E1 E15) (R1 R2 R3 ... R22 R23) (genetic programming) Genetic Algorithms: A Tutorial Reproduction children reproduction parents population Parents are selected at random with selection chances biased in relation to chromosome evaluations. Wendy Williams Metaheuristic Algorithms 8 Genetic Algorithms: A Tutorial Chromosome Modification children modification modified children Modifications are stochastically triggered Operator types are: Mutation Crossover (recombination) Wendy Williams Metaheuristic Algorithms 9 Genetic Algorithms: A Tutorial Mutation: Local Modification Before: (1 0 1 1 0 1 1 0) After: (0 1 1 0 0 1 1 0) Before: (1.38 -69.4 326.44 0.1) After: (1.38 -67.5 326.44 0.1) Causes movement in the search space (local or global) Restores lost information to the population Wendy Williams Metaheuristic Algorithms 10 Genetic Algorithms: A Tutorial Crossover: Recombination * P1 P2 (0 1 1 0 1 0 0 0) (1 1 0 1 1 0 1 0) (0 1 0 0 1 0 0 0) (1 1 1 1 1 0 1 0) C1 C2 Crossover is a critical feature of genetic algorithms: It greatly accelerates search early in evolution of a population It leads to effective combination of schemata (subsolutions on different chromosomes) Wendy Williams Metaheuristic Algorithms 11 Genetic Algorithms: A Tutorial Evaluation modified children evaluated children evaluation The evaluator decodes a chromosome and assigns it a fitness measure The evaluator is the only link between a classical GA and the problem it is solving Wendy Williams Metaheuristic Algorithms 12 Genetic Algorithms: A Tutorial Deletion population discarded members discard Generational GA: entire populations replaced with each iteration Steady-state GA: a few members replaced each generation Wendy Williams Metaheuristic Algorithms 13 Genetic Algorithms: A Tutorial A Simple Example The Traveling Salesman Problem: Find a tour of a given set of cities so that each city is visited only once the total distance traveled is minimized Wendy Williams Metaheuristic Algorithms 14 Genetic Algorithms: A Tutorial Representation Representation is an ordered list of city numbers known as an order-based GA. 1) London 2) Venice 3) Dunedin 4) Singapore CityList1 (3 5 7 2 1 6 4 8) CityList2 (2 5 7 6 8 1 3 4) Wendy Williams Metaheuristic Algorithms 5) Beijing 7) Tokyo 6) Phoenix 8) Victoria 15 Genetic Algorithms: A Tutorial Crossover Crossover combines inversion and recombination: * * Parent1 (3 5 7 2 1 6 4 8) Parent2 (2 5 7 6 8 1 3 4) Child (5 8 7 2 1 6 3 4) This operator is called the Order1 crossover. Wendy Williams Metaheuristic Algorithms 16 Genetic Algorithms: A Tutorial Mutation Mutation involves reordering of the list: Before: * * (5 8 7 2 1 6 3 4) After: (5 8 6 2 1 7 3 4) Wendy Williams Metaheuristic Algorithms 17 Genetic Algorithms: A Tutorial TSP Example: 30 Cities 100 90 80 70 y 60 50 40 30 20 10 0 0 10 20 30 40 50 60 70 80 90 100 x Wendy Williams Metaheuristic Algorithms 18 Genetic Algorithms: A Tutorial Solution i (Distance = 941) TS P 30 (P er for m ance = 941) 100 90 80 70 y 60 50 40 30 20 10 0 0 10 20 30 40 50 60 70 80 90 100 x Wendy Williams Metaheuristic Algorithms 19 Genetic Algorithms: A Tutorial Solution j(Distance = 800) TS P 30 (P er for mance = 800) 100 90 80 70 y 60 50 40 30 20 10 0 0 10 20 30 40 50 60 70 80 90 100 x Wendy Williams Metaheuristic Algorithms 20 Genetic Algorithms: A Tutorial Solution k(Distance = 652) TS P 30 (P er for m ance = 652) 100 90 80 70 y 60 50 40 30 20 10 0 0 10 20 30 40 50 60 70 80 90 100 x Wendy Williams Metaheuristic Algorithms 21 Genetic Algorithms: A Tutorial Best Solution (Distance = 420) TS P 30 S olution (P er for mance = 420) 100 90 80 70 y 60 50 40 30 20 10 0 0 10 20 30 40 50 60 70 80 90 100 x Wendy Williams Metaheuristic Algorithms 22 Genetic Algorithms: A Tutorial Overview of Performance T S P 30 - O ver view o f P er fo r m an ce 1600 1400 Dista nc e 1200 1000 800 600 400 200 0 B es t 1 3 5 7 9 11 13 15 17 19 G e n e ra ti o n s (1 0 0 0 ) Wendy Williams Metaheuristic Algorithms 23 21 23 25 27 29 31 W o rs t A ve ra g e Genetic Algorithms: A Tutorial Some GA Application Types Domain Application Types Control gas pipeline, pole balancing, missile evasion, pursuit Design semiconductor layout, aircraft design, keyboard configuration, communication networks Scheduling manufacturing, facility scheduling, resource allocation Robotics trajectory planning Machine Learning designing neural networks, improving classification algorithms, classifier systems Signal Processing filter design Game Playing poker, checkers, prisoner’s dilemma Combinatorial Optimization set covering, travelling salesman, routing, bin packing, graph colouring and partitioning Wendy Williams Metaheuristic Algorithms 24 Genetic Algorithms: A Tutorial % Genetic Algorithm Operators randomOrder = randperm(popSize); for p = 4:4:popSize rtes = pop(randomOrder(p-3:p),:); dists = totalDist(randomOrder(p-3:p)); [ignore,idx] = min(dists); %#ok bestOf4Route = rtes(idx,:); routeInsertionPoints = sort(ceil(n*rand(1,2))); I = routeInsertionPoints(1); J = routeInsertionPoints(2); for k = 1:4 % Mutate the Best to get Three New Routes tmpPop(k,:) = bestOf4Route; switch k case 2 % Flip tmpPop(k,I:J) = tmpPop(k,J:-1:I); case 3 % Swap tmpPop(k,[I J]) = tmpPop(k,[J I]); case 4 % Slide tmpPop(k,I:J) = tmpPop(k,[I+1:J I]); otherwise % Do Nothing end end newPop(p-3:p,:) = tmpPop; end pop = newPop; end if showResult % Plots the GA Results figure('Name','TSPO_GA | Results','Numbertitle','off'); subplot(2,2,1); pclr = ~get(0,'DefaultAxesColor'); if dims > 2, plot3(xy(:,1),xy(:,2),xy(:,3),'.','Color',pclr); else plot(xy(:,1),xy(:,2),'.','Color',pclr); end title('City Locations'); subplot(2,2,2); imagesc(dmat(optRoute,optRoute)); title('Distance Matrix'); subplot(2,2,3); if dims > 2, plot3(xy(optRoute,1),xy(optRoute,2),xy(optRoute,3),'r.-'); else plot(xy(optRoute,1),xy(optRoute,2),'r.-'); end title(sprintf('Total Distance = %1.4f',minDist)); subplot(2,2,4); plot(distHistory,'b','LineWidth',2); Wendy Williams title('Best Solution History'); set(gca,'XLim',[0 numIter+1],'YLim',[0 1.1*max([1 distHistory])]); Metaheuristic Algorithms end 25 Genetic Algorithms: A Tutorial