140 likes | 281 Views
Online Algorithms. Motivation and Definitions Paging Problem Competitive Analysis Online Load Balancing. Motivation. In many settings, an algorithm needs to make a decision “online” without complete knowledge of the input.
E N D
Online Algorithms • Motivation and Definitions • Paging Problem • Competitive Analysis • Online Load Balancing
Motivation • In many settings, an algorithm needs to make a decision “online” without complete knowledge of the input. • For example, when a page fault occurs, the virtual memory system must decide on a page to evict without knowing what future requests will be • We model this lack of knowledge of the future by defining the concept of online problems
Definition • Optimization problem P • Goal is to minimize or maximize some cost/value • Input is given as a sequence of requests σ • σ1, σ2, … • An algorithm A must service request σi without knowledge of future requests (including whether or not there are more requests) • A(σ) represents the cost of using algorithm A to service sequence σ
Example: Paging Problem • Setting • We have k fast memory pages and an infinite number of slow memory pages • Input: A sequence of requests for slow memory pages • If the page currently also resides in fast memory (hit), we can service this page with 0 cost • If the page only resides in slow memory (fault), we must bring the page into fast memory and evict a page currently in fast memory for cost 1 • Goal: Process the requests with minimum cost.
The offline version of the problem • Suppose we knew the entire request sequence in advance. What is the optimal way to handle any page fault? • 2 fast memory pages • σ =1, 3, 1, 2, 1, 3, 2, 3, 1, 3, 1, 2, 2, 1, 3, 2
Worst-case Analysis of Online Algorithms • What are some natural online algorithms we can define for this problem? • Show that for every online algorithm A, there exists a request sequence σA such that A performs poorly on σA • What does this imply about using this form of worst-case analysis for online algorithms? What is a good online algorithm for the paging problem given this performance metric?
Competitive Analysis • Let A(σ) denote algorithm A’s cost on input sequence σ • Let Opt(σ) denote the optimal algorithm’s cost on input sequence σ • We say that algorithm A is c-competitive if for any sequence σ and some constant b, A(σ) ≤ c Opt(σ) + b • Essentially that A(s)/Opt(s) ≤ c • The competitive ratio cA is the infimum of {c | A is c-competitive}. • The optimal competitive ratio for a problem is • infimumA cA
2 example online algorithms • Consider the following two algorithms • MRU (evict the most recently used page) • LRU (evict the least recently used page) • Consider a scenario with 2 fast memory pages and the following request sequences • σ1 = 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, … • σ2 = 1, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, … • What is LRU(σ1)/OPT(σ1) ? MRU(σ1)/OPT(σ1) ? • What is LRU(σ2)/OPT(σ2) ? MRU(σ2)/OPT(σ2) ?
General questions • Show that for any online algorithm A, there exists a request sequence σA such that A faults on every request of σA while OPT faults on at most /k requests of σA where there are k fast memory pages and there are k+1 slow memory pages • What does this result imply about the best possible competitive ratio of any online algorithm for the paging problem. • How can we try to show that LRU achieves this competitive ratio?
Example: Online Load Balancing • Setting • We have m identical machines • Input: A sequence of jobs with loads σi • We must assign each job to a machine before the next job arrives • Goal: Assign jobs to machines so that the maximum load on any machine is minimized
The offline version of the problem • Suppose we knew the entire request sequence in advance. • Consider the following problem instance: • 2 machines • σ =1, 7, 9, 12, 15, 7, 9 • What is optimal solution for this instance? • What can you say about the hardness of this offline problem?
Online Algorithms and Questions • What is an obvious greedy strategy for this problem? • Consider the following two lower bounds on OPT(σ) • OPT(σ) ≥ maxi σi (largest job is on some machine) • OPT(σ) ≥ Σi σi/m (at best total load is divided evenly) • Prove that the greedy strategy has a competitive ratio of 2 – 1/m • Consider the last job j placed on the max loaded machine for greedy • Greedy(σ) = h, the load of the machine before job j, + σj • Using the lower bound above, argue that Greedy(σ) ≤ (2-1/m) OPT(σ) • Find specific input instances σ where Greedy(σ) = (2-1/m) OPT(σ) for m=2 and 3. • For these input instances, could any online algorithm do better? Argue why not.