the traveling salesman problem in theory & practice lecture 4: polynomial-time solvable special...

55
The Traveling Salesman Problem in Theory & Practice Lecture 4: Polynomial-Time Solvable Special Cases Completed and Practical Heuristics Begun 11 February 2014 David S. Johnson [email protected] http:// davidsjohnson.net Seeley Mudd 523, Tuesdays and Fridays

Upload: ophelia-candace-hancock

Post on 01-Jan-2016

218 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: The Traveling Salesman Problem in Theory & Practice Lecture 4: Polynomial-Time Solvable Special Cases Completed and Practical Heuristics Begun 11 February

The Traveling Salesman Problem in Theory & Practice

Lecture 4: Polynomial-Time Solvable Special Cases Completed and Practical Heuristics Begun

11 February 2014

David S. Johnson

[email protected]://davidsjohnson.net

Seeley Mudd 523, Tuesdays and Fridays

Page 2: The Traveling Salesman Problem in Theory & Practice Lecture 4: Polynomial-Time Solvable Special Cases Completed and Practical Heuristics Begun 11 February

Outline

• Weighted Planar TSP Corrected

• Gilmore-Gomory Algorithm Concluded

• Tour Construction Heuristics Introduced

Page 3: The Traveling Salesman Problem in Theory & Practice Lecture 4: Polynomial-Time Solvable Special Cases Completed and Practical Heuristics Begun 11 February

TSP for Planar Weighted Graphs

• Solvable in time 2O(sqrt(N)) by Divide-and-Conquer (it was claimed…)

• (Recall our best general TSP algorithm takes time O(n22n)).• Exploited planar separator theorem [Lipton & Tarjan, 1979]:

– In any planar graph G with N vertices, the vertices of G can be partitioned into 3 sets, S, A, and B, such that |S| ≤ 2sqrt(2N), both |A| and |B| are bounded by 2N/3, and there is no edge between a vertex in A and one in B. This partition can be found in linear time.

S

BA

∂∂∂∂∂∂∂∂∂∂∂∂∂∂∂

A

S

∂∂∂∂∂∂∂∂∂∂∂∂∂∂∂

B

S

∂∂∂∂∂∂∂∂∂∂∂∂∂∂∂

Page 4: The Traveling Salesman Problem in Theory & Practice Lecture 4: Polynomial-Time Solvable Special Cases Completed and Practical Heuristics Begun 11 February

How an Optimal Tour Might Look

Forced Edges

A B

S

∂∂∂

∂∂∂∂∂∂∂∂∂

∂∂∂

Page 5: The Traveling Salesman Problem in Theory & Practice Lecture 4: Polynomial-Time Solvable Special Cases Completed and Practical Heuristics Begun 11 February

How an Optimal Tour Might Look

Forced Edges

B

∂∂∂

∂∂∂

S

A

∂∂∂

∂∂∂∂∂∂

Page 6: The Traveling Salesman Problem in Theory & Practice Lecture 4: Polynomial-Time Solvable Special Cases Completed and Practical Heuristics Begun 11 February

Previous Implicit Claim

For each possible Hamilton Circuit topology, simply solve these two sub-

problems and glue the solutions together.

But there is a problem with this reasoning.

Page 7: The Traveling Salesman Problem in Theory & Practice Lecture 4: Polynomial-Time Solvable Special Cases Completed and Practical Heuristics Begun 11 February

Think of our “Fixed Edges” as Schemata for Half the Tour

A B

S

∂∂∂

∂∂∂∂∂∂∂∂∂

∂∂∂

∂∂∂∂∂∂∂∂∂

Page 8: The Traveling Salesman Problem in Theory & Practice Lecture 4: Polynomial-Time Solvable Special Cases Completed and Practical Heuristics Begun 11 February

A B

S

∂∂∂

∂∂∂∂∂∂∂∂∂

∂∂∂

∂∂∂∂∂∂∂∂∂

For a given A-side Schemata, more than one B-side Schemata may be valid.

Page 9: The Traveling Salesman Problem in Theory & Practice Lecture 4: Polynomial-Time Solvable Special Cases Completed and Practical Heuristics Begun 11 February

A B

S

∂∂∂

∂∂∂∂∂∂∂∂∂

∂∂∂

∂∂∂∂∂∂∂∂∂

For a given A-side Schemata, more than one B-side Schemata may be valid.

Page 10: The Traveling Salesman Problem in Theory & Practice Lecture 4: Polynomial-Time Solvable Special Cases Completed and Practical Heuristics Begun 11 February

A B

S

∂∂∂

∂∂∂∂∂∂∂∂∂

∂∂∂

∂∂∂∂∂∂∂∂∂

For a given A-side Schemata, more than one B-side Schemata may be valid.

Page 11: The Traveling Salesman Problem in Theory & Practice Lecture 4: Polynomial-Time Solvable Special Cases Completed and Practical Heuristics Begun 11 February

Potential Difficulty

A

S

∂∂∂

∂∂∂∂∂∂∂∂∂

∂∂∂

∂∂∂∂∂∂∂∂∂

Possible Topologies for B: T1, T2, T3, …, Tm.

Possible topologies for A if we force the edges corresponding to Ti:Ti,1, Ti,2, …, Ti,m[i].

Suppose the best topology for B is T2, but the best Ti,j for A is T3,1.

Are we guaranteed that the union of T2 andT3,1 is a tour?

Forced Edges

Page 12: The Traveling Salesman Problem in Theory & Practice Lecture 4: Polynomial-Time Solvable Special Cases Completed and Practical Heuristics Begun 11 February

New Basic Problem to Be Solved by Divide-and-Conquer

• Given: a planar graph G = (V,E), a collection P of k pairs {ui,vi} of vertices, no two pairs overlapping, and a set E’ ⊆ E of forced edges.

• Find: a collection of k vertex-disjoint paths, where the kth path connects ui to vi, such that the union of the paths covers all vertices of G and includes all edges in E’.

• Note: For the TSP, we take k=1, u1 = v1, and E’ = Φ.

Page 13: The Traveling Salesman Problem in Theory & Practice Lecture 4: Polynomial-Time Solvable Special Cases Completed and Practical Heuristics Begun 11 February

Instance (G,E’,P) solved by constructing pairs of sub-problems:

1. Construct a separator system (A,B,S) as described earlier.

2. Let GA be the subgraph induced by A∪S and GB by the subgraph induced by B∪S.

3. Let EA’ be the subset of E’ with both endpoints in A∪S and at least one in A, and let EB’ be the subset of E’ with both endpoints in B∪S and at least one in B. Let ES be the set of edges in G between vertices in S, and let ES’ = ES∩E’.

4. Pick a subset ES’’, ES’ ⊆ ES’’ ⊆ ES such that no vertex is incident on more than 2 edges in ES’’.

5. The A sub-problem will have graph GA and forced-edge set ES’’∪EA’, and the B sub-problem will have graph GB and forced-edge set ES’’∪EB’.

6. The choices for the Path sets PA and PB are derived as follows:

∂∂∂∂∂∂∂∂∂∂∂∂∂∂∂

A B

S

∂∂∂

∂∂∂

∂∂∂

∂∂∂

∂∂∂

∂∂∂

∂∂∂

∂∂∂

Page 14: The Traveling Salesman Problem in Theory & Practice Lecture 4: Polynomial-Time Solvable Special Cases Completed and Practical Heuristics Begun 11 February

Segments

∂∂∂

∂∂∂∂∂∂∂∂∂A B

S-segment: Lies entirely within S, consists of a maximal path using edges of E’’ and including at least two vertices.

A-segment: Lies entirely within A∪S, contains at least one A-vertex, and each endpoint is either an endpoint in P, an independent S-vertex, or an endpoint of an S-segment.

B-segment: Lies entirely within B∪S, contains at least one B-vertex, and each endpoint is either an endpoint in P, an independent S-vertex, or an endpoint of an S-segment.

S-segments

∂∂∂

S-vertex

E’-edge

∂∂∂∂∂∂∂∂∂

Independent S-vertex

Page 15: The Traveling Salesman Problem in Theory & Practice Lecture 4: Polynomial-Time Solvable Special Cases Completed and Practical Heuristics Begun 11 February

Path Schemata• A path for a pair {u,v} in P with u∈A and v∈A∪S can be

– An A-segment with endpoints u and v.

– A sequence of segments, starting with an A-segment and alternating between A- and B-segments thereafter, with adjacent A- and B-segments either sharing an S-vertex as a common endpoint, or being linked by an S-segment with endpoints s and s’, with the A-segment having s for an endpoint and the B-segment having s’ for an endpoint.

• In the first case, we keep {u,v} in PA.

• In the second, we replace {u,v} in PA by the sequence of pairs

representing the A-segments in the path, and add the B-segments to PB.

• We do correspondingly for pairs {u,v} in P with u∈B and v∈B∪S.

• For pairs {u,v} in P with u∈A and v∈B, the path is a sequence of segments, starting with an A-segment and ending with a B-segment, and we again add pairs to PA and PB in the appropriate way.

Page 16: The Traveling Salesman Problem in Theory & Practice Lecture 4: Polynomial-Time Solvable Special Cases Completed and Practical Heuristics Begun 11 February

∂∂∂

∂∂∂

∂∂∂

∂∂∂∂∂∂∂∂∂

∂∂∂

∂∂∂

∂∂∂

Page 17: The Traveling Salesman Problem in Theory & Practice Lecture 4: Polynomial-Time Solvable Special Cases Completed and Practical Heuristics Begun 11 February

Path Schemata• A path for a pair {u,v} in P with u∈A and v∈A∪S can be

– An A-segment with endpoints u and v, or

– A sequence of segments, starting with an A-segment and alternating between A- and B-segments thereafter, with adjacent A- and B-segments either sharing an independent S-vertex as a common endpoint, or being linked by an S-segment with endpoints s and s’, with the A-segment having s for an endpoint and the B-segment having s’ for an endpoint.

• In the first case, we keep {u,v} in PA.

• In the second, we replace {u,v} in PA by the sequence of pairs

representing the A-segments in the path, and add the B-segments to PB.

• We do correspondingly for pairs {u,v} in P with u∈B and v∈B∪S.

• For pairs {u,v} in P with u∈A and v∈B, the path is a sequence of segments, starting with an A-segment and ending with a B-segment, and we again add pairs to PA and PB in the appropriate way.

Page 18: The Traveling Salesman Problem in Theory & Practice Lecture 4: Polynomial-Time Solvable Special Cases Completed and Practical Heuristics Begun 11 February

∂∂∂

∂∂∂

∂∂∂∂∂∂

∂∂∂

∂∂∂∂∂∂∂∂∂∂∂∂

Note: 1. No two A-segments (red segments) share an endpoint, nor do any

two B-segments (blue segments).

2. Every independent S-vertex, and one endpoint of every S-segment, is an endpoint of one A-segment and one B-segment.

Page 19: The Traveling Salesman Problem in Theory & Practice Lecture 4: Polynomial-Time Solvable Special Cases Completed and Practical Heuristics Begun 11 February

Path Schemata• A path for a pair {u,v} in P with u∈A and v∈A∪S can be

– An A-segment with endpoints u and v, or

– A sequence of segments, starting with an A-segment with u as an endpoint, ending with an A-segment with v as an endpoint, in between alternating between A- and B-segments, with adjacent A- and B-segments either sharing an independent S-vertex as a common endpoint, or being linked by an S-segment with endpoints s and s’, with the A-segment having s for an endpoint and the B-segment having s’ for an endpoint.

• In the first case, we keep {u,v} in PA.

• In the second, we replace {u,v} in PA by the sequence of pairs representing

the A-segments in the path, and add the B-segments to PB.

• We do correspondingly for pairs {u,v} in P with u∈B and v∈B∪S.

• For pairs {u,v} in P with u∈A and v∈B, the path is a sequence of segments, starting with an A-segment with endpoint u and ending with a B-segment with endpoint v, and we again add pairs to PA and PB in the appropriate way.

• For pairs {u,v} in P with both u and v in S, if they are both endpoints of the same S-segment, their path is covered by E’ and we can delete {u,v}. Otherwise, it must contain an A-vertex, a B-vertex, or both, and the treatment is as expected.

Page 20: The Traveling Salesman Problem in Theory & Practice Lecture 4: Polynomial-Time Solvable Special Cases Completed and Practical Heuristics Begun 11 February

Overall Connectivity Schema

• The overall schema for a solution to (G,E’,P) is the union the pairs corresponding to the segments making up all the connecting paths for the pairs in P, and can be partitioned into disjoint sets PA and PB

corresponding to those segments that contain elements of A and B, respectively.

• In this way, every possible solution to (G,E’,P) yields a pair of matching sub-problems (GA,EA’,PA) and (GB,EB’,PB), whose solutions will together yield a solution to the original problem.

• To bound the number of such pairs, and also to provide a non-topological way to generate them, we label the vertices of S and exploit planarity.

• Vertices labeled A will be members of pairs in PA, and vertices labeled B will be in pairs in PB.

Page 21: The Traveling Salesman Problem in Theory & Practice Lecture 4: Polynomial-Time Solvable Special Cases Completed and Practical Heuristics Begun 11 February

Case 1: Items not involved in pairs of P.

• Consider an independent S-vertex v. Our cover must contain two edges between v and non-S vertices. There are three choices.

– If both neighbors are in A, delete from GB all edges from v to vertices in B and leave v

unlabeled.

– If both neighbors are in B, delete from GA all edges from v to vertices in A and leave v

unlabeled.

– If one neighbor is in A and the other in B, label v as both A and B.

• Consider an S-segment with endpoints u and v, where u precedes v in the original ordering of the vertices. Our cover must contain an edge linking u to a non-S-vertex and an edge linking v to a non-S-vertex. There are now four choices.

– If both neighbors are in A, delete from GB all edges from u and v to vertices in B and

leave the segment unlabeled.

– If both neighbors are in B, delete from GA all edges from u and v to vertices in A and

leave the segment unlabeled.

– If the neighbor of u is in A and the neighbor of v is in B, label the segment (A,B) .

– If the neighbor of u is in B and the neighbor of v is in A, label the segment (B,A).

Labeling S(Actually, one label per independent S-vertex and per S-segment)

Page 22: The Traveling Salesman Problem in Theory & Practice Lecture 4: Polynomial-Time Solvable Special Cases Completed and Practical Heuristics Begun 11 February

Labeling S

Case 2: Items that involve members of pairs of P.

Note that a member v of a pair will have only one neighbor in our union of paths. Let u be the other member of the pair in P containing v.

• If v is an independent S-vertex, then our cover must contain a segment linking it to a member of A or of B. Choose one and label v with that choice.

• If v is an endpoint of an S-segment, let w be the other end of the S-segment containing v. If w = u, our required set ES’’ already contains a path for the {v,u} pair, so we can delete that pair. Otherwise, u must be in A∪B, and we label v either A or B, noting that the path from v must go through the S-segment.

Note: in neither Case 1 nor Case 2 is there a situation where there are more than 3 choices of label for a vertex or 4 for a segment. Since there are always at least two vertices in a segment, this means that there are at most 3 choices per vertex in S.

Page 23: The Traveling Salesman Problem in Theory & Practice Lecture 4: Polynomial-Time Solvable Special Cases Completed and Practical Heuristics Begun 11 February

Bounding the Total Possibilities to be Considered

Assume as before that N ≥ 225. Every item labeled with an X ∈ {A,B} will generate a pair

corresponding to an X-segment, the other end being either a similarly labeled item in S or a

member of X that is a member of a pair in P.

• The choices involving other S-vertices and S-segments will collectively be constrained to

at most 2|S| = 22sqrt(2N) by planarity.

• The choices involving members of A and B are constrained by the size of P.

• At the top level |P| = 1. Each recursive call can add at most two pairs for each element

of the new separator, which is no more than x=22sqrt(2n) < 6sqrt(n), where n is the

number of vertices in the current graph. The number of vertices in the sub-problems is

reduced to something less than .87 times that for the parent problem, and so the

separator size for them will be less than .95 times its former value and so, at any level,

the total size of P is at most x∑1∞(.95)i < x/(1-.95) = 20x < 120sqrt(N).

• Conservatively, this means that each of the at most 2|S| labels can have no more than

120sqrt(N) choices, for a total of (120sqrt(N))6sqrt(N) < 26(7+log(sqrt(N)))sqrt(N).

To bound the total number of choices, we need to multiply this by the number of choices for

E’’ (23sqrt(N)) and the number of labellings (3|S| < 25sqrt(N)), yielding

2 (50+6log(sqrt(N)))sqrt(N) < 219log(sqrt(N))sqrt(N)

Since log(sqrt(N) > 3.9 when N ≥ 225 and hence 50 < 13log(sqrt(N)).

Page 24: The Traveling Salesman Problem in Theory & Practice Lecture 4: Polynomial-Time Solvable Special Cases Completed and Practical Heuristics Begun 11 February

Running Time Induction

• Claim: We can solve this problem in time O(2αsqrt(N)log(sqrt(N))) for a constant α to be determined later (previously determined to be 217 with the log(sqrt(N)) term omitted).

• Proof: We will show that if the bound holds for N’ < N, then it holds for N as well. As a basis for the induction, we solve the problem by exhaustive search when N ≤ 225 (in large but constant time).

Page 25: The Traveling Salesman Problem in Theory & Practice Lecture 4: Polynomial-Time Solvable Special Cases Completed and Practical Heuristics Begun 11 February

So, suppose N > 225.

Find a planar separator S with max(|A|,|B|) ≤ 2N/3, and |S| ≤ 2sqrt(2N) < 3sqrt(N), which is less than N/5 since N > 225.

Thus neither |A∪S| nor |B∪S| exceeds (0.87)N.

So for each of our less than 219sqrt(N)log(sqrt(N) choices, we can solve the relevant A and B problems in time no more than than

2αsqrt(.87N)log(sqrt(.87N)) < 2(.94)αsqrt(N)log(sqrt(N))

For a total of at most

219sqrt(N)log(sqrt(N))2(.94)αsqrt(N) log(sqrt(N)) = 2(19+(.94)α)sqrt(N) log(sqrt(N)).

19+(.94)α will be less than α if (.06)α > 19. Thus α > 317 will suffice and our overall running time is O(2317sqrt(N)log(sqrt(N))).

QED

Page 26: The Traveling Salesman Problem in Theory & Practice Lecture 4: Polynomial-Time Solvable Special Cases Completed and Practical Heuristics Begun 11 February

Gilmore-Gomory Distances• Cities are pairs of rational numbers vi = (ai,bi), 1 ≤ i ≤ N.

• Distances determined by two real integrable functions f,g: R → R, subject to the constraint that for any x, f(x) + g(x) ≥ 0.

• Cost of from city vi to city vj is

• (The area between ai and bj under the relevant curve f or g.)

• Note that this is not necessarily symmetric.

• The constraint guarantees that the total cost of any cycle is non-negative.

Page 27: The Traveling Salesman Problem in Theory & Practice Lecture 4: Polynomial-Time Solvable Special Cases Completed and Practical Heuristics Begun 11 February

• Standard Heuristic:– Find a minimum-cost directed matching on the bipartite graph with copies of the cities representing

the out-ports of the cities on the left and copies representing the in-ports on the right, with the cost

of the edge from vi(out) to vi(in) being cij.

– A matching thus yields a set of N directed arcs, with each city having in- and out-degree 1. If the resultig graph is a single cycle, then it is an optimal tour and we are done.

– Otherwise, we have a union of directed cycles.

– Patch the cycles together repeatedly by

• picking a pair of cycles

• removing one arc from each, and

• replacing the removed arcs by a pair of arcs joining the two cycles.

The Algorithm

∂∂∂

∂∂∂ ∂

∂∂

∂∂∂

∂∂∂

∂∂∂

∂∂∂ ∂

∂∂

∂∂∂

∂∂∂

∂∂∂

∂∂∂ ∂

∂∂

∂∂∂

∂∂∂

Page 28: The Traveling Salesman Problem in Theory & Practice Lecture 4: Polynomial-Time Solvable Special Cases Completed and Practical Heuristics Begun 11 February

Finding the Matching

• Index the cities so that b1 ≤ b2 ≤ … ≤ bN.

• By sorting, find a permutation π satisfying aπ(1) ≤ aπ(2) ≤ … ≤ aπ(N).

• Our matching then can then be viewed as consisting of the pairs (vi,vπ(i)), 1 ≤ i ≤ N.

• Proof by an uncrossing argument, given last week.

Page 29: The Traveling Salesman Problem in Theory & Practice Lecture 4: Polynomial-Time Solvable Special Cases Completed and Practical Heuristics Begun 11 February

Digression: Tours & Permutations

• Two different correspondences:

1. vπ(i) is the ith city in the tour (“tour order”).

Tour cost =

2. vπ(i) is the successor of vi in the tour (“successor order”).

Tour cost =

• Note: There are n! permutations, but only (n-1)! distinct tours.

1. For tour order, each tour is represented by n different permutations.

2. For permutation order, only (n-1)! of the permutations actually represent tours. The rest represent covers by two or more disjoint cycles. The definition above of “tour cost” for permutation order extends naturally to cost(π) for any permutation π.

Page 30: The Traveling Salesman Problem in Theory & Practice Lecture 4: Polynomial-Time Solvable Special Cases Completed and Practical Heuristics Begun 11 February

Products of Permutations

• Let π and σ be permutations of length n.

• Then the product πσ is defined by

πσ(i) = π(σ(i)), 1 ≤ i ≤ n.

• More generally,

πσ1σ2σ3σk(i) = π(σ1(σ2(σ3((σk(i))))))

• Note: Associative, but not necessarily commutative.

• Let σi,j, i < j, denote the “transposition” that interchanges i and j and leaves everything else the same

Page 31: The Traveling Salesman Problem in Theory & Practice Lecture 4: Polynomial-Time Solvable Special Cases Completed and Practical Heuristics Begun 11 February

i 1 2 3 4 5 6 7 8 9

π(i) 4 6 8 5 1 7 2 9 3

σ1,2(i) 2 1 3 4 5 6 7 8 9

σ2,3(i) 1 3 2 4 5 6 7 8 9

πσ1,2(i) 6 4 3 4 5 6 7 8 9

πσ1,2σ2,3(i) 6 8 4 5 1 7 2 9 3

πσ2,3σ1,2(i) 8 4 6 5 1 7 2 9 3

Permutation π:Transposition σ1,2:Transposition σ2,3:

Product πσ1,2:Product πσ1,2σ2,3:Product πσ2,3σ1,2:

∂∂∂

∂∂∂

∂∂∂ ∂

∂∂

∂∂∂

∂∂∂

∂∂∂

∂∂∂

∂∂∂

1

2

3

4

5

6

9 78

(1,2)(2,3)

∂∂∂

∂∂∂

∂∂∂ ∂

∂∂

∂∂∂

∂∂∂

∂∂∂

∂∂∂

∂∂∂

1

2

3

4

5

6

9 78

(2,3)(1,2)

Page 32: The Traveling Salesman Problem in Theory & Practice Lecture 4: Polynomial-Time Solvable Special Cases Completed and Practical Heuristics Begun 11 February

∂∂∂

∂∂∂

∂∂∂ ∂

∂∂

∂∂∂

∂∂∂

∂∂∂

∂∂∂

∂∂∂

1

2

3

4

5

6

9 78

(1,2)(2,3)

∂∂∂

∂∂∂

∂∂∂ ∂

∂∂

∂∂∂

∂∂∂

∂∂∂

∂∂∂

∂∂∂

1

2

3

4

5

6

9 78

(2,3)(1,2)

Permutation π:Transposition σ = (1,2):Transposition τ = (2,3):

Product πσ:Product πστ:Product πτσ:

i 1 2 3 4 5 6 7 8 9

π(i) 4 6 8 5 1 7 2 9 3

σ(i) 2 1 3 4 5 6 7 8 9

τ(i) 1 3 2 4 5 6 7 8 9

πσ(i) 6 4 3 4 5 6 7 8 9

πστ(i) 6 8 4 5 1 7 2 9 3

πτσ(i) 8 4 6 5 1 7 2 9 3

Page 33: The Traveling Salesman Problem in Theory & Practice Lecture 4: Polynomial-Time Solvable Special Cases Completed and Practical Heuristics Begun 11 February

The Transposition Graph• Let Gπ be the directed graph induced by π, and suppose it contains cycles

C1, C2, …, Ck.

• We construct an auxiliary weighted multi-graph G* whose vertices are the cycles of Gπ. For each transposition σi,j with i < j, there is an edge joining the cycle containing vertex i to the cycle containing vertex j (a self-loop if i = j). The weight of this edge is cost(cπσi,j) – cost(π), the increase in the cost of our assignment if the corresponding swap is performed on Gπ.

• Note that if vertices i and j are in distinct cycles Cg and Ch of Gπ, then performing the swap indicated by σi,j will merge those cycles into a single combined cycle, although if they are in the same cycle Ch of Gπ, then performing the swap will only rearrange the vertices in Ch

• As a consequence, any connected subgraph of G* corresponds to a set of transpositions that, if performed in any order, will turn Gπ into a tour.

• The Gilmore-Gomory algorithm works by computing a particular minimum spanning tree (MST) for G* and performing the corresponding swaps in a particular order.

Page 34: The Traveling Salesman Problem in Theory & Practice Lecture 4: Polynomial-Time Solvable Special Cases Completed and Practical Heuristics Begun 11 February

Costs of Transpositions

• For an interval X of the reals, possibly empty, let Xf, Xg, and Xf+g denote the integrals of f, g, and (f+g) over X, respectively.

• For example, if a ≤ b, then the interval [a,b] is defined, and

[a,b]f =

• On the other hand, if X is empty, then the values are all 0.

• Using this notation, we have

ci,j = ([bi,+∞]∩[-∞,aj])f + ([-∞,bi]∩[aj,+∞])g

• Note that the first intersection is [bi,aj] if bi < aj, and otherwise empty. The second is [aj,bi] if bi > aj, and otherwise empty. So this agrees with our original definitions.

First: Another Way of Looking at Costs

Page 35: The Traveling Salesman Problem in Theory & Practice Lecture 4: Polynomial-Time Solvable Special Cases Completed and Practical Heuristics Begun 11 February

The Cost of a SwapLet σi,j denote the transposition that interchanges i < j.

Let cπ(σ) be the increase in cost derived from replacing the permutation π be πσ, that is,

by performing the swap σ on the assignment denoted by π.

Note that cπ(σi,j) then equals ci,π(j) - ci,π(i) + cj,π(i) - cj,π(j).

Also, note that since i < j, we have bi < bj and aπ(i) < aπ(j).

In our new notation, we have

ci,π(j) - ci,π(i) = ([bi,+∞]∩[-∞,aπ(j)])f + ([-∞,bi]∩[aπ(j),+∞])g

- (([bi,+∞]∩[-∞,aπ(i)])f + ([-∞,bi]∩[aπ(i),+∞])g )

= ([bi,+∞]∩[aπ(i),aπ(j)])f - ([-∞,bi]∩[aπ(i), π(j)])g.

Similarly,

cj,π(i) - cj,π(j) = ([bj,+∞]∩[-∞,aπ(i)])f + ([-∞,bj]∩[aπ(i),+∞])g

- (([bj,+∞]∩[-∞,aπ(j)])f + ([-∞,bj]∩[aπ(j),+∞])g )

= - ([bj,+∞]∩[aπ(i),aπ(j)])f + ([-∞,bj]∩[aπ(i), π(j)])g ).

Thus we have

cπ(σi,j) = ([bi,bj]∩[aπ(i),aπ(j)])f + ([bi,bj]∩[aπ(i), π(j)])g = ([bi,bj]∩[aπ(i),aπ(j)])f+g

Page 36: The Traveling Salesman Problem in Theory & Practice Lecture 4: Polynomial-Time Solvable Special Cases Completed and Practical Heuristics Begun 11 February

The Cost of a Transposition

Optimal Matching

bj

aπ(j)

bi

aπ(i)

σi,j

[bi, bi]∩[aπ(i),aπ(j)]

cπ(σi,j) = ([bi, bi]∩[aπ(i),aπ(j)])f+g

Page 37: The Traveling Salesman Problem in Theory & Practice Lecture 4: Polynomial-Time Solvable Special Cases Completed and Practical Heuristics Begun 11 February

Lemma: There is a MST for G* consisting only of edges corresponding to transpositions σi,i+1, 1 ≤ i < N.

Proof: Suppose not, and let T be an MST containing the minimum possible number of non-adjacent transpositions. Suppose σi,j, j > i+1, is such a

transposition in T, and let Cg and Ch be the cycles of Gπ containing i and j,

respectively. Note that these cycles must be distinct, as otherwise σi,j is a

self-loop, which minimum spanning trees do not contain.

Now consider the set of adjacent transpositions {σi,i+1, σi+1,i+2, …, σj-1,j}. These

by themselves will cause all the cycles containing i, i+1, i+2, …, j-1, and j to merge together, and in particular will cause Cg and Ch to become part of the

same cycle. Hence replacing σi,j by this set will still yield a spanning subgraph

T’ for G*.

Claim: the cost of the transpositions in T’ will be no larger than the cost of the transpositions in T.

Given the Claim, any spanning tree T’’ of T’ will be an MST for G* that has fewer non-adjacent transpositions than T, a contradiction.

So all we need do is prove the Claim and we will be done.

Page 38: The Traveling Salesman Problem in Theory & Practice Lecture 4: Polynomial-Time Solvable Special Cases Completed and Practical Heuristics Begun 11 February

Proof by Picture

Optimal Matching

bj

aπ(j)

bi

aπ(i)

σi,j

[bi, bi]∩[aπ(i),aπ(j)]

Page 39: The Traveling Salesman Problem in Theory & Practice Lecture 4: Polynomial-Time Solvable Special Cases Completed and Practical Heuristics Begun 11 February

Ordering the Swaps• As we have observed, order makes a difference, and the eventual

effect of the swap σi,j need not be cπ(σi,j).

• However, for a set of adjacent swaps, there is an ordering such that the total increase in cost over cost(cπ) is, in fact, the sum, over all σ in T, of cπ(σ), and this can be proved to be the best possible.

• To define this order, say vertex i is of “Type 1” relative to a permutation ψ if bi ≤ aψ(i), and otherwise is of “Type 2”.

• Let the type of a transposition σi,i+1 relative to ψ be that of vertex i.

• Let S1 be the set of transpositions that are of Type 1 relative to our optimal assignment π, and let S2 be the set of transpositions that are of Type 2 relative to π.

• Our order is as follows:

• First do all the transpositions σi,i+1 in S1 in order of decreasing value i. Then do all the transpositions σi,i+1 in S2 in order of increasing value i.

Page 40: The Traveling Salesman Problem in Theory & Practice Lecture 4: Polynomial-Time Solvable Special Cases Completed and Practical Heuristics Begun 11 February

Theorem: Let τ be product of the transpositions in T in the stated order. Then cost(πτ) = cost(π) + ∑σ∈T cπ(σ).

Proof: Say that a permutation ψ is order-preserving on a pair (i,j) if bj > bi ⇒ aψ(j) ≥ aψ(i). Note that our initial permutation π is order-preserving on all pairs. We rely on the following:

Lemma: Let ψ be a permutation that is order-preserving on (i,j) and (p,q) with i < j and p < q. Let ψ’ = ψσp,q. Then cψ’(σi,j) = cψ(σi,j) and ψ’ is order-preserving on (i,j) if any of the following four case apply:

a) p > j,

b) q < i,

c) p = j and vertex j is of Type 1 relative to ψ,

d) q = I and vertex i is of Type 2 relative to ψ.

Moreover, in case (c), vertex j is still of Type 1 relative to ψ’, and in case (d), vertex i is still of Type 2 relative to ψ’.

Proof of Lemma: See next slide.

We shall use the Lemma to show that the transposition costs never change under our permutation order, and hence the Theorem holds.

Page 41: The Traveling Salesman Problem in Theory & Practice Lecture 4: Polynomial-Time Solvable Special Cases Completed and Practical Heuristics Begun 11 February

Say that a permutation ψ is order-preserving on a pair (i,j) if bj > bi ⇒ aψ(j) ≥ aψ(i). We rely on the following:

Lemma: Let ψ be a permutation that is order-preserving on (i,j) and (p,q) with i < j and p < q. Let ψ’ = ψσp,q. Then cψ’(σi,j) = cψ(σi,j) and ψ’ is order-preserving on (i,j) if any of the following four case apply:

a) p > j,

b) q < i,

c) p = j and vertex j is of Type 1 relative to ψ,

d) q = i and vertex i is of Type 2 relative to ψ.

Moreover, in case (c), vertex j is still of Type 1 relative to ψ’, and in case (d), vertex i is still of Type 2 relative to ψ’.

Proof: (a) and (b) are obvious, since the transpositions do not overlap. For (c), we have

Case (d) is similar.

bj = bpbi bq

Page 42: The Traveling Salesman Problem in Theory & Practice Lecture 4: Polynomial-Time Solvable Special Cases Completed and Practical Heuristics Begun 11 February

Say that a permutation ψ is order-preserving on a pair (i,j) if bj > bi ⇒ aψ(j) ≥ aψ(i). We rely on the following:

Lemma: Let ψ be a permutation that is order-preserving on (i,j) and (p,q) with i < j and p < q. Let ψ’ = ψσp,q. Then cψ’(σi,j) = cψ(σi,j) and ψ’ is order-preserving on (i,j) if any of the following four case apply:

a) p > j,

b) q < i,

c) p = j and vertex j is of Type 1 relative to ψ,

d) q = i and vertex i is of Type 2 relative to ψ.

Moreover, in case (c), vertex j is still of Type 1 relative to ψ’, and in case (d), vertex i is still of Type 2 relative to ψ’.

Proof of Cost Theorem:

Recall that our initial permutation π is order-preserving on all pairs by definition.

Consider a Type 1 transposition σh,h+1 encountered in the downward phase, and let it be the σp,q of the Lemma. Consider a remaining unexecuted transposition. If it does not involve p or p+1, case (a) or (b) applies. Otherwise, if it is above σh,h+1 it must be σh+1,h+2 and case (d) applies with h+1 = i. And, finally, if it is below, then it must be σh-1,h and case (c) applies with h = j.

Similarly, consider a Type 2 transposition σh,h+1 encountered in the upward phase, and let it be the σp,q of the Lemma, and consider an unexecuted transposition which does not satisfy (a) or (b). Then that transposition must be Type 2 and hence σh+1,h+2. Thus case (d) applies with h+1 = i. QED

Page 43: The Traveling Salesman Problem in Theory & Practice Lecture 4: Polynomial-Time Solvable Special Cases Completed and Practical Heuristics Begun 11 February

What Remains

We have shown that cost(πτ) = cost(π) + ∑σ∈T cπ(σ), where τ is the

product permutation generated by Gilmore and Gomory’s ordering of their set of MST transpositions T.

It remains to be shown that there is no τ’ with

cost(πτ’) < cost(π) + ∑σ∈T cπ(σ).

It is not surprising that this is true, but..

Gilmore and Gomory take 4.5 pages. The two TSP books prove it by relying on much more general and abstract results about distribution matrices, etc.

A potential topic for a student presentation?

Page 44: The Traveling Salesman Problem in Theory & Practice Lecture 4: Polynomial-Time Solvable Special Cases Completed and Practical Heuristics Begun 11 February

One More Polynomial-Time Solvable Special Case:Fixed-Head Drum Scheduling

S. H. Fuller, “An optimal drum scheduling algorithm,” IEEE Trans. Comput. C-21 (1972), 1153-1165.

Page 45: The Traveling Salesman Problem in Theory & Practice Lecture 4: Polynomial-Time Solvable Special Cases Completed and Practical Heuristics Begun 11 February

Disk Scheduling (Restricted)

Locations of the files one want to retrieve

Distance between two files = time it takes for the head to rotate from the end of one to the beginning of the next.

(In the fixed-head drum version, there is assumed to be a head for each track, and switching between heads is assumed to be instantaneous.)

Page 46: The Traveling Salesman Problem in Theory & Practice Lecture 4: Polynomial-Time Solvable Special Cases Completed and Practical Heuristics Begun 11 February

New Topic: Practical Heuristics

For now, we will concentrate on the Symmetric TSP, where

d(a,b) = d(b,a) for all cities a, b.

Unlike the Christofides and Double MST algorithms, most of the heuristics we discuss will make sense even if the Triangle inequality does not hold,

Although our performance bounds for them do depend on it holding.

And our empirical results typically concern geometric instances.

We will start with theoretical results, but subsequent emphasis will be placed on real-world running time, solution quality, and the trade-offs between them.

We will also cover implementation details that affect running time/tour quality, both those that apply in general and those that exploit geometry.

Page 47: The Traveling Salesman Problem in Theory & Practice Lecture 4: Polynomial-Time Solvable Special Cases Completed and Practical Heuristics Begun 11 February

Nearest Neighbor (NN):1. Start with some city.

2. Repeatedly go next to the nearest unvisited neighbor of the last city added.

3. When all cities have been added, go from the last back to the first.

Page 48: The Traveling Salesman Problem in Theory & Practice Lecture 4: Polynomial-Time Solvable Special Cases Completed and Practical Heuristics Begun 11 February

No -Inequality Danger• Theorem [Karp, 1972]: Given a graph G = (V,E), it is

NP-hard to determine whether G contains a Hamiltonian circuit (collections of edges that make up a tour).

• Given a graph, construct a TSP instance in which

d(c,c’) =

• If Hamiltonian circuit exists, OPT = N, if not, OPT > N2N.

• A polynomial-time approximation algorithm that guaranteed a tour of length no more than 2N OPT would imply P = NP.

1 if {c,c’} EN2N if {c,c’} E{

Page 49: The Traveling Salesman Problem in Theory & Practice Lecture 4: Polynomial-Time Solvable Special Cases Completed and Practical Heuristics Begun 11 February

• Theorem [Rosenkrantz, Stearns, & Lewis,

1977]:

– There exists a constant c, such that if instance I obeys the triangle inequality, then we have NN(I) ≤ clog(N)Opt(I).

– There exists a constant c’, such that for all N > 3, there are N-city instances I obeying the triangle inequality for which we have NN(I) > c’log(N)Opt(I).

– For any algorithm A, let

RN(A) = max{A(I)/OPT(I): I is an N-city instance}

– Then RN(NN) = Θ(log(N)) (worst-case ratio)

Page 50: The Traveling Salesman Problem in Theory & Practice Lecture 4: Polynomial-Time Solvable Special Cases Completed and Practical Heuristics Begun 11 February

Upper Bound Proof (Sketch)• Observation 1: For symmetric instances with the

-inequality, d(c,c’) ≤ OPT(I)/2 for all pairs of cities {c,c’}.

c

c’

Optimal Tour

P1

P2

-inequality d(c,c’) ≤ length(P1) and d(c,c’) ≤ length(P2)

2d(c,c’) ≤ OPT(I)

Page 51: The Traveling Salesman Problem in Theory & Practice Lecture 4: Polynomial-Time Solvable Special Cases Completed and Practical Heuristics Begun 11 February

• Observation 2: For cities c, let L(c) be the length of edge added when c was the last city in the tour.

For all pairs {c,c’}, d(c,c’) ≥ min(L(c),L(c’)).

• Proof: Suppose without loss of generality that c is the first of c,c’ to occur in the NN tour. When c was the last city, the next city chosen, say c*, satisfied d(c,c*) ≤ c(c,c’’) for all unvisited cities c’’. Since c’ was as yet unvisited, this implies d(c,c’) ≥ d(c,c*) = L(c).

• Overall Proof Idea: We will partition C into O(logN) disjoint sets Ci such that cCi L(c) ≤ OPT(I), implying that

NN(I) = cC L(c) = O(logN)OPT(I).

Page 52: The Traveling Salesman Problem in Theory & Practice Lecture 4: Polynomial-Time Solvable Special Cases Completed and Practical Heuristics Begun 11 February

• Set X0 = C, i = 0 and repeat while |Xi| > 3.

• Let Ti be the set of edges in an optimal tour for Xi -- note that |Ti| = |Xi|. By the -inequality, the total length of these edges is at most OPT(I).

• Let Ti’ be the set of edges in Ti with length greater than 2OPT(I)/|Ti| -- note that |Ti’| < |Ti|/2.

• For each edge e = {c,c’} in Ti – Ti’, let f(e) be a city c’’ {c,c’} such that L(c’’) ≤ d(c,c’).

• Set Ci = {f(e): e Ti – Ti’} -- note that

– cCi L(c) ≤ eTi length(e) ≤ OPT(I).

– |Ci| ≥ |Ti – Ti’|/2 ≥ |Ti|/4 = |Xi|/4 .

• Set Xi+1 = Xi – Ci -- note that |Xi+1| ≤ (3/4)|Xi|.

Page 53: The Traveling Salesman Problem in Theory & Practice Lecture 4: Polynomial-Time Solvable Special Cases Completed and Practical Heuristics Begun 11 February

• Given that |Xi+1| ≤ (3/4)|Xi|, i ≥ 0, this process can only

continue while (3/4)iN > 3, i.e.,as long as log(3/4)●i + logN > log(3), or roughly while log(N)-log(3) > -log(3/4)●i = log(4/3)●i.

• Hence the process halts at iteration i*, where

• At this point there are 3 or fewer cities in Xi*+1. Put each of

them in a separate set Ci*+j, 1 ≤ j ≤ |Xi*+1|, for which, by

Observation 1, we will have L(c) ≤ OPT(I)/2.

O(logN)log(4/3)

log(3)log(N)i*

Page 54: The Traveling Salesman Problem in Theory & Practice Lecture 4: Polynomial-Time Solvable Special Cases Completed and Practical Heuristics Begun 11 February

Greedy (Multi-Fragment) (GR):1. Sort the edges, shortest first, and treat them in that order. Start with an empty graph.

2. While the current graph is not a TSP tour, attempt to add the next shortest edge. If it yields a vertex degree exceeding 2 or a tour of length less than N, delete.

Page 55: The Traveling Salesman Problem in Theory & Practice Lecture 4: Polynomial-Time Solvable Special Cases Completed and Practical Heuristics Begun 11 February

Clarke-Wright “Savings” Heuristic1. Start with a pseudo-tour in which an arbitrarily chosen city is the

“hub” and the salesman returns to the hub after visiting each city (a multigraph in which every hub city is connected by two edges to the hub).

2. For each pair of non-hub cities, let the “savings” be the amount by which the pseudo-tour would be shortened if we added an edge between the two and deleted one edge to the hub from each.

3. As long as we do not yet have a tour, find a pair of non-hub cities that have not yet undergone two such shortcuts, and yields the most savings, and perform the shortcut for them.

∂∂∂

∂∂∂

∂∂∂

∂∂∂

∂∂∂∂

∂∂

∂∂∂