150 likes | 227 Views
Efficient Algorithms for the 2 - Center Problems. Tadao Takaoka Department of Computer Science University of Canterbury New Zealand. Absolute 2-center and average 2-center. maximum distance = 2
E N D
Efficient Algorithms for the 2-Center Problems Tadao Takaoka Department of Computer Science University of Canterbury New Zealand
Absolute 2-center and average 2-center • maximum distance • = 2 • average distance • = 9/8 = 1.125 fred12
3-center problem • dis:distance from C to v u : fire stations • graph G • v • u • v center C • u u • v • Minimize abs(C) = max of red lines, ave(C) = sum of red lines • thick red v: houses
Basic definitions • Let G=(V, E) be a directed graph with edge costs of non-negative real numbers. d*(u, v) is the shortest distance from vertex u to v • dis(C, v) = min{d*(u, v) | u in C} • abs(C) = max{dis(C, v) | v in V} absolute measure • ave(C) = ∑v in V dis(C, v) average measure • cabs = min{abs(C) | C ⊆ V |C|=k }: absolute k-center problem • cave = min{ave(C) | C ⊆ V |C|=k }: average k-center problem • Both problems are NP-complete for general k and n
Primitive algorithm for the absolute k-center • begin{algorithm} k-Center with absolute measure • 1. Solve the APSP problem by any fast algorithm • 2. opt_value=999 (infinity) • 3. for C subset V such that |C|=k do { /* O(nk) */ • 4. abs=-999 • 5. for v in V do { /* O(n) */ • 6. dis=999 • 7. for u in C do dis=min{dis, d*(u, v)} /* O(k) */ • 8. abs=max{abs, dis} • } • 9. opt_value=min{opt_value, abs} • } • 10.cabs=opt_value • end{algorithm}
Primitive algorithm for the average k-center • begin{algorithm} k-Center with absolute measure • 1. Solve the APSP problem by any fast algorithm • 2. opt_value=999 (infinity) • 3. for C subset V such that |C|=k do { • 4. ave=0 • 5. for v in V do { • 6. dis=999 • 7. for u in C do dis=min{dis, d*(u, v)} • 8. ave=ave + dis • } • 9. opt_value=min{opt_value, abs} • } • 10. cave=opt_value • end{algorithm}
Analysis of the k-center problemThe two problems have the same complexity • The all pairs shortest path (APSP) problem takes O(M(n)) time, which is sub-cubic. • Loop from line 3 is executed O(nk) times. • Loop from line 5 is executed O(n) times. • Line 7 takes O(k) time. • In total, time is O(M(n) + knk+1), which is O(n3) when k=2. That is, the 2-center problem takes O(n3), cubic, time. The purpose of this research is to bring this complexity down to sub-cubic. • Slightly sub-cubic time for k=2 with time=O(n3loglogn/logn)
Similar to matrix multiplication C=AB c(i, j)=∑k=1, na(i, k)b(k, j) for all i, j • D*={d*(i,j)} shortest distance fro i to j • D’=DT (D transposed), d'(i, j)=d*(j, i) • i, j correspond to fire stations, k correspond to houses • abs(i, j)=maxk=1, n{min{d*(i, k), d'(k, j)}} for all i, j o(n3) • cabs=min i=1,n;j=1,n{abs(i, j)} O(n2) • ave(i, j)=∑k=1, nmin{d*(i, k), d'(k, j)} for all i, j o(n3) • cave=min i=1,n;j=1,n{ave(i, j)} O(n2)
Matrix multiplication by divide and conquer • C=AB N=n/m Aij is an (m, m) matrix • A11 … A1N B11 … B1N C11 … C1N • … … = … • AN1 … ANN BN1 … BNN CN1 … CNN • Cij = ∑k=1, N Aik•Bkj for i, j = 1, …, N • For each Aik•Bkj time, T(m)=O(m2) • Total time = N3T(m)=(n/m)3m2=n3/m.
(max, min)-multiplication and (∑,min)-multiplicationfor small (m, m)-matrices A and B • cij = maxk=1,m{min {aik, bkj}}, (i, j =1, ..., m) • cij = ∑k=1,m{min{aik, bkj}}, (i, j =1, ..., m) • For each (i, j), cij is computed in O(1) time by table look-up. Let M={1, …, m} • S(i, j) = {k | aik ≤ bkj}, T(i, j) = {k | aik > bkj} • maxk=1,n{min{aik, bkj}} = max{maxk in S(i, j){aik}, maxk in T(i, j){bkj}} • h(x) packs binary vector x into an integer. • Use the following table with set(x)=S(i, j) and set(x)=T(i, j). • Table MAXia(h(x))=maxk in set(x){aik}, precompute for all h(x) • MAXjb(h(x))=maxk in set(x){bkj}, precompute for all h(x)
Preproccessing for tables • Sort k-th column of A and k-th row of B and let them be Ek and Fk. Let merged list be Gk • Let Hk and Lk be the lists of ranks in merged lsit Gk of k-th column of A and k-th row of B. We have Gk(Hk(i))=aik, Gk(Lk(j))=bkj, • that is, aik ≤ bkj Hk(i) ≤ Lk(j). • Pack (H1(i), …, Hm(i)) and (L1(j), …, Lm(j)) into single integers for i=1, …, m; j=1, …, m.
Precomputation • Let H(i)=(H1(i), …, Hm(i)) and L(j)=(L1(j), …, Lm(j). Let those numbers be h(H(i)) and h(L(j)). • We define table MAP(h(H), h(L))=h(x) such that x[k]=1 Hk ≤ Lk for binary vector x. • Use x for set(S(i, j)) and x’ for set(T(i, j)) in packed forms. • For the average distance, MAX is replaced by SUM, that is, • SUMia(h(x)) = ∑k in set(x){aik} • SUMjb(h(x)) = ∑k in set(x){bkj}
Example • A = 31 9 21 13 B= 2 4 15 8 merge sorted 1st column of A • 12 7 4 23 18 15 6 9 and sorted 1st row of B • 6 5 71 3 12 9 11 18 G=(2,4,6,8,8,12,15,31) • 8 14 16 15 5 1 20 25 H=(8,6,3,4), L=(1,2,7,5) • H = 8 4 7 4 L = 1 2 7 5 i=2, j=3 • 6 3 1 7 8 7 2 5 • 3 1 8 2 4 2 3 6 • 4 6 5 5 3 1 6 8 • h(H(2))=6317, h(L(3))=7236 MAP(6317, 7236)=h(1,0,1,0) • xij=(1,0,1,0), x’ij=(0,1,0,1) • max{MAXia(h(1,0,1,0)), MAXjb(h(0,1,0,1))} • = max{max{12, 4}, max{6, 20}}=20 • {SUMia(h(1,0,1,0)) + SUMjb(h(0,1,0,1))} • = {{12 + 4} + {6 + 20}}=42
Algorithm by binary search • [α, β] : range for solution α t β • α=0; β=n (α+β)/2 • while β - α > 0 { • t = (α+β)/2 • b[i, j]=1 if d*[i,j]>t, 0 otherwise for i, j=1,..., n • Compute C = B x B /* Boolean matrix multiplication/* • if c[i, j] > 0 for some i and j • then α = (α+β)/2 • else β = (α+β)/2 • } • cabs=α • Time = O(M(n)+B(n)log n), M(n)=O(n2.575), B(n)=O(n2.376) • M(n) for APSP, B(n) for Boolean matrix multiplication
Conclusion and future research • Deep sub-cubic for the average 2-center. • More sub-cubic with faster APSP. O(n3(loglogn)3/log2n) by Chan. • Approximation algorithm for k-center based on 2-center. Possible scenario: Solve 2-center. Classify vertices closer to a center (set V1), and vertices closer to the other (set V2). If the measure for V1 is greater, allpy 2-center on V1, otherwise on V2. Keep going to have k centers.What is the approximation ratio of this method?