Skip to content

Commit

Permalink
Merge pull request #38 from deepthi1107/main
Browse files Browse the repository at this point in the history
second contribution
  • Loading branch information
MridulS authored Apr 4, 2022
2 parents dcd8ba9 + ac40ab1 commit 4cbd893
Showing 1 changed file with 68 additions and 0 deletions.
68 changes: 68 additions & 0 deletions 2022-round-1/deepthi1107/nx_tutorial_script.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
#!/usr/bin/env python
# coding: utf-8

# In[1]:


#importing the required libraries
import networkx as nx


# In[2]:


#Creating DiGraph
graph1=nx.DiGraph()


# In[3]:


#adding node 11,"N1",1,2,3,(4,5)
graph1.add_node(11)
graph1.add_node("N1")
L=[1,2,3]
graph1.add_nodes_from(L)
graph1.add_node((4,5))


# In[4]:


#view of all the nodes inserted to the DiGraph
graph1.nodes()


# In[5]:


#adding edges 11->"N1",1->2,2->3,3->11,N1->(4,5),(4,5)->1
graph1.add_edge(11,"N1")
graph1.add_edge(1,2)
graph1.add_edge(2,3)
graph1.add_edge(3,11)
graph1.add_edge("N1",(4,5))
graph1.add_edge((4,5),1)


# In[6]:


#view of edges, connecting the nodes
graph1.edges()


# In[7]:


#visualization of DiGraph created
nx.draw(graph1,with_labels=1)


# In[8]:


#finding the shoretes path between the nodes and printing the shortest path
s_path = nx.shortest_path(graph1)
print(s_path)

0 comments on commit 4cbd893

Please sign in to comment.