for example, I want to bfs for only k steps, or called k level. How can I do it? Now I know only a little about how to terminate it from Is it possible to change breadth first search termination condition in BGL?.
CodePudding user response:
Maintain a count of levels and when level equals k steps, you can terminate the bfs.
CodePudding user response:
Wrap the first call the BFS in a try .. catch structure
try {
... call the BFS routine ...
}
catch
{
std::cout << "max level reached\n";
{
In the visitor contructor, initialize a level counter.
In the visitor, increment the level and throw an exception when the maximkum is reached.