Plan
1. D´efinitions
2. Repr´esentation des graphes
3. Parcours de graphes
4. Plus courts chemins
5. Arbre couvrant
Graphes 429
D´efinitions
Soit un graphe dirig´e G=(V,E) et une fonction de poids
w:E!IR
Un chemin (du sommet v1au sommet vk)estunes´equencede
nœuds v1,v2,...,vktelle que 8i=1,...,k1, (vi,vi+1)2E.
Le poids (ou coˆut) d’un chemin pest la somme du poids des arˆetes
qui le composent :
w(p)=w(v1,v2)+w(v2,v3)+...+w(vk1,vk)
Exemple
648 Chapter 24 Single-Source Shortest Paths
(a) (b) (c)
0
6
6
7212 4
3
53
s
tx
yz
39
5 11
0
6
6
7212 4
3
53
s
tx
yz
39
5 11
0
6
6
7212 4
3
53
s
tx
yz
39
5 11
Figure 24.2 (a) Aweighted,directedgraphwithshortest-pathweightsfromsources.(b) The
shaded edges form a shortest-paths tree rooted at the source s.(c) Another shortest-paths tree with
the same root.
Shortest paths are not necessarily unique, and neither are shortest-paths trees. For
example, Figure 24.2 shows a weighted, directed graph and two shortest-paths trees
with the same root.
Relaxation
The algorithms in this chapter use the technique of relaxation.Foreachvertex
!2V,wemaintainanattribute!:d,whichisanupperboundontheweightof
ashortestpathfromsourcesto !.Wecall!:dashortest-path estimate.We
initialize the shortest-path estimates and predecessors by the following ‚.V /-time
procedure:
INITIALIZE-SINGLE-SOURCE.G; s/
1for each vertex !2G:V
2!:dD1
3!:"DNIL
4s:dD0
After initialization, we have !:"DNIL for all !2V,s:dD0,and!:dD1for
!2V!fsg.
The process of relaxing an edge .u; !/consists of testing whether we can im-
prove the shortest path to !found so far by going through uand, if so, updat-
ing !:dand !:".Arelaxationstep
1may decrease the value of the shortest-path
1
The use of the term is historical. The outcome of a relaxation step can be viewed as a relaxation
of the constraint !:d"u:dCw.u;!/,which,bythetriangleinequality(Lemma24.10),mustbe
satisfied if u:dDı.s; u/ and !:dDı.s; !/.Thatis,if!:d"u:dCw.u; !/,thereisno“pressure
It may seem strange that the term “relaxation” is used for an operation that tightens an upper bound.
so the constraint is “relaxed.”
to satisfy this constraint,
w(s!y!t!x!z) = 5 + 1 + 6 + 2 = 14
Graphes 430
Plus courts chemins : d´efinition
Un plus court chemin entre deux sommets uet vest un chemin p
de u`a vde poids w(p) le plus faible possible
(u,v) est le poids d’un plus court chemin de u`a v:
(u,v)=min{w(p)|pest un chemin de u`a v}
(S’il n’y a pas de chemin entre uet v,(u,v)=1par d´efinition)
Exemples :
648 Chapter 24 Single-Source Shortest Paths
(a) (b) (c)
0
6
6
7212 4
3
53
s
tx
yz
39
5 11
0
6
6
7212 4
3
53
s
tx
yz
39
5 11
0
6
6
7212 4
3
53
s
tx
yz
39
5 11
Figure 24.2 (a) Aweighted,directedgraphwithshortest-pathweightsfromsources.(b) The
shaded edges form a shortest-paths tree rooted at the source s.(c) Another shortest-paths tree with
the same root.
Shortest paths are not necessarily unique, and neither are shortest-paths trees. For
example, Figure 24.2 shows a weighted, directed graph and two shortest-paths trees
with the same root.
Relaxation
The algorithms in this chapter use the technique of relaxation.Foreachvertex
!2V,wemaintainanattribute!:d,whichisanupperboundontheweightof
ashortestpathfromsourcesto !.Wecall!:dashortest-path estimate.We
initialize the shortest-path estimates and predecessors by the following ‚.V /-time
procedure:
INITIALIZE-SINGLE-SOURCE.G; s/
1for each vertex !2G:V
2!:dD1
3!:"DNIL
4s:dD0
After initialization, we have !:"DNIL for all !2V,s:dD0,and!:dD1for
!2V!fsg.
The process of relaxing an edge .u; !/consists of testing whether we can im-
prove the shortest path to !found so far by going through uand, if so, updat-
ing !:dand !:".Arelaxationstep
1may decrease the value of the shortest-path
1
The use of the term is historical. The outcome of a relaxation step can be viewed as a relaxation
of the constraint !:d"u: dCw.u;!/,which,bythetriangleinequality(Lemma24.10),mustbe
satisfied if u:dDı.s; u/ and !:dDı.s; !/.Thatis,if!:d"u:dCw.u; !/,thereisno“pressure
It may seem strange that the term “relaxation” is used for an operation that tightens an upper bound.
so the constraint is “relaxed.”
to satisfy this constraint,
Graphes 431
Plus courts chemins : exemple d’application
Graphes 432
Propri´et´e de sous-structure optimale
Lemme : Tout sous-chemin d’un chemin le plus court est un chemin
le plus court entre ses extr´emit´es
Preuve : Par labsurde
ISoit un plus court chemin puv entre uet vet soit un sous-chemin pxy
de ce chemin d´efini par ses extr´emit´es xet y
IS’il existe un chemin plus court que pxy entre xet y, on pourrait
remplacer pxy par ce chemin dans le chemin entre uet vet obtenir
ainsi un chemin plus court que puv entre uet v
24-2 Lecture Notes for Chapter 24: Single-Source Shortest Paths
Can think of weights as representing any measure that
!accumulates linearly along a path, and
!we want to minimize.
Examples: time, cost, penalties, loss.
Generalization of breadth-first search to weighted graphs.
Variants
!Single-source: Find shortest paths from a given source vertex s2Vto every
vertex !2V.
!Single-destination: Find shortest paths to a given destination vertex.
!Single-pair: Find shortest path from uto !.Nowayknownthatsbetterin
worst case than solving single-source.
!All-pairs: Find shortest path from uto !for all u; !2V.Wellseealgorithms
for all-pairs in the next chapter.
Negative-weight edges
OK, as long as no negative-weight cycles are reachable from the source.
!If we have a negative-weight cycle, we can just keep going around it, and get
w.s;!/D!1for all !on the cycle.
!But OK if the negative-weight cycle is not reachable from the source.
!Some algorithms work only if there are no negative-weight edges in the graph.
Well be clear when they’re allowed and not allowed.
Optimal substructure
Lemma
Any subpath of a shortest path is a shortest path.
Proof Cut-and-paste.
uxyv
pux pxy pyv
Suppose this path pis a shortest path from uto !.
Then ı.u; !/Dw.p/ Dw.pux /Cw.pxy/Cw.py!/.
Now suppose there exists a shorter path xp0
xy
y.
Then w.p0
xy/<w.p
xy/.
Construct p0:
uxyv
pux p'xy pyv
Graphes 433
1 / 40 100%
La catégorie de ce document est-elle correcte?
Merci pour votre participation!

Faire une suggestion

Avez-vous trouvé des erreurs dans linterface ou les textes ? Ou savez-vous comment améliorer linterface utilisateur de StudyLib ? Nhésitez pas à envoyer vos suggestions. Cest très important pour nous !