diff --git a/include/boost/graph/graph_utility.hpp b/include/boost/graph/graph_utility.hpp index 1880ccee..42a4f60e 100644 --- a/include/boost/graph/graph_utility.hpp +++ b/include/boost/graph/graph_utility.hpp @@ -199,6 +199,30 @@ namespace boost { return *i; } + template + void generate_random_graph + (MutableGraph& g, + typename graph_traits::vertices_size_type V, + typename graph_traits::vertices_size_type E, + bool self_edges = false) + { + typedef graph_traits Traits; + typedef typename Traits::vertices_size_type v_size_t; + typedef typename Traits::edges_size_type e_size_t; + typedef typename Traits::vertex_descriptor vertex_descriptor; + + for (v_size_t i = 0; i < V; ++i) + add_vertex(g); + + for (e_size_t j = 0; j < E; ++j) { + vertex_descriptor a = random_vertex(g), b; + do { + b = random_vertex(g); + } while (self_edges == false && a == b); + add_edge(a, b, g); + } + } + template bool is_adj_dispatch(Graph& g, Vertex a, Vertex b, bidirectional_tag) { @@ -287,6 +311,17 @@ namespace boost { return false; } + // is x a descendant of y? + template + inline bool is_descendant(Node x, Node y, ParentMap p) { + if (p[x] == x) // x is the root of the tree + return false; + else if (p[x] == y) + return true; + else + return is_descendant(p[x], y, p); + } + template std::pair make_list(const T1& t1, const T2& t2)