Lecture 5: Dynamic programmning
Contents
1 Shortest path problems
1
1
.1 S
ing
l
e

sou
r
c
esho
r
t
e
s
tpa
thp
rob
l
em
:r
e
cu
r
s
ion .
.........................
2
1
.
2 A
l
lp
a
i
r
ssh
o
r
t
e
s
tp
a
tha
l
go
r
i
thm .
.................................
4
1
.
3 D
j
ik
s
t
ra
’
sa
l
r
i
thm
:on
et
oa
l
l ...................................
5
1
.
4 Sh
o
r
t
e
s
a
th
sinD
i
r
e
c
t
edA
cy
c
l
i
cG
raph
s.............................
6
2 Formulating shortest path problems
7
3 Dynamic programming
10
3
.
1 Am
e
r
i
c
anop
t
i
onp
r
i
c
in
gonth
eb
om
i
a
lm
od
e
l..........................
11
3
.
2 DPs
o
lu
t
i
ono
fth
ekn
ap
s
a
c
kp
l
em.
...............................
12
4 Relation to Linear Programming
14
5 Observations on Dynamic Programming
14
1
Shortest path problems
A
graph
is the mathematical abstraction of networks (think traﬃc networks, transportation networks, airline
networks, etc.) A graph
G
consist of
(a)
nodes
N
: represent intersections, entities, transfer pts.
(b)
arcs
E
: are directed (oneway) links between nodes. Undirected links are called
edges
.
A
path
in a graph is a sequence of arcs or edges such that
(i) each edge or arc must have only one node incommonw
ithitspredecessor in the sequence
(ii) all arcs are passed in the forward direction
(iii) no nodes are repeated
A
cycle
is a path that begins and ends on the same node, i.e. the Frst and last node
are
repeated.
The following Fgure shows a graph
1
23
4
5
6
10
8
12
15
20
30
15
20
5
This preview has intentionally blurred sections. Sign up to view the full version.
View Full DocumentDynamic programs
2
The nodes in this graphare labeled 1, 2, .
.., 6. There are 4 arcs,namely (1
,
2), (2
,
3), (3
,
4), (4
,
1); 5 edges,
namely (1
,
6), (2
,
6), (1
,
3), (4
,
5), (3
,
5). The sequence of nodes 1
−
2
−
3
−
4, 1
−
2
−
3
−
5
−
4, 4
−
1
−
3
−
5
are examples of paths in this graph. On the other hand the sequences 1
−
4
−
5, 1
−
6
−
1
−
3
−
5are
not
paths in this graph. Examples of cycles include 1
−
2
−
3
−
4
−
1and1
−
6
−
3
−
5
−
1.
In many applications, edges and arcs have
lengths
associated with them. Let
c
ik
denote the length of the
arc (
i, k
). If (
i, k
) is an edge (i.e. bidirectional) then
c
ik
=
c
ki
,otherw
ise
c
ki
=
∞
.A
l
s
ol
e
t
c
ii
=
∞
for all
i
∈
N
. The length of a path is the
sum
of the lengths of edges/arcs in the path.
(a) length of path 1234:
c
12
+
c
23
+
c
34
=15+12+5=32
(b) length of path 54132:
c
54
+
c
41
+
c
13
+
c
32
=20+(
−
30) + 20 + 12 = 22
The goal of the
shortest path problems
in a graph
G
is to Fnd the minimum length paths. These problems
come in many varieties
(a)
s

t
shortest path problem: ±ind the shortest path between the speciFed nodes
s
and
t
.
(b) Singlesource shortest path problem: ±ind shortest paths from a speciFed node
s
to all other nodes in
the graph
(c) Allpairs shortest path problem: ±ind the shortest paths between all pairs of nodes.
The shortest path problem is solved by
recursion
, i.e. by reducing it to a number of stages. To do this we
will need some notation.
1. Singlesource shortest path problem
v
(
t
)
[
k
]
=
length of shortest path from
s
to
k
with
t
or fewer arcs/edges
v
[
k
]
=
length of shortest path from
s
to
k
d
[
k
]
=
node preceding
k
in the best known path from
s
to
k
If there are
n
nodes in a graph then any path can have at most
n
−
1 edges/arcs (why? because n edges
or more would mean repeating nodes). Therefore,
v
[
k
]=
v
(
n
−
1)
[
k
]. Also
v
(0)
[
s
]=0and
v
(0)
[
This is the end of the preview.
Sign up
to
access the rest of the document.
 Summer '09
 OptimizationModelsandMethods
 Graph Theory, WI, Shortest path problem, LSI, Longest path problem

Click to edit the document details