Performing depth-first algorithm from a specific vertex
-
30-09-2019 - |
문제
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?
해결책
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)
다른 팁
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));
제휴하지 않습니다 StackOverflow