370 likes | 662 Views
Approximation Algorithms. When the best just isn’t possible. Approximation Algorithms. Some NP-Complete problems are too important to ignore Approaches: If input small, run it anyway Consider special cases that may run in polynomial time Use an approximation algorithm.
E N D
Approximation Algorithms When the best just isn’t possible Jeff Chastine
Approximation Algorithms • Some NP-Complete problems are too important to ignore • Approaches: • If input small, run it anyway • Consider special cases that may run in polynomial time • Use an approximation algorithm Jeff Chastine
How Sloppy Can We Get? • Optimum solution has cost (measured as minimum or maximum) • Cost is produced by approximation algorithm • We can calculate a ratio • We create -approximation algorithms Jeff Chastine
Approximation Schemes • There are also approximation schemes: • Takes in an instance of the problem • Takes in to create a (1+)-approximation alg • Running time can increase quickly: • Example: • Fully polynomial-time approximation scheme • Running time polynomial in and input • Example: Jeff Chastine
Vertex-Cover Problem • Given find a subset s.t. if then either or • Goal: minimize • This problem is NP-Complete • There is a 2-approximation algorithm • No more than twice the size Jeff Chastine
2-approximation Algorithm APPROX-VERTEX-COVER (G) 1 2 3 while 4 do let be an arbitrary edge of 5 6 remove from every edge incident on 7 return Jeff Chastine
Approximation Walkthrough b c d a e f g Original Graph. Jeff Chastine
Approximation Walkthrough b c d a e f g Pick an arbitrary edge. Here, it’s Jeff Chastine
Approximation Walkthrough b c d a e f g Add those vertices to and remove incident edges Jeff Chastine
Approximation Walkthrough b c d a e f g Pick another arbitrary edge. Here, it’s Jeff Chastine
Approximation Walkthrough b c d a e f g Add those vertices to and remove incident edges Jeff Chastine
Approximation Walkthrough b c d a e f g Pick another edge. Only one left! Jeff Chastine
Approximation Walkthrough b c d a e f g No incident edges, so add to = 6 vertices Jeff Chastine
Optimal Solution b c d a e f g Only 3 vertices! Jeff Chastine
My Question • Why don’t they sort verts by highest degree? • Pick highest degree first • Remove incident edges • Pick next highest and so on Jeff Chastine
Proof • Let A denote edges picked • Optimal solution must include at least an endpoint for each edge in • No two edges share the same endpoint (since we remove incident edges) • No two edges are covered by the same vertex • Thus • Each time an edge is picked, it isn’t in C • Thus and Jeff Chastine
Traveling Salesman Problem • Let be a weighted, non-directed graph • Problem: find a tour of all vertices of minimum weight • Always cheapest to go directly from • Intermediate steps can only add to cost • Called the triangle inequality Jeff Chastine
2-Approximation Algorithm APPROX-TSP-TOUR(G, c) 1 select a vertex to be a “root” vertex 2 compute a Minimum Spanning Tree from using PRIM’s algorithm • let be the list of vertices in a preorder walk of 4 return the hamiltonian cycle in order Jeff Chastine
Walkthrough a d e g b f c h Original graph with Euclidean distance Jeff Chastine
Walkthrough a d e g b f c h Pick a root vertex Jeff Chastine
Walkthrough a d e g b f c h Build a Minimum Spanning Tree using Prims. Jeff Chastine
Walkthrough 1 5 6 8 2 7 3 4 Do IN-ORDER walk of tree. Jeff Chastine
Walkthrough 1 5 6 8 2 7 3 4 Construct Hamiltonian Tour using order. Distance == 19.074 Jeff Chastine
Optimum Solution a d e g b f c h Optimum solution. Distance == 14.715 Jeff Chastine
Proof • If is the optimum tour, then delete any edge from it and compare with a MST s.t. • A full walk of visits each node twice Jeff Chastine
Walkthrough a d e g b f c h Jeff Chastine
Proof • If is the optimum tour, then delete any edge of it and compare with a MST s.t. • A full walk of visits each node twice • However, W isn’t a tour! • Using triangle inequality to delete • Remove all but first visit to each vertex Jeff Chastine
Walkthrough a d e g b f c h ; same as preorder! Jeff Chastine
Proof • If is the optimum tour, then delete any edge of it and compare with a MST s.t. • A full walk of visits each node twice. Thus • However, isn’t a tour! • Using triangle inequality to delete all but first visit to each vertex (this gives preorder) • If is walk of preorder, then Jeff Chastine
Summary • Don’t give up on NP-Complete algorithms • If input is small, brute-force it! • If input is large, try to develop an approximation algorithm Jeff Chastine