Local Search Stuffs In these slides, you will find: –Solution Representation –Local Move/Neighborhood Swap k-Nodes Swap k-Edges –Distance Metric For –Traveling Salesman Problem (TSP) –Knapsack Problem (KP)
TSP: Solution Representation The solution for Traveling Salesman Problem (TSP) is a tour of cities –Usually represented as a circular array A of vertices/nodes/cities. –The range of array indices is [0..n-1] –The starting city is irrelevant, but usually A[0] –A[i] is the city visited at step i –The edges of the tour are defined by (A[i], A[i+1]) for all i [0..n-2] plus the circular edge: (A[n-1],A[0]) Here is an example of 5 cities (n=5) Index01234 City
TSP: Local Move/Neighborhood There are several ways to locally modify TSP tour We list down 2 of them: 1.Swap k-vertices/nodes/cities 2.Swap k-edges
Swap k-vertices/nodes/cities k 2, but usually k=2 Neighborhood size (respectively, the running time of the local search) grows with larger k. –There are more options for k>2 There are k! ways to permute k cities. Swapping k-vertices maintains the feasibility of TSP tour. This type of local move for TSP is not good –It usually doesn’t fix crossings in the tour –But rather add more crossings… –Therefore local neighbors’ quality is usually poorer –A bad feature for local search with gradient-descent type
Example: Swap(index 1,index 3) Index n-1 City’43102…… City40132……
Swap k-edges k 2, but usually 2 or 3 Again, neighborhood size (respectively, the running time of the local search) grows with larger k.. Swapping k-edges maintains the feasibility of TSP tour. This local move is better than swap k-vertices –Typically used in the best performing local search for TSP. The best performing heuristic for TSP: Lin-Kernighan heuristic, uses variant of this swap k-edges… –The local neighborhood induced by this move usually contain tours/solutions with improving quality (crossings fixed). –We can fix crossings using shorter steps than swap k-vertices –In circular array and for k=2, this move is implemented by reversing the content of the sub-array/sub-tour.
Example: Swap(1-3/0-2,1-2/0-3) Index n-1 City’43102…… City43012……
TSP: Distance Metric The most appropriate (natural) distance function to measure distance between two TSP tours is bond/permutation/edge distance, defined as: –The number of different edges between solution a and b. –Using appropriate data structure, this distance function can be computed in linear time O(n), where n is the number of cities. Using the previous example (A: original tour, B: example for 2-nodes swap, C: example for 2-edges swap) –BondDistance(A,B) = 2 –BondDistance(A,C) = 2 Index01234…n-1 City A43102…… City B40132…… City C43012……
KP: Solution Representation The solution for Knapsack Problem (KP) is a set of taken items –Usually represented as a bit string of n items –If b[i] = 0, it means item i is not taken –If b[i] = 1, it means item I is taken Here is an example of 5 items (n=5) Index01234 Item00101 Taken Not
KP: Local Move/Neighborhood There are several ways to locally modify KP solution We list down 2 of them: 1.Toggle k-bits 2.Swap k-bits
Toggle k-bits k 1, but usually k=1 Toggle bit toggles the state of b[i] –From 0 to 1 and vice versa. –Feasibility of the solution must be checked afterwards. This local move is usually not used alone –When the knapsack is full, there is no way to insert any more item (toggle b[i] == 0 to b[i] == 1) –Toggling off will decrease the solution quality, without proper escape mechanism, the local search may get stuck easily.
Example: Toggle (Bit 1) Index01234 Item00101 Taken Not Item01101 Taken Not
Swap k-Bits k 2, but usually 2 For k=2, pick 2 indices i,j such that b[i] != b[j] –One item is inside but the other is outside the knapsack. –Swap them. –Feasibility of the solution must be checked afterwards. This local move is usually used with Toggle k-Bits –This local move doesn’t degrade the solution quality as much as pure Toggle k-Bits. –But complementing this neighborhood with Toggle k-Bits neighborhood usually yield stronger local search heuristic. –Careful search strategy must be employed for dealing with boundary cases of feasibility/infeasibility.
Example: Swap (Bit 1, Bit 4) Index01234 Item00101 Taken Not Item01100 Taken Not
KP: Distance Metric The most appropriate (natural) distance function to measure distance between two KP solution is hamming/exact match distance, defined as: –The number of different bits between solution a and b. –We can determine the distance with one linear scan O(n). Using the previous example (A: original knapsack, B: example for toggle 1 bit, C: example for swap 2 bits) –HammingDistance(A,B) = 1 –HammingDistance(A,C) = 2 Index01234 Knapsack A00101 Knapsack B01101 Knapsack C01100