Generated on Wed Apr 29 2015 11:51:40 for GGL-4.1.2 by doxygen 1.8.3.1
DFS_ApplyRule.hh
Go to the documentation of this file.
1 
2 #ifndef GGL_DFS_APPLYRULE_HH_
3 #define GGL_DFS_APPLYRULE_HH_
4 
5 #include "sgm/SGM_vf2.hh"
6 
7 #include "ggl/Graph.hh"
8 #include "ggl/Graph_Storage.hh"
9 #include "ggl/Rule.hh"
10 
11 namespace ggl {
12 
13 ///////////////////////////////////////////////////////////////////////////////
14 
15 
16 
17  /*! Depths-First-Search for graph grammars
18  *
19  * A generic Depths-First-Search (DFS) implementation that performs a
20  * recursive graph grammar rule application, i.e. it starts a new
21  * iteration of rule matching and application
22  * for each reported result graph of the last iteration.
23  *
24  * The recursion end is to be defined by an instance of the RecursionEnd.
25  *
26  * @author Martin Mann (c) 2011 http://www.bioinf.uni-freiburg.de/~mmann/
27  *
28  */
29  class DFS_ApplyRule : public Graph_Storage {
30 
31  public:
32 
33  /*!
34  * Handler to decide if a solution was found, a trace back is to be
35  * performed or another iteration of DFS is needed.
36  */
37  class DFS_Visitor {
38 
39  public:
40 
41  //! The possible decisions returned by the visitor.
43 
44  //! Destruction
45  virtual
47 
48  /*!
49  * Decides on the status of the current DFS, i.e. if the search
50  * is to be continued, a solution was found, or a traceback has
51  * to be done.
52  *
53  * @param graph the current graph to be decided on
54  * @return the status of the DFS
55  */
56  virtual
57  Decision
58  status( const Graph & graph ) = 0;
59 
60  };
61 
62  //! Container that stores a DFS trace.
63  typedef std::vector< const Graph* > SearchTrace;
64 
65  public:
66 
67  /*! Construction
68  */
69  DFS_ApplyRule( );
70 
71  //! Destruction
72  virtual ~DFS_ApplyRule();
73 
74  /*!
75  * Performs a DFS when applying the given rule onto the defined start
76  * graph.
77  *
78  * @param rules the rules to apply
79  * @param startGraph the start graph for the DFS
80  * @param solutionStorage the container where to report the solution to
81  * @param visitor the visitor instance that guides the DFS. Each result
82  * graph is checked with the visitor to decide if a solution was
83  * found, a trace back is needed or further DFS is to be done.
84  * @param searchTrace if non-NULL, DFS will copy the trace of the DFS
85  * search to the container, i.e. the sequence of graphs
86  * generated along the search
87  * @param doSymmBreak whether or not symmetry breaking should be done
88  * @param sgm the sub graph matcher to be used; if NULL an sgm::SGM_vf2
89  * object is used per default
90  *
91  * @return whether or not a solution was found
92  */
93  bool
94  findSolution( const std::vector< Rule > & rules
95  , const Graph & startGraph
98  , SearchTrace * searchTrace = NULL
99  , const bool doSymmBreak = true
100  , sgm::SubGraphMatching * sgm = NULL );
101 
102 
103  public: // GRAPH_STORAGE INTERFACE -> starts next DFS iteration
104 
105 
106  /*!
107  * The Graph_Storage interface is used to trigger a new DFS iteration.
108  * Thus, each added graph is checked if the DFS is to be aborted or
109  * not. In case the search is to be extended, another rule application
110  * iteration is started.
111  *
112  * @param graph the graph that might start another DFS iteration or
113  * is either a solution or DFS dead end.
114  */
115  void
116  add( const Graph & graph );
117 
118 
119  protected:
120 
121  //! the rule pattern currently applied
122  std::vector< const sgm::Pattern_Interface * > rulePattern;
123  //! the solution storage currently used
125  //! the DFS visitor currently used
127  //! the sub graph matcher currently used
129  //! the match reporter to be informed about each match
130  std::vector< sgm::Match_Reporter * > reporter;
131  //! the final trace to be filled if non-NULL
133  //! the current trace maintained by the current search
135  //! whether or not a solution was found during this search
137 
138  //! Dummy class to trigger DFS abortion via exception handling.
139  class DFS_ABORTION {};
140 
141 
142  };
143 
144 ///////////////////////////////////////////////////////////////////////////////
145 
146 }
147 
148 
149 #include "ggl/DFS_ApplyRule.icc"
150 
151 
152 #endif /* GGL_DFS_APPLYRULE_HH_ */