I'm using Boost Graph to try and make sense of some dependency graphs I have generated in Graphviz Dot format.
Unfortunately I don't know very much about graph theory, so I have a hard time framing what I want to know in terms of graph theory lingo.
From a directed dependency graph with ~150 vertices, I'd like to "zoom in" on one specific vertex V, and build a subgraph containing V, all its incoming edges and their incoming edges, all its outgoing edges and their outgoing edges, sort of like a longest path through V.
These dependency graphs are pretty tangled, so I'd like to remove clutter to make it clearer what might affect the vertex in question.
For example, given;
g
|
v
a -> b -> c -> d
| | |
v v |
e f <-------+
if I were to run the algorithm on c
, I think I want;
g
|
v
a -> b -> c -> d -> f
Not sure if b -> f should be included as well... I think of it as all vertices "before" c should have their in-edges included, and all vertices "after" c should have their out-edges included, but it seems to me that that would lose some information.
It feels like there should be an algorithm that does this (or something more sensible, not sure if I'm trying to do something stupid, cf b->f above), but I'm not sure where to start looking.
Thanks!
Ok, so I'll translate and adapt my tutorial to your specific question. The documentation always assumes tons of "using namespace"; I won't use any so you know what is what. Let's begin :
First, define a Vertex and an Edge :
Create the type or your graph :
Now, you can use a shortcut to the type of the IDs of your Vertices and Edges :
Instanciate your graph :
Read your Graphviz data, and feed the graph :
Notice that
graph[ a VertexID ]
gives a Vertex, butgraph[ an EdgeID ]
gives an Edge. Here's how to add one :So now you have your graph. You want to get the VertexID for Vertex "c". To keep it simple, let's use a linear search :
And finally, to get the neighbours of a vertex :
You can also get edges with
So, for your real question :
Example for in_edges (never compiled or tried, out of the top of my head):
For the other way around, just rename Parent into Children, and use adjacency_iterator / adjacent_vertices.
Hope this helps.
Here's how it ended up. I realized I needed to work entirely in terms of in-edges and out-edges:
This also handles cycles before or after the vertex in question. My source dependency graph had cycles (shudder).
I made some attempts at generalizing collect_*_edges into a templated collect_edges, but I didn't have enough meta-programming debugging energy to spend on it.