1 The TSP : NP-Completeness Approximation and Hardness of Approximation All exact science is...

57
1 The TSP : NP-Completeness Approximation and Hardness of Approximation exact science is dominated by the idea of approximation. -- Bertrand Russell (1872 - 1970) * *TSP = Traveling Salesman Proble Based upon slides of Dana Moshkovitz, Kevin Wayne and others + some old slides

Transcript of 1 The TSP : NP-Completeness Approximation and Hardness of Approximation All exact science is...

Page 1: 1 The TSP : NP-Completeness Approximation and Hardness of Approximation All exact science is dominated by the idea of approximation. -- Bertrand Russell.

1

The TSP : NP-Completeness Approximation and Hardness of Approximation

All exact science is dominated by the idea of approximation.-- Bertrand Russell (1872 - 1970)

*

*TSP = Traveling Salesman Problem

Based upon slides of Dana Moshkovitz,Kevin Wayne and others + some old slides

Page 2: 1 The TSP : NP-Completeness Approximation and Hardness of Approximation All exact science is dominated by the idea of approximation. -- Bertrand Russell.

2

A related problem: HC HAM-CYCLE: given an undirected graph G = (V, E), does there

exist a simple cycle that contains every node in V.

YES: vertices and faces of a dodecahedron.

Page 3: 1 The TSP : NP-Completeness Approximation and Hardness of Approximation All exact science is dominated by the idea of approximation. -- Bertrand Russell.

3

Hamiltonian Cycle HAM-CYCLE: given an undirected graph G = (V, E), does there

exist a simple cycle that contains every node in V.

1

3

5

1'

3'

2

4

2'

4'

NO: bipartite graph with odd number of nodes.

Page 4: 1 The TSP : NP-Completeness Approximation and Hardness of Approximation All exact science is dominated by the idea of approximation. -- Bertrand Russell.

4

Directed Hamiltonian Cycle DIR-HAM-CYCLE: given a digraph G = (V, E), does there

exists a simple directed cycle that contains every node in V?

Claim. DIR-HAM-CYCLE P HAM-CYCLE.

Pf. Given a directed graph G = (V, E), construct an undirected graph G' with 3n nodes. Each node splits up into an output node, a regular node and an input node.

Page 5: 1 The TSP : NP-Completeness Approximation and Hardness of Approximation All exact science is dominated by the idea of approximation. -- Bertrand Russell.

5

Example

c

a

b

G

ain

a

aout

bin

b

bout

cin coutc

Page 6: 1 The TSP : NP-Completeness Approximation and Hardness of Approximation All exact science is dominated by the idea of approximation. -- Bertrand Russell.

6

Example

c

a

b

G

ain

a

aout

bin

b

bout

cin coutc

Page 7: 1 The TSP : NP-Completeness Approximation and Hardness of Approximation All exact science is dominated by the idea of approximation. -- Bertrand Russell.

7

Directed Hamiltonian Cycle Claim. G has a Hamiltonian cycle iff G' does.

Pf. Suppose G has a directed Hamiltonian cycle . Then G' has an undirected Hamiltonian cycle (same order).

Pf. Suppose G' has an undirected Hamiltonian cycle '. ' must visit nodes in G' using one of following two orders:

…, B, G, R, B, G, R, B, G, R, B, …

…, B, R, G, B, R, G, B, R, G, B, … Blue nodes in ' make up directed Hamiltonian cycle in G,

or reverse of one. ▪

Page 8: 1 The TSP : NP-Completeness Approximation and Hardness of Approximation All exact science is dominated by the idea of approximation. -- Bertrand Russell.

8

3-SAT Reduces to Directed Hamiltonian Cycle Claim. 3-SAT P DIR-HAM-CYCLE.

Pf. Given an instance of 3-SAT, we construct an instance of DIR-HAM-CYCLE that has a Hamiltonian cycle iff is satisfiable.

Construction. First, create graph that has 2n Hamiltonian cycles which correspond in a natural way to 2n possible truth assignments.

Page 9: 1 The TSP : NP-Completeness Approximation and Hardness of Approximation All exact science is dominated by the idea of approximation. -- Bertrand Russell.

9

3-SAT Reduces to Directed Hamiltonian Cycle

Construction. Given 3-SAT instance with n variables xi and k clauses.

Construct G to have 2n Hamiltonian cycles. Intuition: traverse path i from left to right set variable xi = 1.

s

t

3k + 3

x1

x2

x3

xi = 1

Page 10: 1 The TSP : NP-Completeness Approximation and Hardness of Approximation All exact science is dominated by the idea of approximation. -- Bertrand Russell.

10

3-SAT Reduces to Directed Hamiltonian Cycle

Construction. Given 3-SAT instance with n variables xi and k clauses. For each clause: add a node and 6 edges.

s

t

clause nodeclause node

x1

x2

x3

Page 11: 1 The TSP : NP-Completeness Approximation and Hardness of Approximation All exact science is dominated by the idea of approximation. -- Bertrand Russell.

11

3-SAT Reduces to Directed Hamiltonian Cycle Claim. is satisfiable iff G has a Hamiltonian cycle.

Pf. Suppose 3-SAT instance has satisfying assignment x*. Then, define Hamiltonian cycle in G as follows:

• if x*i = 1, traverse row i from left to right

• if x*i = 0, traverse row i from right to left

• for each clause Cj , there will be at least one row i in which we are going in "correct" direction to splice node Cj into tour

Page 12: 1 The TSP : NP-Completeness Approximation and Hardness of Approximation All exact science is dominated by the idea of approximation. -- Bertrand Russell.

12

3-SAT Reduces to Directed Hamiltonian Cycle Claim. is satisfiable iff G has a Hamiltonian cycle.

Pf. Suppose G has a Hamiltonian cycle . If enters clause node Cj , it must depart on mate edge.

• thus, nodes immediately before and after Cj are connected by an edge e in G

• removing Cj from cycle, and replacing it with edge e yields Hamiltonian cycle on G - { Cj }

Continuing in this way, we are left with Hamiltonian cycle ' inG - { C1 , C2 , . . . , Ck }.

Set x*i = 1 iff ' traverses row i left to right.

Since visits each clause node Cj , at least one of the paths is traversed in "correct" direction, and each clause is satisfied. ▪

Page 13: 1 The TSP : NP-Completeness Approximation and Hardness of Approximation All exact science is dominated by the idea of approximation. -- Bertrand Russell.

13

3-SAT P Directed HC P HC

Objectives:To explore the Traveling Salesman

Problem. Overview:

TSP: Examples and Defn. Is TSP NP-complete? Approximation algorithm for special cases Hardness of Approximation in general.

Page 14: 1 The TSP : NP-Completeness Approximation and Hardness of Approximation All exact science is dominated by the idea of approximation. -- Bertrand Russell.

14

Traveling Salesman Problem A Tour around USA

TSP. Given a set of n cities and a pairwise distance function d(u, v), is there a tour of length D?

All 13,509 cities in US with a population of at least 500Reference: http://www.tsp.gatech.edu

Page 15: 1 The TSP : NP-Completeness Approximation and Hardness of Approximation All exact science is dominated by the idea of approximation. -- Bertrand Russell.

15

Traveling Salesperson Problem TSP. Given a set of n cities and a pairwise distance function

d(u, v), is there a tour of length D?

Optimal TSP tourReference: http://www.tsp.gatech.edu

Page 16: 1 The TSP : NP-Completeness Approximation and Hardness of Approximation All exact science is dominated by the idea of approximation. -- Bertrand Russell.

16

Traveling Salesperson Problem TSP. Given a set of n cities and a pairwise distance function

d(u, v), is there a tour of length D?

11,849 holes to drill in a programmed logic arrayReference: http://www.tsp.gatech.edu

Page 17: 1 The TSP : NP-Completeness Approximation and Hardness of Approximation All exact science is dominated by the idea of approximation. -- Bertrand Russell.

17

Traveling Salesperson Problem TSP. Given a set of n cities and a pairwise distance function

d(u, v), is there a tour of length D?

Optimal TSP tourReference: http://www.tsp.gatech.edu

Page 18: 1 The TSP : NP-Completeness Approximation and Hardness of Approximation All exact science is dominated by the idea of approximation. -- Bertrand Russell.

18

TSP

Given a weighted graph G=(V,E)

V = Vertices = Cities

E = Edges = Distances between cities

Find the shortest tour that visits all cities

Page 19: 1 The TSP : NP-Completeness Approximation and Hardness of Approximation All exact science is dominated by the idea of approximation. -- Bertrand Russell.

19

TSP

Instance: A complete weighted undirected graph G=(V,E)

(all weights are non-negative).

Problem: To find a Hamiltonian cycle of minimal cost.

3

432

5

1 10

Page 20: 1 The TSP : NP-Completeness Approximation and Hardness of Approximation All exact science is dominated by the idea of approximation. -- Bertrand Russell.

20

Naïve Solution

Try all possible tours and pick the minimum

Dynamic Programming

))!1(( nO

)2( nO

Definitely we need something better

Page 21: 1 The TSP : NP-Completeness Approximation and Hardness of Approximation All exact science is dominated by the idea of approximation. -- Bertrand Russell.

21

Approximation Algorithms

A “good” algorithm is one whose running time is polynomial in the size of the input.

Any hope of doing something in polynomial time for NP-Complete problems?

Page 22: 1 The TSP : NP-Completeness Approximation and Hardness of Approximation All exact science is dominated by the idea of approximation. -- Bertrand Russell.

22

c-approximation algorithm

The algorithm runs in polynomial time The algorithm always produces a

solution which is within a factor of c of the value of the optimal solution

)(

)(

xOPT

xA c

For all inputs x.OPT(x) here denotes the optimal value of the minimization problem

(1/c) A(x) ≤ Opt(x) ≤ A(x)

Page 23: 1 The TSP : NP-Completeness Approximation and Hardness of Approximation All exact science is dominated by the idea of approximation. -- Bertrand Russell.

23

c-approximation algorithm

The algorithm runs in polynomial time The algorithm always produces a

solution which is within a factor of c of the value of the optimal solution

( )

( )

OPT x

A x c

For all inputs x.OPT(x) here denotes the optimal value of the maximization problem

c A(x) ≥ Opt(x) ≥ A(x)

Page 24: 1 The TSP : NP-Completeness Approximation and Hardness of Approximation All exact science is dominated by the idea of approximation. -- Bertrand Russell.

24

So why do we study Approximation Algorithms As algorithms to solve problems which

need a solution As a mathematically rigorous way of

studying heuristics Because they are fun! Because it tells us how hard problems

are

Page 25: 1 The TSP : NP-Completeness Approximation and Hardness of Approximation All exact science is dominated by the idea of approximation. -- Bertrand Russell.

25

Vertex Cover

Any guess on how to design approximation algorithms for vertex cover?

Page 26: 1 The TSP : NP-Completeness Approximation and Hardness of Approximation All exact science is dominated by the idea of approximation. -- Bertrand Russell.

26

Vertex Cover: Greedy

Page 27: 1 The TSP : NP-Completeness Approximation and Hardness of Approximation All exact science is dominated by the idea of approximation. -- Bertrand Russell.

27

Vertex Cover: Greedy

Page 28: 1 The TSP : NP-Completeness Approximation and Hardness of Approximation All exact science is dominated by the idea of approximation. -- Bertrand Russell.

28

Vertex Cover: Greedy

Page 29: 1 The TSP : NP-Completeness Approximation and Hardness of Approximation All exact science is dominated by the idea of approximation. -- Bertrand Russell.

29

Vertex Cover: Greedy

Page 30: 1 The TSP : NP-Completeness Approximation and Hardness of Approximation All exact science is dominated by the idea of approximation. -- Bertrand Russell.

30

Vertex Cover: Greedy

Page 31: 1 The TSP : NP-Completeness Approximation and Hardness of Approximation All exact science is dominated by the idea of approximation. -- Bertrand Russell.

31

Vertex Cover: Greedy

Greedy VC Approx = 8Opt = 6Factor 4/3HW 2 Problem : Example can be extended to O(log n) approximation

Page 32: 1 The TSP : NP-Completeness Approximation and Hardness of Approximation All exact science is dominated by the idea of approximation. -- Bertrand Russell.

32

A Simpler Approximation Algorithm

Choose an edge e in G Add both endpoints to the

Approximate VC Remove e from G and all incident

edges and repeat.

Cover generated is at most twice the optimal cover!

• Nothing better than 2-factor known. • If P <> NP, there is no poly-time algorithm that achieves an approximation factor better than 1.1666 [Has97].

Page 33: 1 The TSP : NP-Completeness Approximation and Hardness of Approximation All exact science is dominated by the idea of approximation. -- Bertrand Russell.

33

What Next?

We’ll show an approximation algorithm for TSP,

with approximation factor 2

for cost functions that satisfy a certain property.

Page 34: 1 The TSP : NP-Completeness Approximation and Hardness of Approximation All exact science is dominated by the idea of approximation. -- Bertrand Russell.

34

Polynomial Algorithm for TSP?

What about the greedy strategy:

At any point, choose the closest vertex not explored

yet?

Page 35: 1 The TSP : NP-Completeness Approximation and Hardness of Approximation All exact science is dominated by the idea of approximation. -- Bertrand Russell.

35

The Greedy Strategy Fails

5

0

3

1

12

10

2

Page 36: 1 The TSP : NP-Completeness Approximation and Hardness of Approximation All exact science is dominated by the idea of approximation. -- Bertrand Russell.

36

The Greedy Strategy Fails

5

0

3

1

12

10

2

Page 37: 1 The TSP : NP-Completeness Approximation and Hardness of Approximation All exact science is dominated by the idea of approximation. -- Bertrand Russell.

37

Another ExampleGreedy strategy fails

0 1-1 3 7-5-11

Even monkeys can do better than this !!!

Don’t be greedy Always!

Page 38: 1 The TSP : NP-Completeness Approximation and Hardness of Approximation All exact science is dominated by the idea of approximation. -- Bertrand Russell.

38

TSP is NP-hard

The corresponding decision problem: Instance: a complete weighted undirected

graph G=(V,E) and a number k. Problem: to find a Hamiltonian path whose

cost is at most k.

Page 39: 1 The TSP : NP-Completeness Approximation and Hardness of Approximation All exact science is dominated by the idea of approximation. -- Bertrand Russell.

39

TSP is NP-hard

Theorem: HAM-CYCLE p TSP.

Proof: By the straightforward efficient reduction illustrated below:

HAM-CYCLE TSP

1 cn1

1

1

n = k = |V|

cn

Page 40: 1 The TSP : NP-Completeness Approximation and Hardness of Approximation All exact science is dominated by the idea of approximation. -- Bertrand Russell.

40

TSP

Is a minimization problem. We want a 2-approximation algorithm But only for the case when the

cost function

satisfies the triangle inequality.

Page 41: 1 The TSP : NP-Completeness Approximation and Hardness of Approximation All exact science is dominated by the idea of approximation. -- Bertrand Russell.

41

The Triangle Inequality

Cost Function: Let c(x,y) be the cost of going from city x to city y.

Triangle Inequality: In most situations, going from x to y directly is no more expensive than going from x to y via an intermediate place z.

Page 42: 1 The TSP : NP-Completeness Approximation and Hardness of Approximation All exact science is dominated by the idea of approximation. -- Bertrand Russell.

42

The Triangle Inequality

Definition: We’ll say the cost function c satisfies the triangle inequality, if

x,y,zV : c(x,z)+c(z,y)c(x,y)

x

yz

Page 43: 1 The TSP : NP-Completeness Approximation and Hardness of Approximation All exact science is dominated by the idea of approximation. -- Bertrand Russell.

43

Approximation Algorithm

1. Grow a Minimum Spanning Tree (MST) for G.

2. Return the cycle resulting from a preorder walk on that tree.

Page 44: 1 The TSP : NP-Completeness Approximation and Hardness of Approximation All exact science is dominated by the idea of approximation. -- Bertrand Russell.

44

Demonstration and Analysis

The cost of a minimal

Hamiltonian cycle the cost of a

MST

Page 45: 1 The TSP : NP-Completeness Approximation and Hardness of Approximation All exact science is dominated by the idea of approximation. -- Bertrand Russell.

45

Demonstration and Analysis

The cost of a preorder walk is twice the cost of

the tree

Page 46: 1 The TSP : NP-Completeness Approximation and Hardness of Approximation All exact science is dominated by the idea of approximation. -- Bertrand Russell.

46

Demonstration and Analysis

Due to the triangle inequality, the

Hamiltonian cycle is not worse.

Page 47: 1 The TSP : NP-Completeness Approximation and Hardness of Approximation All exact science is dominated by the idea of approximation. -- Bertrand Russell.

47

The Bottom Line

optimal HAM cycle

MSTpreorder

walk

our HAM cycle

= ½· ½·

Page 48: 1 The TSP : NP-Completeness Approximation and Hardness of Approximation All exact science is dominated by the idea of approximation. -- Bertrand Russell.

48

What About the General Case?

We’ll show TSP cannot be approximated within any constant factor 1

By showing the corresponding gap version is NP-hard.

Inapproximability

Page 49: 1 The TSP : NP-Completeness Approximation and Hardness of Approximation All exact science is dominated by the idea of approximation. -- Bertrand Russell.

49

gap-TSP[]

Instance: a complete weighted undirected graph G=(V,E).

Problem: to distinguish between the following two cases:

There exists a Hamiltonian cycle, whose cost is at most |V|.

The cost of every Hamiltonian cycle is more than |V|.

Page 50: 1 The TSP : NP-Completeness Approximation and Hardness of Approximation All exact science is dominated by the idea of approximation. -- Bertrand Russell.

50

Instances

min cost

|V| |V|

1

1

1

0+1

0

0

1

Page 51: 1 The TSP : NP-Completeness Approximation and Hardness of Approximation All exact science is dominated by the idea of approximation. -- Bertrand Russell.

51

What Should an Algorithm for gap-TSP Return?

|V| |V|

YES! NO!

min cost

gap

DON’T-CARE...

Page 52: 1 The TSP : NP-Completeness Approximation and Hardness of Approximation All exact science is dominated by the idea of approximation. -- Bertrand Russell.

52

gap-TSP & Approximation

Observation: Efficient approximation of factor for TSP implies an efficient algorithm for gap-TSP[].

Page 53: 1 The TSP : NP-Completeness Approximation and Hardness of Approximation All exact science is dominated by the idea of approximation. -- Bertrand Russell.

53

gap-TSP is NP-hard

Theorem: For any constant 1,

HAM-CYCLE p gap-TSP[].

Proof Idea: Edges from G cost 1. Other edges cost much more.

Page 54: 1 The TSP : NP-Completeness Approximation and Hardness of Approximation All exact science is dominated by the idea of approximation. -- Bertrand Russell.

54

The Reduction Illustrated

HAM-CYCLE gap-TSP

1 |V|+11

1

1

|V|+1

Verify (a) correctness (b)

efficiency

Page 55: 1 The TSP : NP-Completeness Approximation and Hardness of Approximation All exact science is dominated by the idea of approximation. -- Bertrand Russell.

55

Approximating TSP is NP-hard

gap-TSP[] is NP-hard

Approximating TSP within factor is NP-hard

Page 56: 1 The TSP : NP-Completeness Approximation and Hardness of Approximation All exact science is dominated by the idea of approximation. -- Bertrand Russell.

56

Summary

We’ve studied the Traveling Salesman Problem (TSP).

We’ve seen it is NP-hard. Nevertheless, when the cost function

satisfies the triangle inequality, there exists an approximation algorithm with ratio-bound 2.

Page 57: 1 The TSP : NP-Completeness Approximation and Hardness of Approximation All exact science is dominated by the idea of approximation. -- Bertrand Russell.

57

Summary

For the general case we’ve proven there is probably no efficient approximation algorithm for TSP.

Moreover, we’ve demonstrated a generic method for showing approximation problems are NP-hard.