TSP with GAs an example of problem analysis and optimization TSP - by the categories 1. 2. 3. 4. 5. representation fitness variation selection initialization many choices easy many choices augmented algorithms Representations TSP is a permutation problem sequential (path) adjacent ordinal boolean adjacency matrix boolean precedence matrix Representations sequential (path) 3-4-6-2-5-1 adjacency 1 2 3 4 5 6 3 5 4 6 1 2 ordinal 3,3,4,2,2,1 {1,2,3,4,5,6} {1,2,4,5,6} {1,2,5,6} {1,2,5} {1,5} {1} 3 4 6 1 5 2 3 Crossover Variations based on 1 sequential (path) representation 4 6 5 2 1 2 PMX (partially-mapped crossover) 3-4-6-2-5-1 6 1-2-3-4-5-6 5 swap segments x-x-3-4-5-x x-x-6-2-5-x analysis: what is inherited? retain where possible parent 1 2 x-x-3-4-5-1 position? y y/n 1-x-6-2-5-x relative order? y y/n map from swap adjacency? y n 6-2-3-4-5-1 1-4-6-2-5-3 3 4 3 Crossover Variations based on 1 sequential (path) representation OX (order crossover) 4 6 5 2 1 2 3 6 CX (cycle crossover) 5 using complementary representations Grefenstette’s heuristic (p.202) ER (edge recombination) analysis: what is inherited? parent 1 2 position? ? ? relative order? ? ? adjacency? ? ? 4 3 Single parent variations on 1 sequential (path) representation Inversion (like 2-opt) 4 6 5 2 1 2 3 6 Insertion 5 Displacement Reciprocal exchange analysis: what is inherited? from parent position ? relative order? ? adjacency? ? 4 3 Multi-parent variations on 1 sequential (path) representation Herdy’s heuristic (p.201) 4 6 5 2 1 2 3 6 5 analysis: what is inherited? from parents position ? relative order? ? adjacency? ? 4 3 Crossover Variations based on adjacency representation Alternating edges 1 2 3 4 5 6 1 2 3 4 5 6 3 5 4 6 1 2 2 3 4 5 6 1 edge from random parent 1 2 3 4 5 6 3 repeat, random city if cycle 1 2 3 4 5 6 3 1 4 5 6 2 1-3-4-5-6-2 4 6 1 5 2 1 2 3 6 5 analysis: what is inherited? parent 1 2 position? ? ? relative order? ? ? adjacency? ? ? 4 3 Variations based on ordinal representation classic crossover works without repair . . . but how good is it? 4 6 1 5 2 1 2 3 6 5 analysis: what is inherited? parent 1 2 position? ? ? relative order? ? ? adjacency? ? ? 4 Representations precedence matrix vij = 1 if i before j, i≠j 1 0 1 1 1 2 0 0 1 1 3 0 0 0 0 4 0 0 1 0 5 0 1 1 1 6 0 0 1 1 1 2 3 4 5 1 0 0 0 0 0 6 1 1 0 0 1 0 3 4 6 1 5 2 Variations based on 1 precedence matrix representation intersection union 1 2 3 4 5 6 1 0 0 0 0 0 0 1 2 3 4 5 6 1 0 1 1 1 1 1 2 1 0 0 0 1 0 2 0 0 1 1 1 1 3 1 1 0 1 1 1 3 0 0 0 1 1 1 4 1 1 0 0 1 1 4 0 0 0 0 1 1 5 1 0 0 0 0 0 5 0 0 0 0 0 1 6 1 1 0 0 1 0 6 0 0 0 0 0 0 3 4 6 5 2 1 2 3 6 analysis: what is inherited? parent 1 2 position? ? ? relative order? ? ? adjacency? ? ? 5 4 Representations adjacency matrix vij = 1 if ij is directed edge 1 0 0 0 0 2 0 0 0 0 3 1 0 0 0 4 0 0 1 0 5 0 1 0 0 6 0 0 0 1 1 2 3 4 5 1 0 0 0 0 0 6 0 1 0 0 0 0 3 4 6 1 5 2 Variations based on adjacency matrix representation submatrix rearrangement common links 1 2 3 4 5 6 1 0 0 1 0 0 0 1 2 3 4 5 6 1 0 1 0 0 0 0 2 0 0 0 0 1 0 2 0 0 1 0 0 0 3 0 0 0 1 0 0 3 0 0 0 1 0 0 4 0 0 0 0 0 1 4 0 0 0 0 1 0 5 1 0 0 0 0 0 5 0 0 0 0 0 1 6 0 1 0 0 0 0 6 1 0 0 0 0 0 3 4 6 1 5 2 1 2 3 6 analysis: what is inherited? parent 1 2 position? ? ? relative order? ? ? adjacency? ? ? 5 4 Selection strategies Incest-prevention - solutions can’t cross over with close relatives goal: maintain variety in population LIKE TABU Extending EA’s with local search procedure evolutionary algorithm**(p.215) t <-- 0 initialize P(t) // population local-optimize(P(t)) while (~termination-condition) do t <-- t+1 P’(t) <-- alter(P(t-1)) // offspring local-optimize(P’(t)) P(t) <-- select (P’(t), P(t-1)) end end (I have revised this algorithm) interpretation procedure evolutionary algorithm**(p.215) t <-- 0 initialize P(t) // population local-optimize(P(t)) while (~termination-condition) do t <-- t+1 P’(t) <-- alter(P(t-1)) // offspring local-optimize(P’(t)) P(t) <-- select (P’(t), P(t-1)) end end populations are locally optimized alterations produce ‘infeasible’ (not locally optimal) solutions that are repaired by local optimization example: Muhlenbein, p.215 OX (order crossover) and 2-opt local optimization Edge assembly crossover (EAX) Extended EA algorithm 1. expensive crossover with local optimization heuristic (variation) 2. repeatedly used with same parents looking for a child better than both (locally optimized selection) Edge assembly crossover (EAX) Extended EA algorithm 1. expensive crossover with local optimization heuristic (variation) 3 4 4 6 1 5 3 4 6 6 2 5 4 5 3 3 6 1 1 5 2 2 1 2 Edge assembly crossover (EAX) Extended EA algorithm (p.217) 2. repeatedly used with same parents looking for a child better than both (locally optimized selection) 3 4 4 4 6 6 1 5 2 3 4 4 4 2 4 5 3 6 5 3 5 3 5 3 1 23 1 23 1 2 1 6 5 6 1 5 6 5 6 1 4 6 2 2 1 2 The champion TSP algorithm: Inver-over operator procedure inver-over initialize P while not done for each Si P S’ <-- inver-over-op(Si) if (eval(S’) ≤ eval(Si)) Si <-- S’ Inver-over operator Asymmetric multi-parent operator inver-over-op(Si) S’ <-- Si c <-- random city from S’ repeat if (rand() < p) select c’ from S’, c’≠c else select Sj, Sj ≠ Si c’ <-- city next to c in S’ do 2-opt swap between c, c’ in S’ c <-- c’ until c’ follows c in Si return S’ Inver-over S’: 3-7-2-5-1-6-4 c <-- 2 p? c’<--6S’ S’:3-7-2-6-1-5-4 c <--6 2 new edges inver-over-op(Si) S’ <-- Si c <-- random city from S’ repeat if (rand() < p) select c’ from S’, c’≠c else select Sj, Sj ≠ Si c’ <-- city next to c in S’ do 2-opt between c, c’ in S’ c <-- c’ until c’ follows c in Si return S’ c’<--1 Sj: 7-4-6-2-1-5-3 S’: 3-7-2-1-5-6-4 c <--1 1 inherited edge 1 new edge