Shortest path Algorithm - PowerPoint PPT Presentation

1 / 17
About This Presentation
Title:

Shortest path Algorithm

Description:

Iterate this procedure until all vertices are labeled. ... Iterating the procedure gives successively g=v6,d=v7,f=v8 and e=v9 .The acyclic ... – PowerPoint PPT presentation

Number of Views:36
Avg rating:3.0/5.0
Slides: 18
Provided by: mrt4
Category:

less

Transcript and Presenter's Notes

Title: Shortest path Algorithm


1
Shortest path Algorithm
  • Operational Research
  • By
  • TMJA Cooray

2
  • An important problem in OR is to find the
    shortest path in a network from a given point to
    any other point in the network.

3
  • Definition A directed edge in a network N is
    often called an arc. We write uv to denote an
    arc directed from u to v. The set of arcs of N is
    denoted by A(N).
  • We shall consider a directed and acyclic ( no
    directed cycle) network N, here.
  • Every acyclic directed network contains a
    source , say x.
  • An acyclic ordering of the vertices of a directed
    network N is an ordering of V(N) such that vertex
    x comes before vertex y whenever A(N) contains an
    arc directed from x to y.
  • This will imply that x is the only source in N,
    since every other vertex must have at least one
    arc directed to into it.

4
  • ResultLet N be an acyclic directed network. Then
    we can give the vertices of N an acyclic
    ordering.
  • Proof Since N is acyclic, N contains a source,
    say x. Give x the label v1 and delete x and all
    the arcs incident with x, from N to form a new
    network N1N-x.
  • The network N1 is also acyclic and hence contains
    a source. Say y, give y the label v2 and delete y
    and the incident edges to form the next network.
    N2N1-y.
  • Iterate this procedure until all vertices are
    labeled. Then we get v1,v2,vn an acyclic
    ordering of the vertices of N.

5
c
b
6
8
d
8 6
4 7
4 3 2 5
e
i
a
9 3 5

4
h
f
5
6
g
6
  • The vertex a is the only source in N, give a the
    label v1 and delete ab,ai and ah to give the
    network N1.
  • The vertex i is the only source in N1.give i the
    label v2 and delete ib, ic,ig and ih to give N2.
  • The vertices b and h are the two sources of N2.
    Choose one arbitrarily say b, label as v3.delete
    b and edges bc to form N3.
  • N3 contains two sources c and h. select c and
    label as v4. Delete c and cd, cf, and cg to give
    network N4.
  • N4 contains the unique source h and give it the
    label v5. delete h and hg. Iterating the
    procedure gives successively gv6,dv7,fv8 and
    ev9 .The acyclic ordering is complete. ?

7
  • Acyclic network with the vertices labeled in an
    acyclic order.

6
8
8 6
4 7
4 3 2 5
9 3 5

4
5
6
8
Definition
  • Denote the weight on the arc/edge uv
    A(N), by w(uv), for all uv A(N),.
  • The length of a directed path P ,to be the sum of
    the weights on the arc of P and denote it by
    len(P).
  • The lsp(x,y) denote the length of a shortest
    directed path from a vertex x to a vertex y.

9
Algorithm to find a shortest path from a source
to every other vertex in an acyclic directed
network (v1,v2,..vn vertices in N))
  • 1.(Initialization step) Put the vertex v1 into T,
    so that V(T)v1,give v1 the label lsp(v1,v1)0
  • 2.(Recursive step) Suppose V(T)v1,v2,..vk and
    that the vertex vj has the label lsp(v1,vj), for
    j1,2,k. Choose vi so that vivk1 A(N), and
    lsp(v1, vi)w(vivk1 ) is as small as possible.
  • Add the vertex vk1. and the arc vivk1 to T
    give vk1 the label lsp(v1, vk1) lsp(v1,
    vi)w(vivk1 )
  • 3.(stop condition) Stop when T contains all the
    vertices of N.

10
  • We apply this algorithm to find the length of
    the shortest directed path from the vertex a in
    the network N shown in slide 7
  • to every other vertex in V(N).
  • (The first step is to give V(N) an acyclic
    ordering. As shown in slide 7.)
  • Put v1 into T, give v1 label lsp(v1,v1)0
  • Consider v2. The only arc into v2 is the arc v1v2
    with weight 7. we therefore add v2 and the arc
    v1v2 to T, and give v2 the label
    lsp(v1,v2)lsp(v1,v1)w(v1v2)07

11
  • Consider v3. there are two arcs into v3.
  • The arc v1v3 lsp(v1,v3)lsp(v1,v1)w(v1v3)088
  • Arc v2v3 lsp(v1,v3)lsp(v1,v2)w(v2v3)7613
  • The minimum is 8, hence we add v3 and the arc
    v1v3 to T, and give v3 the label 8.
  • Consider v4 two arcs v2v4 and v3v4into v4 give
    respectively
  • lsp(v1,v4)lsp(v1,v2)w(v2v4)7411
  • lsp(v1,v4)lsp(v1,v3)w(v3v4)8614
  • Minimum is 8. Give v4 the label 11.add v1v4 to T

12
  • Continuing the same procedure,
  • Consider v5 label v5 as 9 and add v1v5 to T.
  • Consider v6 label v6 as 12 and arc v2v6 to T.
  • Consider v7 label as 15 and v6v7 to T.
  • Consider v8 label as 15 and v4v8 to T .
  • Consider v9 label as 19 and v8v9 to T
  • Every vertex has been labeled with the length of
    the shortest path from v1.
  • Stop the procedure.
  • T is now a spanning tree

13
  • Spanning tree with the labeling
  • Shortest path

(8)
(11)
v4
v3
v7
(15)
(7)
v9
v2
v1
(19)
(0)
v5
v8
(9)
v6
(15)
(12)
14
Longest path algorithm.
  • Definition
  • llp(x,y) denotes the length of the longest
    directed path from a vertex x to a vertex y.

15
Algorithm to find a longest path from a source
to every other vertex in an acyclic directed
network (v1,v2,..vn vertices in N))
  • 1.(Initialization step) Put the vertex v1 into T,
    so that V(T)v1,give v1 the label lsp(v1,v1)0
  • 2.(Recursive step) Suppose V(T)v1,v2,..vk and
    that the vertex vj has the label llp(v1,vj), for
    j1,2,k. Choose vi so that vivk1A(N),and
    llp(v1, vi)w(vivk1 ) is as large as possible.
  • Add the vertex vk1 and the arcvivk1 to T
    give vk1 the label llp(v1, vk1) llp(v1,
    vi)w(vivk1 )
  • 3.(stop condition) Stop when T contains all the
    vertices of N.

16
  • Spanning tree with the labeling
  • ( longest path)

(13)
v4
v3
(19)
v7
(29)
(0)
(7)
v9
v2
(36)
v1
v5
(10)
v8
(26)
v6
(32)
17
(No Transcript)
Write a Comment
User Comments (0)
About PowerShow.com