1 online algorithms 叶德仕 2 online offline traditional theoretical analysis is concerned with...

12
1 Online algorithms 叶叶叶 [email protected]

Upload: blake-bishop

Post on 18-Jan-2018

213 views

Category:

Documents


0 download

DESCRIPTION

3 Simple Example (Ski-Rental Problem) Karp92 Rental: $100/tour Purchase: $1,000 (can be used forever) Question: Buy or Rental? Inputs: 11111….. (1: new ski tour) You do not know how many more 1’s are coming. You have to decide buy or rental at each input 1.

TRANSCRIPT

Page 1: 1 Online algorithms 叶德仕 2 Online  offline Traditional theoretical analysis is concerned with off-line problems where the complete

1

Online algorithms

叶德仕[email protected]

Page 2: 1 Online algorithms 叶德仕 2 Online  offline Traditional theoretical analysis is concerned with off-line problems where the complete

2

Online & offline

Traditional theoretical analysis is concerned with off-line problems where the complete input is given and we look for a time-efficient algorithm. In on-line problems the input is not known in advance but instead it is revealed during the operation of the algorithm.

Page 3: 1 Online algorithms 叶德仕 2 Online  offline Traditional theoretical analysis is concerned with off-line problems where the complete

3

Simple Example(Ski-Rental Problem) Karp92

Rental: $100/tourPurchase: $1,000 (can be used forever)Question: Buy or Rental?Inputs: 11111….. (1: new ski tour)You do not know how many more 1’s are coming.You have to decide buy or rental at each input 1.

Page 4: 1 Online algorithms 叶德仕 2 Online  offline Traditional theoretical analysis is concerned with off-line problems where the complete

4

Three Online Algorithms

1. Always rental.2. But at the first 1.3. Buy at the 10th 1 (rental before

then)Your action must be decided at each1 (tour) uniquely by the algorithm

Page 5: 1 Online algorithms 叶德仕 2 Online  offline Traditional theoretical analysis is concerned with off-line problems where the complete

5

CR (Competitive Ratio)

1001000nr

Cost of algorithm Cost of optimal offline algorithm

AlgOpt

Alg r Opt c

r

Competitive Analysis

Rental:$100Buy: $1,000

1. Always rental:

Page 6: 1 Online algorithms 叶德仕 2 Online  offline Traditional theoretical analysis is concerned with off-line problems where the complete

6

CR (Competitive Ratio)

Cost of algorithm Cost of optimal offline algorithm

AlgOpt

Alg r Opt c

r

Competitive Analysis

Rental:$100Buy: $1,000

1000 10.0100

r 2. Buy at the beginning

Page 7: 1 Online algorithms 叶德仕 2 Online  offline Traditional theoretical analysis is concerned with off-line problems where the complete

7

CR (Competitive Ratio)

Cost of algorithm Cost of optimal offline algorithm

AlgOpt

rAlg Opt c

r

Competitive Analysis

Rental:$100Buy: $1,000

100 9 1000 1.91000

r 3. Buy before

the 10th tour

Page 8: 1 Online algorithms 叶德仕 2 Online  offline Traditional theoretical analysis is concerned with off-line problems where the complete

8

General lower bound

Thm: There is no online algorithm can achieve competitive ratio less than 2 -1/B.Proof. The adversary decides the duration T.

1) If buy before B - 1 , stops T.2) If never buy, increase T3) Once buy B between B – 1 and 2B, stops T.

Page 9: 1 Online algorithms 叶德仕 2 Online  offline Traditional theoretical analysis is concerned with off-line problems where the complete

9

Ski rental problem

A skier must decide every day she goes skiing whether to rent or buy skis, unless or until she decides to buy them. The cost to rent skis for a day is 1 unit, while the cost to buy skis is B units. The skiier doesn’t know how many days she will go on skiing before she gets tired of it (or breaks a leg). Call this (unknown) number of days T.

Page 10: 1 Online algorithms 叶德仕 2 Online  offline Traditional theoretical analysis is concerned with off-line problems where the complete

10

Analysis

Claim: The competitive ratio 2 − 1/B.

Page 11: 1 Online algorithms 叶德仕 2 Online  offline Traditional theoretical analysis is concerned with off-line problems where the complete

11

Randomized Ski rental

Suppose that the cost B of buying skis is 3 units.Suppose that our skier buys the skis on Day 1,2,3 with probabilities p1, p2, p3 respectively, where p1 + p2 + p3 = 1. If the adversary decides that the skier will give up skiing after T days The expected total cost will be:

Page 12: 1 Online algorithms 叶德仕 2 Online  offline Traditional theoretical analysis is concerned with off-line problems where the complete

12

Randomized Ski rental

The expected competitive ratio is 27/19 = 1.42105Proof. Let p1 = 4/19, p2 = 6/19, p3 = 9/19