-
-
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
9 changed files
with
650 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 @@ | ||
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 |
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 @@ | ||
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,31 @@ | ||
# Import the libraries | ||
import networkx as nx | ||
import matplotlib.pyplot as plt | ||
|
||
# Create the DiGraph object | ||
DG = nx.DiGraph() | ||
|
||
# Add nodes/edges of type int | ||
DG.add_node(1) # add an initial node 1 | ||
DG.add_edge(1, 2) # add an edge from 1 to 2 | ||
|
||
# Add nodes of type str | ||
DG.add_node("alice") # add node "alice" | ||
DG.add_node("bob") # add node "bob" | ||
|
||
# Add nodes/edges of type tuple | ||
DG.add_edge("bob", (3, 4)) # link "bob" to new nodes 3, 4 | ||
DG.add_edge(1, ("alice", "bob")) # add an edge from 1 to "alice" and "bob" | ||
DG.add_edge(1, (4, 5)) # link node 1 to 3, 4 | ||
DG.add_edges_from([(5, 6), (6, 7)]) # add edges from 5, 6 to 7 | ||
|
||
# Print the number of nodes and edges | ||
print("The number of nodes in DG:", DG.number_of_nodes()) | ||
print("The number of edges in DG:", DG.number_of_edges()) | ||
|
||
# Draw the DiGraph | ||
nx.draw(DG, with_labels=True) | ||
|
||
# Calculate and print out the shortest path in DG | ||
sp = nx.shortest_path(DG) | ||
print("The shortest path in DG: ", 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 |
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 |