-
-
Notifications
You must be signed in to change notification settings - Fork 75
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'networkx:main' into main
- Loading branch information
Showing
35 changed files
with
3,965 additions
and
0 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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 libraries | ||
import networkx as nx | ||
|
||
#Digraph object | ||
DG = nx.DiGraph() | ||
DG.add_edges_from([(1, 2), (1, 3)]) # node 1,2,3 and connected them from 1->2->3 | ||
DG.add_edge("Hello", "World!") # node and connecting them "Hello" -> "World!" | ||
DG.add_edge("World!", (5, 6)) # node (5,6) and connecting them "World!" -> (5,6) | ||
DG.add_edge(1, (5, 6)) # edge 1 -> (5,6) | ||
DG.add_edge(1, "World!") # edge 1 -> "World!" | ||
|
||
# DiGraph | ||
nx.draw(DG, with_labels=True) | ||
|
||
# Calculate the shortest path and print it | ||
sp = nx.shortest_path(DG) | ||
print(sp) |
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 @@ | ||
2.7.2rc1.dev0 |
Large diffs are not rendered by default.
Oops, something went wrong.
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,34 @@ | ||
# Importing the libraries | ||
import networkx as nx | ||
|
||
|
||
# Creating DiGraph object | ||
G = nx.DiGraph() | ||
|
||
# Adding nodes of type int | ||
G.add_node(24) | ||
G.add_node(38) | ||
|
||
# Adding nodes of type str | ||
G.add_node("Amy") | ||
G.add_node("Jake") | ||
G.add_node("Rosa") | ||
G.add_node("Gina") | ||
|
||
# Adding edges to nodes | ||
G.add_edges_from([("Gina","Rosa"),("Gina","Amy"),("Gina","Jake"),("Jake","Amy")]) # Gina-->Rosa | Gina-->Amy | Gina-->Jake | Jake-->Amy | ||
G.add_edges_from([("Gina",24),("Jake",38)]) # Gina-->24 | Jake-->38 | ||
G.add_edge("Rosa",38) # Rosa-->38 | ||
G.add_edge(24,(16,17)) # 24-->(16,17) | ||
G.add_edge("Rosa",(16,17)) # Rosa-->(16,17) | ||
|
||
# Drawing the DiGraph | ||
nx.draw(G, with_labels=True) | ||
|
||
# Printing the number of nodes and edges | ||
print("Number of Nodes:", G.number_of_nodes()) | ||
print("Number of Edges:", G.number_of_edges()) | ||
|
||
# Calculating the shortest path and printing it | ||
shortest_path = nx.shortest_path(G) | ||
print(shortest_path) |
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 @@ | ||
2.7.1 |
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 @@ | ||
2.7.1 |
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,35 @@ | ||
#!/usr/bin/python3 | ||
|
||
import networkx as nx | ||
import matplotlib.pyplot as plt | ||
|
||
# Create a NetworkX DiGraph graph object | ||
DG = nx.DiGraph() | ||
|
||
# Adding nodes of multiple type | ||
|
||
# Adding nodes of type int (integer) | ||
DG.add_nodes_from([1, 2, 3,]) | ||
|
||
# Adding nodes of type str (string) | ||
|
||
DG.add_nodes_from(['smile', 'code', 'Consistency']) | ||
|
||
# Adding nodes of type typle | ||
DG.add_nodes_from([(5,6), (7, 8), (9, 10)]) | ||
|
||
# Adding multiple edges between nodes | ||
|
||
DG.add_edges_from([(1, 'smile'), (2, 3), (3, (5, 6)), | ||
('code', (7,8)), ('consistency', (9, 10)), | ||
('smile', 3),((7,8), 3), ('consitency', 'smile'), (1, (5,6)), | ||
((9, 10), 1)]) | ||
|
||
# Calculating shortest path between all pairs of node | ||
|
||
path = dict(nx.all_pairs_shortest_path(DG)) | ||
print(path) | ||
|
||
# plotting graph using networkx.draw | ||
|
||
nx.draw(DG) |
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 @@ | ||
2.7.1 |
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 @@ | ||
2.7.1 |
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
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 @@ | ||
https://github.com/aliveevie/networkx/pull/new/structured_labelled_array-4217 |
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,12 @@ | ||
import networkx as nx | ||
TG = nx.DiGraph() | ||
TG.add_nodes_from([ | ||
(4, {"color": "red"}), | ||
(5, {"color": "green"}), | ||
(6, {"color": "blue"}), | ||
(7, {"internship":"outreachy"}), | ||
]) | ||
TG.add_edges_from([(4, 5), (6, 7)]) | ||
sp = dict(nx.all_pairs_shortest_path(TG)) | ||
nx.draw(TG) | ||
sp |
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 @@ | ||
2.7.1 |
Large diffs are not rendered by default.
Oops, something went wrong.
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,39 @@ | ||
import networkx as nx | ||
|
||
DG = nx.DiGraph() | ||
|
||
# Adding nodes | ||
DG.add_node("a") | ||
DG.add_node("t") | ||
DG.add_node("w") | ||
DG.add_node("f") | ||
DG.add_node("o") | ||
DG.add_node("q") | ||
DG.add_node("e") | ||
|
||
|
||
# Adding edges to nodes | ||
DG.add_edges_from([("a","t"),("a","f"),("t","o"),("w","o"), ("f","t"), ("q","e")]) | ||
DG.add_edges_from([("a",4),("f",8), ("t", 2), ("w", 5), ("f", 7), ("q", 1)]) | ||
DG.add_edge("o", 10) | ||
DG.add_edge("w",(1,7)) | ||
|
||
# Drawing the DiGraph | ||
nx.draw(DG, with_labels=True) | ||
|
||
# Find and print the shortest path | ||
shortest_path = nx.shortest_path(DG) | ||
print(shortest_path) | ||
print(list(DG.successors('a'))) | ||
|
||
# Output: | ||
# print(shortest_path) {'a': {'a': ['a'], 't': ['a', 't'], 'f': ['a', 'f'], 4: ['a', 4], | ||
# 'o': ['a', 't', 'o'], 2: ['a', 't', 2], 8: ['a', 'f', 8], 7: ['a', 'f', 7], | ||
# 10: ['a', 't', 'o', 10]}, 't': {'t': ['t'], 'o': ['t', 'o'], 2: ['t', 2], 10: ['t', 'o', 10]}, | ||
# 'w': {'w': ['w'], 'o': ['w', 'o'], 5: ['w', 5], (1, 7): ['w', (1, 7)], 10: ['w', 'o', 10]}, | ||
# 'f': {'f': ['f'], 't': ['f', 't'], 8: ['f', 8], 7: ['f', 7], 'o': ['f', 't', 'o'], | ||
# 2: ['f', 't', 2], 10: ['f', 't', 'o', 10]}, 'o': {'o': ['o'], 10: ['o', 10]}, | ||
# 'q': {'q': ['q'], 'e': ['q', 'e'], 1: ['q', 1]}, 'e': {'e': ['e']}, 4: {4: [4]}, | ||
# 8: {8: [8]}, 2: {2: [2]}, 5: {5: [5]}, 7: {7: [7]}, 1: {1: [1]}, 10: {10: [10]}, | ||
# (1, 7): {(1, 7): [(1, 7)]}} | ||
# print(list(DG.successors('a'))): ['t', 'f', 4] |
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 @@ | ||
2.7.1 |
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,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) | ||
|
Oops, something went wrong.