I'm using a boost::directed_graph and am running DFS on it to determine the dependencies of a particular node. I pass the name of the node I'm interested in to the visitor implementation. My issue is that during the DFS if I, for example, enumerate the left subtree of the graph and then in the right subtree come across a cross edge back to the left subtree, DFS will not re-enumerate those nodes because it has already visited them. I'd like to run DFS again with the node pointed to by the cross edge as the root. Example:
The node I want to find dependencies for is C (which is enumerated 4th). I want to get back A and B as dependencies, so it seems to me that when I get a cross edge like this I should run DFS on the subgraph with A as the root to get those nodes.
typedef boost::directed_graph<Plugin> graph;
typedef graph::edge_descriptor graph_e_des;
typedef std::vector<std::wstring> DependencyVector;
class DependencyVisitor : public boost::default_dfs_visitor
{
public:
DependencyVisitor(DependencyVector& dependencies, std::wstring& name) :
m_dependencies(dependencies),
m_name(name)
{
}
void forward_or_cross_edge(graph_e_des e, const graph& g)
{
DependencyVector dependencies;
std::wstring name = g[e.m_target].name;
DependencyVisitor v(dependencies, name);
boost::depth_first_search(g[e.m_target], boost::visitor(v));
m_dependencies.insert(std::end(m_dependencies), std::begin(dependencies), std::begin(dependencies));
}
private:
DependencyVector& m_dependencies;
std::wstring m_name;
};
I tried calling boost::depth_first_search again using what forward_or_cross_edge provides but I don't know how to get a new graph at the desired node. I was reading about boost::filtered_graph or boost::subgraph but it wasn't clear of those were the right solutions.
Thanks in advance.
