Quote: Original post by ToohrVyk
Wait, is your graph a tree ?
Indeed. travikk, your proposed XML format doesn't look like it makes any sense. Consider a very simple graph: three nodes connected in a triangle. How would you represent that with the structure you proposed? Unless your format means something very different from what it looks like it means, it can't.
Ideas:
1 - Adjacency lists. In XML, this might be,
<nodeList> <node name="some name" id="1"> <neighbor id="10"></neighbor> <neighbor id="5"></neighbor> <neighbor id="7"></neighbor> </node> <node name="some name" id="2"> <neighbor id="3"></neighbor> </node></nodeList>
(Disclaimer: XML is not my forte. I can see its use, but it smells of buzzwords to me.)
2 - Adjacency matrix. It's a 2d array. Element i,j contains a 1 if node i is connected to element j and a 0 otherwise. Note this is a symmetric matrix, so you only need to store half of it.
3 - Edge list. You could do this in XML. Basically, you have "edge" and "node" objects; your "edge" objects know which "nodes" they connect, and your "nodes" know which "edges" connect to them.
4 - Incidence matrix. Each row corresponds to a vertex; each column corresponds to an edge. There's a 1 in i,j, if edge j connects to vertex i.
If I'd tried writing a file format to store graphs many years ago, I'd probably have ended up with something a bit like #1 (but probably not XML -- probably a simpler text format, me being lazy). Knowing what I do now, I might just dump an adjacency matrix to a file. It has the advantage of being pretty easy. Plus, if you bother to actually store it as a bitmap, it's quite efficient. Which of these is more efficient depends on how connected your graph is, which in turn determines how sparse your adjacency matrix is.
[Edited by - Emergent on March 26, 2008 8:24:10 PM]