Public Types | Public Member Functions | Private Attributes | List of all members
WireCell::IndexedGraph< VertexType > Class Template Reference

#include <IndexedGraph.h>

Public Types

typedef VertexType vertex_t
 
typedef boost::adjacency_list< boost::setS, boost::vecS, boost::undirectedS, vertex_tgraph_t
 
typedef boost::graph_traits< graph_t >::vertex_descriptor vdesc_t
 
typedef boost::graph_traits< graph_t >::edge_descriptor edesc_t
 
typedef std::unordered_map< int, std::vector< vertex_t > > vertex_grouping_t
 Return connected component subgraphs. More...
 
typedef std::unordered_map< vertex_t, vdesc_tindex_t
 

Public Member Functions

 IndexedGraph ()
 
 IndexedGraph (const graph_t &g)
 
std::vector< vertex_tneighbors (vertex_t obj) const
 
bool has (vertex_t vobj) const
 
edesc_t edge (vertex_t vobj1, vertex_t vobj2)
 
vdesc_t vertex (vertex_t vobj)
 
vdesc_t replace (vertex_t vold, vertex_t vnew)
 
void clear ()
 
vertex_grouping_t groups ()
 
const graph_tgraph () const
 
graph_tgraph ()
 
index_tindex ()
 
const index_tindex () const
 

Private Attributes

graph_t m_graph
 
index_t m_index
 

Detailed Description

template<typename VertexType>
class WireCell::IndexedGraph< VertexType >

Definition at line 31 of file IndexedGraph.h.

Member Typedef Documentation

template<typename VertexType>
typedef boost::graph_traits<graph_t>::edge_descriptor WireCell::IndexedGraph< VertexType >::edesc_t

Definition at line 46 of file IndexedGraph.h.

template<typename VertexType>
typedef boost::adjacency_list<boost::setS, boost::vecS, boost::undirectedS, vertex_t> WireCell::IndexedGraph< VertexType >::graph_t

Definition at line 44 of file IndexedGraph.h.

template<typename VertexType>
typedef std::unordered_map<vertex_t, vdesc_t> WireCell::IndexedGraph< VertexType >::index_t

Definition at line 149 of file IndexedGraph.h.

template<typename VertexType>
typedef boost::graph_traits<graph_t>::vertex_descriptor WireCell::IndexedGraph< VertexType >::vdesc_t

Definition at line 45 of file IndexedGraph.h.

template<typename VertexType>
typedef std::unordered_map<int, std::vector<vertex_t> > WireCell::IndexedGraph< VertexType >::vertex_grouping_t

Return connected component subgraphs.

Definition at line 128 of file IndexedGraph.h.

template<typename VertexType>
typedef VertexType WireCell::IndexedGraph< VertexType >::vertex_t

Definition at line 33 of file IndexedGraph.h.

Constructor & Destructor Documentation

template<typename VertexType>
WireCell::IndexedGraph< VertexType >::IndexedGraph ( )
inline

Definition at line 48 of file IndexedGraph.h.

48 {}
template<typename VertexType>
WireCell::IndexedGraph< VertexType >::IndexedGraph ( const graph_t g)
inline

Definition at line 50 of file IndexedGraph.h.

50  {
51 
52  // can't do straight copy() with setS unless give vertex index map.
53  typedef std::unordered_map<vdesc_t, size_t> vertex_map_t;
54  vertex_map_t vmap;
55  boost::associative_property_map<vertex_map_t> pmapindx(vmap);
56  int count = 0;
57  for (auto v : boost::make_iterator_range(boost::vertices(g))) {
58  boost::put(pmapindx, v, count++);
59  }
60  boost::copy_graph(g, m_graph, boost::vertex_index_map( pmapindx ) );
61 
62  // make index
63  for (auto v : boost::make_iterator_range(boost::vertices(m_graph))) {
64  m_index[m_graph[v]] = v;
65  }
66  }
void put(Configuration &cfg, const std::string &dotpath, const T &val)
Put value in configuration at the dotted path.
static const double g
Definition: Units.h:145

Member Function Documentation

template<typename VertexType>
void WireCell::IndexedGraph< VertexType >::clear ( void  )
inline

Definition at line 121 of file IndexedGraph.h.

121  {
122  m_index.clear();
123  m_graph.clear();
124  }
template<typename VertexType>
edesc_t WireCell::IndexedGraph< VertexType >::edge ( vertex_t  vobj1,
vertex_t  vobj2 
)
inline

Definition at line 93 of file IndexedGraph.h.

93  {
94  vdesc_t v1 = vertex(vobj1);
95  vdesc_t v2 = vertex(vobj2);
96  auto ret = boost::add_edge(v1, v2, m_graph);
97  return ret.first;
98  }
boost::graph_traits< graph_t >::vertex_descriptor vdesc_t
Definition: IndexedGraph.h:45
vdesc_t vertex(vertex_t vobj)
Definition: IndexedGraph.h:101
template<typename VertexType>
const graph_t& WireCell::IndexedGraph< VertexType >::graph ( ) const
inline

Definition at line 141 of file IndexedGraph.h.

141 { return m_graph; }
template<typename VertexType>
graph_t& WireCell::IndexedGraph< VertexType >::graph ( )
inline

Definition at line 145 of file IndexedGraph.h.

145 { return m_graph; }
template<typename VertexType>
vertex_grouping_t WireCell::IndexedGraph< VertexType >::groups ( )
inline

Definition at line 129 of file IndexedGraph.h.

129  {
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) { // invert
135  ret[vg.second].push_back(m_graph[vg.first]);
136  }
137  return ret;
138  }
std::unordered_map< int, std::vector< vertex_t > > vertex_grouping_t
Return connected component subgraphs.
Definition: IndexedGraph.h:128
template<typename VertexType>
bool WireCell::IndexedGraph< VertexType >::has ( vertex_t  vobj) const
inline

Definition at line 84 of file IndexedGraph.h.

84  {
85  auto it = m_index.find(vobj);
86  if (it == m_index.end()) {
87  return false;
88  }
89  return true;
90  }
template<typename VertexType>
index_t& WireCell::IndexedGraph< VertexType >::index ( )
inline

Definition at line 150 of file IndexedGraph.h.

150 { return m_index; }
template<typename VertexType>
const index_t& WireCell::IndexedGraph< VertexType >::index ( ) const
inline

Definition at line 151 of file IndexedGraph.h.

151 { return m_index; }
template<typename VertexType>
std::vector<vertex_t> WireCell::IndexedGraph< VertexType >::neighbors ( vertex_t  obj) const
inline

Definition at line 69 of file IndexedGraph.h.

69  {
70  std::vector<vertex_t> ret;
71  auto it = m_index.find(obj);
72  if (it == m_index.end()) {
73  return ret;
74  }
75  vdesc_t vd = it->second;
76  for (auto edge : boost::make_iterator_range(boost::out_edges(vd, m_graph))) {
78  ret.push_back(m_graph[neigh]);
79  }
80  return ret;
81  }
boost::graph_traits< graph_t >::vertex_descriptor vdesc_t
Definition: IndexedGraph.h:45
edesc_t edge(vertex_t vobj1, vertex_t vobj2)
Definition: IndexedGraph.h:93
template<typename VertexType>
vdesc_t WireCell::IndexedGraph< VertexType >::replace ( vertex_t  vold,
vertex_t  vnew 
)
inline

Definition at line 113 of file IndexedGraph.h.

113  {
114  auto vd = vertex(vold);
115  m_graph[vd] = vnew;
116  m_index[vnew] = vd;
117  return vd;
118  }
vdesc_t vertex(vertex_t vobj)
Definition: IndexedGraph.h:101
template<typename VertexType>
vdesc_t WireCell::IndexedGraph< VertexType >::vertex ( vertex_t  vobj)
inline

Definition at line 101 of file IndexedGraph.h.

101  {
102  auto it = m_index.find(vobj);
103  if (it != m_index.end()) {
104  return it->second;
105  }
106  vdesc_t vd = boost::add_vertex(vobj, m_graph);
107  m_index[vobj] = vd;
108  return vd;
109  }
boost::graph_traits< graph_t >::vertex_descriptor vdesc_t
Definition: IndexedGraph.h:45

Member Data Documentation

template<typename VertexType>
graph_t WireCell::IndexedGraph< VertexType >::m_graph
private

Definition at line 154 of file IndexedGraph.h.

template<typename VertexType>
index_t WireCell::IndexedGraph< VertexType >::m_index
private

Definition at line 155 of file IndexedGraph.h.


The documentation for this class was generated from the following file: