Running breadth-first search on an unweighted, directed graph on 2 vertices where each vertex is connected to the other yields a predecessor map where the source of the breadth-first search is not its own predecessor. The following program is sufficient to produce this behavior:
#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;
}
This seems to contradict the Boost Graph Library documentation. More importantly, the predecessor map should represent a spanning tree of the graph breadth-first search is run on, which is not the case when the source of the search is not its own predecessor.