-
-
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 #108 from Qudirah/main
Access my Second Task
- Loading branch information
Showing
2 changed files
with
21 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,21 @@ | ||
import networkx as nx | ||
import matplotlib as plt | ||
|
||
G=nx.DiGraph() #calling on the digraph function | ||
node_lists=['Qudirah','Outreachy','intern',5,(2,4)] #creating a list of nodes to add | ||
G.add_nodes_from(node_lists) | ||
edges_list=[('Qudirah','intern',{"length":1}) #creating a list of edges with attribute length | ||
,('intern','Outreachy',{"length":0.5}),('Qudirah',(2,4),{"length":5}),('intern',5,{"length":0.452}),('5',(2,4),{"length":10})] | ||
G.add_edges_from(edges_list) | ||
path=dict(nx.all_pairs_dijkstra_path_length(G,weight='length')) | ||
def print_distance(): | ||
"""function prints each of the nodes with shortest distance to every other node""" | ||
for i in node_lists: | ||
for m,n in path[i].items(): | ||
print("Shortest distance between "+str(i)+' and '+str(m)+' is '+str(n)) | ||
def plot_network(): | ||
"""function to plot the network diagram""" | ||
nx.draw(G,with_labels=True) | ||
|
||
print_distance() | ||
plot_network() |
File renamed without changes.