A Toolbox for Online Algorithms Marcin Bieńkowski U niversity of Wroc ław phd open 2011

46
A Toolbox for Online Algorithms Marcin Bieńkowski University of Wrocław phd open 2011

description

A Toolbox for Online Algorithms Marcin Bieńkowski U niversity of Wroc ław phd open 2011. A (short) story about an angry student who was (eventually) right. What you need are smart tools and not smart problems. This course: quite good tools for very simple problems. What’s in the box?. - PowerPoint PPT Presentation

Transcript of A Toolbox for Online Algorithms Marcin Bieńkowski U niversity of Wroc ław phd open 2011

Page 1: A Toolbox for Online Algorithms Marcin Bieńkowski U niversity of Wroc ław phd open 2011

A Toolbox for Online Algorithms

Marcin BieńkowskiUniversity of Wrocław

phd open 2011

Page 2: A Toolbox for Online Algorithms Marcin Bieńkowski U niversity of Wroc ław phd open 2011

A Toolbox for Online Algorithms 2Marcin Bieńkowski

A (short) story

about an angry student

who was (eventually) right.

Page 3: A Toolbox for Online Algorithms Marcin Bieńkowski U niversity of Wroc ław phd open 2011

A Toolbox for Online Algorithms 3Marcin Bieńkowski

What you need

are smart tools

and not smart problems

This course:

quite good tools

for very simple problems

Page 4: A Toolbox for Online Algorithms Marcin Bieńkowski U niversity of Wroc ław phd open 2011

A Toolbox for Online Algorithms 4Marcin Bieńkowski

What’s in the box?

10 minute crash course into online algorithms

Toolbox Potential functions Work functions Linear programming Classify and randomly select

Page 5: A Toolbox for Online Algorithms Marcin Bieńkowski U niversity of Wroc ław phd open 2011

A Toolbox for Online Algorithms 5Marcin Bieńkowski

Online algorithms

Page 6: A Toolbox for Online Algorithms Marcin Bieńkowski U niversity of Wroc ław phd open 2011

A Toolbox for Online Algorithms 6Marcin Bieńkowski

Online algorithms (1)

Optimization problemse.g. set cover, independent set, facility location, TSP, …

Approximate solutionsfor any instance we want

Online problems = input is revealed graduallyfor any instance we want

scarce computational resources

scarce computational resources+ we don’t know the future

offline optimum

Page 7: A Toolbox for Online Algorithms Marcin Bieńkowski U niversity of Wroc ław phd open 2011

A Toolbox for Online Algorithms 7Marcin Bieńkowski

Online algorithms (2)

Deterministic algorithmsfor any instance we want

Randomized algorithmsfor any instance we want

We say that is -competitive

Page 8: A Toolbox for Online Algorithms Marcin Bieńkowski U niversity of Wroc ław phd open 2011

A Toolbox for Online Algorithms 8Marcin Bieńkowski

Online algorithms example

Ski Rental Problem (SRP)

Each day, in the morning, a skier may either borrow skis for 1$ or buy them for B$

Input: in the evening a skier may break his/her leg

Objective: minimize the total cost

Page 9: A Toolbox for Online Algorithms Marcin Bieńkowski U niversity of Wroc ław phd open 2011

A Toolbox for Online Algorithms 9Marcin Bieńkowski

Online algorithms example: SRP (1)

1-approximation algorithm is trivial: is the day when skier breaks leg If T · B, rent all the time If T > B, buy at the first day

For any instance ,

What about online solutions?

Page 10: A Toolbox for Online Algorithms Marcin Bieńkowski U niversity of Wroc ław phd open 2011

A Toolbox for Online Algorithms 10Marcin Bieńkowski

Online algorithms example: SRP (2)

Bad (but natural) strategies:

Skier always rentsFor the instance I where the leg is never broken and

Skier buys at the first dayFor the instance I where the leg is broken at the first day

and

Page 11: A Toolbox for Online Algorithms Marcin Bieńkowski U niversity of Wroc ław phd open 2011

A Toolbox for Online Algorithms 11Marcin Bieńkowski

Online algorithms example: SRP (3)

Best online strategy: rent for B-1 days and buy at day B.

Analysis:If T < B, then If T ¸ B, then and this strategy is -competitive

This is the best deterministic online algorithm

Page 12: A Toolbox for Online Algorithms Marcin Bieńkowski U niversity of Wroc ław phd open 2011

A Toolbox for Online Algorithms 12Marcin Bieńkowski

Online algorithms example: SRP (4)

Best randomized online strategy: Choose purchase day randomly:

day k · B with probability proportional to For large B the such strategy is -competitive

But WHY this probability distribution?! Make several observations and solve the system of equations… … or wait till tomorrow till you see LP-based approach!

Page 13: A Toolbox for Online Algorithms Marcin Bieńkowski U niversity of Wroc ław phd open 2011

A Toolbox for Online Algorithms 13Marcin Bieńkowski

World is online

Many real life problems have online nature: network protocols routing scheduling exploration cache organization some data structures financial decisions and many more

Page 14: A Toolbox for Online Algorithms Marcin Bieńkowski U niversity of Wroc ław phd open 2011

A Toolbox for Online Algorithms 14Marcin Bieńkowski

Toolbox Outline

1. Potential functions (PF)

2. Work functions

3. Linear programming

4. Classify and randomly select

Page 15: A Toolbox for Online Algorithms Marcin Bieńkowski U niversity of Wroc ław phd open 2011

A Toolbox for Online Algorithms 15Marcin Bieńkowski

PF: a toy problem

Problem: List reorganization (singly-linked)

Input: sequence of the following operationsinsert(x): inserts x at the end of the list, cost L+1search(x): finds x on the list, cost = position of xdelete(x): deletes x from the list, cost as for search.

Model: After search or insert, ALG may move x towards the front of the

list for free. Afterwards, ALG may swap arbitrary adjacent elements paying 1.

C F A D G H B J

Page 16: A Toolbox for Online Algorithms Marcin Bieńkowski U niversity of Wroc ław phd open 2011

A Toolbox for Online Algorithms 16Marcin Bieńkowski

PF: a natural algorithm

Algorithm Move To Front (MTF)After each insert(x) or search(x) operation, move x to the beginning of the list (for free).

Page 17: A Toolbox for Online Algorithms Marcin Bieńkowski U niversity of Wroc ław phd open 2011

A Toolbox for Online Algorithms 17Marcin Bieńkowski

PF: costs (1)

Typical online setting: the problem consists of many rounds.In round : there is a request the algorithm serves it and pays

What is OPT doing?

Casual approach: simulate both ALG and OPT (actually any other algorithm) on the same sequence and relate their costs.

OPT? Do I look I care?Neither should you!

Besides, computing OPT is NP-complete

Page 18: A Toolbox for Online Algorithms Marcin Bieńkowski U niversity of Wroc ław phd open 2011

A Toolbox for Online Algorithms 18Marcin Bieńkowski

PF: costs (2)

Typical online setting: the problem consists of many rounds.In round : there is a request the algorithm serves it and pays

Casual approach: simulate both ALG and OPT (actually any other algorithm) on the same sequence and relate their costs.

We want:

Showing for all steps would be sufficient, but it is not the case!

Page 19: A Toolbox for Online Algorithms Marcin Bieńkowski U niversity of Wroc ław phd open 2011

A Toolbox for Online Algorithms 19Marcin Bieńkowski

PF: introduction to potential

We want:

Solution: take a potential function , such that1. 2.

where

Does it help? Also known as: How the heck can I guess the correct potential function?

There is a rule of the thumb that USUALLY works.

PROOF

Page 20: A Toolbox for Online Algorithms Marcin Bieńkowski U niversity of Wroc ław phd open 2011

A Toolbox for Online Algorithms 20Marcin Bieńkowski

PF: states

For many online problems, algorithms are in states and the costdepends on request and state only.

State space:

ALGOPT

Rule of the thumb:Define as a constant times the cost of changing state from ALG to OPT.

Why does it help (in the bad case)?When is small and is large…… then ALG changes state towards OPT, decreasing the potential!

Access(x) request x is at the beginning of OPT x is at the end of MTF

MTF moves x to the beginning of the list

Page 21: A Toolbox for Online Algorithms Marcin Bieńkowski U niversity of Wroc ław phd open 2011

A Toolbox for Online Algorithms 21Marcin Bieńkowski

PF: potential for MTF

Algorithm Move To Front (MTF):After each insert(x) or search(x) operation, move x to the beginning of the list (for free).

Potential function:Inversion: a pair (x,y) such that: x is before y in MTF list x is after y in OPT list

Potential function = number of inversions

Theorem:MTF is 2-competitive. PROOF

Page 22: A Toolbox for Online Algorithms Marcin Bieńkowski U niversity of Wroc ław phd open 2011

A Toolbox for Online Algorithms 22Marcin Bieńkowski

Toolbox Outline

1. Potential functions

2. Work functions (WF)

3. Linear programming

4. Classify and randomly select

Page 23: A Toolbox for Online Algorithms Marcin Bieńkowski U niversity of Wroc ław phd open 2011

A Toolbox for Online Algorithms 23Marcin Bieńkowski

WF: a toy problem (1)

Problem: File migration A graph, distances on the edges. One indivisible file of size D (e.g., shared database) placed

at one node.

Input: sequence of requests (accesses to the database).

In one step t: ALG serve the request paying ALG may move the file to any node

paying

Note that d satisfies triangle inequality

Page 24: A Toolbox for Online Algorithms Marcin Bieńkowski U niversity of Wroc ław phd open 2011

A Toolbox for Online Algorithms 24Marcin Bieńkowski

WF: a toy problem (2)

Let’s make it even simpler Just two nodes connected by an edge of length 1 File is initially at node a

a b

Elementary, dear Watson

Page 25: A Toolbox for Online Algorithms Marcin Bieńkowski U niversity of Wroc ław phd open 2011

A Toolbox for Online Algorithms 25Marcin Bieńkowski

WF: randomization

Our algorithm will be randomized!

Behavioral definition:``At the end of step t, move the file to some random node.’’

Distributional definition:``At the end of step t, choose probability distribution over nodes, i.e., file is at v with probability .’’

Lemma:We may emulate distributional definition of ALG by behavioral one. The cost of changing from to is

a b

PROOF

Page 26: A Toolbox for Online Algorithms Marcin Bieńkowski U niversity of Wroc ław phd open 2011

A Toolbox for Online Algorithms 26Marcin Bieńkowski

WF: work functions (1)

After t requests, we may compute work function :The optimal cost of serving sequence up to step t and ending with file at node x.

Computing the work functionCan be computed efficiently by a simple dynamic programming We assume that ALG may move the file before the input seq. starting conditions: and

Page 27: A Toolbox for Online Algorithms Marcin Bieńkowski U niversity of Wroc ław phd open 2011

A Toolbox for Online Algorithms 27Marcin Bieńkowski

WF: work functions (2)

After t requests, we may compute work function :The optimal cost of serving sequence up to step t and ending with file at node x.

Relation to OPT It does not mean that OPT has the file at such minimizer! However, we may assume that (the amortized) OPT cost in

step t is

Page 28: A Toolbox for Online Algorithms Marcin Bieńkowski U niversity of Wroc ław phd open 2011

A Toolbox for Online Algorithms 28Marcin Bieńkowski

WF: work function evolution

Define gradientObservation: . Moreover, if g = D (or –D), then the algorithm should have the file at a (or at b) with probability 1.

In this example, we assume D = 2

0

1234567

DFor such configuration, request at a does not change the work function (or OPT cost)

Good guidance! Let’s extrapolate it to intermediate values!

Page 29: A Toolbox for Online Algorithms Marcin Bieńkowski U niversity of Wroc ław phd open 2011

A Toolbox for Online Algorithms 29Marcin Bieńkowski

GradientRecall:

Work Function AlgorithmAt step t, choose distribution , such that

WF: the algorithm

TheoremWork function algorithm is -competitive.

0

1234567

D

and

PROOF

Page 30: A Toolbox for Online Algorithms Marcin Bieńkowski U niversity of Wroc ław phd open 2011

A Toolbox for Online Algorithms 30Marcin Bieńkowski

Thank you for your attention!(and see you tomorrow)

Page 31: A Toolbox for Online Algorithms Marcin Bieńkowski U niversity of Wroc ław phd open 2011

A Toolbox for Online Algorithms 31Marcin Bieńkowski

Toolbox Outline

1. Potential functions

2. Work functions

3. Linear programming (LP)

4. Classify and randomly select

Page 32: A Toolbox for Online Algorithms Marcin Bieńkowski U niversity of Wroc ław phd open 2011

A Toolbox for Online Algorithms 32Marcin Bieńkowski

LP: a toy problem (1)

Problem: set cover n elements family of m sets covering all elements

is the cost of set

Input: sequence of elements to coverOutput: at each step, output the subset of that covers all

elements seen so far.Online factor: removing already chosen sets not possible!

12

4

4

2

In this example:

Page 33: A Toolbox for Online Algorithms Marcin Bieńkowski U niversity of Wroc ław phd open 2011

A Toolbox for Online Algorithms 33Marcin Bieńkowski

LP: a toy problem (2)

Make the problem easier: FRACTIONAL set cover n elements family of m sets covering all elements

is the cost of set

Input: sequence of elements to coverOutput: at each step, output the function

which covers each already seen element , i.e.,

Online factor: removing already chosen fractions of sets not possible!

12

4

4

2

Page 34: A Toolbox for Online Algorithms Marcin Bieńkowski U niversity of Wroc ław phd open 2011

A Toolbox for Online Algorithms 34Marcin Bieńkowski

LP: offline solution (1)

What about offline (fractional) solution after step k? We have to cover elements

Yes, you guessed right, use linear programming!

minimize:

subject to: (for all 1 · i · k)

(for all )

12

4

4

2

Page 35: A Toolbox for Online Algorithms Marcin Bieńkowski U niversity of Wroc ław phd open 2011

A Toolbox for Online Algorithms 35Marcin Bieńkowski

LP: offline solution (2)

Do you recall?

For potential functions we did not care about OPT at all

For work functions, our constructionrelied heavily on OPT

Are we going to use it now? We may compute it!For the algorithm: NO. For the analysis: YES.

Page 36: A Toolbox for Online Algorithms Marcin Bieńkowski U niversity of Wroc ław phd open 2011

A Toolbox for Online Algorithms 36Marcin Bieńkowski

Primal program (Pk)

min.:

subject to:

(for all )

(for all )

LP: dual program

``If you have an LP, write a dual program and stare at it long enough’’ (quote from a random Stanford professor)

Dual program (Dk)

max.:

subject to:

(for all )

(for all )

Strong duality theorem: OPT(Pk) = OPT(Dk)

Page 37: A Toolbox for Online Algorithms Marcin Bieńkowski U niversity of Wroc ław phd open 2011

A Toolbox for Online Algorithms 37Marcin Bieńkowski

LP: online solution (1)

We generate our online feasible solutions to primal and dual programs.

Online = monotonic for analysis only

Observation: implies competitiveratio at most PROOF

Feasible dual solution is sometimes hard to

achieve…

Page 38: A Toolbox for Online Algorithms Marcin Bieńkowski U niversity of Wroc ław phd open 2011

A Toolbox for Online Algorithms 38Marcin Bieńkowski

LP: online solution (2)

We generate: feasible solutions to primal program solutions to dual program in which each constraint is violated at

most by factor H.

Corollary: implies competitiveratio at most

This one is feasible!

Page 39: A Toolbox for Online Algorithms Marcin Bieńkowski U niversity of Wroc ław phd open 2011

A Toolbox for Online Algorithms 39Marcin Bieńkowski

Dual program (Dk)

maximize: subject to:

(for all )

(for all )

LP: the algorithm (1)Primal program (Pk)

minimize: subject to:

(for all )

(for all )

Assume we have a solution for Pk-1

Pk contains one extra constraint

Algorithm for step k: While :

For each containing let

Observation 1: Generated primal solution is feasible TRIVIAL

Observation 2: Observation 3: Each constraint of the dual solution is violated at

most by factor O(log m)

PROOF

PROOF

Page 40: A Toolbox for Online Algorithms Marcin Bieńkowski U niversity of Wroc ław phd open 2011

A Toolbox for Online Algorithms 40Marcin Bieńkowski

LP: the algorithm (2)

Observation 1: Generated primal solution is feasibleObservation 2: Observation 3: Each constraint of the dual solution is violated at

most by factor O(log m)

Corollary: ALG is O(2 log m) = O(log m)-competitive

Page 41: A Toolbox for Online Algorithms Marcin Bieńkowski U niversity of Wroc ław phd open 2011

A Toolbox for Online Algorithms 41Marcin Bieńkowski

Toolbox Outline

1. Potential functions

2. Work functions

3. Linear programming

4. Classify and randomly select (CRS)

Page 42: A Toolbox for Online Algorithms Marcin Bieńkowski U niversity of Wroc ław phd open 2011

A Toolbox for Online Algorithms 42Marcin Bieńkowski

CRS: a toy problem (1)

Problem: Call admission A graph, capacities of the edges.

Input: sequence of call requests: pairs (si, ti).

For each call request: decide whether to admit this call (INFINITE DURATION!) if so choose a routing path for it not violating capacities

Goal: maximize the number of accepted calls

23 1

232

2132

Way too complicated, dear

Watson

Page 43: A Toolbox for Online Algorithms Marcin Bieńkowski U niversity of Wroc ław phd open 2011

A Toolbox for Online Algorithms 43Marcin Bieńkowski

CRS: a toy problem (2)

Problem: Call admission on line A line graph of n nodes all edges have capacity 1

Input: sequence of call requests: pairs (si, ti).

For each call request: decide whether to admit this call (INFINITE DURATION!)

without violating capacities if so choose a routing path

Goal: maximize the number of accepted calls

Page 44: A Toolbox for Online Algorithms Marcin Bieńkowski U niversity of Wroc ław phd open 2011

A Toolbox for Online Algorithms 44Marcin Bieńkowski

CRS: deterministic lower bound

Lemma:Any deterministic algorithm on n-node line graph has the competitive ratio at least n-1.

For a nontrivial competitive ratio, we need randomization!

PROOF

Page 45: A Toolbox for Online Algorithms Marcin Bieńkowski U niversity of Wroc ław phd open 2011

A Toolbox for Online Algorithms 45Marcin Bieńkowski

CRS: randomized solution (1)

We assume that n = 2k. We divide all edges into k classes.

i-th level call = contains edges from , but not edges from

Algorithm CRS: Choose j randomly from Accept greedily all calls from level j, and reject all other calls

Theorem: CRS is (log n)-competitive.

2-nd level call

PROOF

Page 46: A Toolbox for Online Algorithms Marcin Bieńkowski U niversity of Wroc ław phd open 2011

A Toolbox for Online Algorithms 46Marcin Bieńkowski

Thank you for your attention!