Rahul Singhal, Nimantha Baranasuriya, Karthik Yadati, Girisha De Silva, Zhou Ziling Online Algorithms Today’s Outline Introduction Hiring Problem k-Server Problem Introduction to Online Algorithms Online Algorithms • Work without full knowledge of the future • Deal with a sequence of events • Future events are unknown to the algorithm • The algorithm has to deal with one event at each time. • The next event happens only after the algorithm is done dealing with the previous event A Service (1) ( 2)... (t ) (t 1) Goal : Minimize total cost incurred in serving 𝜎 The Paging/Caching Problem A A Page Fault: Requested page is not in fast memory Fast Memory Service (1) ( 2)... (t ) (t 1) Access to a page in the memory system Slow Memory 𝜎 = 1, 6, 4, 1, 4, 7, 6, 1, 3, … Request sequence of pages Goal: Minimize the total cost incurred in serving 𝜎 Goal: Minimize the number of page faults Online vs. Offline • We compare the behavior of the online algorithm to an optimal offline algorithm, OPT, which is familiar with the sequence • The offline algorithm knows the exact properties of all the events in the sequence Absolute Competitive Ratio • We measure the performance of an online algorithm by the competitive ratio • This is the ratio between what the online algorithms pays to what the optimal offline algorithm pays Absolute Competitive Ratio • Formally: let 𝐴𝐿𝐺(𝜎) be the cost of the online algorithm on the sequence 𝜎. Let 𝑂𝑃𝑇 𝜎 be the optimal offline cost on 𝜎. Then the competitive ratio is: ALG ( ) CR OPT ( ) Types of Online Algorithms • Randomization • Deterministic INPUT ALGORITHM OUTPUT INPUT ALGORITHM OUTPUT RANDOM NUMBERS • Generating same output for same input • Examples • LIFO, FIFO paging … etc. • In addition to the input, the algorithm takes a source of random numbers and makes random choices during execution • Behavior can vary even on a fixed input • Example • Randomized paging algorithm Adversaries (Bad Guy) • Competitiveness is defined with respect to an adversary • Role of an adversary • It constructs 𝜎 • It also serves 𝜎 • Adversary knows the description of the deterministic online algorithm • What does the adversary know about the random choices made by the randomized online algorithm? Oblivious Adversary • One who must construct the request sequence in advance (based only on the description of the online algorithm but before any moves are made) A Service (1) ( 2)... (t 1) (t ) (m) ADV Adaptive Online Adversary • One who makes the next request based on the algorithm's answers to previous events A Service (1) ( 2)... (t 1) (t ) ADV The Ski Rental Problem • Buying costs $D (never pay again) • Renting costs $1 per day Problem: • Days of skiing(d) is not known in advance • Adversary breaks his knee no more skiing Goal: Minimize the total cost Optimal Offline Ski Rental Algorithm OPT : if d < D, then rent if d >= D, then buy on day 1 • Analysis • COPT = min(d, D) Deterministic Ski Rental online Algorithm Rent until day K Buy skis on day K • Analysis • Adversary breaks legs at day K (d = K) to maximize the cost • Optimize value of K (to minimize the cost) • CALG = K – 1 + D • COPT = min(d, D) = min(K, D) • CR = min ((K -1 + D )/K , (K -1 + D )/D ) • We get K = D ( Buy on day D) Randomized Ski Rental Algorithm Flip a coin (on day 0) heads: buy on D/2 (p = ½) tails: buy on D (p = ½) Adversary breaks legs on day d • Analysis: • Case 1: d < D/2 • COPT = d (Rent d days) • CALG = d (Rent d days) • CR = d/d = 1 Randomized Ski Rental Algorithm Flip a coin (on day 0) heads: buy on D/2 (p = ½) tails: buy on D (p = ½) Adversary breaks legs on day d • Analysis: • Case 2: d = D/2 Buy on D • COPT = d (= D/2) • CALG = ½(D/2) + ½(D + D/2) = D • CR = D/(D/2) = 2 Buy on D/2 Randomized Ski Rental Algorithm Flip a coin (on day 0) heads: buy on D/2 (p = ½) tails: buy on D (p = ½) Adversary breaks legs on day d • Analysis: • Case 3: D/2 < d < D Buy on D Buy on D/2 • COPT = d • CALG = ½(d) + ½(D + D/2) = d/2 + 3D/4 • CR = (d/2 + 3D/4)/d Randomized Ski Rental Algorithm Flip a coin (on day 0) heads: buy on D/2 (p = ½) tails: buy on D (p = ½) Adversary breaks legs on day d • Analysis: • Case 4: d >= D Buy on D • COPT = D • CALG = ½(D + D) + ½(D/2 + D) = (1.75)D • CR = (1.75)D/D = 1.75 Buy on D/2 Randomized Ski Rental Algorithm (Generalized) Flip a biased coin (on day 0) heads: buy on D/2 (p) tails: buy on D (1 - p) Adversary breaks legs on day d • Analysis: • Case 1: d < D/2 • COPT = d (Rent d days) • CALG = d (Rent d days) • CR = d/d = 1 Randomized Ski Rental Algorithm (Generalized) Flip a biased coin (on day 0) heads: buy on D/2 (p) tails: buy on D (1 - p) Adversary breaks legs on day d • Analysis: • Case 2: d = D/2 Buy on D/2 • COPT = d = D/2 • CALG = p(D + D/2) + (1 – p)D/2 • CR = 2p + 1 Buy on D Randomized Ski Rental Algorithm (Generalized) Flip a biased coin (on day 0) heads: buy on D/2 (p) tails: buy on D (1 - p) Adversary breaks legs on day d • Analysis: • Case 3: d = D Buy on D/2 • COPT = d = D • CALG = p(D + D/2) + (1 – p)2D • CR = 2 – p/2 Buy on D Randomized Ski Rental Algorithm (Generalized) Flip a biased coin (on day 0) heads: buy on D/2 (p) tails: buy on D (1 - p) Adversary breaks legs on day d • Optimize: • 2p + 1 = 2 – p/2 • p = 2/5 = 0.4 • CR = 1.8 Hiring Problem Hiring Problem Decision making under Uncertainty The Problem • Hire an employee • Process: • Interview one at a time • Select or reject • Goal: Hire the best candidate The Offline Solution • Has knowledge of all candidates • Just hire the best candidate • Pr(Success) = 1 The Online Algorithm • Interview first t candidates • g = best candidate seen so far • Interview remaining n-t candidates • Hire first candidate better than g Adversary Effect t 4 3 1 2 Adversary Effect t 4 3 1 2 The Online Algorithm • Order candidates by random permutation • Interview first t candidates • g = best candidate seen so far • Interview remaining n-t candidates • Hire first candidate better than g Algorithm Instances t 4 3 1 2 Algorithm Instances t 4 3 1 2 Algorithm Instances t 4 3 1 2 Algorithm Instances t 4 3 1 2 Analysis • Analyze two things • Pr(Success) • t that increases Pr(Success) … 1 4 t 3 … … j 1 n 2 Analysis 𝑆 = 𝐸𝑣𝑒𝑛𝑡 𝑡ℎ𝑎𝑡 𝑤𝑒 𝑠𝑢𝑐𝑐𝑒𝑒𝑑 𝑖𝑛 𝑐ℎ𝑜𝑜𝑠𝑖𝑛𝑔 𝑡ℎ𝑒 𝑏𝑒𝑠𝑡 𝑐𝑎𝑛𝑑𝑖𝑑𝑎𝑡𝑒 𝑆𝑗 = 𝐸𝑣𝑒𝑛𝑡 𝑡ℎ𝑎𝑡 𝑤𝑒 𝑐ℎ𝑜𝑜𝑠𝑒 𝑐𝑎𝑛𝑑𝑖𝑑𝑎𝑡𝑒 𝑗 𝑛 Pr 𝑆 = 𝑛 Pr 𝑆𝑗 = 𝑗=1 … 1 4 t 3 Pr(𝑆𝑗 ) 𝑗=𝑡+1 … … j 1 n 2 Analysis Pr 𝑆𝑗 = Pr 𝑗 𝑖𝑠 𝑡ℎ𝑒 𝑏𝑒𝑠𝑡 . Pr(𝑡ℎ𝑒 𝑎𝑙𝑔𝑜𝑟𝑖𝑡ℎ𝑚 𝑑𝑖𝑑𝑛′ 𝑡 𝑠𝑒𝑙𝑒𝑐𝑡 𝑎𝑛𝑦 𝑐𝑎𝑛𝑑𝑖𝑑𝑎𝑡𝑒 𝑏𝑒𝑡𝑤𝑒𝑒𝑛 𝑡 + 1 𝑎𝑛𝑑 𝑗 − 1) Pr 𝑆𝑗 = Pr 𝑗 𝑖𝑠 𝑡ℎ𝑒 𝑏𝑒𝑠𝑡 . Pr(𝑡ℎ𝑒 𝑏𝑒𝑠𝑡 𝑐𝑎𝑛𝑑𝑖𝑑𝑎𝑡𝑒 𝑎𝑚𝑜𝑛𝑔 𝑡ℎ𝑒 𝑓𝑖𝑟𝑠𝑡 𝑗 − 1 𝑐𝑎𝑛𝑑𝑖𝑑𝑎𝑡𝑒𝑠 𝑤𝑎𝑠 𝑖𝑛 𝑡ℎ𝑒 𝑓𝑖𝑟𝑠𝑡 𝑡 𝑠𝑙𝑜𝑡𝑠) … 1 4 t 3 … … j 1 n 2 Analysis Pr 𝑆𝑗 = Pr 𝑗 𝑖𝑠 𝑡ℎ𝑒 𝑏𝑒𝑠𝑡 . Pr(𝑡ℎ𝑒 𝑏𝑒𝑠𝑡 𝑐𝑎𝑛𝑑𝑖𝑑𝑎𝑡𝑒 𝑎𝑚𝑜𝑛𝑔 𝑡ℎ𝑒 𝑓𝑖𝑟𝑠𝑡 𝑗 − 1 𝑐𝑎𝑛𝑑𝑖𝑑𝑎𝑡𝑒𝑠 𝑖𝑠 𝑖𝑛 𝑡ℎ𝑒 𝑓𝑖𝑟𝑠𝑡 𝑡 𝑠𝑙𝑜𝑡𝑠) 1 𝑘 Pr 𝑆𝑗 = . 𝑛 𝑗 −1 … 1 4 k 3 𝑛 ⇒ Pr 𝑆 = 𝑗=𝑡+1 … 1 𝑡 . 𝑛 𝑗 −1 … j 1 n 2 Analysis Pr 𝑆𝑗 = Pr 𝑗 𝑖𝑠 𝑡ℎ𝑒 𝑏𝑒𝑠𝑡 . Pr(𝑡ℎ𝑒 𝑏𝑒𝑠𝑡 𝑐𝑎𝑛𝑑𝑖𝑑𝑎𝑡𝑒 𝑎𝑚𝑜𝑛𝑔 𝑡ℎ𝑒 𝑓𝑖𝑟𝑠𝑡 𝑗 − 1 𝑐𝑎𝑛𝑑𝑖𝑑𝑎𝑡𝑒𝑠 𝑖𝑠 𝑖𝑛 𝑡ℎ𝑒 𝑓𝑖𝑟𝑠𝑡 𝑘 𝑠𝑙𝑜𝑡𝑠) 1 𝑡 Pr 𝑆𝑗 = . 𝑛 𝑗 −1 … 1 4 k 3 𝑛 ⇒ Pr 𝑆 = 𝑗=𝑡+1 … 1 𝑡 . 𝑛 𝑗 −1 … j 1 n 2 Analysis 𝑛 Pr 𝑆 = 𝑗=𝑡+1 𝑡 Pr 𝑆 = 𝑛 𝑛 𝑡 𝑛 𝑗=𝑡+1 1 𝑑𝑥 ≤ 𝑥 1 𝑡 . 𝑛 𝑗 −1 1 𝑗 −1 𝑛−1 𝑗=𝑡 1 ≤ 𝑗 𝑡 = 𝑛 𝑛−1 𝑡−1 𝑛−1 𝑗=𝑡 1 𝑗 1 𝑑𝑥 𝑥 𝑡 𝑡 (ln 𝑛 − ln 𝑡) ≤ Pr 𝑆 ≤ (ln 𝑛 − 1 − ln(𝑡 − 1)) 𝑛 𝑛 Analysis 𝑡 𝑡 (ln 𝑛 − ln 𝑡) ≤ Pr 𝑆 ≤ (ln 𝑛 − 1 − ln(𝑡 − 1)) 𝑛 𝑛 𝑛 𝑡= 𝑒 1 ≤ Pr(𝑆) 𝑒 Competitive Ratio • Cost = Number of runs needed to succeed • COPT = 1 • CALG = 𝑒 • 𝐶𝐴𝐿𝐺 𝐶𝑜𝑚𝑝𝑒𝑡𝑖𝑡𝑖𝑣𝑒 𝑅𝑎𝑡𝑖𝑜 = 𝐶𝑂𝑃𝑇 = 𝑒 1 = 𝑒 k-Server Problem k-Server Problem Outline • Introduction to the k-Server problem • Preliminaries • Optimal offline algorithm • Balanced algorithm (BAL) • Lower bound for CR • State-of-the-art k-Server algorithm The Problem • Let 𝐺 be an n-vertex graph with positive edge lengths obeying the triangle inequality, and let 𝑘 mobile servers occupy vertices of 𝐺 • Then, • Planning the motion of 𝑘 mobile servers on the vertices of a graph under a sequence of requests for service is the k-server problem • Goal • Minimize the cost that incurs because of the movement of the server(s) The Problem S1 B D C E A S2 Request-Sequence (𝜎)= { A, B, E, …….. } The Problem • k-server algorithms are defined on metric spaces! • The graph • Should consist of positive edge lengths • Must obey the triangle inequality • Initial location of the servers are specified • Each Request • Specifies a vertex • Satisfying a request requires a server to be placed in the specified vertex The Problem • The request sequence • Should be satisfied in-order • The cost of satisfying is the total distance moved by the servers • The k-server problem is • symmetric if for all vertices 𝑖 and 𝑗, the distance from 𝑖 to 𝑗 is equal to the distance from 𝑗 to 𝑖 • asymmetric otherwise The Online k-Server Problem • An Online k-server problem • Operates under an additional constraint • Must decide which server to move to satisfy a given request without knowing the future requests Example: Paging Problems • Two level memory system • k pages in the fast memory • Total n pages of memory • Page faults could occur! • Goal: replace a page in the fast memory to minimize the number of page faults Example: Paging Problem Y S1 X Z W S2 {x, z , w...} Examining the k-Server problem • Competitiveness • A given algorithm is competitive if its c-competitive for some constant 𝒄 • Let 𝐶𝐴 (𝜎) denote the cost incurred by an algorithm A in satisfying a request sequence 𝜎 then • An online algorithm B is c-competitive if, for all offline alg. 𝐴 and σ, 𝐶𝐵 𝜎 ≤ 𝑐. 𝐶𝐴 𝜎 + 𝑎 Preliminaries • Triangle inequality + symmetry V W U Triangle inequality : 𝑑𝑢,𝑤 ≤ 𝑑𝑢,𝑣 + 𝑑𝑣,𝑤 symmetry : for all 𝑖 and 𝑗 (where 𝑖, 𝑗 ∈ 𝑉) 𝑑𝑖,𝑗 = 𝑑𝑗,𝑖 Preliminaries • The Lazy Algorithm • An algorithm B is called lazy if it moves a single server to handle each request at an unoccupied vertex, but does not move otherwise! Preliminaries: The Lazy Algorithm S1 X Y W Z {x, z , w...} S2 Preliminaries • Lemma 1: • For any algorithm 𝑩, there exists a modified algorithm 𝑩′ that is lazy, does not cost more, and is online if 𝑩 is • The lemma establishes that • We may restrict our attention to lazy algorithms Preliminaries • Lemma 2: • If 𝑩 is a server algorithm that ignores all requests to covered vertices and is c-competitive on all of its hard request sequences, then 𝑩 is c-competitive • Lemma 1 and 2 show that in-order to prove that our algorithms are competitive, it is sufficient to compare them to lazy algorithms on hard sequences Optimal Offline Algorithm • A dynamic programming solution would be sufficient • Let 𝐶𝑂𝑃𝑇 (𝜎, 𝑆) be a function whose value is the cost of a minimum cost algorithm • That handles the request 𝜎 • Ends up in state 𝑆 Optimal Offline Algorithm • Assuming that servers are initially covering a set of vertices 𝑆0 𝐶𝑂𝑃𝑇 𝐶𝑂𝑃𝑇 0, 𝜀, 𝑆 = 𝑢𝑛𝑑𝑒𝑓𝑖𝑛𝑒𝑑, 𝑖𝑓 𝑆 = 𝑆0 𝑜𝑡ℎ𝑒𝑟𝑤𝑖𝑠𝑒 𝑚𝑖𝑛 𝑇 {𝐶𝑂𝑃𝑇 𝜎, 𝑇 + 𝑑 𝑇, 𝑆 }, 𝑖𝑓 𝑣 𝑖𝑠 𝑐𝑜𝑣𝑒𝑟𝑒𝑑 𝑖𝑛 𝑆 𝜎𝑣, 𝑆 = 𝑢𝑛𝑑𝑒𝑓𝑖𝑛𝑒𝑑, 𝑜𝑡ℎ𝑒𝑟𝑤𝑖𝑠𝑒 Optimal Offline Algorithm • Assuming that servers are initially covering a set of vertices 𝑆0 𝐶𝑂𝑃𝑇 𝐶𝑂𝑃𝑇 0, 𝜀, 𝑆 = 𝑢𝑛𝑑𝑒𝑓𝑖𝑛𝑒𝑑, 𝑖𝑓 𝑆 = 𝑆0 𝑜𝑡ℎ𝑒𝑟𝑤𝑖𝑠𝑒 𝑚𝑖𝑛 𝑇 {𝐶𝑂𝑃𝑇 𝜎, 𝑇 + 𝑑 𝑇, 𝑆 }, 𝑖𝑓 𝑣 𝑖𝑠 𝑐𝑜𝑣𝑒𝑟𝑒𝑑 𝑖𝑛 𝑆 𝜎𝑣, 𝑆 = 𝑢𝑛𝑑𝑒𝑓𝑖𝑛𝑒𝑑, 𝑜𝑡ℎ𝑒𝑟𝑤𝑖𝑠𝑒 Will a Greedy Solution Work? • Suppose the following greedy algorithm is proposed for an online k-server problem • Given a request for vertex v, if v is not covered by a server, move a server to vertex v from the closest vertex that is covered k-Server Problem Outline • Introduction to the k-Server problem • Preliminaries • Optimal offline algorithm • Balance(BAL) algorithm • Lower bound for CR • State-of-the-art k-Server algorithm Residues • Call 𝑅𝐶 𝜎, 𝑆 the c-residue function and it is defined as, 𝑅𝑐 𝜎, 𝑆 = 𝑐. 𝐶𝑂𝑃𝑇 𝜎, 𝑆 − 𝐶𝐵 (𝜎) • Function to measure how well an online algorithm B is doing compared to the Optimal Residues: Competitiveness • An online algorithm is B is c-competitive if there exists a constant a such that for any offline alg. 𝐴 and σ, 𝐶𝐵 𝜎 ≤ 𝑐. 𝐶𝐴 𝜎 + 𝑎 • Therefore if there exists some constant 𝑎 such that 𝑅𝑐 𝜎, 𝑆 ≥ −𝑎 for any 𝜎 and 𝑆 then B is said to c-competitive • Our proof for competitiveness will use this approach Balance(BAL) Algorithm: Problem Setting • We have 𝒏 nodes in a graph and 𝒏 − 𝟏 servers to serve the requests • At any time, only one node is uncovered • For an optimal algorithm A and a request sequence σ 𝐶𝐵 𝜎 ≤ 𝑐. 𝐶𝐴 𝜎 + 𝑎 • For the current algorithm, we prove 𝒄 = 𝒏 − 𝟏 Algorithm • For each server, the total distance moved from the start of the sequence • If the server is currently at vertex 𝑖, then 𝐷𝑖 • Consider a request at node 𝑗 • If 𝑗 is already covered, do nothing • Else, move the server on node 𝑖 to node 𝑗 • 𝑖 is chosen to minimize 𝐷𝑖 + 𝑑𝑖𝑗 • Move any server that would have the smallest cumulative cost after moving Example D2 = 11 S3 S4 D4 = 2 3 2 4 D1+d15=8+8=16 D2+d25=11+5=16 D3+d35=10+4=14 D4+d45=2+3=5 6 4 5 D1 = 8 S1 3 7 1 5 8 6 3 D3 = 10 4 5 S2 Request-Sequence (𝜎)= { …….,2, 3, 4, 5, 4, …….. } Example D2 = 11 D4 = 8 S3 3 2 4 6 4 5 D1 = 8 S1 3 7 1 D1+d14=8+6=14 D2+d24=11+3=14 D3+d34=10+5=15 D5+d54=5+3=8 5 8 6 3 D3 = 10 S2 4 5 S4 D5 = 5 Request-Sequence (𝜎)= { …….,2, 3, 4, 5, 4, …….. } Lemma • Let 1 be the most recently covered vertex, n be the uncovered vertex and i be any other vertex −𝑑1𝑖 ≤ 𝐷𝑖 − 𝐷1 ≤ 𝑑𝑖𝑛 − 𝑑1𝑛 • Proof follows.. Lemma - Proof • Proof by induction (claim) • 𝐷𝑖 − 𝐷𝑗 ≤ 𝑑𝑖𝑗 • This is true initially. Suppose it is true up to some point and a new request arrives for vertex 𝑛 Lemma – Proof • Suppose the server moves from node 𝑘, in response to the request • 𝐷𝑘 + 𝑑𝑘𝑛 ≤ 𝐷𝑖 + 𝑑𝑖𝑛 ∀ 𝑖 • Most recently covered vertex = 𝑛 (1’) • New vacant vertex = 𝑘 (𝑛’) • New cumulative distance for the server at 1’ • 𝐷1′ = 𝐷𝑘 + 𝑑𝑘𝑛 ’ • Other cumulative distances are unchanged Lemma – Proof • First, for any i, (𝐷𝑘 + 𝑑𝑘𝑛 ≤ 𝐷𝑖 + 𝑑𝑖𝑛 ∀ 𝑖) 𝐷1′ − 𝐷𝑖 = 𝐷𝑘 + 𝑑𝑘𝑛 − 𝐷𝑖 ≤ 𝑑𝑖𝑛 = 𝑑1′ 𝑖 • Further, 𝐷𝑖 − 𝐷1′ = 𝐷𝑖 − 𝐷𝑘 − 𝑑𝑘𝑛 ≤ 𝑑𝑖𝑘 − 𝑑𝑘𝑛 = 𝑑𝑖𝑛′ − 𝑑1′ 𝑛′ ≤ 𝑑1′ 𝑖 −𝑑1𝑖 ≤ 𝐷𝑖 − 𝐷1 ≤ 𝑑𝑖𝑛 − 𝑑1𝑛 Theorem • The algorithm is an (𝑛 − 1)-competitive algorithm for the symmetric (𝑛 − 1)-server problem on an 𝑛vertex graph • Consider a vector of residues that compares the algorithm’s cost to (𝑛 − 1) times the cost of an optimal algorithm • Proof in Appendix A Disadvantage • • • • Not competitive in metric spaces with 𝑁 > 𝑘 + 1 Example: 𝑁 = 4; 𝑘 = 2 (at 3, 4) and 𝐿 > 𝑙 Request sequence (σ) = {1,2,3,4,1,2,3,4,…,1,2,3,4} Online algorithm pays L for each request, but offline algorithm pays l for first request and m afterwards • Performance ratio L/l (Not competitive) 1 L 4 S1 l 2 3 S2 k-Server Problem Outline • Introduction to the k-Server problem • Preliminaries • Optimal offline algorithm • Balance(BAL) algorithm • Lower bound for CR • State-of-the-art k-Server algorithm 2 Questions • Can we do better than BAL? • Lower bound for competitive ratio • Deterministic algorithm • Randomized algorithm • Is there an algorithm which is good for all metric space? • Work Function Algorithm (WFA) Deterministic Lower Bound • A more general lower bound: • We compare a 𝑘-server online algorithm with a ℎ-server offline algorithm, for any 1 ≤ ℎ ≤ 𝑘 • Let M be any metric space with at least (𝑘 + 1) nodes • 𝑘/(𝑘 − ℎ + 1) is a lower bound on the competitive ratio of any online k-server algorithm for M Deterministic Lower Bound • What can the online algorithm do in BEST: • Pick any 𝑘 + 1 nodes in M • The online algorithm has 𝑘 server, there is 1 node cannot be severed at each step (call it a hole) • Cruel adversary: request the hole at each step • Define 𝑟𝑖 is the ith request, • total cost: 𝑛−1 𝑖=1 𝑑(𝑟𝑖 , 𝑟𝑖+1 ). 𝑟2 𝑟1 𝑟2 𝑟1 𝑟3 Deterministic Lower Bound • For the request sequence {𝑟1 , 𝑟2 , … , 𝑟𝑛 }, what can the offline algorithm do: • Define 𝐵 as a set of offline h-server algorithms, • For each h-subset 𝑆 ⊂ 𝑀, 𝑟1 ∈ 𝑆 , define 𝐵𝑠 ∈ 𝐵 be an offline algorithm that operates as follows: • Start with state 𝑆 • Serve 𝑟𝑖 with the server occupying 𝑟𝑖−1 𝐵𝑠1 𝑟1 𝐵𝑠2 𝑟1 𝐵𝑠3 𝑟1 Deterministic Lower Bound • • If a move is necessary, serve 𝑟𝑖 with the server occupying 𝑟𝑖−1 After each request is processed, different algorithms will always be in different configurations 𝐵𝑠1 𝑟1 𝐵𝑠2 𝑟1 Deterministic Lower Bound • • If a move is necessary, serve 𝑟𝑖 with the server occupying 𝑟𝑖−1 After each request is processed, different algorithms will always be in different configurations 𝐵𝑠1 𝐵𝑠2 𝑟2 𝑟1 𝑟2 𝑟1 Deterministic Lower Bound • How many such algorithms in B that starts with different initial states: • One server must in 𝑟1 , place ℎ − 1 servers into 𝑘 nodes • 𝑘 ℎ−1 different states 𝑟1 𝑟1 𝑟1 Deterministic Lower Bound • For each request 𝑟𝑖 , how many algorithms move from 𝑟𝑖−1 to 𝑟𝑖 ? • • • • The hole (𝑟𝑖 ) is requested One server is on (𝑟𝑖−1 ) Place ℎ − 1 server into 𝑘 − 1 nodes Number of algorithms need to move: • 𝑘−1 ℎ−1 𝑟2 𝑟1 Deterministic Lower Bound • The total cost for all the algorithms in all steps: • 𝑘−1 ℎ−1 𝑛−1 𝑖=1 𝑑(𝑟𝑖 , 𝑟𝑖+1 ) Deterministic Lower Bound • Average performance • 𝑘−1 ℎ−1 𝑘 ℎ−1 • = 𝑛−1 𝑖=1 𝑑 𝑟𝑖 , 𝑟𝑖+1 = 𝑘−ℎ+1 (𝑂𝑛𝑙𝑖𝑛𝑒 𝑘 𝑘−ℎ+1 𝑘 𝑛−1 𝑖=1 𝑑 𝑟𝑖 , 𝑟𝑖+1 𝐶𝑜𝑠𝑡) • Since there is at least one of these algorithms incurs costs no greater than the average, the proof completes Randomized Lower Bound • Adaptive-Online adversary: • A randomized algorithm can be considered as select one algorithm from a set of deterministic algorithms Adversary 𝑩𝑺𝟏 𝐴1 Online-Alg 𝐴2 𝐴3 𝐴4 𝑩𝑺𝟐 𝑩𝑺𝟑 𝑩𝑺𝟒 Randomized Lower Bound • From the results of deterministic algorithm lower bound: • If adversary selects columns uniform randomly, the expected cost is 𝑘−1 ℎ−1 𝑘 ℎ−1 𝑛−1 𝑖=1 𝑑 𝑟𝑖 , 𝑟𝑖+1 = 𝑘−ℎ+1 𝑘 𝑛−1 𝑖=1 𝑑 𝑟𝑖 , 𝑟𝑖+1 Adversary 𝑩𝑺𝟏 𝐴1 Online-Alg 𝐴2 𝐴3 𝐴4 𝑩𝑺𝟐 𝑩𝑺𝟑 𝑩𝑺𝟒 Randomized Lower Bound • If adversary selects columns uniform randomly, the expected cost is 𝑘−1 ℎ−1 𝑘 ℎ−1 𝑛−1 𝑖=1 𝑑 𝑟𝑖 , 𝑟𝑖+1 = 𝑘−ℎ+1 𝑘 𝑛−1 𝑖=1 𝑑 𝑟𝑖 , 𝑟𝑖+1 • There must exist one column such that the cost is less than or equal to the expectation Adversary 𝑩𝑺𝟏 𝐴1 Online-Alg 𝐴2 𝐴3 𝐴4 𝑩𝑺𝟐 𝑩𝑺𝟑 𝑩𝑺𝟒 2 Questions • Can we do better than BAL? • Lower bound for competitive ratio • Deterministic algorithm • Randomized algorithm • Lower bound: 𝑘 𝑘−ℎ+1 • K-server conjecture: • There is an algorithm for solving the k-server problem in an arbitrary metric space and for any number k of servers that has competitive ratio at most k • Is there an algorithm that is good for all metric space? • Work Function Algorithm (WFA) Work Function Algorithm • Goal: To minimize the competitive ratio • Idea: Mimic optimal offline algorithm • Competitive ratio: • 2𝑘 − 1 competitive for all metric spaces • Known to be 𝑘 competitive for some special metric spaces: e.g. all metric space with 𝑘 + 2 points, line, star • Details in Appendix B Summary • Online algorithms • Receive and process the input in partial amounts • Receive a sequence of requests and service each one before servicing the next one • Generate output without knowledge of the entire input • Examples • Ski rental problem, Hiring problem, k-Server problem • Online algorithms are analyzed by comparing its performance to an optimal offline algorithm • Competitive analysis • Real-world applications: • Paging/Caching, Routing, Scheduling Q&A References • [1] Allan Borodin and Ran El-Yaniv. 1998. Online Computation and Competitive Analysis. Cambridge University Press, New York, NY, USA. • [2] Mark S Manasse, Lyle A McGeoch, Daniel D Sleator, Competitive algorithms for server problems, Journal of Algorithms, Volume 11, Issue 2, June 1990, Pages 208-230, ISSN 01966774, 10.1016/0196-6774(90)90003-W. • [3] Mark Manasse, Lyle McGeoch, and Daniel Sleator. 1988. Competitive algorithms for online problems. In Proceedings of the twentieth annual ACM symposium on Theory of computing(STOC '88). ACM, New York, NY, USA, 322-333. DOI=10.1145/62212.62243. • [4] Michael Mitzenmacher and Eli Upfal. 2005. Probability and Computing: Randomized Algorithms and Probabilistic Analysis. Cambridge University Press, New York, NY, USA. • [5] Thomas H. Cormen, Clifford Stein, Ronald L. Rivest, and Charles E. Leiserson. 2001. Introduction to Algorithms (2nd ed.). McGraw-Hill Higher Education. Appendix A Theorem • The algorithm is an (𝑛 − 1)-competitive algorithm for the symmetric (𝑛 − 1)-server problem on an 𝑛vertex graph • Consider a vector of residues that compares the algorithm’s cost to (𝑛 − 1) times the cost of an optimal algorithm Theorem - Proof • There are 𝑛 − 1 ways the algorithm can use 𝑛 − 1 servers to cover a requested vertex and the 𝑛 − 2 other vertices • 𝑛 − 1 non-infinite residues at any step • 𝑅𝑖 – Residue that compares the algorithm’s cost to (𝑛 − 1) times the cost of an algorithm that leaves vertex 𝑖 uncovered Theorem - Proof • Let 1 be the most recently requested vertex • Let 𝑛 be the uncovered vertex • Let 2, 3, … . , 𝑛 − 1 be the other vertices • Let 𝑅𝑛 = −(𝑛 − 1)𝑑1𝑛 • Let 𝑅𝑖 = 0 (1 < 𝑖 < 𝑛) • 𝑅1 is undefined as vertex 1 must be covered by any algorithm Theorem - Proof • We only need to consider the request sequence that always hits 𝑛, the algorithm’s vacant vertex • For this sequence, following invariants holds 𝑛 − 1 𝐷1 − 𝑑1𝑛 − 𝑅𝑗 = 𝑛 − 1 𝐷𝑗 − 𝑘 𝐷𝑘 𝑘 𝐷𝑘 𝑖𝑓 𝑗 = 𝑛 𝑂𝑡ℎ𝑒𝑟𝑤𝑖𝑠𝑒 Theorem - Proof • In conjunction with the lemma, ∀ 𝑖, 𝑗, 𝑅𝑖 ≤ 𝑅𝑗 + 𝑛 − 1 𝑑𝑖𝑗 • Inductive step: If the invariants hold, then they will hold after a request at vertex 𝑛 • If 𝑖 minimizes the expression 𝐷𝑖 + 𝑑𝑖𝑛 , then the algorithm handles the request by moving from 𝑖 to 𝑛 Theorem - Proof • Vertex 𝑛 = 1’; 𝑖 = 𝑛’ • New cumulative distance for the server now at 1’, denoted by 𝐷1′ 𝐷1′ = 𝐷𝑖 + 𝑑𝑖𝑛 • For every other server the cumulative distance is unchanged Theorem - Proof • New residues 𝑅𝑛 + 𝑛 − 1 𝑑1𝑛 − 𝑑𝑖𝑛 𝑖𝑓 𝑗 = 1 ′ 𝑅𝑗 = min 𝑅𝑗 , 𝑅𝑛 + 𝑛 − 1 𝑑𝑗𝑛 − 𝑑𝑖𝑛 • Using the inequality (∀ 𝑖, 𝑗, 𝑅𝑖 ≤ 𝑅𝑗 + 𝑛 − 1 𝑑𝑖𝑗 ), 𝑅𝑛 + 𝑛 − 1 𝑑1𝑛 − 𝑑𝑖𝑛 𝑖𝑓 𝑗 = 1 𝑅𝑗 = 𝑅𝑗 − 𝑑𝑖𝑛 𝑂𝑡ℎ𝑒𝑟𝑤𝑖𝑠𝑒 ′ Theorem - Proof • Using the inductive hypothesis, 𝑅 𝑗′ = 𝑛 − 1 𝐷𝑗 − 𝑘 𝐷𝑘 − 𝑑𝑖𝑛 • Using the update rule for the cumulative distances, 𝑅 𝑗′ = 𝑛 − 1 𝐷1′ − 𝑑1′ 𝑛′ − 𝑛 − 1 𝐷𝑗 − 𝑘 𝐷𝑘 𝑘 𝐷𝑘 𝑖𝑓 𝑗 = 𝑛 𝑂𝑡ℎ𝑒𝑟𝑤𝑖𝑠𝑒 Appendix B Work Function Algorithm • Goal: To minimize the competitive ratio • Idea: mimic optimal offline algorithm – Recall: (work function) • 𝑤σ (𝑆) = 𝐶𝑂𝑃𝑇 (𝜎, 𝑆) is the optimal (offline) cost for servicing 𝜎 starting at 𝑆0 and ending up at state 𝑆 Work Function Algorithm • Work Function Algorithm: – Let 𝜎 be a request sequence and let 𝑆 be the state of an online algorithm after servicing 𝜎 . • Service a new request 𝑟 by moving its servers to a state 𝑆𝑛 with 𝑟 ∈ 𝑆𝑛 that minimizes – 𝑤σ𝑟 𝑆𝑛 + 𝑑(𝑆𝑛−1 , 𝑆𝑛 ) On-line Algorithm 𝑆0 𝑆1 …… 𝑆𝑛−1 …… 𝑇 𝑑(𝑆𝑛−1 , 𝑆𝑛 ) r ∈ 𝑆𝑛 Off-line Algorithm 𝑆0 𝑇1 r ∈ 𝑆𝑛 𝑤σ𝑟 𝑆𝑛 Work Function Algorithm • Service a new request 𝑟 by moving its servers to a state 𝑆𝑛 with 𝑟 ∈ 𝑆𝑛 that minimizes 𝑤σ𝑟 𝑆𝑛 + 𝑑(𝑆𝑛 , 𝑆𝑛−1 ) • Fact: 𝑤σ𝑟 𝑆𝑛 = 𝑤σ 𝑆𝑛 , since r ∈ 𝑆𝑛 • Fact: 𝑆𝑛 = 𝑆𝑛−1 − 𝑎 + 𝑟 for some 𝑎 ∈ 𝑆𝑛−1 , and 𝑑 𝑆𝑛 , 𝑆𝑛−1 = 𝑑 𝑎, 𝑟 • 𝑚𝑖𝑛𝑎∈𝑆𝑛−1 {𝑤σ𝑟 𝑆𝑛 + 𝑑(𝑆𝑛 , 𝑆𝑛−1 )} = 𝑚𝑖𝑛𝑎∈𝑆𝑛−1 {𝑤𝜎 (𝑆𝑛−1 − 𝑎 + On-line Algorithm 𝑆0 𝑆1 …… 𝑆𝑛−1 …… 𝑇 𝑑(𝑎, 𝑟) r ∈ 𝑆𝑛 Off-line Algorithm 𝑆0 𝑇1 r ∈ 𝑆𝑛 𝑤σ𝑟 𝑆𝑛 = 𝑤σ 𝑆𝑛 𝑆𝑛−1 𝑤σ𝑟 𝑆𝑛−1 Work Function Algorithm • Online algorithm cost: 𝑑(𝑎, 𝑟) • Offline pseudo-cost: 𝑤σ𝑟 𝑆𝑛 − 𝑤σ (𝑆𝑛−1 ) • Summing offline pseudo-cost over all moves: • 𝑤σ𝑟 𝑆𝑛 − 𝑤𝑒 𝑆0 = 𝑤σ𝑟 𝑆𝑛 > 𝑤σ𝑟 𝑆 • 𝑤σ𝑟 𝑆 is the optimal offline cost On-line Algorithm 𝑆0 𝑆1 …… 𝑆𝑛−1 …… 𝑇 𝑑(𝑎, 𝑟) r ∈ 𝑆𝑛 Off-line Algorithm 𝑆0 𝑇1 r ∈ 𝑆𝑛 𝑤σ𝑟 𝑆𝑛 = 𝑤σ 𝑆𝑛 𝑆𝑛−1 𝑤σ𝑟 𝑆𝑛−1 Work Function Algorithm • For each move, add online cost and pseudo cost: • 𝑑 𝑎, 𝑟 + 𝑤σ𝑟 𝑆𝑛 − 𝑤σ 𝑆𝑛−1 = 𝑤σ𝑟 𝑆𝑛−1 − 𝑤σ 𝑆𝑛−1 • Bounded by 𝑚𝑎𝑥𝑄 𝑤σ𝑟 𝑄 − 𝑤σ 𝑄 , we call it extended cost On-line Algorithm 𝑆0 𝑑1 𝑆1 𝑑2 …… 𝑆𝑛−1 …… 𝑇 𝑑(𝑎, 𝑟) 𝑑𝑛 r ∈ 𝑆𝑛 Off-line Algorithm 𝑆0 𝑇1 r ∈ 𝑆𝑛 𝑤σ𝑟 𝑆𝑛 = 𝑤σ 𝑆𝑛 𝑑(𝑎, 𝑟) 𝑆𝑛−1 𝑤σ𝑟 𝑆𝑛−1 Work Function Algorithm • Total extended cost for all moves give us a bound for competitive ratio • Add over all moves: • 𝑛𝑖=1(𝑑𝑖 + 𝑤σ𝑖 𝑆𝑖 − 𝑤σ𝑖−1 𝑆𝑖−1 ) • = 𝐶𝑜𝑛𝑙𝑖𝑛𝑒 + 𝑤σ𝑟 𝑆𝑛 • 𝐶𝑜𝑛𝑙𝑖𝑛𝑒 + 𝑤σ𝑟 𝑆 < 𝐶𝑜𝑛𝑙𝑖𝑛𝑒 + 𝑤σ𝑟 𝑆𝑛 < 𝑇𝑜𝑡𝑎𝑙 𝑒𝑥𝑡𝑒𝑛𝑑𝑒𝑑 𝑐𝑜𝑠𝑡 • If the total extended cost is bounded by (c + Work Function Algorithm • It can be proven that: • Define potential function • ψ 𝑤, 𝑈, 𝐵1 , … , 𝐵𝑘 = 𝑘𝑤 𝑈 + 𝑘 𝑖=1(𝑤 𝐵𝑖 − 𝑘 𝑗=1 𝑑(𝑢𝑖 , 𝑏𝑖𝑗 )) • θ(𝑤) is the minimum value over all states of 𝑈, 𝐵𝑖 • For each move θ 𝑤σ𝑖 − θ 𝑤σ𝑖 ≥ (𝑒𝑥𝑡𝑒𝑛𝑑𝑒𝑑 𝑐𝑜𝑠𝑡)𝑖 • Adding all moves together: • θ 𝑤σ𝑛 − θ 𝑤σ𝑒 ≥ (𝑡𝑜𝑡𝑎𝑙 𝑒𝑥𝑡𝑒𝑛𝑑𝑒𝑑 𝑐𝑜𝑠𝑡) • 𝑡𝑜𝑡𝑎𝑙 𝑒𝑥𝑡𝑒𝑛𝑑𝑒𝑑 𝑐𝑜𝑠𝑡 + θ 𝑤σ𝑒 ≤ θ 𝑤σ𝑛 ≤ 2𝑘𝑤σ𝑛 (𝑄) Work Function Algorithm • Putting all together: • WFA is 2𝑘 − 1 − competitive