2
0
mirror of https://github.com/boostorg/graph.git synced 2026-02-27 17:12:11 +00:00

rolling back, splitting out the neighbor bfs

[SVN r10735]
This commit is contained in:
Jeremy Siek
2001-08-02 15:56:57 +00:00
parent df57d4ff71
commit 1b2fdeaa9a

View File

@@ -112,15 +112,11 @@ namespace boost {
namespace detail {
struct normal_bfs_tag { };
struct neighbor_bfs_tag { };
template <class IncidenceGraph, class Buffer, class BFSVisitor,
class ColorMap, class Directedness>
class ColorMap>
void bfs_impl(const IncidenceGraph& g,
typename graph_traits<IncidenceGraph>::vertex_descriptor s,
Buffer& Q, BFSVisitor vis, ColorMap color,
Directedness, normal_bfs_tag)
Buffer& Q, BFSVisitor vis, ColorMap color)
{
function_requires< IncidenceGraphConcept<IncidenceGraph> >();
typedef graph_traits<IncidenceGraph> GTraits;
@@ -151,6 +147,7 @@ namespace boost {
Q.push(v);
} else {
vis.non_tree_edge(e, g);
if (v_color == Color::gray())
vis.gray_target(e, g);
else
@@ -161,94 +158,11 @@ namespace boost {
vis.finish_vertex(u, g);
} // while
}
template <class BidirectionalGraph, class Buffer, class BFSVisitor,
class ColorMap>
void bfs_impl
(const BidirectionalGraph& g,
typename graph_traits<BidirectionalGraph>::vertex_descriptor s,
Buffer& Q, BFSVisitor vis, ColorMap color, directed_tag,
neighbor_bfs_tag)
{
function_requires< BidirectionalGraphConcept<BidirectionalGraph> >();
typedef graph_traits<BidirectionalGraph> GTraits;
typedef typename GTraits::vertex_descriptor Vertex;
typedef typename GTraits::edge_descriptor Edge;
function_requires< BFSVisitorConcept<BFSVisitor, BidirectionalGraph> >();
function_requires< ReadWritePropertyMapConcept<ColorMap, Vertex> >();
typedef typename property_traits<ColorMap>::value_type ColorValue;
typedef color_traits<ColorValue> Color;
put(color, s, Color::gray());
vis.discover_vertex(s, g);
Q.push(s);
while (! Q.empty()) {
Vertex u = Q.top();
Q.pop(); // pop before push to avoid problem if Q is priority_queue.
vis.examine_vertex(u, g);
typename GTraits::out_edge_iterator ei, ei_end;
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);
ColorValue v_color = get(color, v);
if (v_color == Color::white()) {
vis.tree_edge(e, 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);
}
} // for out-edges
typename GTraits::in_edge_iterator in_ei, in_ei_end;
for (tie(in_ei, in_ei_end) = in_edges(u, g);
in_ei != in_ei_end; ++in_ei) {
Edge e = *in_ei;
vis.examine_edge(e, g);
Vertex v = source(e, g);
ColorValue v_color = get(color, v);
if (v_color == Color::white()) {
vis.tree_edge(e, 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);
}
} // for in-edges
put(color, u, Color::black());
vis.finish_vertex(u, g);
} // while
}
// Just use the normal BFS for undirected graphs
template <class IncidenceGraph, class Buffer, class BFSVisitor,
class ColorMap>
void bfs_impl
(const IncidenceGraph& g,
typename graph_traits<IncidenceGraph>::vertex_descriptor s,
Buffer& Q, BFSVisitor vis, ColorMap color,
undirected_tag tag, neighbor_bfs_tag)
{
bfs_impl(g, s, Q, vis, color, tag, normal_bfs_tag());
}
template <class VertexListGraph, class ColorMap, class BFSVisitor,
class P, class T, class R, class BFSKind>
class P, class T, class R>
void bfs_helper
(BFSKind kind, VertexListGraph& g,
(VertexListGraph& g,
typename graph_traits<VertexListGraph>::vertex_descriptor s,
ColorMap color,
BFSVisitor vis,
@@ -268,12 +182,10 @@ namespace boost {
put(color, *i, Color::white());
vis.initialize_vertex(*i, g);
}
typename graph_traits<VertexListGraph>::directed_category
directedness;
bfs_impl
(g, s,
choose_param(get_param(params, buffer_param_t()), Qref).ref,
vis, color, directedness, kind);
vis, color);
}
//-------------------------------------------------------------------------
@@ -283,15 +195,15 @@ namespace boost {
template <class ColorMap>
struct bfs_dispatch {
template <class VertexListGraph, class P, class T, class R, class BFSKind>
template <class VertexListGraph, class P, class T, class R>
static void apply
(BFSKind kind, VertexListGraph& g,
(VertexListGraph& g,
typename graph_traits<VertexListGraph>::vertex_descriptor s,
const bgl_named_params<P, T, R>& params,
ColorMap color)
{
bfs_helper
(kind, g, s, color,
(g, s, color,
choose_param(get_param(params, graph_visitor),
make_bfs_visitor(null_visitor())),
params);
@@ -300,11 +212,9 @@ namespace boost {
template <>
struct bfs_dispatch<detail::error_property_not_found> {
template <class VertexListGraph, class P, class T, class R,
class BFSKind>
template <class VertexListGraph, class P, class T, class R>
static void apply
(BFSKind kind,
VertexListGraph& g,
(VertexListGraph& g,
typename graph_traits<VertexListGraph>::vertex_descriptor s,
const bgl_named_params<P, T, R>& params,
detail::error_property_not_found)
@@ -313,7 +223,7 @@ namespace boost {
null_visitor null_vis;
bfs_helper
(kind, g, s,
(g, s,
make_iterator_property_map
(color_vec.begin(),
choose_const_pmap(get_param(params, vertex_index),
@@ -334,27 +244,14 @@ namespace boost {
typename graph_traits<VertexListGraph>::vertex_descriptor s,
const bgl_named_params<P, T, R>& params)
{
// The graph is passed by *const* reference so that graph adaptors (temporaries)
// can be passed into this function. However, the graph is not really const
// since we may write to property maps of the graph.
// The graph is passed by *const* reference so that graph adaptors
// (temporaries) can be passed into this function. However, the
// graph is not really const since we may write to property maps
// of the graph.
VertexListGraph& ng = const_cast<VertexListGraph&>(g);
typedef typename property_value< bgl_named_params<P,T,R>, vertex_color_t>::type C;
detail::bfs_dispatch<C>::apply(detail::normal_bfs_tag(), ng, s, params,
get_param(params, vertex_color));
}
template <class VertexListGraph, class P, class T, class R>
void neighbor_breadth_first_search
(const VertexListGraph& g,
typename graph_traits<VertexListGraph>::vertex_descriptor s,
const bgl_named_params<P, T, R>& params)
{
// The graph is passed by *const* reference so that graph adaptors (temporaries)
// can be passed into this function. However, the graph is not really const
// since we may write to property maps of the graph.
VertexListGraph& ng = const_cast<VertexListGraph&>(g);
typedef typename property_value< bgl_named_params<P,T,R>, vertex_color_t>::type C;
detail::bfs_dispatch<C>::apply(detail::neighbor_bfs_tag(), ng, s, params,
typedef typename property_value< bgl_named_params<P,T,R>,
vertex_color_t>::type C;
detail::bfs_dispatch<C>::apply(ng, s, params,
get_param(params, vertex_color));
}
@@ -373,39 +270,12 @@ namespace boost {
queue_t Q;
detail::wrap_ref<queue_t> Qref(Q);
typename graph_traits<IncidenceGraph>::directed_category directedness;
detail::bfs_impl
breadth_first_search
(g, s,
choose_param(get_param(params, buffer_param_t()), Qref).ref,
choose_param(get_param(params, graph_visitor),
make_bfs_visitor(null_visitor())),
choose_pmap(get_param(params, vertex_color), g, vertex_color),
directedness, detail::normal_bfs_tag()
);
}
template <class IncidenceGraph, class P, class T, class R>
void neighbor_breadth_first_visit
(IncidenceGraph& g,
typename graph_traits<IncidenceGraph>::vertex_descriptor s,
const bgl_named_params<P, T, R>& params)
{
typedef graph_traits<IncidenceGraph> Traits;
// Buffer default
typedef boost::queue<typename Traits::vertex_descriptor> queue_t;
queue_t Q;
detail::wrap_ref<queue_t> Qref(Q);
typename graph_traits<IncidenceGraph>::directed_category directedness;
detail::bfs_impl
(g, s,
choose_param(get_param(params, buffer_param_t()), Qref).ref,
choose_param(get_param(params, graph_visitor),
make_bfs_visitor(null_visitor())),
choose_pmap(get_param(params, vertex_color), g, vertex_color),
directedness, detail::neighbor_bfs_tag()
choose_pmap(get_param(params, vertex_color), g, vertex_color)
);
}