Why does the algorithm X work with adjacency_list where
VertexList=vecS but not when VertexList=listS?
Often the reason is that the algorithm expects to find the
vertex_index property stored in the graph. When
VertexList=vecS, the adjacency_list automatically
has a vertex_index property. However, when VertexList=listS
this is not the case, and the vertex_index property must be
explicitly added, and initialized. For example,
// specify the graph type
typedef adjacency_list<listS, listS, undirectedS,
property<vertex_index_t, std::size_t>,
no_property
> graph_t;
// construct a graph object
graph_t G(num_nodes);
// obtain a property map for the vertex_index property
property_map<graph_t, vertex_index_t>::type
index = get(vertex_index, G);
// initialize the vertex_index property values
graph_traits<graph_t>::vertex_iterator vi, vend;
graph_traits<graph_t>::vertices_size_type cnt = 0;
for(tie(vi,vend) = vertices(G); vi != vend; ++vi)
put(index, *vi, cnt++);