Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
cours
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
jeremy.meissner
cours
Commits
96d77b97
Verified
Commit
96d77b97
authored
2 years ago
by
orestis.malaspin
Browse files
Options
Downloads
Patches
Plain Diff
find floyd
parent
d024a9aa
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
slides/cours_25.md
+133
-1
133 additions, 1 deletion
slides/cours_25.md
slides/figs/floyd_exercice.png
+0
-0
0 additions, 0 deletions
slides/figs/floyd_exercice.png
with
133 additions
and
1 deletion
slides/cours_25.md
+
133
−
1
View file @
96d77b97
...
@@ -949,7 +949,8 @@ matrice floyd_warshall(distance, n, w)
...
@@ -949,7 +949,8 @@ matrice floyd_warshall(distance, n, w)
pour k de 1 à n
pour k de 1 à n
pour i de 1 à n
pour i de 1 à n
pour j de 1 à n
pour j de 1 à n
distance[i][j] = min(distance[i][j], distance[i][k] + distance[k][j])
distance[i][j] = min(distance[i][j],
distance[i][k] + distance[k][j])
retourne distance
retourne distance
```
```
...
@@ -957,3 +958,134 @@ matrice floyd_warshall(distance, n, w)
...
@@ -957,3 +958,134 @@ matrice floyd_warshall(distance, n, w)
## La matrice de précédence
## La matrice de précédence
*
On a pas encore vu comment reconstruire le plusc court chemin!
*
On définit, $P_{ij}^{(k)}$, qui est le prédécesseur du sommet $j$ depuis $i$ avec les sommets intermédiaires $
\i
n
\{
1, 2, ..., k
\}
$.
$$
P^{(0)}_{ij}=
\l
eft
\{
\b
egin{array}{ll}
\m
box{vide}, &
\m
box{si } i=j
\m
box{, ou }w(i,j)=
\i
nfty
\\
i, &
\m
box{sinon}.
\e
nd{array}
\r
ight.
$$
*
Mise à jour
$$
P^{(k)}_{ij}=
\l
eft
\{
\b
egin{array}{ll}
P^{(k-1)}_{
\m
athbf{i}j}, &
\m
box{si } d_{ij}^{(k)}
\l
eq d_{ik}^{(k-1)}+d_{kj}^{(k-1)}
\\
P^{(k-1)}_{
\m
athbf{k}j}, &
\m
box{sinon}.
\e
nd{array}
\r
ight.
$$
. . .
*
Moralité: si le chemin est plus court en passant par $k$, alors il faut qu'il soit le prédécesseur!
# Algorithme de Floyd--Warshall
## La matrice de précédence (pseudo-code, 3min)
. . .
```
C
matrice, matrice floyd_warshall(distance, n, w)
pour k de 1 à n
pour i de 1 à n
pour j de 1 à n
n_distance = distance[i][k] + distance[k][j]
if n_distance < distance[i][j]
distance[i][j] = n_distance
précédence[i][j] = précédence[k][j]
retourne distance, précédence
```
# Algorithme de Floyd--Warshall (exercice)
::: columns
:::: column

::::
:::: column
## Que vaut $P^{(0)}$ (3min)?
. . .
$$
P^{(0)}=
\b
egin{bmatrix}
-
& 1 & 1 & - & 1
\\
2 & - & 2 & - & 2
\\
3 & 3 & - & 3 & 3
\\
4 & - & - & - & 4
\\
-
& - & - & 5 & -
\\
\e
nd{bmatrix}
$$
::::
:::
# Algorithme de Floyd--Warshall (exercice)
::: columns
:::: column

::::
:::: column
## Que vaut $P^{(5)}$ (10min)?
. . .
$$
P^{(5)}=
\b
egin{bmatrix}
-
& 1 & 1 & 5 & 1
\\
2 & - & 1 & 5 & 2
\\
2 & 3 & - & 3 & 3
\\
4 & 1 & 1 & - & 1
\\
4 & 1 & 1 & 5 & -
\\
\e
nd{bmatrix}
$$
::::
:::
# Exercice: retrouver le chemin entre 1 et 4 (5min)
$$
P=
\b
egin{bmatrix}
-
& 1 & 1 & 5 & 1
\\
2 & - & 1 & 5 & 2
\\
2 & 3 & - & 3 & 3
\\
4 & 1 & 1 & - & 4
\\
4 & 1 & 1 & 5 & -
\\
\e
nd{bmatrix}
$$
. . .
## Solution
*
Le sommet $5=P_{14}$, on a donc, $5
\r
ightarrow 4$, on veut connaître le prédécesseur de 5.
*
Le sommet $1=P_{15}$, on a donc, $1
\r
ightarrow 5
\r
ightarrow 4$. The end.
# Exercice complet
## Appliquer l'algorithme de Floyd--Warshall au graphe suivant

This diff is collapsed.
Click to expand it.
slides/figs/floyd_exercice.png
0 → 100644
+
0
−
0
View file @
96d77b97
91.4 KiB
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment