I'm creating graphs from data from a JSON file and I'd like it so that when I traverse through both edges and vertices (e.g. in_edges(), vertices() or topological_sort() ) of the graph, it's in the exact same order regardless of the insertion order. In other words, to produce the same graph even if I shuffle the order of the JSON.
What would be the best way to do this? I'm currently using VecS as my Vertex and Edge types - would switching to SetS achieve this?
I'm currently thinking about using a wrapper struct around VertexDescriptors and EdgeDescriptors and also a wrapper class around a boost graph so that I can iterate over the graph internally, and return a sorted ordering of the Vertex/EdgeDescriptor wrapper struct instead.
You don't really show any examples, so let me dream up an example, and how I'd probably parse these.
Let the following JSON documents represent the same graphs:
And then flipping all possible properties at random and re-ordering the array elements at random, reformatting strings to contain escapes etc.:
I'd propose a helper function to build equivalent graphs from those documents:
For now, I've assumed simple vertex ids
[0, numvertices). Note how the edges are sorted in aset<>before adding them to the graph.Here's the combined listing showing equivalence after building the adjacency list:
Live On Coliru
Printing