13 #ifndef WIRECELL_INDEXEDGRAPH 14 #define WIRECELL_INDEXEDGRAPH 17 #include <boost/graph/connected_components.hpp> 18 #include <boost/graph/graph_traits.hpp> 19 #include <boost/graph/adjacency_list.hpp> 20 #include <boost/graph/copy.hpp> 22 #include <unordered_set> 30 template <
typename VertexType>
42 typedef boost::adjacency_list<boost::setS, boost::vecS,
45 typedef typename boost::graph_traits<graph_t>::vertex_descriptor
vdesc_t;
46 typedef typename boost::graph_traits<graph_t>::edge_descriptor
edesc_t;
53 typedef std::unordered_map<vdesc_t, size_t> vertex_map_t;
55 boost::associative_property_map<vertex_map_t> pmapindx(vmap);
57 for (
auto v : boost::make_iterator_range(boost::vertices(g))) {
60 boost::copy_graph(g,
m_graph, boost::vertex_index_map( pmapindx ) );
63 for (
auto v : boost::make_iterator_range(boost::vertices(
m_graph))) {
69 std::vector<vertex_t>
neighbors(vertex_t obj)
const {
70 std::vector<vertex_t> ret;
75 vdesc_t vd = it->second;
76 for (
auto edge : boost::make_iterator_range(boost::out_edges(vd,
m_graph))) {
84 bool has(vertex_t vobj)
const {
93 edesc_t
edge(vertex_t vobj1, vertex_t vobj2) {
94 vdesc_t v1 =
vertex(vobj1);
95 vdesc_t v2 =
vertex(vobj2);
96 auto ret = boost::add_edge(v1, v2,
m_graph);
106 vdesc_t vd = boost::add_vertex(vobj,
m_graph);
113 vdesc_t
replace(vertex_t vold, vertex_t vnew) {
130 std::unordered_map<vdesc_t, int> stripes;
131 boost::connected_components(
m_graph,
132 boost::make_assoc_property_map(stripes));
133 vertex_grouping_t ret;
134 for (
auto& vg : stripes) {
135 ret[vg.second].push_back(
m_graph[vg.first]);
149 typedef std::unordered_map<vertex_t, vdesc_t>
index_t;
std::unordered_map< int, std::vector< vertex_t > > vertex_grouping_t
Return connected component subgraphs.
std::vector< vertex_t > neighbors(vertex_t obj) const
const index_t & index() const
IndexedGraph(const graph_t &g)
const graph_t & graph() const
boost::graph_traits< graph_t >::vertex_descriptor vdesc_t
void put(Configuration &cfg, const std::string &dotpath, const T &val)
Put value in configuration at the dotted path.
vdesc_t vertex(vertex_t vobj)
boost::adjacency_list< boost::setS, boost::vecS, boost::undirectedS, vertex_t > graph_t
vertex_grouping_t groups()
vdesc_t replace(vertex_t vold, vertex_t vnew)
boost::graph_traits< graph_t >::edge_descriptor edesc_t
edesc_t edge(vertex_t vobj1, vertex_t vobj2)
bool has(vertex_t vobj) const
std::unordered_map< vertex_t, vdesc_t > index_t