문제

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));

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top