Generated on Wed Apr 29 2015 11:51:40 for GGL-4.1.2 by doxygen 1.8.3.1
Graph_boostV_p.hh
Go to the documentation of this file.
1 #ifndef SGM_GRAPH_BOOSTV_P_HH_
2 #define SGM_GRAPH_BOOSTV_P_HH_
3 
4 #include "sgm/Graph_Interface.hh"
5 #include "sgm/Graph_Interface.hh"
6 
7 #include <boost/graph/adjacency_list.hpp>
8 
9 #include <vector>
10 #include <utility>
11 
12 namespace sgm {
13 
14 
15 #define SGM_GRAPH_BOOSTV_P_TEMPLATE \
16  template < class GRAPH, \
17  typename NODE_LABEL_PROPERTY, \
18  typename EDGE_LABEL_PROPERTY, \
19  typename NODE_INDEX_PROPERTY \
20  >
21 
22 #define SGM_GRAPH_BOOSTV_P_TYPE \
23  Graph_boostV_p < GRAPH \
24  , NODE_LABEL_PROPERTY \
25  , EDGE_LABEL_PROPERTY \
26  , NODE_INDEX_PROPERTY \
27  >
28 
29  /*! @brief Graph_Interface wrapper for set of boost graphs
30  *
31  * This class implements the Graph interface of a labeled undirected
32  * graph. It is used as an interface of a vector of POINTERS of
33  * undirected labeled
34  * boost graphs to the sub graph matching algorithms of the library.
35  * The template parameter GRAPH represents the type of the
36  * boost graphs to use. The type names NODE_LABEL_PROPERTY and
37  * EDGE_LABEL_PROPERTY are used to generate the node and edge labels of
38  * the graph. The type name NODE_INDEX_PROPERTY is used to derive the
39  * corresponding local node index for a certain vertex in a graph.
40  * The mapped set of graphs is represented as ONE unconnected
41  * graph to the library.
42  *
43  * @author Martin Mann (c) 2008 http://www.bioinf.uni-freiburg.de/~mmann/
44  */
45  template < class GRAPH,
46  typename NODE_LABEL_PROPERTY = boost::vertex_name_t,
47  typename EDGE_LABEL_PROPERTY = boost::edge_name_t,
48  typename NODE_INDEX_PROPERTY = boost::vertex_index_t >
50 
51  protected:
52 
53  //! index property map
54  typedef typename boost::property_map<GRAPH, NODE_INDEX_PROPERTY>::const_type NodeIndexMap;
55 
56  //! edge label property map
57  typedef typename boost::property_map<GRAPH, EDGE_LABEL_PROPERTY>::const_type EdgeLabelMap;
58 
59  //! the vector of graphs to map
60  const std::vector< const GRAPH * > & graphs;
61 
62  //! the sum of node numbers up to graphs[i]
63  std::vector< size_t > graphSize;
64 
65  public:
66 
67  //! the location information of a node in the global index to the
68  //! graph index in graphs and the local node index in that graph.
69  //! LocalIndex.first gives the graph index in [0,graphs.size())
70  //! LocalIndex.second gives the local node in [0,graphs[LI.first].nodes)
71  typedef std::pair< size_t, size_t > LocalIndex;
72 
73  typedef GRAPH InternalBoostGraph;
74 
75 
76  //! Construction of the interface graph.
77  //! @param graphs the vector of boost graph pointers to use as
78  //! internal data structure (all != NULL)
79  Graph_boostV_p( const std::vector< const GRAPH * > & graphs );
80 
81  //! Destruction
82  virtual
84 
85  //! Access to the number of nodes of the graph
86  //! @return the overall node number
87  virtual
88  size_t
89  getNodeNumber(void) const;
90 
91  //! Access to the local index in graphs of the virtual global node i
92  //! @param i index of the global node of intrest
93  //! @return the local index of i in graphs and the local index of i in
94  //! that graph
96  getLocalIndex( const IndexType & i ) const;
97 
98  //! Access to the label of a specified node
99  //! @param i the index of the node of interest
100  //! @return a string representation of the node label
101  virtual
102  std::string
103  getNodeLabel(const IndexType & i) const;
104 
105 
106  //! Access to the internal list of GRAPH object pointers
107  //! @return a reference to the graphs object
108  const std::vector< const GRAPH* > &
109  getGraphs(void) const;
110 
111 
112  public:
113 
114  /*!
115  * Special edge descriptor to enable the iteration over the edges
116  * contained in the internally used boost graph instance.
117  *
118  */
120  protected:
121 
122  protected:
123  //! the source of the edge described
125  //! the target of the edge described
127  //! the out edge iterator of the current target node within
128  //! the local adjacency list
129  typename GRAPH::out_edge_iterator cur_edge;
130  //! the edge iterator that marks the end of
131  //! the local adjacency list
132  typename GRAPH::out_edge_iterator list_end;
133 
134  //! access to the graph instance
135  const GRAPH& graph;
136 
137  //! the index shift to correct node indices to the global index
138  const size_t nodeIndexShift;
139 
140  //! node index access
142  //! edge label access
144 
145  public:
146 
147  //! Construction of a new edge descriptor given the our edge
148  //! iterators
149  //! @param cur_edge the current boost edge iterator
150  //! @param neigh_end the end of the edge iteration
151  //! @param graph the graph instance the edge iterator is based on
152  //! @param nodeIndexShift index shift needed to correct node
153  //! indices to the global index
154  EdgeDescriptor( const typename GRAPH::out_edge_iterator& cur_edge,
155  const typename GRAPH::out_edge_iterator& neigh_end,
156  const GRAPH& graph,
157  const size_t nodeIndexShift
158  );
159 
160  //! Destruction
161  virtual
162  ~EdgeDescriptor();
163 
164  //! Access to the label of the edge.
165  //! @return the edge label
166  virtual
167  const std::string&
168  getEdgeLabel(void) const;
169 
170  //! Equality comparison
171  //! @param ed the edge to compare to
172  //! @return true if both descriptors describe the same edge
173  virtual
174  bool
175  operator==(const EdgeDescriptor& ed ) const;
176 
177  //! Inequality comparison
178  //! @param ed the edge to compare to
179  //! @return true if both descriptors describe different edges
180  virtual
181  bool
182  operator!=(const EdgeDescriptor& ed ) const;
183 
184  //! Inequality comparison
185  //! @param ed the edge to compare to
186  //! @return true if both descriptors describe different edges
187  virtual
188  bool
190 
191  //! Iterator support
192  //! @return the next EdgeDescriptor in the adjacency
193  virtual
195  operator++();
196 
197  //! Create a heap copy of this object. NOTE: this has to be
198  //! removed by the calling function.
199  //! @return a new heap copy of this object
200  virtual
202  clone() const;
203 
204  };
205 
206  //! Access to iteration begin for the edge in the adjacency list of
207  //! a specified node
208  //! @param i the index of the node of interest
209  //! @return the iterator to the first edge within the adjacency of i
210  virtual
212  getOutEdgesBegin( const IndexType & i ) const;
213 
214  //! Access to iteration end for the edge in the adjacency list of
215  //! a specified node
216  //! @param i the index of the node of interest
217  //! @return the iterator the end of the adjacency iteration of i
218  virtual
220  getOutEdgesEnd( const IndexType & i ) const;
221 
222 
223  //////////////////// STATIC MEMBERS ///////////////////////////////////
224 
225  public:
226 
227  //! Static member function that allows for the indexing of the nodes
228  //! in the graphs. For each graph it opens the property map for
229  //! NODE_INDEX_PROPERTY and sets an index with [0,num_vertices(g))
230  //! along the ordering defined by the vertex iterators.
231  //! Therefore, this function can be used to set the necessary local
232  //! indexes before creating a Graph_boostV_p object.
233  //! NOTE : The property map is NOT CONSTRUCTED has to be already part
234  //! of the GRAPH definition! It is ONLY FILLED!
235  static
236  void
237  indexGraphs ( std::vector< GRAPH * > & graphs );
238  };
239 
240 } // namespace sgm
241 
242 
243  // include template implementation of the class
244 #include "sgm/Graph_boostV_p.icc"
245 
246 
247 #endif /*GRAPH_BOOSTV_P_HH_*/