1 online algorithms typically when we solve problems and design algorithms we assume that we know...

32
1 Online algorithms Typically when we solve problems and design algorithms we assume that we know all the data a priori. However in many practical situations this may not be true and rather than have the input in advance it may be presented to us as we proceed. Input is revealed to the algorithm incrementally Output is produced incrementally Some output must be produced before the entire input is known to the algorithm Decision making under partial information Unknown information: the future

Upload: juliet-small

Post on 01-Jan-2016

217 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: 1 Online algorithms Typically when we solve problems and design algorithms we assume that we know all the data a priori. However in many practical situations

1

Online algorithms

Typically when we solve problems and design algorithms we assume that we know all the data a priori. However in many practical situations this may not be true and rather than have the input in advance it may be presented to us as we proceed.

Input is revealed to the algorithm incrementally Output is produced incrementally Some output must be produced before the entire input is

known to the algorithm Decision making under partial information Unknown information: the future

Page 2: 1 Online algorithms Typically when we solve problems and design algorithms we assume that we know all the data a priori. However in many practical situations

2

Applications

Resource Allocation Scheduling Memory Management

Robot Motion Planning Exploring an unknown terrain Finding a destination

Computational Finance

Page 3: 1 Online algorithms Typically when we solve problems and design algorithms we assume that we know all the data a priori. However in many practical situations

3

Methods of Analysis

Definition An online algorithm A is R-competitive if for all input sequences I, A(I) ≤ROPT(I), where A(I) is the cost of the online strategy A for I and OPT(I) is the cost of the optimal offline algorithm for I.

In many cases the definition of competitiveness is slightly relaxed by imposing that A(I) ≤ROPT(I)+c for some constant c independent of I.

Page 4: 1 Online algorithms Typically when we solve problems and design algorithms we assume that we know all the data a priori. However in many practical situations

4

Ski Rental Problem

you are a skier and each day need to either rent skis for $1 or buy a pair of skis for $T which will last for the rest of the season. Unfortunately you do not know when the ski season will end. If you knew a priori the length of the season (this is the online case) say L then it is obvious that you should rent if L<T and buy if L≥T. On the other hand, an online strategy for this problem would first fix an integer k and then rent for k days and buy on day k+1 if it has the opportunity.

Page 5: 1 Online algorithms Typically when we solve problems and design algorithms we assume that we know all the data a priori. However in many practical situations

5

One strategy is to buy on the first day. This strategy is T-competitive and the worst input sequence is obtained when L=1. Another online strategy is to rent for the first T-1 days and then buy. If L<T the cost of the online and optimal offline strategy is the same. If L≥T the cost of the online strategy is 2T-1 and the cost of the optimal offline strategy is T. Hence this algorithm is (2-1/T)-competitive and it is fairly easy to show that it is the optimal online algorithm.

Page 6: 1 Online algorithms Typically when we solve problems and design algorithms we assume that we know all the data a priori. However in many practical situations

6

The Online Transportation Problem

5 miles

2 miles

3 miles

4 miles

2 miles

Page 7: 1 Online algorithms Typically when we solve problems and design algorithms we assume that we know all the data a priori. However in many practical situations

7

The Online Transportation Problem

Given: a set of hospitals, each with a different sized

ambulance fleet emergency sites that arise in unpredictable

locations over time, each in immediate need of an ambulance

Return: an assignment of ambulances to emergencies that

minimizes the total distance traveled by all the ambulances

Page 8: 1 Online algorithms Typically when we solve problems and design algorithms we assume that we know all the data a priori. However in many practical situations

8

Why Greedy can be Bad Consider A, a large hospital with a dozen available

ambulances, and B, a small hospital with only 2 ambulances.

Imagine an emergency breaks out between A and B, but a bit closer to B.

A B

10 miles 9 miles

Page 9: 1 Online algorithms Typically when we solve problems and design algorithms we assume that we know all the data a priori. However in many practical situations

9

Why Greedy can be Bad Since B is closer, we dispatch an ambulance from B. But what if two emergencies then break out on the other

side of B from A?

This solution costs 31 miles!

A B

9 miles

A 20 miles

2 miles

Page 10: 1 Online algorithms Typically when we solve problems and design algorithms we assume that we know all the data a priori. However in many practical situations

10

Why Greedy can be Bad

If instead we chose hospital A for the first emergency, then used the ambulances at hospital B for the second

and third...

...the distance traveled is much less!

A B

2 miles

A

10 miles

2 miles

Page 11: 1 Online algorithms Typically when we solve problems and design algorithms we assume that we know all the data a priori. However in many practical situations

11

Online Matching Problem

Definition 9.14 Given an undirected graph G = (V, E), a matching is a subset of edges M E such that for all vertices v∈V, at most one edge of M is incident on v. We say that a vertex v ∈V is matched by matching M if some edge in M is incident on v; otherwise, v is unmatched. A maximum matching is a matching of maximum cardinality.

Definition 9.15 Perfect matching is one in which every vertex in V is matched

Maximum weight matching:Matching in a weighted graph in which the sum of the weights of its edges is maximum.

Page 12: 1 Online algorithms Typically when we solve problems and design algorithms we assume that we know all the data a priori. However in many practical situations

12

Bipartite Graph Graph G = ( L R, E) with L R = , namely

A graph is bipartite if its vertex set can be partitioned into two subsets L and R so that each edge has one endpoint in L and the other endpoint in R.

Page 13: 1 Online algorithms Typically when we solve problems and design algorithms we assume that we know all the data a priori. However in many practical situations

Intuition

Let the left set of vertices be men Let the right set of vertices be women Suppose each edge represents a pair of man and woman

who like each other

Maximum matching tries to maximize the number of couples!

Page 14: 1 Online algorithms Typically when we solve problems and design algorithms we assume that we know all the data a priori. However in many practical situations

Online Bipartite matching problem

A matchmaker and n boys are gathered in a room. n girls appear, one at a time. Each girl has a list of boys who are acceptable to her, which she reveals to the matchmaker as she appears. The matchmaker immediately matches the new girl to one of the boys on her list, if any of them are available. The goal is to maximize the number of matches.

14

Page 15: 1 Online algorithms Typically when we solve problems and design algorithms we assume that we know all the data a priori. However in many practical situations

Online bipartite matching

V

(boys)

U

(girls)

Page 16: 1 Online algorithms Typically when we solve problems and design algorithms we assume that we know all the data a priori. However in many practical situations

Online bipartite matching

V

(boys)

U

(girls)

Page 17: 1 Online algorithms Typically when we solve problems and design algorithms we assume that we know all the data a priori. However in many practical situations

Online bipartite matching

V

(boys)

U

(girls)

Page 18: 1 Online algorithms Typically when we solve problems and design algorithms we assume that we know all the data a priori. However in many practical situations

Online bipartite matching

V

(boys)

U

(girls)

Page 19: 1 Online algorithms Typically when we solve problems and design algorithms we assume that we know all the data a priori. However in many practical situations

Online bipartite matching

V

(boys)

U

(girls)

Page 20: 1 Online algorithms Typically when we solve problems and design algorithms we assume that we know all the data a priori. However in many practical situations

Online bipartite matching

V

(boys)

U

(girls)

Page 21: 1 Online algorithms Typically when we solve problems and design algorithms we assume that we know all the data a priori. However in many practical situations

Online bipartite matching

V

(boys)

U

(girls)

Page 22: 1 Online algorithms Typically when we solve problems and design algorithms we assume that we know all the data a priori. However in many practical situations

Adwords Problem

Created by search engine companies Google Yahoo! MSN

Multi-billion dollar market

Totally revolutionized advertising, especially

by small companies.

Page 23: 1 Online algorithms Typically when we solve problems and design algorithms we assume that we know all the data a priori. However in many practical situations

Monika Henzinger, 2004: Find an on-line

algorithm that maximizes Google’s revenue.

Page 24: 1 Online algorithms Typically when we solve problems and design algorithms we assume that we know all the data a priori. However in many practical situations

The Adwords Problem:

N advertisers; Daily Budgets B1, B2, …, BN Each advertiser provides bids for keywords he is interested

in.

Search Engine

Page 25: 1 Online algorithms Typically when we solve problems and design algorithms we assume that we know all the data a priori. However in many practical situations

The Adwords Problem:

N advertisers; Daily Budgets B1, B2, …, BN Each advertiser provides bids for keywords he is interested

in.

Search Enginequeries (online)

Page 26: 1 Online algorithms Typically when we solve problems and design algorithms we assume that we know all the data a priori. However in many practical situations

The Adwords Problem:

N advertisers; Daily Budgets B1, B2, …, BN Each advertiser provides bids for keywords he is interested

in.

Search EngineSelect one Ad

Advertiser pays his bid

queries (online)

Page 27: 1 Online algorithms Typically when we solve problems and design algorithms we assume that we know all the data a priori. However in many practical situations

The Adwords Problem:

N advertisers; Daily Budgets B1, B2, …, BN Each advertiser provides bids for keywords he is interested

in.

Search EngineSelect one Ad

Advertiser pays his bid

queries (online)

Maximize total revenue

Online competitive analysis - compare with best offline allocation

Page 28: 1 Online algorithms Typically when we solve problems and design algorithms we assume that we know all the data a priori. However in many practical situations

The Adwords Problem:

N advertisers; Daily Budgets B1, B2, …, BN Each advertiser provides bids for keywords he is interested

in.

Search EngineSelect one Ad

Advertiser pays his bid

queries (online)

Maximize total revenue

Example – Assign to highest bidder: only ½ the offline revenue

Page 29: 1 Online algorithms Typically when we solve problems and design algorithms we assume that we know all the data a priori. However in many practical situations

Example:

$1 $0.99

$1 $0

Book

CD

Bidder1Bidder 2

B1 = B2 = $100

Queries: 100 Books then 100 CDs

Bidder 1 Bidder 2

Algorithm Greedy

LOST

Revenue100$

Page 30: 1 Online algorithms Typically when we solve problems and design algorithms we assume that we know all the data a priori. However in many practical situations

Example:

$1 $0.99

$1 $0

Book

CD

Bidder1Bidder 2

B1 = B2 = $100

Queries: 100 Books then 100 CDs

Bidder 1 Bidder 2

Optimal Allocation

Revenue199$

Page 31: 1 Online algorithms Typically when we solve problems and design algorithms we assume that we know all the data a priori. However in many practical situations

Generalizes online bipartite matching

Each daily budget is $1, and

each bid is $0/1.

Page 32: 1 Online algorithms Typically when we solve problems and design algorithms we assume that we know all the data a priori. However in many practical situations

32

Challenges Faced

Intuition: A good algorithm must find a balance between distance of an emergency from the hospitals and the resources remaining at each hospital.

Negative Results: Such balancing is not possible. The competitive ratio of every deterministic online algorithm is bad (linear in the number of hospitals).

Random online algorithm.