Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

digraph python script task #107

Merged
merged 1 commit into from
Oct 15, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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")