Reputation: 21
I'm using the networkx in python to creat a lot of graphs,and after this I need to use the Isomorphic algorithm to process them.Is there a way to save all these graph together for later retrieval like create a list for them?
Here is an example graph:
import networkx as nx
G = nx.Graph()
G.add_node(0, label='H')
G.add_node(1, label='P')
G.add_node(2, label='H')
G.add_edge(0, 1, weight=2)
G.add_edge(0, 2, weight=8)
Upvotes: 1
Views: 1902
Reputation: 3775
You can save/load your graph with networkx save/load functions, here is an example that saves the graph in pickle format:
import networkx as nx
import matplotlib.pyplot as plt
G = nx.Graph()
G.add_node(0, label='H')
G.add_node(1, label='P')
G.add_node(2, label='H')
G.add_edge(0, 1, weight=2)
G.add_edge(0, 2, weight=8)
# save graph
nx.write_gpickle(G, "pathToGraphPickleFile.nx")
# load graph
G2 = nx.read_gpickle("pathToGraphPickleFile.nx")
# display loaded graph
nx.draw(G2)
plt.show()
For other functions:https://networkx.github.io/documentation/stable/reference/readwrite/index.html
Upvotes: 2