Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
dfs.h
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file dfs.h
1 /* This software is distributed under the GNU Lesser General Public License */
2 //==========================================================================
3 //
4 // dfs.h
5 //
6 //==========================================================================
7 // $Id: dfs.h,v 1.25 2003/03/24 15:58:54 raitner Exp $
8 
9 #ifndef GTL_DFS_H
10 #define GTL_DFS_H
11 
12 #include <GTL/GTL.h>
13 #include <GTL/algorithm.h>
14 
16 
88 class GTL_EXTERN dfs : public algorithm
89 {
90 public:
94  dfs ();
95 
96 
100  virtual ~dfs ();
101 
102  int run (graph& G);
103 
115  virtual int check (graph& G);
116 
117  virtual void reset ();
118 
119 
120  //---------------------------------------------------------------------
121  // Parameters
122  //---------------------------------------------------------------------
123 
129  void start_node (const node& n)
130  { start = n; }
131 
137  node start_node () const {return start;}
138 
157  void scan_whole_graph (bool set) {whole_graph = set;}
158 
166  bool scan_whole_graph () const {return whole_graph;}
167 
174  void calc_comp_num (bool set);
175 
182  bool calc_comp_num () const {return comp_number != 0;}
183 
184 
194  void store_preds (bool set);
195 
202  bool store_preds () const {return preds != 0;}
203 
214  void store_non_tree_edges (bool set);
215 
223  bool store_non_tree_edges () const {return back_edges != 0;}
224 
225  //---------------------------------------------------------------------
226  // Access
227  //----------------------------------------------------------------------
228 
235  bool reached (const node& n) const
236  {return dfs_number[n] != 0;}
237 
247  int dfs_num (const node& n) const
248  {return dfs_number[n];}
249 
259  int operator[] (const node& n) const
260  {return dfs_number[n];}
261 
270  int comp_num (const node& n) const
271  {assert (comp_number); return (*comp_number)[n];}
272 
283  node father (const node& n) const
284  {assert (preds); return (*preds)[n];}
285 
289  typedef list<edge>::const_iterator tree_edges_iterator;
290 
300  tree_edges_iterator tree_edges_begin () const
301  {return tree.begin();}
302 
308  tree_edges_iterator tree_edges_end () const
309  {return tree.end();}
310 
314  typedef list<node>::const_iterator dfs_iterator;
315 
321  dfs_iterator begin () const
322  {return dfs_order.begin();}
323 
330  dfs_iterator end () const
331  {return dfs_order.end();}
332 
336  typedef list<edge>::const_iterator non_tree_edges_iterator;
337 
344  non_tree_edges_iterator non_tree_edges_begin () const
345  {assert (back_edges); return back_edges->begin(); }
346 
354  non_tree_edges_iterator non_tree_edges_end () const
355  {assert (back_edges); return back_edges->end(); }
356 
360  typedef list<dfs_iterator>::const_iterator roots_iterator;
361 
389  roots_iterator roots_begin () const
390  {return roots.begin();}
391 
398  roots_iterator roots_end () const
399  {return roots.end();}
400 
407  int number_of_reached_nodes () const
408  {return reached_nodes;}
409 
410 
411  //-----------------------------------------------------------------------
412  // Handler - for customization purposes
413  //-----------------------------------------------------------------------
414 
420  virtual void init_handler (graph& G) {}
421 
427  virtual void end_handler (graph& G) {}
428 
436  virtual void entry_handler (graph& G, node& n, node& f) {}
437 
446  virtual void leave_handler (graph& G, node& n, node& f) {}
447 
456  virtual void before_recursive_call_handler (graph& G, edge& e, node& n) {}
457 
467  virtual void after_recursive_call_handler (graph& G, edge& e, node& n) {}
468 
478  virtual void old_adj_node_handler (graph& G, edge& e, node& n) {}
479 
490  virtual void new_start_handler (graph& G, node& n) { };
491 
492 private:
493 
497  void dfs_sub (graph&, node&, node&);
498 
499 protected:
500 
501  //----------------------------------------------------------------------
502  // Data
503  //----------------------------------------------------------------------
504 
516  list<edge> tree;
520  list<node> dfs_order;
536  list<dfs_iterator> roots;
537 
538 
539  //-----------------------------------------------------------------------
540  // Optional
541  //-----------------------------------------------------------------------
542 
554  list<edge>* back_edges;
563 };
564 
566 
567 #endif // GTL_DFS_H
568 
569 //--------------------------------------------------------------------------
570 // end of file
571 //--------------------------------------------------------------------------