Flat files and relational databases give us a mechanism to serialize structured data. XML is superb for serializing un-structured tree-like data.
But many problems are best represented by graphs. A thermal simulation program will, for instance, work with temperature nodes connected to each others through resistive edges.
So what is the best way to serialize a graph structure? I know XML can, to some extent, do it—in the same way that a relational database can serialize a complex web of objects: it usually works but can easily get ugly.
I know about the dot language used by the graphviz program, but I’m not sure this is the best way to do it. This question is probably the sort of thing academia might be working on and I’d love to have references to any papers discussing this.
How do you represent your graph in memory?
Basically you have two (good) options:
in which the adjacency list representation is best used for a sparse graph, and a matrix representation for the dense graphs.
If you used suchs representations then you could serialize those representations instead.
If it has to be human readable you could still opt for creating your own serialization algorithm. For example you could write down the matrix representation like you would do with any ‘normal’ matrix: just print out the columns and rows, and all the data in it like so:
(this is a non-optimized, non weighted representation, but can be used for directed graphs)