Skip to content

Commit 5b3bcbf

Browse files
committed
use md for a hidden notebook in graph-shortest-path
1 parent 3c4b256 commit 5b3bcbf

File tree

1 file changed

+48
-43
lines changed

1 file changed

+48
-43
lines changed

notebooks/tps/graph-shortest-path/v0/README-graph-shortest-path-nb.py renamed to notebooks/tps/graph-shortest-path/v0/README-graph-shortest-path-v0-nb.md

Lines changed: 48 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,38 @@
1-
# -*- coding: utf-8 -*-
2-
# ---
3-
# jupyter:
4-
# jupytext:
5-
# cell_metadata_filter: all,-hidden,-heading_collapsed,-run_control
6-
# notebook_metadata_filter: all,-language_info,-toc,-jupytext.text_representation.jupytext_version,-jupytext.text_representation.format_version
7-
# text_representation:
8-
# extension: .py
9-
# format_name: percent
10-
# kernelspec:
11-
# display_name: Python 3 (ipykernel)
12-
# language: python
13-
# name: python3
14-
# notebookname: parcours de graphe
15-
# version: '1.0'
16-
# ---
17-
18-
# %% [markdown]
19-
# <div class="licence">
20-
# <span>Licence CC BY-NC-ND</span>
21-
# <span>Thierry Parmentelat</span>
22-
# </div>
23-
24-
# %% [markdown]
25-
# ### plus court chemin - algorithme de Dijkstra
26-
27-
# %% [markdown]
28-
# digression sur ce sujet
29-
#
30-
31-
# %% trusted=true
1+
---
2+
jupytext:
3+
encoding: '# -*- coding: utf-8 -*-'
4+
text_representation:
5+
extension: .md
6+
format_name: myst
7+
kernelspec:
8+
display_name: Python 3 (ipykernel)
9+
language: python
10+
name: python3
11+
language_info:
12+
name: python
13+
nbconvert_exporter: python
14+
pygments_lexer: ipython3
15+
notebookname: parcours de graphe
16+
---
17+
18+
<div class="licence">
19+
<span>Licence CC BY-NC-ND</span>
20+
<span>Thierry Parmentelat</span>
21+
</div>
22+
23+
+++
24+
25+
### plus court chemin - algorithme de Dijkstra
26+
27+
+++
28+
29+
digression sur ce sujet
30+
31+
```{code-cell} ipython3
3232
import graphviz
33+
```
3334

34-
# %% trusted=true
35+
```{code-cell} ipython3
3536
g = graphviz.Digraph(engine='dot')
3637
g.edge('v1', 'v3', label='5')
3738
g.edge('v1', 'v2', label='1')
@@ -43,17 +44,19 @@
4344
g.edge('v4', 'v6', label='3')
4445
g.edge('v5', 'v6', label='1')
4546
g
47+
```
4648

47-
# %% trusted=true
49+
```{code-cell} ipython3
4850
graph = {
4951
'v1': {'v3': 5, 'v2': 1},
5052
'v3': {'v4': 1},
5153
'v2': {'v3': 1, 'v4': 3},
5254
'v4': {'v5': 1, 'v6': 3},
5355
'v5': {'v6': 1},
5456
}
57+
```
5558

56-
# %% trusted=true
59+
```{code-cell} ipython3
5760
# inf stands for infinity
5861
from math import inf
5962
@@ -71,9 +74,9 @@ def record(self, vertex, total):
7174
if total < self.min_distance:
7275
self.min_vertex = vertex
7376
self.min_distance = total
77+
```
7478

75-
76-
# %% trusted=true
79+
```{code-cell} ipython3
7780
# calcule seulement la distance
7881
def shortest_distance(graph_data, src, dst):
7982
explored = {src: 0}
@@ -92,12 +95,13 @@ def shortest_distance(graph_data, src, dst):
9295
return
9396
explored[best_vertex] = closest.min_distance
9497
print(f"YES ! shortest distance is {explored[dst]}")
98+
```
9599

96-
97-
# %% trusted=true
100+
```{code-cell} ipython3
98101
shortest_distance(graph, 'v1', 'v6')
102+
```
99103

100-
# %% trusted=true
104+
```{code-cell} ipython3
101105
from math import inf
102106
103107
class ClosestPreviousNext(dict):
@@ -116,9 +120,9 @@ def record(self, previous, vertex, total):
116120
self.min_previous = previous
117121
self.min_vertex = vertex
118122
self.min_distance = total
123+
```
119124

120-
121-
# %% trusted=true
125+
```{code-cell} ipython3
122126
# même algo mais mémorise aussi le chemin
123127
def shortest_path(graph_data, src, dst):
124128
# on en garde un peu plus dans cette structure
@@ -140,7 +144,8 @@ def shortest_path(graph_data, src, dst):
140144
explored[best_vertex] = (
141145
closest.min_distance, explored[best_previous][1] + [best_vertex])
142146
print(f"YES ! shortest path is {explored[dst]}")
147+
```
143148

144-
145-
# %% trusted=true
149+
```{code-cell} ipython3
146150
shortest_path(graph, 'v1', 'v6')
151+
```

0 commit comments

Comments
 (0)