11ApproximationAlgorithms 2x2
11ApproximationAlgorithms 2x2
ρ-approximation algorithm.
Guaranteed to run in poly-time.
Guaranteed to solve arbitrary instance of the problem
Guaranteed to find solution within ratio ρ of true optimum.
1 2
Load Balancing
11.1 Load Balancing Input. m identical machines; n jobs, job j has processing time tj.
Job j must run contiguously on one machine.
A machine can process at most one job at a time.
Def. The makespan is the maximum load on any machine L = maxi Li.
4
Load Balancing: List Scheduling Load Balancing: List Scheduling Analysis
List-Scheduling(m, n, t1,t2,…,tn) {
for i = 1 to m { Lemma 1. The optimal makespan L* ≥ maxj tj.
Li ← 0 load on machine i
jobs assigned to machine i
Pf. Some machine must process the most time-consuming job. ▪
J(i) ← φ
}
Lemma 2. The optimal makespan L * " m1 # j t j .
for j = 1 to n {
machine i has smallest load
Pf.
i = argmink Lk
J(i) ← J(i) ∪ {j} assign job j to machine i The total processing time is Σj tj .
Li ← Li + tj update load of machine i One of m machines must
! do at least a 1/m fraction of total work. ▪
}
return J(1), …, J(m)
}
5 6
Load Balancing: List Scheduling Analysis Load Balancing: List Scheduling Analysis
Li " tj # m1 $ k Lk
blue jobs scheduled before j = m1 $ k t k
Lemma 1 # L*
Lemma 2
!
0
Li - t j L = Li
7 8
Load Balancing: List Scheduling Analysis Load Balancing: List Scheduling Analysis
Ex: m machines, m(m-1) jobs length 1 jobs, one job of length m Ex: m machines, m(m-1) jobs length 1 jobs, one job of length m
machine 2 idle
machine 3 idle
machine 4 idle
m = 10 machine 5 idle m = 10
machine 6 idle
machine 7 idle
machine 8 idle
machine 9 idle
machine 10 idle
9 10
Longest processing time (LPT). Sort n jobs in descending order of Observation. If at most m jobs, then list-scheduling is optimal.
processing time, and then run list scheduling algorithm. Pf. Each job put on its own machine. ▪
Ex: m machines, n = 2m+1 jobs, 2 jobs of length m+1, m+2, …, 2m-1 and
one job of length m.
13
Input. Set of n sites s1, …, sn and integer k > 0. Input. Set of n sites s1, …, sn and integer k > 0.
Center selection problem. Select k centers C so that maximum Center selection problem. Select k centers C so that maximum
distance from a site to nearest center is minimized. distance from a site to nearest center is minimized.
k=4
Notation.
dist(x, y) = distance between x and y.
dist(si, C) = min c ∈ C dist(si, c) = distance from si to closest center.
r(C) = maxi dist(si, C) = smallest covering radius.
r(C)
15 16
Center Selection Example Greedy Algorithm: A False Start
Ex: each site is a point in the plane, a center can be any point in the Greedy algorithm. Put the first center at the best possible location
plane, dist(x, y) = Euclidean distance. for a single center, and then keep adding centers so as to reduce the
covering radius each time by as much as possible.
Remark: search can be infinite!
Remark: arbitrarily bad!
r(C)
greedy center 1
center
k = 2 centers site
center
site
17 18
Greedy algorithm. Repeatedly choose the next center to be the site Theorem. Let C* be an optimal set of centers. Then r(C) ≤ 2r(C*).
farthest from any existing center. Pf. (by contradiction) Assume r(C*) < ½ r(C).
For each site ci in C, consider ball of radius ½ r(C) around it.
Greedy-Center-Selection(k, n, s1,s2,…,sn) { Exactly one ci* in each ball; let ci be the site paired with ci*.
Consider any site s and its closest center ci* in C*.
C = φ dist(s, C) ≤ dist(s, ci) ≤ dist(s, ci*) + dist(ci*, ci) ≤ 2r(C*).
repeat k times { Thus r(C) ≤ 2r(C*). ▪
Select a site si with maximum dist(si, C) Δ-inequality ≤ r(C*) since ci* is closest center
Add si to C
} site farthest from any center
return C
} ½ r(C) ½ r(C)
19 20
Center Selection
21
Weighted vertex cover. Given a graph G with vertex weights, find a Pricing method. Each edge must be covered by some vertex.
vertex cover of minimum weight. Edge e = (i, j) pays price pe ≥ 0 to use vertex i and j.
2 4
2 9
Lemma. For any vertex cover S and any fair prices pe: ∑e pe ≤ w(S).
2 9 2 9 Pf. ▪
23 24
Pricing Method Pricing Method
Weighted-Vertex-Cover-Approx(G, w) {
foreach e in E
pe = 0 ! pe = wi
e = (i , j )
Figure 11.8
25 26
w(S) = # wi = # # pe $ # # pe = 2 # pe $ 2w(S*).
i" S i" S e=(i, j) i"V e=(i, j) e" E
all nodes in S are tight S ⊆ V, each edge counted twice fairness lemma
prices ≥ 0
!
27
Weighted Vertex Cover Weighted Vertex Cover: IP Formulation
Weighted vertex cover. Given an undirected graph G = (V, E) with Weighted vertex cover. Given an undirected graph G = (V, E) with
vertex weights wi ≥ 0, find a minimum weight subset of nodes S such vertex weights wi ≥ 0, find a minimum weight subset of nodes S such
that every edge is incident to at least one vertex in S. that every edge is incident to at least one vertex in S.
16 B G
7 10 " 0 if vertex i is not in vertex cover
xi = #
$ 1 if vertex i is in vertex cover
6 C
3 H 9 Vertex covers in 1-1 correspondence with 0/1 assignments:
S = {i ∈ V : xi = 1}
23
!
D I 33
Objective function: maximize Σi wi xi.
7 E J
10 32
Must take either i or j: xi + xj ≥ 1.
total weight = 55
29 30
Weighted vertex cover. Integer programming formulation. INTEGER-PROGRAMMING. Given integers aij and bi, find integers xj that
satisfy:
( ILP) min # wi xi n
i " V max c t x " aij x j # bi 1$ i $ m
s. t. xi + x j $ 1 (i, j) " E s. t. Ax " b
j=1
xj # 0 1$ j $ n
xi " {0,1} i " V x integral
xj integral 1 $ j $ n
!
!
Observation. If x* is optimal solution to (ILP), then S = {i ∈ V : x*i = 1} Observation. Vertex cover formulation
! proves that integer
is a min weight vertex cover. programming is NP-hard search problem.
even if all coefficients are 0/1 and
at most two variables per inequality
31 32
Linear Programming LP Feasible Region
Linear.
! No x2, xy, arccos(x), x(1-x), etc.
!
Weighted vertex cover. Linear programming formulation. Theorem. If x* is optimal solution to (LP), then S = {i ∈ V : x*i ≥ ½} is a
vertex cover whose weight is at most twice the min possible weight.
( LP) min # wi xi
i " V Pf. [S is a vertex cover]
s. t. xi + x j $ 1 (i, j) " E Consider an edge (i, j) ∈ E.
xi $ 0 i "V Since x*i + x*j ≥ 1, either x*i ≥ ½ or x*j ≥ ½ ⇒ (i, j) covered.
LP is a relaxation x*i ≥ ½
35 36
Weighted Vertex Cover
10 √5 - 21
37
Generalized Load Balancing Generalized Load Balancing: Integer Linear Program and Relaxation
Input. Set of m machines M; set of n jobs J. ILP formulation. xij = time machine i spends processing job j.
Job j must run contiguously on an authorized machine in Mj ⊆ M.
Job j has processing time tj. (IP) min L
Each machine can process at most one job at a time. s. t. " x i j = tj for all j # J
i
" xi j $ L for all i # M
Def. Let J(i) be the subset of jobs assigned to machine i. The j
load of machine i is Li = Σj ∈ J(i) tj. xi j # {0, t j } for all j # J and i # M j
xi j = 0 for all j # J and i % M j
Def. The makespan is the maximum load on any machine = maxi Li.
LP relaxation.
!
(LP) min L
Generalized load balancing. Assign each job to an authorized machine
s. t. " x i j = tj for all j # J
to minimize makespan. i
" xi j $ L for all i # M
j
xi j % 0 for all j # J and i # M j
xi j = 0 for all j # J and i & M j
39 40
Generalized Load Balancing: Lower Bounds Generalized Load Balancing: Structure of LP Solution
Lemma 1. Let L be the optimal value to the LP. Then, the optimal Lemma 3. Let x be solution to LP. Let G(x) be the graph with an edge
makespan L* ≥ L. from machine i to job j if xij > 0. Then G(x) is acyclic.
Pf. LP has fewer constraints than IP formulation.
can transform x into another LP solution where
Pf. (deferred) G(x) is acyclic if LP solver doesn't return such an x
Lemma 2. The optimal makespan L* ≥ maxj tj.
Pf. Some machine must process the most time-consuming job. ▪
xij > 0
machine
41 42
Rounded solution. Find LP solution x where G(x) is a forest. Root Lemma 5. If job j is a leaf node and machine i = parent(j), then xij = tj.
forest G(x) at some arbitrary machine node r. Pf. Since i is a leaf, xij = 0 for all j ≠ parent(i). LP constraint
If job j is a leaf node, assign j to its parent machine i. guarantees Σi xij = tj. ▪
If job j is not a leaf node, assign j to one of its children.
Lemma 6. At most one non-leaf job is assigned to a machine.
Lemma 4. Rounded solution only assigns jobs to authorized machines. Pf. The only possible non-leaf job assigned to machine i is parent(i). ▪
Pf. If job j is assigned to machine i, then xij > 0. LP solution can only
assign positive value to authorized machines. ▪
job job
machine machine
43 44
Generalized Load Balancing: Analysis Generalized Load Balancing: Flow Formulation
!
– parent(i)
! tparent(i) " L *
Thus, the!overall load Li ≤ 2L*. ▪ Observation. Solution to feasible flow problem with value L are in one-
to-one correspondence with LP solutions of value L.
45 46
Lemma 3. Let (x, L) be solution to LP. Let G(x) be the graph with an Running time. The bottleneck operation in our 2-approximation is
edge from machine i to job j if xij > 0. We can find another solution (x', solving one LP with mn + 1 variables.
L) such that G(x') is acyclic.
Remark. Can solve LP using flow techniques on a graph with m+n+1 nodes:
Pf. Let C be a cycle in G(x). given L, find feasible flow if it exists. Binary search to find L*.
Augment flow along the cycle C. flow conservation maintained
1 5 5
4 3 4 4
augment along C
G(x) G(x')
47 48
Polynomial Time Approximation Scheme
11.8 Knapsack Problem PTAS. (1 + ε)-approximation algorithm for any constant ε > 0.
Load balancing. [Hochbaum-Shmoys 1987]
Euclidean TSP. [Arora 1996]
This section. PTAS for knapsack problem via rounding and scaling.
50
Knapsack problem. KNAPSACK: Given a finite set X, nonnegative weights wi, nonnegative
Given n objects and a "knapsack." values vi, a weight limit W, and a target value V, is there a subset S ⊆ X
Item i has value vi > 0 and weighs wi > 0. we'll assume wi ≤ W such that:
Knapsack can carry weight up to W. # wi $ W
i"S
Goal: fill knapsack so as to maximize total value.
# vi % V
i"S
Item Value Weight
Ex: { 3, 4 } has value 40.
1 1 1 SUBSET-SUM: Given a finite set X, nonnegative values ui, and an integer
2 6 2 U, is there a subset S ⊆!X whose elements sum to exactly U?
W = 11
3 18 5
4 22 6 Claim. SUBSET-SUM ≤ P KNAPSACK.
5 28 7
Pf. Given instance (u1, …, un, U) of SUBSET-SUM, create KNAPSACK
instance:
vi = wi = ui # ui $ U
i"S
V = W =U # ui % U
i"S
51 52
!
Knapsack Problem: Dynamic Programming 1 Knapsack Problem: Dynamic Programming II
Def. OPT(i, w) = max value subset of items 1,..., i with weight limit w. Def. OPT(i, v) = min weight subset of items 1, …, i that yields value
Case 1: OPT does not select item i. exactly v.
– OPT selects best of 1, …, i–1 using up to weight limit w Case 1: OPT does not select item i.
Case 2: OPT selects item i. – OPT selects best of 1, …, i-1 that achieves exactly value v
– new weight limit = w – wi Case 2: OPT selects item i.
– OPT selects best of 1, …, i–1 using up to weight limit w – wi – consumes weight wi, new value needed = v – vi
– OPT selects best of 1, …, i-1 that achieves exactly value v
# 0 if i = 0 $ 0 if v = 0
%
OPT(i, w) = $ OPT(i "1, w) if wi > w &
& " if i = 0, v > 0
% max OPT(i "1, w), v + OPT(i "1, w " w ) otherwise OPT (i, v) = %
& { i i } OPT (i #1, v) if vi > v
&
&' min { OPT (i #1, v), wi + OPT (i #1, v # vi ) } otherwise
Running time. O(n W).
W = weight limit.
! V* ≤ n vmax
Not polynomial in input size!
! Running time. O(n V*) = O(n2 vmax).
V* = optimal value = maximum v such that OPT(n, v) ≤ W.
Not polynomial in input size!
53 54
#v % #v %
Intuition for approximation algorithm. Knapsack FPTAS. Round up all values: vi = $ i & ", vˆi = $ i &
$"& $"&
Round all values up to lie in smaller range.
Run dynamic programming algorithm on rounded instance. – vmax = largest value in original instance
Return optimal items in rounded instance. – ε = precision parameter
!
– θ = scaling factor = ε vmax / n
W = 11 W = 11 ! #v % #n%
vˆmax = $ max & = $ &
$ " & $'&
original instance rounded instance !
55 56
!
Knapsack: FPTAS
#v %
Knapsack FPTAS. Round up all values: vi = $ i & "
$"& Extra Slides
! always round up
# vi $ # vi
i " S* i " S*
$ # vi + n% |S| ≤ n
i" S DP alg can take vmax
57
Claim. Load balancing is hard even if only 2 machines. Theorem. Unless P = NP, there is no ρ-approximation algorithm for
Pf. NUMBER-PARTITIONING ≤ P LOAD-BALANCE. metric k-center problem for any ρ < 2.
59 60