NegativeWeight edges: - PowerPoint PPT Presentation

About This Presentation
Title:

NegativeWeight edges:

Description:

If no negative-weight cycles reachable from the source s, then for all v V, the ... reachable from a vertex whose shortest path is - ,it,too,has a shortest-path weight ... – PowerPoint PPT presentation

Number of Views:49
Avg rating:3.0/5.0
Slides: 23
Provided by: xuy4
Category:

less

Transcript and Presenter's Notes

Title: NegativeWeight edges:


1
Negative-Weight edges
  • Edge weight may be negative.
  • negative-weight cycles the total weight in the
    cycle (circuit) is negative.
  • If no negative-weight cycles reachable from the
    source s, then for all v ?V, the shortest-path
    weight remains well defined,even if it
    has a negative value.
  • If there is a negative-weight cycle on some path
    from s to v, we define - .

2
a
b
-4
h
i
-1
3
2
4
3
c
d
6
8
3
-8
5
11
5
g
0
s
-3
e
f
3
j
2
7
-6
Figure1 Negative edge weights in a directed
graph.Shown within each vertex is
its shortest-path weight from source s.Because
vertices e and f form a negative-weight cycle
reachable from s,they have shortest-path weights
of - . Because vertex g is reachable from a
vertex whose shortest path is - ,it,too,has
a shortest-path weight of - .Vertices such
as h, i ,and j are not reachable from s,and so
their shortest-path weights are , even
though they lie on a negative-weight cycle.
3
Relaxation
  • The process of relaxing an edge (u,v) consists of
    testing whether we can improve the shortest path
    to v found so far by going through u and,if
    so,updating dv and v.
  • RELAX(u,v,w)
  • if dvgtduw(u,v)
  • then dv ? duw(u,v) (based on
    Lemma 25.3)
  • v ? u

4
u
v
u
v
2
2
5
9
5
6
RELAX(u,v)
RELAX(u,v)
u
v
u
v
2
2
5
7
5
6
(a)
(b)
Figure2 Relaxation of an edge (u,v).The
shortest-path estimate of each vertex is shown
within the vertex. (a)Because dvgtduw(u,v)
prior to relaxation, the value of dv decreases.
(b)Here, dv duw(u,v) before the
relaxation step,so dv is unchanged by
relaxation.
5
Bellman-Ford algorithm
  • The Bellman-Ford algorithm solves the
    single-source shortest-paths problem in the more
    general case in which edge weights can be
    negative.
  • It report FALSE if a negative-weight circuit
    exists.

6
Continue
  • BELLMAN-FORD(G,w,s)
  • INITIALIZE-SINGLE-SOURCE(G,s)
  • for i ? 1 to VG -1
  • do for each edge (u,v) ? EG (The
    order here is arbitrary)
  • do RELAX(u,v,w)
  • for each edge (u,v)? EG
  • do if dvgtduw(u,v)
  • then return FALSE
  • return TRUE
  • Time complexity O(VE).

7
(a)
8
5
u
v
6
8
-2
6
-3
8
0
7
z
-4
2
7
7
8
9
x
y
(b)
9
5
u
v
6
4
-2
6
-3
8
0
7
z
-4
2
7
7
2
9
x
y
(c)
10
5
u
v
2
4
-2
6
-3
8
0
7
z
-4
2
7
2
7
9
x
y
(d)
11
5
u
v
2
4
-2
6
-3
8
0
7
z
-4
2
7
7
-2
9
x
y
(e)
12
Theorem (hard) after the i-th iteration, the
cost of a shortest path from s to any node v
containing i edges is obtained.
  • Proof We prove it by induction on i.
  • The theorem is true for i1.
  • The shortest path from s to v containing at most
    one edge is the the edge (s, v) (if exists).
  • Assume that the theorem is true for ik. Then we
    are going to show that the theorem is true for
    ik1.
  • Let P s-gt v1-gt v2 -gtvm-gt v be the shortest path
    from s to v containing at most k1 edges. Then
    P1 s-gt v1-gt v2 -gtvm must be the shortest path
    from s to vm containing at most k edges. By
    assumption, P1 has been obtained after (k)-th
    iteration. In the (k1)-th iteration, we tried
    to RELAX(vm, v, w) on node vm. Thus, path P is
    obtained after the (k1)-th iteration.

13
Corollary If negative-weight circuit exists in
the given graph, in the n-th iteration, the cost
of a shortest path from s to some node v will be
further reduced.
  • Demonstrated by the following example.
  • Note For each iteration, the order of edges used
    does not effect the Theorem. However, the
    intermediate results may vary. The final results
    will be the same.

14
5
1
6
-2
8
7
7
9
2
2
5
-8
An example with negative-weight cycle
15
(No Transcript)
16
(No Transcript)
17
(No Transcript)
18
(No Transcript)
19
5
6
11
1
6
-2
0
8
12
7
7
9
2
6
15
2
5
-8
8
1
20
(No Transcript)
21
5
6
11
1
6
-2
0
8
12
7
7
9
2
5
15
2
5
-8
8
0
x
22
2
5
-3
1
6
-2
8
7
7
9
2
2
5
-6
Exercise use Bellman-Ford algorithm for the graph
Write a Comment
User Comments (0)
About PowerShow.com