2
0
mirror of https://github.com/boostorg/graph.git synced 2026-01-30 07:52:10 +00:00

added is_connected

[SVN r8986]
This commit is contained in:
Jeremy Siek
2001-02-06 19:40:26 +00:00
parent 06d42a60d7
commit 86ef707164

View File

@@ -313,8 +313,12 @@ namespace boost {
}
// is x a descendant of y?
template <typename Node, typename ParentMap>
inline bool is_descendant(Node x, Node y, ParentMap parent) {
template <typename ParentMap>
inline bool is_descendant
(typename property_traits<ParentMap>::value_type x,
typename property_traits<ParentMap>::value_type y,
ParentMap parent)
{
if (get(parent, x) == x) // x is the root of the tree
return false;
else if (get(parent, x) == y)
@@ -324,19 +328,48 @@ namespace boost {
}
// is y reachable from x?
template <typename Graph, typename ColorMap>
template <typename IncidenceGraph, typename VertexColorMap>
inline bool is_reachable
(typename graph_traits<Graph>::vertex_descriptor x,
typename graph_traits<Graph>::vertex_descriptor y,
const Graph& g,
ColorMap color) // should be white for every vertex
(typename graph_traits<IncidenceGraph>::vertex_descriptor x,
typename graph_traits<IncidenceGraph>::vertex_descriptor y,
const IncidenceGraph& g,
VertexColorMap color) // should start out white for every vertex
{
typedef typename property_traits<ColorMap>::value_type ColorValue;
typedef typename property_traits<VertexColorMap>::value_type ColorValue;
dfs_visitor<> vis;
depth_first_visit(g, x, vis, color);
return get(color, y) != color_traits<ColorValue>::white();
}
// Is the undirected graph connected?
// Is the directed graph strongly connected?
template <typename VertexListGraph, typename VertexColorMap>
inline bool is_connected(const VertexListGraph& g, VertexColorMap color)
{
typedef typename property_traits<VertexColorMap>::value_type ColorValue;
typedef color_traits<ColorValue> Color;
typename graph_traits<VertexListGraph>::vertex_iterator
ui, ui_end, vi, vi_end, ci, ci_end;
for (tie(ui, ui_end) = vertices(g); ui != ui_end; ++ui)
for (tie(vi, vi_end) = vertices(g); vi != vi_end; ++vi)
if (*ui != *vi) {
for (tie(ci, ci_end) = vertices(g); ci != ci_end; ++ci)
put(color, *ci, Color::white());
if (! is_reachable(*ui, *vi, color))
return false;
}
return true;
}
template <typename Graph>
bool is_self_loop
(typename graph_traits<Graph>::edge_descriptor e,
const Graph& g)
{
return source(e, g) == target(e, g);
}
template <class T1, class T2>
std::pair<T1,T2>
make_list(const T1& t1, const T2& t2)