I am trying to save and then retrieve an igraph Graph with the graph attributes. Specifically, I have a two-terminal graph, and I am storing the source and sink as graph attributes so I can retrieve them in constant time. Note, the vertices are not in any specific order (e.g., the first vertex is the source and the last is the sink).
I have searched the documentation but I can't see that any of the formats support storing/retrieving graph attributes. Am I missing anything?
My fallback is to use boolean source/sink vertex attributes, but that takes more space and requires linear time to retrieve the right vertices.
GraphML supports numeric and string attributes that can be attached to the entire graph, to individual vertices or to individual edges (actually, it supports even more complex ones but igraph's GraphML implementation is limited to numeric and string attributes). So, you could use Graph.write_graphml()
and Graph.Read_GraphML()
. Also, you can simply save an igraph graph using Python's pickle
module (i.e. use pickle.dump()
and pickle.load()
) and you will get all the graph/vertex/edge attributes back (even complex Python objects) -- the only catch is that the pickle
format is not interoperable with other tools outside the Python world.