Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
53 views

Approximation Algorithms

Dr. Pratyay Kuila discusses approximation algorithms for NP-hard problems. He defines different types of approximation algorithms, including absolute approximation algorithms, f(n)-approximation algorithms, and ε-approximation algorithms. He then provides examples of approximation algorithms for the vertex cover problem and traveling salesman problem (TSP). For vertex cover, he presents a 2-approximation algorithm and proves it has an approximation ratio of 2. For TSP, he outlines an approximation algorithm that uses a minimum spanning tree and proves it is a 2-approximation algorithm under the triangle inequality.

Uploaded by

Aman Verma
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
53 views

Approximation Algorithms

Dr. Pratyay Kuila discusses approximation algorithms for NP-hard problems. He defines different types of approximation algorithms, including absolute approximation algorithms, f(n)-approximation algorithms, and ε-approximation algorithms. He then provides examples of approximation algorithms for the vertex cover problem and traveling salesman problem (TSP). For vertex cover, he presents a 2-approximation algorithm and proves it has an approximation ratio of 2. For TSP, he outlines an approximation algorithm that uses a minimum spanning tree and proves it is a 2-approximation algorithm under the triangle inequality.

Uploaded by

Aman Verma
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 27

Dr.

Pratyay Kuila

Dept. of Computer Science & Engineering


NIT Sikkim-737139
 Generally, no NP-hard problems can be solved for optimal solution in
polynomial time.
 Many NP-hard problems have great practical importance and it is
desirable to solve in a reasonable amount of time.
 We have to compromise with quality of solution, i.e., we have to remove
the requirement that the algorithm that solves the optimization problem P
must always generate the optimal solution.
 What, if the algorithm for P must always generate a feasible solution with
value close to the value of an optimal solution (i.e., an approximate
solution).
 An approximation algorithm generates near optimal solution or
approximate solution.

Dr. Pratyay Kuila, NIT Sikkim 2


 Let OPT(I) be the optimal solution of a problem P for a given instance I.
 F(I) be a feasible solution of P by an approximation algorithm A. F(I) is
less than (greater than) OPT(I), if P is a maximization (minimization)
problem.
Definition 1 (Absolute approximation algorithm): A is an absolute
approximation algorithm for the problem P, if and only if for every instance
I of P, |OPT(I) - F(I)| ≤ k for some constant k.
Definition 2 (f(n)-approximation algorithm): A is an f(n)-approximation
algorithm for problem P, if and only if for every instance I of size n,

 F ( I ) OPT ( I ) 
Max  ,   f ( n)
 OPT ( I ) F ( I ) 

Dr. Pratyay Kuila, NIT Sikkim 3


 A f(n)-approximation algorithm is applicable to both minimization and
maximization problems.
 For a maximization problem, 0 < F(I) ≤ OPT(I), the ratio OPT(I)/ F(I) gives
the factor by which the cost of an optimal solution is larger than the cost of
the approximate solution.
 For a minimization problem, 0 < OPT(I) ≤ F(I), the ratio F(I) /OPT(I) gives
the factor by which the cost of the approximate solution is larger than the
cost of an optimal solution.
 Thus the approximation ratio of an approximation algorithm is never less
than 1.
 Therefore, a 1-approximation algorithm produces an optimal solution.
 An approximation algorithm with a large approximation ratio gives much
worse than optimal.
Definition 3 (ε-approximation algorithm): An ε-approximation algorithm is an
f(n)-approximation algorithm for which f(n) ≤ ε for some constant ε.

Dr. Pratyay Kuila, NIT Sikkim 4


Problem: A vertex cover of an undirected graph G = (V, E) is a subset
of vertices V' ⊆ V such that ∀ (u, v) E, either u ∈ V' or v ∈ V' or both.
It is to find a vertex cover of minimum size.

An Approximate Solution:

Algorithm: APPROX-VERTEX-COVER (G)


{
C= Φ
E0 = E [G]
While E0 ≠ Φ do
Let (u, v) be an arbitrary edge of E0
C = C ← {u, v}
Remove from E0 every edge incident on either u or v.
End
Return C
}

Dr. Pratyay Kuila, NIT Sikkim 5


An Illustration:

Fig. (a):Input Graph


Fig. (e): Final Vertex Cover
C = {b, c, e, f, d, g}

Fig. (f ):The Optimal vertex cover {b, e, d}


Comments: Optimal Solution is almost half of the Approximate Solution

Dr. Pratyay Kuila, NIT Sikkim 6


Theorem 1: The APPROX-VERTEX-COVER is a polynomial-time
2-approximation algorithm.
Proof:
o The algorithm, AVC runs in O(V+E), which is polynomial time.
o Let OPT be a set of optimal vertex cover.
o Let F be the set of vertices returned by AVC.
o As per the algorithm, AVC loops until all edges in the graph is removed.
o Now, we will show that | F |/|OPT | ≤ 2.

o Let A be the set of all edges chosen in the loop.


o Since all edges incident on the chosen nodes in F are removed, no two
edges in A share an endpoint.
o An edge is chosen in the loop when neither of its endpoints are already in F.
o Thus, | F |=2|A|.

Dr. Pratyay Kuila, NIT Sikkim 7


Proof (Cont…):
o Any vertex cover must include at least one endpoint of each edge in A.
Therefore, the optimal cover OPT also include at least one endpoint of
each edge in A.
o No two edges in A share an endpoint. Thus, no two edges in A are
covered by the same vertex from OPT.
o Therefore, number of edges in A can not be higher than the number of
vertices in OPT.
o Thus, |A| ≤ |OPT |. And we have |F|=2|A|.
i.e., |F|≤ 2|OPT|.
i.e., |F|/|OPT| ≤ 2.

Thus, AVC has approximation ratio of 2 or it is a 2-approximation algorithm.

Dr. Pratyay Kuila, NIT Sikkim 8


 Given a complete undirected graph G=(V, E) that has a nonnegative
integer cost c(u, v) associated with each edge (u, v)∈ E, find a
hamiltonian cycle (a tour) of G with minimum cost.

 Let c(A) denote the total cost of the edges in the subset A ⊆ E.
c(u, v)
c(A) = (u,v)∈A

 The cost function c satisfies the triangle inequality if for all vertices
u, v, w ∈ V, c(u, w) ≤ c(u, v) + c(v, w).

 TSP is an NP-complete problem.

Dr. Pratyay Kuila, NIT Sikkim 9


Algorithm: Approx-TSP(G, c)
===========================================
1) Select a vertex r ∈V [G] to be a “root” vertex.
2) Compute a minimum spanning tree T for G from root r
using MST-PRIM(G, c, r).
3) Let H be a list of vertices, ordered according to when they
are first visited in a pre-order tree walk of T.
4) Return the hamiltonian cycle H.

Dr. Pratyay Kuila, NIT Sikkim 10


Example: Approximate TSP (1)

A complete undirected graph. A minimum spanning tree T of the


The cost function between two complete graph, as computed by
points is the ordinary Euclidean MST-PRIM. Vertex a is the root
distance. vertex.

Dr. Pratyay Kuila, NIT Sikkim 11


Example: Approximate TSP (2)
A walk of T, starting at a. A full walk of
the tree visits the vertices in the order a,
b, c, b, h, b, a, d, e, f, e, g, e, d, a.

A pre-order walk of T lists a vertex


just when it is first encountered, as
indicated by the dot next to each vertex,
yielding the ordering a, b, c, h, d, e, f, g.

Dr. Pratyay Kuila, NIT Sikkim 12


Example: Approximate TSP (3)

A tour obtained by visiting the


An optimal tour H* for the
vertices in the order given by the
original complete graph.
pre-order walk, which is the tour H
returned by APPROX-TSP-TOUR.

Dr. Pratyay Kuila, NIT Sikkim 13


ATSP is 2-approximation algorithm (1)
Theorem: APPROX-TSP-TOUR is a 2-approximation algorithm for the
traveling-salesman problem with the triangle inequality.
Proof:
 Let H* denotes an optimal tour for the given set of vertices.
 If an edge is removed from H*, the result is a spanning tree, say Ts. Thus,
c(Ts) ≤ c(H*).
 Let T be a minimum spanning tree. Then, c(T) ≤ c(Ts).
 Thus, c(T) ≤ c(H*).

 Let W be a full walk of T.


 Then, W lists the vertices when they are first visited and also whenever
they are returned to after a visit to a sub-tree.
 Since the full walk traverses every edge of T exactly twice, c(W) = 2c(T ).
 From c(T) ≤ c(H*) and c(W) = 2c(T ), we get c(W) ≤ 2c(H*).

Dr. Pratyay Kuila, NIT Sikkim 14


ATSP is 2-approximation algorithm (2)
Proof: (Cont…)
 However, W is not a tour, since it visits some vertices more than once.
 By the triangle inequality, we can delete a visit to any vertex from W and
the cost does not increase. (If a vertex v is deleted from W between visits to
u and w, the resulting ordering specifies going directly from u to w.)
 By repeatedly applying this operation, we can remove from W all but the
first visit to each vertex. In previous example, this leaves the ordering a, b,
c, h, d, e, f, g.
 Let H be the cycle corresponding to this preorder walk.
 H is a Hamiltonian cycle, because every vertex is visited exactly once.
 Since H is obtained by deleting vertices from the full walk W, c(H) ≤ c(W).
 c(H) ≤ 2c(H*) since c(H) ≤ c(W) & c(W) ≤ 2c(H*).
That is, APPROX-TSP-TOUR is a 2-approximation algorithm.

Dr. Pratyay Kuila, NIT Sikkim 15


• Let T = {t1, t2…, tn} be the set of tasks.

• Let M = {m1, m2…, mp} be the set of machines where, n > p.


• τi denotes the time required to finish the task ti, ti  T, τi ℚ where ℚ be the
set of rational numbers.
• Gi denotes the set of machines. Here, the task ti can only be assigned to any
one of the machine from Gi, where Gi ⊆ M. For example, Gr = {m1, m3, m7}
means that tr can be assigned to any one of the m1, m3 or m7.
• Wj denotes the overall completion time of the machine mj.
• Now, we address the problem of task scheduling, where our main objective is
to minimize the overall maximum completion time of the machines, i.e.,

Minimize W ={ Wi | ∀mi  M }

Dr. Pratyay Kuila, NIT Sikkim 16


Algorithm: ApproxTaskScheduling
=============================================
Step 1: Sort the tasks T = {t1, t2…, tn} in decreasing order on their
finishing time τi .
Step 2: for i = 0 to p
CT [i]= 0;
Step 3: while (T ≠ NULL) do
3.1: Select successive task (say ti) from T.
3.2: Select the machine (say mk) from Gi with minimum
completion time, CT.
3.3: CT [k] = CT [k] + τi.
3.4: Assign ti to mk and delete ti from T.
Step 3: Stop.

Dr. Pratyay Kuila, NIT Sikkim 17


Lemma 1: The algorithm ApproxTaskScheduling is a 1.5-Approximation algorithm.
Proof:
 Let OPT be the maximum finishing time of a machine in an optimal solution.
Obviously, OPT ≥ τi .
 mi be the machine with maximum finishing time, i.e., Wi = Max{Wj |∀mj  M}.
 tr be the last task assigned to mi. (Therefore, before the assignment, mi had the
smallest finishing time.)
 I denotes the smallest instance of the problem (where algorithm conflicts with
optimal solution).
 As we are assuming that I is the smallest instance, so the algorithm conflicts
with optimal solution only after assignment of tr.

Dr. Pratyay Kuila, NIT Sikkim 18


Lemma 1: The algorithm ApproxTaskScheduling is a 1.5-Approximation algorithm.
Proof: (Cont…)

 Without loss of generality, we may assume that at least one machine (specially
mi ) is assigned by two tasks or more (Why?).
 This implies that , τr ≤ OPT (I)/2 as tr is the least execution time task (How?).
 Therefore, before assignment of tr, finish time of mi was (Wi  τr), which is less
than or equal to OPT(I).
So,
Wi  τr ≤ OPT (I).
i.e., Wi ≤ OPT (I) + τr .
i.e., Wi ≤ OPT (I) + OPT (I) /2 [ As, τr ≤ OPT (I)/2]
i.e., Wi ≤ 1.5OPT (I)

So, the algorithm is never more than a factor 1.5 from optimal solution.
Therefore it is a 1.5-Approximation algorithm.

Dr. Pratyay Kuila, NIT Sikkim 19


Task scheduling without sorting.

Algorithm: 2-ApproxTaskScheduling
=============================================
Step 1: Sort the tasks T = {t1, t2…, tn} in decreasing order on their
finishing time τi .
Step 2: for i =0 to p
CT [i]=0;
Step 3: while (T ≠ NULL) do
3.1: Select successive task (say ti) from T.
3.2: Select the machine (say mk) from Gi with minimum
completion time, CT.
3.3: CT [k]=CT [k]+ τi.
3.4: Assign ti to mk and delete ti from T.
Step 3: Stop.

Dr. Pratyay Kuila, NIT Sikkim 20


An Illustration: Let us assume T = {t1, t2…, t13} with all τi =1 except τ13 = 4 and
M = {m1, m2…, m4}. Scheduling using both the algorithms is as follow.

Using 1.5-ApproxTaskScheduling Using 2-ApproxTaskScheduling


algorithm algorithm

Dr. Pratyay Kuila, NIT Sikkim 21


Lemma 2: The algorithm 2ApproxTaskScheduling is a 2-Approximation algorithm.
Proof:
 (The first part is same as the previous proof of Lemma 1.)
 Without loss of generality, we may assume that at least one machine (specially
mi ) is assigned by two tasks or more (Why?).
 This implies that, τr ≤ OPT (I)/2 as tr is the least execution time task τr ≤ OPT
(I).
 Therefore, before assignment of tr, finish time of mi was (Wi  τr), which is less
than or equal to OPT(I). So,
Wi  τr ≤ OPT (I).
i.e., Wi ≤ OPT (I) + τr .
i.e., Wi ≤ OPT (I) + OPT (I)
i.e., Wi ≤ 2OPT (I)

So, the algorithm is never more than a factor 2 from optimal solution.
Therefore it is a 2-Approximation algorithm.

Dr. Pratyay Kuila, NIT Sikkim 22


1. What if the set of tasks has dependency? Design an approximation
algorithm for task scheduling with task dependency. Assume that a task can
be assigned to any machine.

 The workflow of such dependent tasks is represented as directed acyclic


graph (DAG), G = {T, E}, where T is the set of tasks and E is the set of edges
representing the precedence constraints amongst the tasks.
 An edge(ti, tj) = (ti  tj)  E represents the dependency between the task ti
and task tj.
 This implies that the execution of tj can only be started after completion of
the task ti, i.e., the execution of the subtask tj is solely dependent on the
output of the ti.
Dr. Pratyay Kuila, NIT Sikkim 23
Problem: An instance(X, F) of the set-covering problem consists of a finite set
X and a family F of subsets of X such that every element of X belongs to at least
one subset in F:
X  S
S F

We say that a subset S  F covers its elements. The problem is to find a


minimum-size subset C ⊆ F whose members covers all of X:

X  S
S C
We say that C covers X.

Dr. Pratyay Kuila, NIT Sikkim 24


An Example:
• The set X Consists of 12 black
points

• Given F= {S1, S2, S3, S4, S5, S6}

• Minimum Size Set Cover:


C = {S3, S4, S5}

Dr. Pratyay Kuila, NIT Sikkim 25


Algorithm Greedy-Set-cover(X, F)
{
U X
C 

While U≠ Φ
{
Select an S ∈ F that maximizes |S ∩ U |
U U  S
C  C  {S }
}
Return C
}

• Greedy Approximate Solution of the previous problem is {S1, S4, S5, S3}
• Approximation ratio?

Dr. Pratyay Kuila, NIT Sikkim 26


References:

1. T. H. Cormen, C. E. Leiserson, R. L. Rivest, Introduction to Algorithms,


Prentice hall.
2. Jon Kelinberg and Eva Tardos, Algorithm Design, Pearson

Dr. Pratyay Kuila, NIT Sikkim 27

You might also like