Question

I am trying to find a way to perform the depth-first algorithm from a specific vertex by using the boost graph library.

The depth-first algorithm provided by Boost library evaluates the graph beginning from the start vertex to the last vertex. But what if the graph has to be searched from a specific vertex?

Any suggestions?

Was it helpful?

Solution

Have a look at BGL's documentation.

There is an overload where you can provide the start vertex.

template <class Graph, class DFSVisitor, class ColorMap>
void depth_first_search(const Graph& g, DFSVisitor vis, ColorMap color, 
                        typename graph_traits<Graph>::vertex_descriptor start)

OTHER TIPS

BGL Provides two mechanisms for setting the starting vertex of depth_first_search. You can either use the overload operator which requires supplying a ColorMap, or you can directly set the property of your visitor:

boost::depth_first_search(myGraph, boost::visitor(myVisitor).root_vertex(myVertex));

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top