diff --git a/include/boost/graph/breadth_first_search.hpp b/include/boost/graph/breadth_first_search.hpp index e41f4345..16b3211d 100644 --- a/include/boost/graph/breadth_first_search.hpp +++ b/include/boost/graph/breadth_first_search.hpp @@ -83,15 +83,14 @@ namespace boost { while (! Q.empty()) { Vertex u = Q.top(); Q.pop(); vis.examine_vertex(u, g); for (tie(ei, ei_end) = out_edges(u, g); ei != ei_end; ++ei) { - Edge e = *ei; vis.examine_edge(e, g); - Vertex v = target(e, g); + Vertex v = target(*ei, g); vis.examine_edge(*ei, g); ColorValue v_color = get(color, v); - if (v_color == Color::white()) { vis.tree_edge(e, g); + if (v_color == Color::white()) { vis.tree_edge(*ei, g); put(color, v, Color::gray()); vis.discover_vertex(v, g); Q.push(v); - } else { vis.non_tree_edge(e, g); - if (v_color == Color::gray()) vis.gray_target(e, g); - else vis.black_target(e, g); + } else { vis.non_tree_edge(*ei, g); + if (v_color == Color::gray()) vis.gray_target(*ei, g); + else vis.black_target(*ei, g); } } // end for put(color, u, Color::black()); vis.finish_vertex(u, g); diff --git a/include/boost/graph/depth_first_search.hpp b/include/boost/graph/depth_first_search.hpp index 42052f49..623b3c25 100644 --- a/include/boost/graph/depth_first_search.hpp +++ b/include/boost/graph/depth_first_search.hpp @@ -70,26 +70,23 @@ namespace boost { { function_requires >(); function_requires >(); + typedef typename graph_traits::vertex_descriptor Vertex; + function_requires< ReadWritePropertyMapConcept >(); typedef typename property_traits::value_type ColorValue; function_requires< ColorValueConcept >(); typedef color_traits Color; - - put(color, u, Color::gray()); - vis.discover_vertex(u, g); typename graph_traits::out_edge_iterator ei, ei_end; + + put(color, u, Color::gray()); vis.discover_vertex(u, g); for (tie(ei, ei_end) = out_edges(u, g); ei != ei_end; ++ei) { - vis.examine_edge(*ei, g); - ColorValue v_color = get(color, target(*ei, g)); - if (v_color == Color::white()) { - vis.tree_edge(*ei, g); - depth_first_visit_impl(g, target(*ei, g), vis, color); - } else if (v_color == Color::gray()) - vis.back_edge(*ei, g); - else - vis.forward_or_cross_edge(*ei, g); + Vertex v = target(*ei, g); vis.examine_edge(*ei, g); + ColorValue v_color = get(color, v); + if (v_color == Color::white()) { vis.tree_edge(*ei, g); + depth_first_visit_impl(g, v, vis, color); + } else if (v_color == Color::gray()) vis.back_edge(*ei, g); + else vis.forward_or_cross_edge(*ei, g); } - put(color, u, Color::black()); - vis.finish_vertex(u, g); + put(color, u, Color::black()); vis.finish_vertex(u, g); } } // namespace detail @@ -105,19 +102,16 @@ namespace boost { typename graph_traits::vertex_iterator ui, ui_end; for (tie(ui, ui_end) = vertices(g); ui != ui_end; ++ui) { - put(color, *ui, Color::white()); - vis.initialize_vertex(*ui, g); + put(color, *ui, Color::white()); vis.initialize_vertex(*ui, g); } - if (start_vertex != *vertices(g).first) { - vis.start_vertex(start_vertex, g); + if (start_vertex != *vertices(g).first){ vis.start_vertex(start_vertex, g); detail::depth_first_visit_impl(g, start_vertex, vis, color); } for (tie(ui, ui_end) = vertices(g); ui != ui_end; ++ui) { ColorValue u_color = get(color, *ui); - if (u_color == Color::white()) { - vis.start_vertex(*ui, g); + if (u_color == Color::white()) { vis.start_vertex(*ui, g); detail::depth_first_visit_impl(g, *ui, vis, color); } }