I'm using the boost graph library to represent graph data. Algorithms and serialization are pretty well supported and the documentation is quite thorough.
That been said, I've come to a point where I need to "version my graph", and cannot find any related tutorial or example. By version I mean the ability to:
- Efficiently record version information in a graph, e.g.
v1.0
,v1.1
etc, and provide a succinct way to work with a specific version of the graph. - Handle serialization and information retrieval. E.g. how do I store the versioned graph and can I produce the "relative difference" between two versions?
I'd like to know if there is a widely accepted algorithmic approach or a BGL specific recipe that would apply in my case.
As a minimal example you can consider the family tree example:
#include <boost/config.hpp>
#include <iostream>
#include <vector>
#include <string>
#include <boost/graph/adjacency_list.hpp>
#include <boost/tuple/tuple.hpp>
enum family
{
Jeanie,
Debbie,
Rick,
John,
Amanda,
Margaret,
Benjamin,
N
};
int main()
{
using namespace boost;
const char* name[] = { "Jeanie", "Debbie", "Rick", "John", "Amanda",
"Margaret", "Benjamin" };
adjacency_list<> g(N);
// 1. How do I extend the graph accounting for versions?
add_edge(Jeanie, Debbie, g);
add_edge(Jeanie, Rick, g);
add_edge(Jeanie, John, g);
add_edge(Debbie, Amanda, g);
add_edge(Rick, Margaret, g);
add_edge(John, Benjamin, g);
graph_traits< adjacency_list<> >::vertex_iterator i, end;
graph_traits< adjacency_list<> >::adjacency_iterator ai, a_end;
property_map< adjacency_list<>, vertex_index_t >::type index_map
= get(vertex_index, g);
// 2. How do I iterate the graph based on versions?
for (boost::tie(i, end) = vertices(g); i != end; ++i)
{
std::cout << name[get(index_map, *i)];
boost::tie(ai, a_end) = adjacent_vertices(*i, g);
if (ai == a_end)
std::cout << " has no children";
else
std::cout << " is the parent of ";
for (; ai != a_end; ++ai)
{
std::cout << name[get(index_map, *ai)];
if (boost::next(ai) != a_end)
std::cout << ", ";
}
std::cout << std::endl;
}
return EXIT_SUCCESS;
}
My question imposes three problems which I annotate in the code:
- If the family tree had a version of the family in the 1990's and one in 2010's, how could I extend the graph considering
v1990
andv2010
? - When working with a specific version, can I isolate or exclusively use that version's data in my computations?
- How is serialization affected?