Shortest Path with Negative Weights - Algorithm and Complexity Analysis - Lecture Slides, Slides of Computer Science

These are the Lecture Slides of Algorithm and Complexity Analysis which includes Approximation Algorithms, Coping with Np-Hardness, Fully Polynomial-Time, Brute-Force Algorithms, Approximation Scheme, Knapsack Problem, Profit Subset of Items, Nonnegative Values etc. Key important points are:Shortest Path with Negative Weights, Negative Cycle Detection, Currency Exchange Arbitrage, Tramp Steamer Problem, Optimal Pipelining, Negative Cost Cycle, Finding Shortest Paths

Typology: Slides

2012/2013

Uploaded on 03/21/2013

dharmaveer
dharmaveer 🇮🇳

4.5

(4)

54 documents

1 / 6

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Shortest Path With Negative Weights
s
3
t
2
6
7
4
5
10
18
-16
9
6
15 -8
30
20
44
16
11
6
19
6
2
Contents
Contents.
Directed shortest path with negative weights.
Negative cycle detection.
application: currency exchange arbitrage
Tramp steamer problem.
application: optimal pipelining of VLSI chips
3
Shortest Paths with Negative Weights
Negative cost cycle.
If some path from s to v contains a negative cost cycle, there does not
exist a shortest s-v path; otherwise, there exists one that is simple.
s v
W
c(W) < 0
3
4
5
-6
7
-4
4
Shortest Paths with Negative Weights
OPT(i, v) = length of shortest s-v path using at most i arcs.
Let P be such a path.
Case 1: P uses at most i-1 arcs.
Case 2: P uses exactly i arcs.
if (u, v) is last arc, then OPT selects best s-u path using at most
i-1 arcs, and then uses (u, v)
Goal: compute OPT(n-1, t) and find a corresponding s-t path.
{}
+
=
=
otherwise),(),1(),,1(min
0i if0
),( min
),(
vucuiOPTviOPT
viOPT
Evu
Docsity.com
pf3
pf4
pf5

Partial preview of the text

Download Shortest Path with Negative Weights - Algorithm and Complexity Analysis - Lecture Slides and more Slides Computer Science in PDF only on Docsity!

Shortest Path With Negative Weights

s

3

t

2

6

7

4

5

(^1018)

9

6 15

30 20

44

11 16

6

19

6

Contents

Contents.^ n^

Directed shortest path with negative weights. n^

Negative cycle detection.^ –

application: currency exchange arbitrage n^

Tramp steamer problem.^ –

application: optimal pipelining of VLSI chips

3

Shortest Paths with Negative Weights

Negative cost cycle.If some path from s to v contains a negative cost cycle, there does notexist a shortest s-v path; otherwise, there exists one that is simple.

s^

v

W c(W) < 0

3 4

5

-6 7

Shortest Paths with Negative Weights

OPT(i, v) = length of shortest s-v path using at most i arcs.^ n^

Let P be such a path. n^

Case 1: P uses at most i-1 arcs. n^

Case 2: P uses exactly i arcs.^ –

if (u, v) is last arc, then OPT selects best s-u path using at mosti-1 arcs, and then uses (u, v)

Goal: compute OPT(n-1, t) and find a corresponding s-t path.

{^

^ 

otherwise

) , ( ) , 1 (

min

i if

min

) , (

v u c u i

OPT

v i

OPT

vi

OPT

E v u

Docsity.com

5

Shortest Paths with Negative Weights: Algorithm

INPUT: G

(V,

E),

s, t

n^

=^

|V|

ARRAY: OPT[0..n, V]FOREACH v

V

OPT[0,

v] =

OPT[0,s]

FOR i

to n

FOREACH v

V

m^

=^

OPT[i-1,

v]

m’

FOREACH (u,

v)

E

m’ =

min

(m’, OPT[i-1,

u] +

c[u,v])

OPT[i, v] =

min(m,

m’)

RETURN OPT[n-1, t]

Dynamic Programming Shortest Path

{^

min

) , (

v u c u i

OPT E v u

Shortest Paths: Running Time

Dynamic programming algorithm requires

(mn) time and space.

n^

Outer loop repeats n times. n^

Inner loop for vertex v considers indegree(v) arcs. Finding the shortest paths.^ n^

Could maintain predecessor variables. n^

Alternative: compute optimal distances, consider only zeroreduced cost arcs.

m

v

V v

indegree

7

Shortest Paths: Detecting Negative Cycles L1: if OPT(n,v) < OPT(n-1,v) for some node v, then (any) shortest pathfrom s to v using at most n arcs contains a cycle; moreover any suchcycle has negative cost.^ n^

Proof (by contradiction). n^

Since OPT(n,v) < OPT(n-1,v), P has n arcs. n^

Let C be any directed cycle in P. n^

Deleting C gives us a path from s to v of fewer than n arcs

C has negative cost.

s^

v

C c(C) < 0

Shortest Paths: Detecting Negative Cycles L1: if OPT(n,v) < OPT(n-1,v) for some node v, then (any) shortest pathfrom s to v using at most n arcs contains a cycle; moreover any suchcycle has negative cost.^ n^

Proof (by contradiction). n^

Since OPT(n,v) < OPT(n-1,v), P has n arcs. n^

Let C be any directed cycle in P. n^

Deleting C gives us a path from s to v of fewer than n arcs

C has negative cost. Corollary: can detect negativecost cycle in O(mn) time.^ n^

Need to trace backthrough sub-problems.

2

1 3

5

4

18

2

5

6

s^0

0

0

0

0

Docsity.com

13

Tramp-Steamer Problem

Tramp-steamer (min cost to time ratio) problem.^ n^

A tramp steamer travels from port to port carrying cargo. A voyagefrom port v to port w earn p(v,w) dollars, and requires t(v,w) days. n^

Captain wants a tour that achieves largest mean daily profit.

p = 30t = 7 p = 12t = 3

p = -3t = 5

mean daily profit =

Westward Ho (

Tramp-Steamer Problem

Tramp-steamer (min cost to time ratio) problem.^ n^

Input: digraph G = (V, E), arc costs c, and arc traversal times t > 0. n^

Goal: find a directed cycle W that minimizes ratio Novel application.^ n^

Minimize cycle time (maximize frequency) of logic chip on IBMprocessor chips by adjusting clocking schedule. Special case.^ n^

Find a negative cost cycle.

(^

∈ ∈^ We

e W e^

ce t

W

15

Tramp-Steamer Problem

Linearize objective function.^ n^

Let

μ

  • be value of minimum ratio cycle.

n^

Let

μ

be a constant.

n^

Define

l

= ce

- e^

μ

t e

Case 1: there exists negative cost cycle W using lengths

l

. e

Case 2: every directed cycle has positive cost using lengths

le

μ^

∈ ∈

W e^

e W e^

e

W e^

e

e^

c t

t

c

cycle

every

for

cycle

every

for

W

c t

W

t

c

W e^

e W e^

e

W e^

e

e

Tramp-Steamer Problem

Linearize objective function.^ n^

Let

μ

  • be value of minimum ratio cycle.

n^

Let

μ

be a constant.

n^

Define

l

= ce

- e^

μ

t e

Case 3: every directed cycle has nonnegative cost using lengths

le

and there exists a zero cost cycle W.*

cycle

every

for

W

cycle

every

for

W

t c t

c

W e^

e W e^

e

W e^

e

e


μ^

∑∈ ∑∈^ We

e W e^

ce t

Docsity.com

17

Tramp-Steamer Problem

Linearize objective function.^ n^

Let

μ

  • be value of minimum ratio cycle.

n^

Let

μ

be a constant.

n^

Define

l

= ce

- e^

μ

t e

Case 1: there exists negative cost cycle W using lengths

l

. e

n^

μ *** <**

μ

Case 2: every directed cycle has positive cost using lengths

le

n^

μ *** >**

μ

Case 3: every directed cycle has nonnegative cost using lengths

le

and there exists a zero cost cycle W.*^ n^

μ *** =**

μ

Tramp-Steamer: Sequential Search Procedure Theorem: sequential algorithm terminates.^ n^

Case 1

⇒ μ

strictly decreases from one iteration to the next.

n^

μ^ Let is the ratio of some cycle, and only finitely many cycles.

μ

be a

known

upper bound on

μ

REPEAT (forever)

l e

c

e^

–^

μ

Solve shortest

path problem

with

lengths

l

e

IF

(negative

cost

cycle

W

w.r.t.

l

)e

μ ←

μ

(W)

ELSE

Find

a zero

cost cycle W*

w.r.t.

l

.e

RETURN W*.

Sequential Tramp Steamer

19

Tramp-Steamer: Binary Search Procedure^ W

cycle left

-C, right

C

REPEAT (forever)

IF (

μ (W)

μ

RETURN W

μ ←

(left +

right) /

l e

c

e^

–^

μ

Solve

shortest

path problem

with lengths

l

e

IF (negative

cost

cycle

w.r.t.

l

)e

right

μ

W^

negative

cost

cycle w.r.t.

l

e

ELSE IF (zero cost cycle

W*)

RETURN W*.

ELSE

left

μ

Binary Search Tramp Steamer

left

μ

*^

≤^

right

Tramp-Steamer: Binary Search Procedure Invariant: interval

[left, right]

and cycle W satisfy:

left

μ

*^

≤^

μ (W) <

right

n^

Proof by induction follows from cases 1-2. Lemma. Upon termination, the algorithm returns a min ratio cycle.^ n^

Immediate from case 3. Assumption.^ n^

All arc costs are integers between

–C and C.

n^

All arc traversal times are integers between –T and T. Lemma. The algorithm terminates after O(log(nCT)) iterations.^ n^

Proof on next slide. Theorem. The algorithm finds min ratio cycle in O(mn log (nCT)) time.

Docsity.com