diff --git a/examples/bfs_basics.cpp b/examples/bfs_basics.cpp index 74924717..d4447640 100644 --- a/examples/bfs_basics.cpp +++ b/examples/bfs_basics.cpp @@ -86,30 +86,40 @@ int main(int argc, char* argv[]) // color property needed in breadth-first search std::vector color(num_vertices(G)); + typedef boost::property_map::type IndexMap; + IndexMap vertex_id = get(vertex_index(), G); + // discover time property std::vector dtime(num_vertices(G)); // finish time property std::vector ftime(num_vertices(G)); + typedef std::vector::iterator RAIter; + typedef random_access_iterator_property_map IterMap; + + IterMap discover(dtime.begin(), vertex_id); + IterMap finish(ftime.begin(), vertex_id); + // Call the 4 argument version of BFS. // There is also a 3 argument version (assume color is in the graph) // and a 5 argument version (adds an argument for the queue). int time = 0; boost::breadth_first_search (G, vertex(s, G), make_bfs_visitor( - std::make_pair(stamp_times(dtime.begin(), time, on_discover_vertex()), - stamp_times(ftime.begin(), time, on_finish_vertex()))), - color.begin()); + std::make_pair(stamp_times(discover, time, on_discover_vertex()), + stamp_times(finish, time, on_finish_vertex()))), + make_iterator_property_map(color.begin(), vertex_id, color[0])); cout << "order of discovery: "; // Perform some STL magic to order the vertices // according to their discover time - vector discover_order(N); + std::vector discover_order(N); iota(discover_order.begin(), discover_order.end(), 0); std::sort(discover_order.begin(), discover_order.end(), - indirect_cmp >(dtime.begin())); + indirect_cmp >(discover)); for (i = 0; i < N; ++i) cout << name[ discover_order[i] ] << " "; @@ -120,7 +130,7 @@ int main(int argc, char* argv[]) vector finish_order(N); iota(finish_order.begin(), finish_order.end(), 0); std::sort(finish_order.begin(), finish_order.end(), - indirect_cmp >(ftime.begin())); + indirect_cmp >(finish)); for (i = 0; i < N; ++i) cout << name[ finish_order[i] ] << " "; diff --git a/examples/dave.cpp b/examples/dave.cpp index f9457db2..1798c0c6 100644 --- a/examples/dave.cpp +++ b/examples/dave.cpp @@ -117,7 +117,7 @@ struct edge_printer template void operator()(T x, Graph& g) { m_os << "(" << get(m_pa, source(x, g)) << "," - << get(m_pa, target(x, g)) << ") "; + << get(m_pa, target(x, g)) << ") "; } PA m_pa; std::ostream& m_os; @@ -173,12 +173,14 @@ main(int argc, char* argv[]) enum { a, b, c, d, e, f, g, N}; Graph G(N); + boost::property_map::type + vertex_id = get(vertex_index(), G); - vector distance(N, numeric_limits::max()); + std::vector distance(N, numeric_limits::max()); typedef boost::graph_traits::vertex_descriptor Vertex; - vector parent(N); + std::vector parent(N); - typedef pair E; + typedef std::pair E; E edges[] = { E(a,c), E(a,d), E(b,a), E(b,d), @@ -209,27 +211,32 @@ main(int argc, char* argv[]) boost::breadth_first_search (G, vertex(a, G), make_bfs_visitor( - std::make_pair(write_property(name, cout_char, on_discover_vertex()), - std::make_pair(write_property(distance.begin(), cout_int, - on_discover_vertex()), - std::make_pair(print_edge(name, std::cout, on_examine_edge()), + std::make_pair(write_property(make_iterator_property_map(name, vertex_id, name[0]), + cout_char, on_discover_vertex()), + std::make_pair(write_property(make_iterator_property_map(distance.begin(), vertex_id, distance[0]), + cout_int, on_discover_vertex()), + std::make_pair(print_edge(make_iterator_property_map(name, vertex_id, name[0]), + std::cout, on_examine_edge()), print_endl(std::cout, on_finish_vertex() )))))); - dijkstra_shortest_paths(G, vertex(a, G), distance.begin(), + dijkstra_shortest_paths(G, vertex(a, G), + make_iterator_property_map(distance.begin(), vertex_id, distance[0]), make_ucs_visitor(std::make_pair(copy_graph(G_copy, on_examine_edge()), - record_predecessors(parent.begin(), - on_edge_relaxed())))); + record_predecessors(make_iterator_property_map(parent.begin(), vertex_id, parent[0]), + on_edge_relaxed())))); cout << endl; cout << "Result:" << endl; breadth_first_search (G_copy, vertex(a, G_copy), make_bfs_visitor( - std::make_pair(write_property(name, cout_char, on_discover_vertex()), - std::make_pair(write_property(distance.begin(), cout_int, - on_discover_vertex()), - std::make_pair(print_edge(name, std::cout, on_examine_edge()), + std::make_pair(write_property(make_iterator_property_map(name, vertex_id, name[0]), + cout_char, on_discover_vertex()), + std::make_pair(write_property(make_iterator_property_map(distance.begin(), vertex_id, distance[0]), + cout_int, on_discover_vertex()), + std::make_pair(print_edge(make_iterator_property_map(name, vertex_id, name[0]), + std::cout, on_examine_edge()), print_endl(std::cout, on_finish_vertex() - )))))); + )))))); return 0; } diff --git a/examples/dfs_parenthesis.cpp b/examples/dfs_parenthesis.cpp index f7911bd5..d3373e3f 100644 --- a/examples/dfs_parenthesis.cpp +++ b/examples/dfs_parenthesis.cpp @@ -75,13 +75,16 @@ main(int argc, char* argv[]) typedef boost::graph_traits::vertex_descriptor Vertex; typedef boost::graph_traits::vertices_size_type size_type; + boost::property_map::type + vertex_id = get(vertex_index(), G); std::vector color(num_vertices(G)); std::cout << "DFS parenthesis:" << std::endl; depth_first_search(G, make_dfs_visitor(std::make_pair(open_paren(), close_paren())), - color.begin()); + make_iterator_property_map(color.begin(), + vertex_id, color[0])); std::cout << std::endl; return 0; } diff --git a/examples/visitor.cpp b/examples/visitor.cpp index 5f4066d6..bf80e4f3 100644 --- a/examples/visitor.cpp +++ b/examples/visitor.cpp @@ -96,6 +96,8 @@ main(int argc, char* argv[]) typedef boost::graph_traits::vertex_descriptor Vertex; typedef boost::graph_traits::vertices_size_type size_type; + boost::property_map::type + vertex_id = get(vertex_index(), G); std::vector c(num_vertices(G)); std::vector d(num_vertices(G)); @@ -107,14 +109,14 @@ main(int argc, char* argv[]) std::make_pair(print_edge("back", on_back_edge()), print_edge("forward or cross", on_forward_or_cross_edge()) ))), - c.begin()); + make_iterator_property_map(c.begin(), vertex_id, c[0])); cout << endl << "BFS categorized directed graph" << endl; boost::breadth_first_search (G, vertex(0, G), make_bfs_visitor( std::make_pair(print_edge("tree", on_tree_edge()), print_edge("cycle", on_cycle_edge()))), - c.begin()); + make_iterator_property_map(c.begin(), vertex_id, c[0])); return 0; }