Commit 6d1a9eff authored by Tiago Peixoto's avatar Tiago Peixoto

Implement label_biconnected_components()

parent 217b9d7a
......@@ -26,13 +26,28 @@ using namespace std;
using namespace boost;
using namespace graph_tool;
void do_label_components(GraphInterface& gi, boost::any prop)
void do_label_components(GraphInterface& gi, boost::any prop)
{
run_action<>()(gi, label_components(),
writable_vertex_scalar_properties())(prop);
}
size_t do_label_biconnected_components(GraphInterface& gi, boost::any comp,
boost::any art)
{
size_t nc;
run_action<graph_tool::detail::never_directed>()
(gi, bind<void>(label_biconnected_components(), _1, _2, _3,
ref(nc)),
writable_edge_scalar_properties(),
writable_vertex_scalar_properties())
(comp, art);
return nc;
}
void export_components()
{
python::def("label_components", &do_label_components);
python::def("label_biconnected_components",
&do_label_biconnected_components);
};
......@@ -18,6 +18,7 @@
#include <boost/graph/connected_components.hpp>
#include <boost/graph/strong_components.hpp>
#include <boost/graph/biconnected_components.hpp>
namespace graph_tool
{
......@@ -25,8 +26,8 @@ using namespace std;
using namespace boost;
// this will label the components of a graph to a given vertex property, from
// [0, number of components - 1]. If the graph is directed the "strong
// components" are used.
// [0, number of components - 1]. If the graph is directed the strong
// components are used.
struct label_components
{
template <class Graph, class CompMap>
......@@ -54,6 +55,39 @@ struct label_components
}
};
struct label_biconnected_components
{
template <class ArtMap>
class vertex_inserter
{
public:
vertex_inserter(ArtMap art_map): _art_map(art_map) {}
vertex_inserter& operator++() { return *this; }
vertex_inserter& operator++(int) { return *this; }
vertex_inserter& operator*() { return *this; }
vertex_inserter& operator=
(const typename property_traits<ArtMap>::key_type& e)
{
put(_art_map, e, 1);
return *this;
}
private:
ArtMap _art_map;
};
template <class Graph, class CompMap, class ArtMap>
void operator()(const Graph& g, CompMap comp_map, ArtMap art_map,
size_t& nc) const
{
nc = biconnected_components(g, comp_map,
vertex_inserter<ArtMap>(art_map)).first;
}
};
} // graph_tool namespace
#endif // GRAPH_COMPONENTS_HH
......@@ -28,7 +28,8 @@ from .. core import _degree, _prop
from numpy import *
__all__ = ["vertex_hist", "edge_hist", "vertex_average", "edge_average",
"label_components", "label_parallel_edges", "remove_parallel_edges",
"label_components", "label_biconnected_components",
"label_parallel_edges", "remove_parallel_edges",
"label_self_loops", "remove_self_loops", "remove_labeled_edges"]
def vertex_hist(g, deg, bins=[1], float_count=True):
......@@ -295,6 +296,21 @@ def label_components(g, vprop=None, directed=None):
g.pop_filter(directed=True)
return vprop
def label_biconnected_components(g, eprop=None, vprop=None):
if vprop == None:
vprop = g.new_vertex_property("bool")
if eprop == None:
eprop = g.new_edge_property("int32_t")
g.stash_filter(directed=True)
g.set_directed(False)
nc = libgraph_tool_stats.\
label_biconnected_components(g._Graph__graph, _prop("e", g, eprop),
_prop("v", g, vprop))
g.pop_filter(directed=True)
return eprop, vprop, nc
def remove_labeled_edges(g, label):
g.stash_filter(all=False, directed=True, reversed=True)
libgraph_tool_stats.\
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment