Download as pdf or txt
Download as pdf or txt
You are on page 1of 46

A Toolbox for Online Algorithms

Marcin Biekowski
University of Wrocaw phd open 2011

A (short) story about an angry student who was (eventually) right.

Marcin Biekowski

A Toolbox for Online Algorithms

What you need course: This are smart tools good tools quite and not smart problems for very simple problems

Marcin Biekowski

A Toolbox for Online Algorithms

Whats in the box?

10 minute crash course into online algorithms Toolbox Potential functions Work functions Linear programming Classify and randomly select

Marcin Biekowski

Online algorithms

Marcin Biekowski

A Toolbox for Online Algorithms

Online algorithms (1)


Optimization problems e.g. set cover, independent set, facility location, TSP, Approximate solutions for any instance we want scarce computational resources

Online problems = input is revealed gradually for any instance we want scarce computational resources + we dont know the future offline optimum
Marcin Biekowski

Online algorithms (2)

Deterministic algorithms for any instance we want Randomized algorithms for any instance we want

We say that

is

-competitive

Marcin Biekowski

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

Marcin Biekowski

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?

Marcin Biekowski

Online algorithms example: SRP (2)


Bad (but natural) strategies: Skier always rents For the instance I where the leg is never broken and Skier buys at the first day For the instance I where the leg is broken at the first day and

Marcin Biekowski

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 this strategy is

and -competitive

This is the best deterministic online algorithm

Marcin Biekowski

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!

Marcin Biekowski

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

Marcin Biekowski

Toolbox Outline

1. Potential functions (PF) 2. Work functions 3. Linear programming 4. Classify and randomly select

Marcin Biekowski

PF: a toy problem


Problem: List reorganization (singly-linked)
C F A D G H B J

Input: sequence of the following operations insert(x): inserts x at the end of the list, cost L+1 search(x): finds x on the list, cost = position of x delete(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.
Marcin Biekowski

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).

Marcin Biekowski

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?
Besides, computing OPT? Do I look I OPT iscare? NP-complete Neither should you!

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

Marcin Biekowski

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 sufficient, but it is not the case!


Marcin Biekowski

for all steps would be

PF: introduction to potential


We want:

Solution: take a potential function such that 1. 2. where

PROOF

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.
Marcin Biekowski

PF: states
For many online problems, algorithms are in states and the cost depends on request and state only.

State space:

ALG

OPT

Rule of the thumb: Define as a constant times the cost of changing state from ALG to Access(x) request OPT.
x is at the beginning of OPT x is at the end of MTF

Why does it help (in the bad case)? When is small and is large then ALG changes state towards OPT, MTF moves x to decreasing the potential! the beginning of the list
Marcin Biekowski

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.
Marcin Biekowski

PROOF

Toolbox Outline

1. Potential functions 2. Work functions (WF) 3. Linear programming 4. Classify and randomly select

Marcin Biekowski

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.

Note that d satisfies triangle inequality


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
Marcin Biekowski

WF: a toy problem (2)


Lets make it even simpler Just two nodes connected by an edge of length 1 File is initially at node a Elementary, dear Watson

Marcin Biekowski

WF: randomization
Our algorithm will be randomized!
a b

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 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
Marcin Biekowski

over

PROOF

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 function Can be computed efficiently by a simple dynamic programming We assume that ALG may move the file before the input seq. starting conditions: and

Marcin Biekowski

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 :

Marcin Biekowski

WF: work function evolution


7 6 5 4 3 2 1 0

In this example, we assume D = 2


D

For such configuration, request at a does not change the work function (or OPT cost) Good guidance! Lets extrapolate it to intermediate values!

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

Marcin Biekowski

WF: the algorithm


7 6 5 4 3 2 1 0

Gradient Recall: Work Function Algorithm At step t, choose distribution such that

and

Theorem Work function algorithm is


Marcin Biekowski

-competitive. PROOF

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

Marcin Biekowski

A Toolbox for Online Algorithms

30

Toolbox Outline

1. Potential functions 2. Work functions 3. Linear programming (LP) 4. Classify and randomly select

Marcin Biekowski

LP: a toy problem (1)


Problem: set cover n elements family of m sets covering all elements is the cost of set
2 1 4 2

In this example:

Input: sequence of elements to cover Output: at each step, output the subset of that covers all elements seen so far. Online factor: removing already chosen sets not possible!
Marcin Biekowski

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
2 1 4 2

Input: sequence of elements to cover Output: at each step, output the function which covers each already seen element , i.e., Online factor: removing already chosen fractions of sets not possible!
Marcin Biekowski

LP: offline solution (1)


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

Yes, you guessed right, use linear programming! minimize: subject to: (for all ) (for all 1 i k)

Marcin Biekowski

LP: offline solution (2)


Do you recall? For potential functions we did not care about OPT at all For work functions, our construction relied heavily on OPT Are we going to use it now? We may compute it! For the algorithm: NO. For the analysis: YES.

Marcin Biekowski

LP: dual program


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

Primal program (Pk) min.: subject to: (for all ) (for all max.:

Dual program (Dk)

subject to: (for all ) (for all

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


Marcin Biekowski

LP: online solution (1)


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

Online = monotonic

for analysis only

Feasible dual solution is sometimes hard to achieve


Observation: ratio at most
Marcin Biekowski

implies competitive

PROOF

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.

This one is feasible!

Corollary: ratio at most


Marcin Biekowski

implies competitive

LP: the algorithm (1)


Primal program (Pk) minimize: (for all (for all ) subject to: ) maximize: Dual program (Dk) 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 2: PROOF Observation 3: Each constraint of the dual solution is violated at 1: Generated primal solution is feasible TRIVIAL PROOF Observationmost by factor O(log m)
Marcin Biekowski

LP: the algorithm (2)


Observation 1: Generated primal solution is feasible Observation 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


Marcin Biekowski

Toolbox Outline

1. Potential functions 2. Work functions 3. Linear programming 4. Classify and randomly select (CRS)

Marcin Biekowski

CRS: a toy problem (1)


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

Way too complicated, dear Watson

Input: sequence of call requests: pairs (s i, 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
Marcin Biekowski

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

Marcin Biekowski

CRS: deterministic lower bound

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

For a nontrivial competitive ratio, we need randomization!

Marcin Biekowski

CRS: randomized solution (1)


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

2-nd level call

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.
Marcin Biekowski

PROOF

Thank you for your attention!

Marcin Biekowski

A Toolbox for Online Algorithms

46

You might also like