在2个顶点上的未加权有向图上运行广度优先搜索,其中每个顶点连接到另一个顶点,产生前驱映射,其中广度优先搜索的源不是其自己的前驱 . 以下程序足以产生此行为:

#include <vector>
#include <boost/graph/adjacency_list.hpp>
#include <boost/graph/breadth_first_search.hpp>

using namespace boost;
using std::vector;

enum family { one, two, N };

typedef adjacency_list< vecS, vecS, directedS> Graph;
typedef graph_traits<Graph>::vertex_descriptor Vertex;

int main() {
    Graph g(N);

    const char *name[] = { "one", "two" };

    add_edge(one, two, g);
    add_edge(two, one, g);

    vector<Vertex> p(num_vertices(g));

    breadth_first_search(g, two, visitor(make_bfs_visitor(
                     record_predecessors(&p[0],
                             on_tree_edge()))));

    //At this point, p[0] == 1 and p[1] == 0

    return 0;
}

这似乎与Boost Graph Library文档相矛盾 . 更重要的是,前一个映射应该表示运行图的广度优先搜索的生成树,而当搜索源不是它自己的前任时则不是这种情况 .