-
-
Notifications
You must be signed in to change notification settings - Fork 75
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'networkx:main' into main
- Loading branch information
Showing
3 changed files
with
19 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
2.7.1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
2.7.1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import networkx as nx | ||
import matplotlib.pyplot as plt | ||
|
||
# creating DiGraph object | ||
DG = nx.DiGraph() | ||
DG.add_edges_from([(1, 2), (2, 3)]) # adding node 1,2,3 and connecting them 1->2->3 | ||
DG.add_edge("hello", "world") # adding node and connecting them "hello" -> "world" | ||
DG.add_edge("world", (5, 6)) # adding node (5,6) and connecting them "world" -> (5,6) | ||
DG.add_edge(1, (5, 6)) # adding edge 1 -> (5,6) | ||
DG.add_edge(1, "world") # adding edge 1 -> "world" | ||
|
||
# Drawing the DiGraph | ||
nx.draw(DG, with_labels=True) | ||
|
||
# Calculating the shortest path and printing it | ||
sp = nx.shortest_path(DG) | ||
print(sp) |