KEMBAR78
Approximation Algorithms TSP | PPTX
Approximation Algorithms
for NP – Hard Problems
Dr. P. Subathra
Professor
Dept. of IT
KAMARAJ College of Engg. & Tech.
(AUTONOMOUS)
Madurai
1
Approximation Algorithms
• We discuss a different approach to handling
difficult problems of combinatorial
optimization
• Traveling salesman problem and the knapsack
problem
• The decision versions of these problems are
NP-complete.
• The optimization versions fall in the class of
NP-hard problems
2
Approximation Algorithms
• There are no known polynomial-time
algorithms for these problems
• So how do we handle them?
• If an instance of the problem in question is
very small
– exhaustive-search algorithm
– dynamic programming technique
– branch-and-bound technique (comparatively
larger problems can be solved)
3
Approximation Algorithms
• There is a radically different way of dealing
with difficult optimization problems:
• solve them approximately by a fast algorithm.
• applications where a good but not necessarily
optimal solution will suffice
• approximation algorithms run based on some
problem-specific heuristic.
4
Approximation Algorithms
• A heuristic is a common-sense rule drawn
from experience rather than from a
mathematically proved assertion.
5
How accurate this approximation is?
• The accuracy of an approximate solution sa to
a problem of minimizing some function f by
the size of the relative error of this
approximation,
where s ∗ is an exact solution to the problem.
6
How accurate this approximation is?
• accuracy ratio
• Minimization Problem
• Maximization Problem
• The closer r(sa) is to 1, the better the
approximate solution is.
7
POLYNOMIAL-TIME APPROXIMATION
ALGORITHM
DEFINITION
• A polynomial-time approximation algorithm is said to
be a c-approximation algorithm, where c ≥ 1, if the
accuracy ratio of the approximation it produces does
not exceed c for any instance of the problem in
question:
• The best (i.e., the smallest) value of c is called the
performance ratio of the algorithm and denoted RA.
8
POLYNOMIAL-TIME APPROXIMATION
ALGORITHM
• We would like to have approximation
algorithms with RA as close to 1 as possible.
• Some approximation algorithms have infinitely
large performance ratios (RA=∞).
9
Travelling Salesman Problem
Approximation Algorithms
10
Travelling Salesman Problem
• There are more than a dozen approximation
algorithms that solve TSP in a reasonable
amount of time producing an approximate
solution.
• Example:
– Greedy Algorithms for the TSP
– Minimum-Spanning-Tree–Based Algorithms
– Local Search Heuristics
11
Travelling Salesman Problem
– Greedy Algorithms for the TSP
• Nearest-neighbor algorithm
• Multifragment-heuristic algorithm
– Minimum-Spanning-Tree–Based Algorithms
• Twice-around-the-tree algorithm
• Christofides Algorithm
– Local Search Heuristics
• 2-opt algorithms
• 3-opt algorithms
• Lin-Kernighan algorithms
12
Approximation Algorithm for TSP
Greedy Algorithms for the TSP
• Nearest-neighbor algorithm
• Multifragment-heuristic algorithm
13
Greedy Algorithms for the TSP:
Nearest-neighbor algorithm
Nearest-neighbor algorithm
• Algorithm:
Step 1 Choose an arbitrary city as the start.
Step 2 Repeat the following operation until
all the cities have been visited:
go to the unvisited city nearest the one
visited last (ties can be broken arbitrarily).
Step 3 Return to the starting city.
14
Nearest-neighbor algorithm
With a as the starting vertex,
the nearest-neighbor algorithm
yields the tour (Hamiltonian
circuit) sa:
a − b − c − d − a of length 10.
15
Nearest-neighbor algorithm
An optimal solution can be s*:
a − c − d − b − a of length 8.
16
Nearest-neighbor algorithm
The accuracy ratio of this
approximation is
• If the last links weight is ∞,
then the cost of the solution
will be infinity.
• Hence, RA =∞for this
algorithm
17
Greedy Algorithms for the TSP:
Multifragment-heuristic algorithm
Multifragment-heuristic algorithm
• It is problem of finding a minimum-weight
collection of edges in a given complete
weighted graph so that all the vertices have
degree 2.
18
Multifragment-heuristic algorithm
• Step 1
– Sort the edges in increasing order of their weights. (Ties
can be broken arbitrarily.)
– Initialize the set of tour edges to be constructed to the
empty set.
• Step 2
– Repeat this step n times, where n is the number of cities in
the instance being solved:
– add the next edge on the sorted edge list to the set of tour
edges, provided this addition does not create a vertex of
degree 3 or a cycle of length less than n;
– otherwise, skip the edge.
• Step 3
– Return the set of tour edges.
19
Multifragment-heuristic algorithm
• Sorted Edges as per weights:
{(a,b), (c,d), (b,c), (a,c), (b,d), (a,d)}
{ 1 , 1 , 2 , 3 , 3 , 6 }
• Initial Tour Set = {}
• Inset edge to Tour Set = {(a,b)} - OK
• Inset edge to Tour Set = {(c,d)} – OK
• Inset edge to Tour Set = {(b,c)} - OK
• Inset edge to Tour Set = {(a,c)} – NO
• Inset edge to Tour Set = {(b,d)} – NO
• Inset edge to Tour Set = {(a,d)} - OK
20
Multifragment-heuristic algorithm
• This method is applied to Eucledian Graphs
which follows the below conditions:
– triangle inequality d[i, j ]≤ d[i, k]+ d[k, j] for any
triple of cities i, j, and K
– symmetry d[i, j ]= d[j, i] for any pair of cities i and j
• Accuracy ratio satisfy the following inequality
21
Approximation Algorithm for TSP
Minimum-Spanning-Tree–Based Algorithms
• Twice-around-the-tree algorithm
• Christofides Algorithm
• There are approximation algorithms for the
traveling salesman problem that exploit a
connection between Hamiltonian circuits and
spanning trees of the same graph.
• Removing an edge from a Hamiltonian circuit
yields a spanning tree, so we use Min Span Tree
to produce a TSP tour
22
Minimum-Spanning-Tree–Based Algorithms
Twice-around-the-tree algorithm
• Step 1 Construct a minimum spanning tree of the graph
corresponding to a given instance of the traveling salesman
problem.
• Step 2 Starting at an arbitrary vertex, perform a walk around the
minimum spanning tree recording all the vertices passed by. (DFS
traversal.)
• Step 3 Scan the vertex list obtained in Step 2 and eliminate from it
all repeated occurrences of the same vertex except the starting one
at the end of the list. The vertices remaining on the list will form a
Hamiltonian circuit, which is the output of the algorithm.
23
Twice-around-the-tree algorithm
Initial Graph Minimum Spanning Tree
24
Twice-around-the-tree algorithm
Minimum Spanning Tree DFS - a, b, c, b, d, e, d, b, a.
25
Twice-around-the-tree algorithm
DFS - a, b, c, b, d, e, d, b, a. Eliminating the Second
Occurrences
a – b – c – d – e - a
26
Twice-around-the-tree algorithm
Initial Graph TSP : Cost = 4+6+10+7+12 = 39
27
Minimum-Spanning-Tree–Based Algorithms
Christofides Algorithm
• It also uses a minimum spanning tree like twice-
around-the-tree algorithm
• Eulerian circuit exists in a connected multigraph if and
only if all its vertices have even degrees.
• The Christofides algorithm obtains such a multigraph
by adding to the graph the edges of a minimum-weight
matching of all the odd-degree vertices in its minimum
spanning tree.
• Then the algorithm finds an Eulerian circuit in the
multigraph and transforms it into a Hamiltonian circuit
28
Christofides Algorithm
Algorithm
Step 1. Find a minimum spanning tree T
Step 2. Find a minimum matching M for the odd-
degree vertices in T
Step 3. Add M to T
Step 4. Find an Euler tour
Step 5. Cut short
29
Christofides Algorithm – Step 1
Initial Graph Minimum Spanning Tree
30
Christofides Algorithm – Step 2
• Odd degree edges:
a, b, c, e
• Possible matching pairs
with cost are :
(a,b) & (c,e) = 4+11 = 15
(a,c) & (b,e) = 8+ 9 = 17
(a,e) & (b,c) = 12+ 6 = 18
• Minimum of it is:
(a,b) & (c,e) = 4+11 = 15
31
Christofides Algorithm – Step 2
• Odd degree edges:
a, b, c, e
• Possible matching pairs
with cost are :
(a,b) & (c,e) = 4+11 = 15
(a,c) & (b,e) = 8+ 9 = 17
(a,e) & (b,c) = 12+ 6 = 18
• Minimum of it is:
(a,b) & (c,e) = 4+11 = 15
32
Christofides Algorithm – Step 3
Minimum Spanning Tree Matching Pair Added to MST
33
Christofides Algorithm – Step 4
Matching Pair Added to MST Euler Tour / Euler Circuit
a – b- c – e – d – b - a
34
Christofides Algorithm – Step 5
Initial Graph Cut Short - Eliminate Repetition
a – b- c – e – d – b - a
a – b - c – e – d - a
Hamiltonian Circuit
35
Approximation Algorithm for TSP
Local Search Heuristics
• 2-opt algorithms
• 3-opt algorithms
• Lin-Kernighan algorithms
• Good approximations to optimal tours can be
obtained by iterative-improvement algorithms,
which are also called local search heuristics.
36
LOCAL SEARCH HEURISTICS
• These algorithms start with some initial tour
• On each iteration, the algorithm explores a
neighborhood around the current tour by replacing a
few edges in the current tour by other edges.
• If the changes produce a shorter tour, the algorithm
makes it the current tour and continues by exploring its
neighborhood in the same manner
• otherwise, the current tour is returned as the
algorithm’s output and the algorithm stops
37
LOCAL SEARCH HEURISTICS
2-OPT ALGORITHMS
• The 2-opt algorithm works by deleting a pair
of nonadjacent edges in a tour and
reconnecting their endpoints by the different
pair of edges to obtain another Tour
• This operation is called the 2-change.
38
2-OPT ALGORITHMS
39
2-OPT ALGORITHM
• Choice 1
40
2-OPT ALGORITHM
• Choice 2
41
2-OPT ALGORITHM
• Choice 3
42
2-OPT ALGORITHM
• Choice 4
43
3-OPT ALGORITHMS
• 2 different options
44
Lin-Kernighan algorithm
• The Lin-Kernighan algorithm is a variable-opt
algorithm: its move can be viewed as a 3-opt
move followed by a sequence of 2-opt moves.
45
Approximation Algorithms for TSP
– Greedy Algorithms for the TSP
• Nearest-neighbor algorithm
• Multifragment-heuristic algorithm
– Minimum-Spanning-Tree–Based Algorithms
• Twice-around-the-tree algorithm
• Christofides Algorithm
– Local Search Heuristics
• 2-opt algorithms
• 3-opt algorithms
• Lin-Kernighan algorithms
46
Approximation Algorithms for TSP
47
APPLICATIONS OF TSP
• Circuit Board and VLSI – chip fabrication
• X-ray crystallography
• Genetic Engineering
48

Approximation Algorithms TSP

  • 1.
    Approximation Algorithms for NP– Hard Problems Dr. P. Subathra Professor Dept. of IT KAMARAJ College of Engg. & Tech. (AUTONOMOUS) Madurai 1
  • 2.
    Approximation Algorithms • Wediscuss a different approach to handling difficult problems of combinatorial optimization • Traveling salesman problem and the knapsack problem • The decision versions of these problems are NP-complete. • The optimization versions fall in the class of NP-hard problems 2
  • 3.
    Approximation Algorithms • Thereare no known polynomial-time algorithms for these problems • So how do we handle them? • If an instance of the problem in question is very small – exhaustive-search algorithm – dynamic programming technique – branch-and-bound technique (comparatively larger problems can be solved) 3
  • 4.
    Approximation Algorithms • Thereis a radically different way of dealing with difficult optimization problems: • solve them approximately by a fast algorithm. • applications where a good but not necessarily optimal solution will suffice • approximation algorithms run based on some problem-specific heuristic. 4
  • 5.
    Approximation Algorithms • Aheuristic is a common-sense rule drawn from experience rather than from a mathematically proved assertion. 5
  • 6.
    How accurate thisapproximation is? • The accuracy of an approximate solution sa to a problem of minimizing some function f by the size of the relative error of this approximation, where s ∗ is an exact solution to the problem. 6
  • 7.
    How accurate thisapproximation is? • accuracy ratio • Minimization Problem • Maximization Problem • The closer r(sa) is to 1, the better the approximate solution is. 7
  • 8.
    POLYNOMIAL-TIME APPROXIMATION ALGORITHM DEFINITION • Apolynomial-time approximation algorithm is said to be a c-approximation algorithm, where c ≥ 1, if the accuracy ratio of the approximation it produces does not exceed c for any instance of the problem in question: • The best (i.e., the smallest) value of c is called the performance ratio of the algorithm and denoted RA. 8
  • 9.
    POLYNOMIAL-TIME APPROXIMATION ALGORITHM • Wewould like to have approximation algorithms with RA as close to 1 as possible. • Some approximation algorithms have infinitely large performance ratios (RA=∞). 9
  • 10.
  • 11.
    Travelling Salesman Problem •There are more than a dozen approximation algorithms that solve TSP in a reasonable amount of time producing an approximate solution. • Example: – Greedy Algorithms for the TSP – Minimum-Spanning-Tree–Based Algorithms – Local Search Heuristics 11
  • 12.
    Travelling Salesman Problem –Greedy Algorithms for the TSP • Nearest-neighbor algorithm • Multifragment-heuristic algorithm – Minimum-Spanning-Tree–Based Algorithms • Twice-around-the-tree algorithm • Christofides Algorithm – Local Search Heuristics • 2-opt algorithms • 3-opt algorithms • Lin-Kernighan algorithms 12
  • 13.
    Approximation Algorithm forTSP Greedy Algorithms for the TSP • Nearest-neighbor algorithm • Multifragment-heuristic algorithm 13
  • 14.
    Greedy Algorithms forthe TSP: Nearest-neighbor algorithm Nearest-neighbor algorithm • Algorithm: Step 1 Choose an arbitrary city as the start. Step 2 Repeat the following operation until all the cities have been visited: go to the unvisited city nearest the one visited last (ties can be broken arbitrarily). Step 3 Return to the starting city. 14
  • 15.
    Nearest-neighbor algorithm With aas the starting vertex, the nearest-neighbor algorithm yields the tour (Hamiltonian circuit) sa: a − b − c − d − a of length 10. 15
  • 16.
    Nearest-neighbor algorithm An optimalsolution can be s*: a − c − d − b − a of length 8. 16
  • 17.
    Nearest-neighbor algorithm The accuracyratio of this approximation is • If the last links weight is ∞, then the cost of the solution will be infinity. • Hence, RA =∞for this algorithm 17
  • 18.
    Greedy Algorithms forthe TSP: Multifragment-heuristic algorithm Multifragment-heuristic algorithm • It is problem of finding a minimum-weight collection of edges in a given complete weighted graph so that all the vertices have degree 2. 18
  • 19.
    Multifragment-heuristic algorithm • Step1 – Sort the edges in increasing order of their weights. (Ties can be broken arbitrarily.) – Initialize the set of tour edges to be constructed to the empty set. • Step 2 – Repeat this step n times, where n is the number of cities in the instance being solved: – add the next edge on the sorted edge list to the set of tour edges, provided this addition does not create a vertex of degree 3 or a cycle of length less than n; – otherwise, skip the edge. • Step 3 – Return the set of tour edges. 19
  • 20.
    Multifragment-heuristic algorithm • SortedEdges as per weights: {(a,b), (c,d), (b,c), (a,c), (b,d), (a,d)} { 1 , 1 , 2 , 3 , 3 , 6 } • Initial Tour Set = {} • Inset edge to Tour Set = {(a,b)} - OK • Inset edge to Tour Set = {(c,d)} – OK • Inset edge to Tour Set = {(b,c)} - OK • Inset edge to Tour Set = {(a,c)} – NO • Inset edge to Tour Set = {(b,d)} – NO • Inset edge to Tour Set = {(a,d)} - OK 20
  • 21.
    Multifragment-heuristic algorithm • Thismethod is applied to Eucledian Graphs which follows the below conditions: – triangle inequality d[i, j ]≤ d[i, k]+ d[k, j] for any triple of cities i, j, and K – symmetry d[i, j ]= d[j, i] for any pair of cities i and j • Accuracy ratio satisfy the following inequality 21
  • 22.
    Approximation Algorithm forTSP Minimum-Spanning-Tree–Based Algorithms • Twice-around-the-tree algorithm • Christofides Algorithm • There are approximation algorithms for the traveling salesman problem that exploit a connection between Hamiltonian circuits and spanning trees of the same graph. • Removing an edge from a Hamiltonian circuit yields a spanning tree, so we use Min Span Tree to produce a TSP tour 22
  • 23.
    Minimum-Spanning-Tree–Based Algorithms Twice-around-the-tree algorithm •Step 1 Construct a minimum spanning tree of the graph corresponding to a given instance of the traveling salesman problem. • Step 2 Starting at an arbitrary vertex, perform a walk around the minimum spanning tree recording all the vertices passed by. (DFS traversal.) • Step 3 Scan the vertex list obtained in Step 2 and eliminate from it all repeated occurrences of the same vertex except the starting one at the end of the list. The vertices remaining on the list will form a Hamiltonian circuit, which is the output of the algorithm. 23
  • 24.
  • 25.
    Twice-around-the-tree algorithm Minimum SpanningTree DFS - a, b, c, b, d, e, d, b, a. 25
  • 26.
    Twice-around-the-tree algorithm DFS -a, b, c, b, d, e, d, b, a. Eliminating the Second Occurrences a – b – c – d – e - a 26
  • 27.
    Twice-around-the-tree algorithm Initial GraphTSP : Cost = 4+6+10+7+12 = 39 27
  • 28.
    Minimum-Spanning-Tree–Based Algorithms Christofides Algorithm •It also uses a minimum spanning tree like twice- around-the-tree algorithm • Eulerian circuit exists in a connected multigraph if and only if all its vertices have even degrees. • The Christofides algorithm obtains such a multigraph by adding to the graph the edges of a minimum-weight matching of all the odd-degree vertices in its minimum spanning tree. • Then the algorithm finds an Eulerian circuit in the multigraph and transforms it into a Hamiltonian circuit 28
  • 29.
    Christofides Algorithm Algorithm Step 1.Find a minimum spanning tree T Step 2. Find a minimum matching M for the odd- degree vertices in T Step 3. Add M to T Step 4. Find an Euler tour Step 5. Cut short 29
  • 30.
    Christofides Algorithm –Step 1 Initial Graph Minimum Spanning Tree 30
  • 31.
    Christofides Algorithm –Step 2 • Odd degree edges: a, b, c, e • Possible matching pairs with cost are : (a,b) & (c,e) = 4+11 = 15 (a,c) & (b,e) = 8+ 9 = 17 (a,e) & (b,c) = 12+ 6 = 18 • Minimum of it is: (a,b) & (c,e) = 4+11 = 15 31
  • 32.
    Christofides Algorithm –Step 2 • Odd degree edges: a, b, c, e • Possible matching pairs with cost are : (a,b) & (c,e) = 4+11 = 15 (a,c) & (b,e) = 8+ 9 = 17 (a,e) & (b,c) = 12+ 6 = 18 • Minimum of it is: (a,b) & (c,e) = 4+11 = 15 32
  • 33.
    Christofides Algorithm –Step 3 Minimum Spanning Tree Matching Pair Added to MST 33
  • 34.
    Christofides Algorithm –Step 4 Matching Pair Added to MST Euler Tour / Euler Circuit a – b- c – e – d – b - a 34
  • 35.
    Christofides Algorithm –Step 5 Initial Graph Cut Short - Eliminate Repetition a – b- c – e – d – b - a a – b - c – e – d - a Hamiltonian Circuit 35
  • 36.
    Approximation Algorithm forTSP Local Search Heuristics • 2-opt algorithms • 3-opt algorithms • Lin-Kernighan algorithms • Good approximations to optimal tours can be obtained by iterative-improvement algorithms, which are also called local search heuristics. 36
  • 37.
    LOCAL SEARCH HEURISTICS •These algorithms start with some initial tour • On each iteration, the algorithm explores a neighborhood around the current tour by replacing a few edges in the current tour by other edges. • If the changes produce a shorter tour, the algorithm makes it the current tour and continues by exploring its neighborhood in the same manner • otherwise, the current tour is returned as the algorithm’s output and the algorithm stops 37
  • 38.
    LOCAL SEARCH HEURISTICS 2-OPTALGORITHMS • The 2-opt algorithm works by deleting a pair of nonadjacent edges in a tour and reconnecting their endpoints by the different pair of edges to obtain another Tour • This operation is called the 2-change. 38
  • 39.
  • 40.
  • 41.
  • 42.
  • 43.
  • 44.
    3-OPT ALGORITHMS • 2different options 44
  • 45.
    Lin-Kernighan algorithm • TheLin-Kernighan algorithm is a variable-opt algorithm: its move can be viewed as a 3-opt move followed by a sequence of 2-opt moves. 45
  • 46.
    Approximation Algorithms forTSP – Greedy Algorithms for the TSP • Nearest-neighbor algorithm • Multifragment-heuristic algorithm – Minimum-Spanning-Tree–Based Algorithms • Twice-around-the-tree algorithm • Christofides Algorithm – Local Search Heuristics • 2-opt algorithms • 3-opt algorithms • Lin-Kernighan algorithms 46
  • 47.
  • 48.
    APPLICATIONS OF TSP •Circuit Board and VLSI – chip fabrication • X-ray crystallography • Genetic Engineering 48