11 -1 Chapter 12 On-Line Algorithms. 11 -2 On-Line Algorithms On-line algorithms are used to solve...

Post on 19-Jan-2018

235 views 0 download

description

11 -3 Competitive Analysis Let C onl (C off ) denote the cost of executing an on-line (optimal off-line) algorithm on the same data set. If C onl  c∙C off + b where b is a constant, we say that the performance ratio of this on-line algorithm is c and this algorithm is c-competitive.

Transcript of 11 -1 Chapter 12 On-Line Algorithms. 11 -2 On-Line Algorithms On-line algorithms are used to solve...

11 -1

Chapter 12

On-Line Algorithms

11 -2

On-Line Algorithms On-line algorithms are used to solve on-line problems.

The disk scheduling problem The requests of disk servers are totally unknown and

arrive one by one. The paging problem

We don’t know which pages will be accessed before executing our programs.

If the data arrive on-line, we still have to take action to take care of each datum which has just arrived.

Since no complete information is available, the action may seem to be correct at this time, but may turn out to be wrong later.

All the actions cannot be reversed. On-line algorithms are all approximation algorithms in the sense

that they can never guarantee to produce optimal solutions.

11 -3

Competitive Analysis Let Conl (Coff) denote the cost of executing

an on-line (optimal off-line) algorithm on the same data set.

If Conl c∙Coff + b where b is a constant, we say that the performance ratio of this on-line algorithm is c and this algorithm is c-competitive.

11 -4

On-Line Euclidean Spanning Tree Problem

Given a set of points in the plane, our goal is to construct a spanning tree out of these points as small as possible.

The points are revealed one by one. Whenever a point is revealed, some action must be taken to connect this point to the already constructed tree.

11 -5

A Greedy Algorithm for On-Line Euclidean Spanning

Tree Problem•Assume that n points v1 , v2 , ... , vn are revealed in the order. •When vk arrives, add the shortest edge between vk and v1 , v2 , ... , vk1 to the spanning tree presently constructed.

11 -6

A Greedy Algorithm for On-Line Euclidean Spanning

Tree Problem

•Points arrive in the order as specified.

11 -7

Analysis The algorithm is O(log n)-competitive.

Let S denote a set of n points. Let l denote the length of a minimal

spanning tree constructed on S. Let Tonl denote the spanning tree constructed

by our on-line algorithm.

11 -8

AnalysisThe kth largest edge on Tonl has length at most 2l / k, 1 k n 1. Let Sk be the set of points whose additions to the tree Tonl would

cause Tonl to have edges with lengths larger than 2l / k.

The length of an optimal traveling salesperson problem tour on Sk must be larger than Sk2l / k.

Since the length of an optimal traveling salesperson problem tour on a set of points is at most two times the length of a minimal spanning tree of the same set of the points, the length of a minimal spanning tree on Sk is greater than Skl / k.

Since the length of a minimal spanning tree on Sk is less than that on S, we have |Skl / k< l or equivalently, Sk < k.

11 -9

AnalysisThe total length of Tonl is thus at most

×O(log n).

(The length of Tonl ) / l is at most O(log n).

A lower bound of the competitive ratio of the problem is

O(log n / log log n).

The algorithm is near optimal.

lkln

k

221

1

lk

n

k

1

1

1

11 -10

The On-Line k-Server Problem

We are given a graph with n vertices and each edge is associated

with a positive edge length.

Let there be k servers stationed at k vertices where k < n.

Given a sequence of requests of servers, we have to decide how to

move servers around to satisfy the requests.

The cost of serving a request is the total distances between the

servers moved to satisfy the request.

11 -11

The On-Line k-Server Problem

Three servers s1 , s2 , and s3 are located at a, e, and g, respectively. Suppose we have a request at vertex i. Then one possible move is to move s2 , to vertex i.

11 -12

A Worst Case for the Greedy On-Line k-Server

Algorithm Moving the

nearest server for the request

11 -13

The Modified Greedy On-Line k-Server Algorithm on Planar

Trees A server si is active with

respect to a request located at x; if there are no more servers in the interval (di, x ], where di denote the location of si.

Method: When a request is located

at x, move all of the active servers with respect to x continuously with the same speed towards x until one of them reaches x. If during this moving period, an active server becomes inactive, then it halts.

11 -14

Analysis Let   denote the value of the potential function

after the adversary moves in response to the ith request and before our algorithm makes any move for the ith request.

Let denote the value of the potential function after our algorithm makes the move after the ith request and before the (i + 1)th request.

i~

i

11 -15

Analysis Let Oi and Ai denote the costs of our algorithm and the

adversary algorithm for the ith request, respectively. Let O and A denote the total costs of our algorithm

and the adversary algorithm after all requests are made, respectively

If we can prove(1) , 1 i n, for some , and (2) , 1 i n, for some , then O A + 0 and iii A 1

~

iii O ~

01

AO

11 -16

Analysis At any time instance, let the k servers of our algorithm be

located at b1 , b2 , ... , bk , and the k servers of our adversary algorithm be located at a1 , a2 , ... , ak .

Let us define a bipartite graph with components v1 , v2 , ... , vk and v1, v2, ... , vk where vi (vi) represents bi (ai) and the weight of edge (vi

, vj) is bi , aj. Let Mmin denote the minimum weighted matching on this

bipartite graph. Our potential function is defined as

ji

ji bbMk ,min

11 -17

Analysis Assume that q servers of our algorithm

move d distance for the ith request.

We have

Finally

iii kA 1~

qdii ~

0kAO

11 -18

AnalysisThe algorithm is k-competitive.

A lower bound of the competitive ratio of the

problem is k.

The algorithm is optimal.

11 -19

The Obstacle Traversal Problem

There is a set of square obstacles.

All of the sides of these squares are parallel to the axes.

The length of each side of the squares is less than or equal to 1.

There are a starting point, denoted as s and a goal point, denoted as t. Our job is to find a shortest

path from s to t which avoids the obstacles.

11 -20

An Algorithm Based on the Balance Strategy

Assume that the line from s to t has an angle with the horizontal axis.

Let denote the direction from s to t. Let d denote the distance between s and t.

4

11 -21

An Algorithm Based on the Balance Strategy

Three cases:Case 1: The searcher is traveling between obstacles. Case 2: The searcher hits the horizontal side of an obstacle. That is, it hits AD. Case 3: The searcher hits the vertical side of an obstacle. That is, it hits AB.

11 -22

An Algorithm Based on the Balance Strategy

Rule 1: When the searcher is traveling between obstacles, it travels in the direction . That is, it travels as if there were no obstacles.

Rule 2: When the searcher hits the horizontal side of a square AD at point E, it travels from E to D and goes up to F such that EF is parallel to the s - t line. Afterwards, it resumes the direction . (ED+DF) / EF = cos + sin .

11 -23

An Algorithm Based on the Balance Strategy

Rule 3: If searcher P hits AB within interval BG at H, it would go up to B, travel right until it hits I such that HI is parallel to the s -t. Afterwards, it resumes the direction . (+) / = cos + sin .

11 -24

An Algorithm Based on the Balance Strategy

Rule 4: If searcher P hits AB within interval AG, it either goes up or goes down. If it goes up, it goes to B, turns to the right until it hits corner C as shown in (a). If it goes down, it goes to A, turns to the right until it hits corner D as shown in (b). After hitting the corner, it resumes the direction .

11 -25

An Algorithm Based on the Balance Strategy

1 = JB+ BC 2 = JA+ AD It was proved that at least one of 1/1 and 2/2 is no more than

3/2.

11 -26

An Algorithm Based on the Balance Strategy

We partition the interval AG into equal segments of length

A segment is labeled up if its lowest point satisfies 1/1 and is labeled down if its lowest point satisfies 2/2 .

A segment is "pure" if it has only one label and others "mixed".

Let Ji be the lowest point of the ith segment and let Ji be the intersection of the line from Ji in the direction with side CD.

If the ith segment is pure, we define i = D Ji/ C Ji if this

segment is labeled only up and i = C Ji/ D Ji if this segment is labeled only down.

dk

11 -27

An Algorithm Based on the Balance Strategy

Rule 5: Assume that searcher P hits the interval at point J which belongs to the ith segment. Case 1: J is above the s - t line. Check the label of the

ith segment. If it is labeled down, move down. Otherwise, check balance. If balance , move down and subtract from balance; otherwise, add k to balance and move up.

Case 2: J is below the s - t line. Check the label of the ith segment. If it is labeled up, then move up. Otherwise, check balance. If balance , move up and subtract from balance; otherwise add k to balance and move down.

kiki

kiki

11 -28

An Algorithm Based on the Balance Strategy

Rule 6: If searcher P hits the same x-coordinate or y-coordinate of the goal, it goes directly to the goal.

11 -29

Analysis The distance traveled by our searcher by

using our on-line algorithm is no more than

3d/2 when d is large. Our algorithm is optimal because there is no

on-line algorithm to solve the problem whose competitive ratio is less than 3/2.

11 -30

The On-Line Bipartite Matching Problem

A bipartite matching M for a bipartite weighted graph G = (V, E) with vertices bipartitioning R and B, each of cardinality n, is a subset of E where no two edges in the set are incident to one single vertex and each edge in the set is incident to both R and B.

The vertices in R are all known to us in advance and the vertices in B are revealed one by one.

After the ith vertex in B arrives, it must be matched with an unmatched vertex in R and this decision can not be changed later.

Our goal is to keep the total weight of this on-line matching small.

11 -31

A Lower Bound Let b1 , ... , bn be the n vertices

in B. Let ri , 1 i n, denote the

matched vertex with bi when bi appears.

The weight of (b1 , ri) is 1 for all i.

The weight of (bi , rj) is 0 for i = 2, 3, ... , n if j < i.

The weight of (bi , rj) is 2 for i = 2, 3, ... , n if j i.

11 -32

A Lower Bound For any on-line algorithm with b1 , b2

, ... , bn revealed in order, there exists the total matching cost 1 + 2(n 1) = 2n 1.

The optimal cost for an off-line algorithm is 1.

r1 matched with b2 with cost 0. r2 matched with b3 with cost 0. rn matched with b1 with cost 1.

No on-line bipartite matching algorithm can achieve a competitive ratio less than 2n –1.

11 -33

An Algorithm Based on the Compensation

Strategy Let Mi1 denote our on-line matching before

bi is revealed. Let M

i be an optimal bipartite matching between {b1 , b2 , ... , bi} and r1 , r2 , ... , ri. such that among all optimal bipartite matchings between {b1 , b2 , ... , bi} and r1 , r2 , ... , ri , M

i Mi'1 is the smallest.

11 -34

An Algorithm Based on the Compensation

Strategy Let Ri denote the set of elements of R in M

i . We can prove that Ri only adds one element to

Ri1. Since in Mi1, rj is matched with bj for j =1,

2, ... , i 1; to compensate, we match ri with bi in Mi .

11 -35

An Algorithm Based on the Compensation

Strategy

11 -36

Analysis Our algorithm is (2n –1)-competitive. Our algorithm is optimal.

11 -37

The On-Line m-Machine Problem

We are given m identical machines and jobs are arriving one by one.

The execution time for the ith job is known when the ith job arrives.

As soon as a job arrives, it must be assigned immediately to one of the m machines.

The goal is to schedule the jobs nonpreemptively on the m machines so as to minimize the makespan, the completion time of the last job.

11 -38

List Algorithm Assign the arriving job to the machine which has the least total

processing time. ( (2)-competitive) Example: We are given six jobs, denoted as j1 , j2 , ... , j6 and their

execution times are 1, 2, ... , 6 respectively.

Solution by List Algorithm Off-Line Optimal Solution

m1

11 -39

An Algorithm Based on the Moderation Strategy

Let ai denote the execution time of the ith arriving job, where 1 i n. Assume m 70. Let [0.445 1 / (2m), 0.445 + 1 / (2m)] and m be integral. At time i, that is, when i jobs have been scheduled, let Ri be the

subsequence of the first m machines on the list, and Li the subsequence of the last m m machines.

11 -40

An Algorithm Based on the Moderation Strategy

Let the sequences of heights of Ri and Li be denoted as Rhi and Lhi respectively.

Let A(P) and M(P) denote the average and minimum, respectively, of the heights in P, where P is a sequence of heights.

Method:

When job i +1 arrives, place job i +1 on the first machine in Li , if

M(Lhi) + ai+1 (2) A(Rhi);

otherwise, place job i +1 on the first machine on the list Ri , the one with least height overall. If necessary, permute the list of machines so that height remains nondecreasing.

This algorithm is (2)-competitive for m 70.