Skip to content

Commit

Permalink
added is_connected
Browse files Browse the repository at this point in the history
[SVN r8986]
  • Loading branch information
jsiek committed Feb 6, 2001
1 parent 06d42a6 commit 86ef707
Showing 1 changed file with 41 additions and 8 deletions.
49 changes: 41 additions & 8 deletions include/boost/graph/graph_utility.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down

0 comments on commit 86ef707

Please sign in to comment.