Generated on Wed Apr 29 2015 11:51:40 for GGL-4.1.2 by doxygen 1.8.3.1
RuleGraph.hh
Go to the documentation of this file.
1 #ifndef GGL_RULEGRAPH_HH_
2 #define GGL_RULEGRAPH_HH_
3 
4 
5 ////////////////////////////////////////////////////////////////////////////////
6 
7 #include "ggl/Rule.hh"
8 
9 #include <sgm/Graph_Interface.hh>
10 #include <sgm/Pattern.hh>
11 #include <sgm/PA_OrderCheck.hh>
12 
13 #include <set>
14 
15 namespace ggl {
16 
17 
18 
19  /*! @brief Rule left side pattern
20  *
21  * Implements the sgm::Pattern_Interface class to allow for the search of
22  * the left side of a given ggl::Rule object using the sgm library.
23  *
24  * @author Martin Mann (c) 2008 http://www.bioinf.uni-freiburg.de/~mmann/
25  */
27 
28  public:
29 
30  typedef std::set<IndexType> IndexSet;
31 
32  protected:
33 
34  //! handle to the property map used to derive the edge label
35  typedef boost::property_map<Rule::CoreGraph, Rule::EdgeLabelProperty>::const_type EdgeLabelMap;
36  //! handle to the property map used to derive the node label
37  typedef boost::property_map<Rule::CoreGraph, Rule::NodeLabelProperty>::const_type NodeLabelMap;
38  //! handle to the property map used to derive the local node indices
39  typedef boost::property_map<Rule::CoreGraph, Rule::NodeIndexProperty>::const_type NodeIndexMap;
40  //! handle to the property map used to derive the local edge context
41  typedef boost::property_map<Rule::CoreGraph, Rule::EdgeContextProperty>::const_type EdgeContextMap;
42  //! handle to the property map used to derive the local node context
43  typedef boost::property_map<Rule::CoreGraph, Rule::NodeContextProperty>::const_type NodeContextMap;
44 
45  //! The Rule object to map into the Graph_Interface.
46  const Rule& rule;
47 
48  //! Holds the first index of each component of this graph
49  //! Has to be sorted in increasing indices !!!
51 
52  //! Compontent labeling
54 
55  //! the list of order checks to apply to break all symmetries for this
56  //! rule
58 
59  //! direct access of the edge label map of the core graph
61  //! direct access of the node label map of the core graph
63  //! direct access of the node index map of the core graph
65  //! direct access of the edge context map of the core graph
67  //! direct access of the node context map of the core graph
69 
70  public:
71 
72  //! Constructs a LeftSidePattern for the given rule
73  //! @param rule the Rule this object will be a left side pattern of
74  LeftSidePattern( const Rule& rule );
75 
76  //! Copy construction.
77  //! @param toCopy the left side pattern to copy
78  LeftSidePattern( const LeftSidePattern& toCopy );
79 
80  virtual
82 
83  //! Access to the number of nodes of the graph
84  //! @return the overall node number
85  virtual
86  size_t
87  getNodeNumber(void) const;
88 
89  //! Access to the label of a specified node
90  //! @param i the index of the node of interest
91  //! @return a string representation of the node label
92  virtual
93  std::string
94  getNodeLabel(const IndexType & i) const;
95 
96  //! Constant access to the internal Rule object.
97  //! @return the internal Rule object
98  virtual
99  const Rule &
100  getRule(void) const;
101 
102  /*! Creates a Pattern_Automorphism object to handle symmetries when
103  * matching the LeftSidePattern of this rule.
104  * The GRAPHMATCHER template argument is used to choose a
105  * sgm::GraphMatcher class to be used for automorphism detection.
106  * @return the Pattern_Automorphism for this rule
107  */
108  template< class GRAPHMATCHER >
110  getGraphAutomorphismT( ) const;
111 
112  /*! Creates a Pattern_Automorphism object to handle symmetries when
113  * matching the LeftSidePattern of this rule. Calls
114  * getGraphAutomorphismT< sgm::GM_vf2 >().
115  * @return the Pattern_Automorphism for this rule
116  */
117  virtual
119  getGraphAutomorphism( ) const;
120 
121  /*! Access to the additional constraints that have to be fulfilled by
122  * a valid matching of the left side of a graph grammar rule.
123  * @return the additional sgm::Pattern_Interface::Match_Constraint's to be matched
124  */
125  virtual
126  const ConstraintVec &
127  getConstraints( void ) const;
128 
129  /*! Access to *this, since this is the pattern graph..
130  * @return the pattern graph to be matched
131  */
132  virtual
133  const Graph_Interface &
134  getPatternGraph( void ) const;
135 
136  //! Access to the wildcard to be used when matching this pattern onto
137  //! some other graph.
138  //! @return the wildcard string to be used for edge and node labels,
139  //! or NULL if no wildcard should be applied
140  virtual
141  const std::string *
142  getUsedWildcard( void ) const;
143 
144 
145  /*!
146  * Special edge descriptor to enable the iteration over the edges
147  * contained in the internally used boost graph instance.
148  *
149  */
150  class EdgeDescriptor : public Graph_Interface::EdgeDescriptor {
151  protected:
152  //! the source of the edge described
153  using Graph_Interface::EdgeDescriptor::from;
154  //! the target of the edge described
155  using Graph_Interface::EdgeDescriptor::to;
156  //! the out edge iterator of the current target node within
157  //! the local adjacency list
158  Rule::CoreGraph::out_edge_iterator cur_edge;
159  //! the edge iterator that marks the end of
160  //! the local adjacency list
161  Rule::CoreGraph::out_edge_iterator list_end;
162 
163  //! access to the parent instance for fast graph access
165 
166  public:
167 
168  //! Construction of a new edge descriptor given the our edge
169  //! iterators
170  //! @param cur_edge the current boost edge iterator
171  //! @param neigh_end the end of the edge iteration
172  //! @param parent access to the parent instance for graph access
173  EdgeDescriptor( const Rule::CoreGraph::out_edge_iterator& cur_edge,
174  const Rule::CoreGraph::out_edge_iterator& neigh_end,
175  const LeftSidePattern & parent );
176 
177  //! Destruction
178  virtual
179  ~EdgeDescriptor();
180 
181  //! Access to the label of the edge.
182  //! @return the edge label
183  virtual
184  const std::string&
185  getEdgeLabel(void) const;
186 
187  //! Equality comparison
188  //! @param ed the edge to compare to
189  //! @return true if both descriptors describe the same edge
190  bool
191  operator==(const EdgeDescriptor& ed ) const;
192 
193  //! Inequality comparison
194  //! @param ed the edge to compare to
195  //! @return true if both descriptors describe different edges
196  bool
197  operator!=(const EdgeDescriptor& ed ) const;
198 
199  //! Inequality comparison
200  //! @param ed the edge to compare to
201  //! @return true if both descriptors describe different edges
202  bool
203  operator!=(const Graph_Interface::EdgeDescriptor& ed ) const;
204 
205  //! Iterator support
206  //! @return the next EdgeDescriptor in the adjacency
207  virtual
209  operator++();
210 
211  //! Create a heap copy of this object. NOTE: this has to be
212  //! removed by the calling function.
213  //! @return a new heap copy of this object
214  virtual
216  clone() const;
217 
218  };
219 
220  //! Access to iteration begin for the edge in the adjacency list of
221  //! a specified node
222  //! @param i the index of the node of interest
223  //! @return the iterator to the first edge within the adjacency of i
224  virtual
226  getOutEdgesBegin( const IndexType & i ) const;
227 
228  //! Access to iteration end for the edge in the adjacency list of
229  //! a specified node
230  //! @param i the index of the node of interest
231  //! @return the iterator the end of the adjacency iteration of i
232  virtual
234  getOutEdgesEnd( const IndexType & i ) const;
235 
236  /*!
237  * Access to the component labeling of this pattern.
238  * @return the component labeling
239  */
240  const CompLabel&
241  getComponentLabeling( void ) const;
242 
243  /*!
244  * Access to the first index of each component of this pattern.
245  * @return a set of the first index for each component
246  */
247  const IndexSet&
248  getFirstOfEachComponent( void ) const;
249 
250  };
251 
252 
253 ////////////////////////////////////////////////////////////////////////////////
254 ////////////////////////////////////////////////////////////////////////////////
255 
256 } // namespace ggl
257 
258 
259 ////////////////////////////////////////////////////////////////////////////////
260 
261 namespace ggl {
262 
263 
264  /*! @brief Rule right side graph
265  *
266  * Implements the sgm::Graph_Interface class to allow for the search of
267  * the right side of a given Rule object using the sgm library.
268  *
269  * @author Martin Mann (c) 2008 http://www.bioinf.uni-freiburg.de/~mmann/
270  */
272 
273  protected:
274 
275  //! handle to the property map used to derive the edge label
276  typedef boost::property_map<Rule::CoreGraph, Rule::EdgeLabelProperty>::const_type EdgeLabelMap;
277  //! handle to the property map used to derive the node label
278  typedef boost::property_map<Rule::CoreGraph, Rule::NodeLabelProperty>::const_type NodeLabelMap;
279  //! handle to the property map used to derive the right node label
280  typedef boost::property_map<Rule::CoreGraph, Rule::NodeRightLabelProperty>::const_type NodeRightLabelMap;
281  //! handle to the property map used to derive the local node indices
282  typedef boost::property_map<Rule::CoreGraph, Rule::NodeIndexProperty>::const_type NodeIndexMap;
283  //! handle to the property map used to derive the local edge context
284  typedef boost::property_map<Rule::CoreGraph, Rule::EdgeContextProperty>::const_type EdgeContextMap;
285  //! handle to the property map used to derive the local node context
286  typedef boost::property_map<Rule::CoreGraph, Rule::NodeContextProperty>::const_type NodeContextMap;
287 
288 
289  //! The Rule object to map into the Graph_Interface.
290  const Rule& rule;
291 
292 
293  //! direct access of the edge label map of the core graph
295  //! direct access of the node label map of the core graph
297  //! direct access of the node label map of the core graph
299  //! direct access of the node index map of the core graph
301  //! direct access of the edge context map of the core graph
303  //! direct access of the node context map of the core graph
305 
306  public:
307 
308  RightSidePattern( const Rule& rule );
309 
310  virtual
312 
313  //! Access to the number of nodes of the graph
314  //! @return the overall node number
315  virtual
316  size_t
317  getNodeNumber(void) const;
318 
319  //! Access to the label of a specified node
320  //! @param i the index of the node of interest
321  //! @return a string representation of the node label
322  virtual
323  std::string
324  getNodeLabel(const IndexType & i) const;
325 
326  //! Constant access to the internal Rule object.
327  //! @return the internal Rule object
328  virtual
329  const Rule &
330  getRule(void) const;
331 
332 
333  /*!
334  * Special edge descriptor to enable the iteration over the edges
335  * contained in the internally used boost graph instance.
336  *
337  */
338  class EdgeDescriptor : public Graph_Interface::EdgeDescriptor {
339  protected:
340  //! the source of the edge described
341  using Graph_Interface::EdgeDescriptor::from;
342  //! the target of the edge described
343  using Graph_Interface::EdgeDescriptor::to;
344  //! the out edge iterator of the current target node within
345  //! the local adjacency list
346  Rule::CoreGraph::out_edge_iterator cur_edge;
347  //! the edge iterator that marks the end of
348  //! the local adjacency list
349  Rule::CoreGraph::out_edge_iterator list_end;
350 
351  //! access to the parent instance for fast graph access
353 
354  public:
355 
356  //! Construction of a new edge descriptor given the our edge
357  //! iterators
358  //! @param cur_edge the current boost edge iterator
359  //! @param neigh_end the end of the edge iteration
360  //! @param parent access to the parent instance for graph access
361  EdgeDescriptor( const Rule::CoreGraph::out_edge_iterator& cur_edge,
362  const Rule::CoreGraph::out_edge_iterator& neigh_end,
363  const RightSidePattern & parent );
364 
365  //! Destruction
366  virtual
367  ~EdgeDescriptor();
368 
369  //! Access to the label of the edge.
370  //! @return the edge label
371  virtual
372  const std::string&
373  getEdgeLabel(void) const;
374 
375  //! Equality comparison
376  //! @param ed the edge to compare to
377  //! @return true if both descriptors describe the same edge
378  bool
379  operator==(const EdgeDescriptor& ed ) const;
380 
381  //! Inequality comparison
382  //! @param ed the edge to compare to
383  //! @return true if both descriptors describe different edges
384  bool
385  operator!=(const EdgeDescriptor& ed ) const;
386 
387  //! Inequality comparison
388  //! @param ed the edge to compare to
389  //! @return true if both descriptors describe different edges
390  bool
391  operator!=(const Graph_Interface::EdgeDescriptor& ed ) const;
392 
393  //! Iterator support
394  //! @return the next EdgeDescriptor in the adjacency
395  virtual
397  operator++();
398 
399  //! Create a heap copy of this object. NOTE: this has to be
400  //! removed by the calling function.
401  //! @return a new heap copy of this object
402  virtual
404  clone() const;
405 
406  };
407 
408  //! Access to iteration begin for the edge in the adjacency list of
409  //! a specified node
410  //! @param i the index of the node of interest
411  //! @return the iterator to the first edge within the adjacency of i
412  virtual
414  getOutEdgesBegin( const IndexType & i ) const;
415 
416  //! Access to iteration end for the edge in the adjacency list of
417  //! a specified node
418  //! @param i the index of the node of interest
419  //! @return the iterator the end of the adjacency iteration of i
420  virtual
422  getOutEdgesEnd( const IndexType & i ) const;
423 
424 
425  };
426 
427 
428 ////////////////////////////////////////////////////////////////////////////////
429 ////////////////////////////////////////////////////////////////////////////////
430 
431 } // namespace ggl
432 
433 // template implementation
434 #include "ggl/RuleGraph.icc"
435 
436 
437 #endif /*RULEGRAPH_HH_*/