Skip to content

Commit

Permalink
Merge pull request #107 from hrshshrm/main
Browse files Browse the repository at this point in the history
digraph python script task
  • Loading branch information
MridulS authored Oct 15, 2022
2 parents 274876a + 4881c32 commit f301199
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions 2022-round-2/hrshshrm/nx_tutorial_script.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import networkx as nx

# Create a NetworkX DiGraph graph object
DG = nx.DiGraph()

# Add nodes of multiple types to this graph object
listOfNodes = [ 1, 7, ("NetworkX", "Outreachy"), "DiGraph", ("Agent", 47), "2B" ]
DG.add_nodes_from(listOfNodes)

# Add multiple edges between these nodes
listOfEdges = [
(1, 7),
(1, "2B"),
(1, ("Agent", 47)),
(7, "2B"),
(7, "DiGraph"),
(("NetworkX", "Outreachy"), "DiGraph"),
(("NetworkX", "Outreachy"), 7),
(("NetworkX", "Outreachy"), ("Agent", 47)),
(("Agent", 47), 1),
("2B", "DiGraph"),
("2B", ('NetworkX', 'Outreachy'),)
]
DG.add_edges_from(listOfEdges)

# Find the shortest path between all pairs of nodes in this graph and print them.
shortestPaths = dict(nx.all_pairs_shortest_path(DG))
for key in shortestPaths:
print(key, shortestPaths[key])

# Plot the graph using networkx.draw
nx.draw(DG, nx.shell_layout(DG), with_labels=True, font_weight="bold")

0 comments on commit f301199

Please sign in to comment.