-
-
Notifications
You must be signed in to change notification settings - Fork 74
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #19 from parikshit14/forth-task
completed task forth
- Loading branch information
Showing
1 changed file
with
17 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,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) |