Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
bfs.h
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file bfs.h
1 /* This software is distributed under the GNU Lesser General Public License */
2 //==========================================================================
3 //
4 // bfs.h
5 //
6 //==========================================================================
7 // $Id: bfs.h,v 1.14 2003/03/24 15:58:54 raitner Exp $
8 
9 #ifndef GTL_BFS_H
10 #define GTL_BFS_H
11 
12 #include <GTL/GTL.h>
13 #include <GTL/algorithm.h>
14 #include <GTL/node_map.h>
15 
16 #include <deque>
17 
19 
87 class GTL_EXTERN bfs : public algorithm
88 {
89 public:
90 
94  bfs ();
95 
99  virtual ~bfs ();
100 
101  int run (graph& G);
102 
112  virtual int check (graph& G) { return GTL_OK; }
113 
114  virtual void reset ();
115 
116  //-----------------------------------------------------------------------
117  // Parameters
118  //-----------------------------------------------------------------------
119 
129  void start_node (const node& n) {start = n;}
130 
136  node start_node () const {return start;}
137 
155  void scan_whole_graph (bool set) {whole_graph = set;}
156 
163  bool scan_whole_graph () const {return whole_graph;}
164 
175  void calc_level (bool set);
176 
183  bool calc_level () const {return level_number != 0;}
184 
194  void store_non_tree_edges (bool set);
195 
203  bool store_non_tree_edges () const {return non_tree != 0;}
204 
205 
215  void store_preds (bool set);
216 
223  bool store_preds () const {return preds != 0;}
224 
231  bool reached (const node& n) const
232  {return bfs_number[n] != 0;}
233 
243  int bfs_num (const node& n) const
244  {return bfs_number[n];}
245 
255  int operator[] (const node& n) const
256  {return bfs_number[n];}
257 
268  int level (const node& n) const
269  {assert (level_number); return (*level_number)[n];}
270 
284  node father (const node& n) const
285  {assert (preds); return (*preds)[n];}
286 
290  typedef list<edge>::const_iterator tree_edges_iterator;
291 
301  tree_edges_iterator tree_edges_begin () const
302  {return tree.begin();}
303 
310  tree_edges_iterator tree_edges_end () const
311  {return tree.end();}
312 
316  typedef list<node>::const_iterator bfs_iterator;
317 
323  bfs_iterator begin () const
324  {return bfs_order.begin();}
325 
332  bfs_iterator end () const
333  {return bfs_order.end();}
334 
338  typedef list<edge>::const_iterator non_tree_edges_iterator;
339 
346  non_tree_edges_iterator non_tree_edges_begin () const
347  {assert (non_tree); return non_tree->begin(); }
348 
356  non_tree_edges_iterator non_tree_edges_end () const
357  {assert (non_tree); return non_tree->end(); }
358 
362  typedef list<bfs_iterator>::const_iterator roots_iterator;
363 
393  roots_iterator roots_begin () const
394  {return roots.begin();}
395 
402  roots_iterator roots_end () const
403  {return roots.end();}
404 
411  int number_of_reached_nodes () const
412  {return reached_nodes;}
413 
414  //-----------------------------------------------------------------------
415  // Handler
416  //-----------------------------------------------------------------------
417 
423  virtual void init_handler (graph& G) { };
424 
430  virtual void end_handler (graph& G) { };
431 
438  virtual void popped_node_handler (graph& G, node& n) { };
439 
449  virtual void finished_node_handler (graph& G, node& n) { };
450 
461  virtual void unused_node_handler (graph& G, node& n, node& f) { };
462 
473  virtual void used_node_handler (graph& G, node& n, node& f) { };
474 
486  virtual void new_start_handler (graph& G, node& n) { };
487 
488 private:
489 
490  void bfs_sub (graph&, const node&, edge_map<int>*);
491 
492 protected:
493 
494  //-----------------------------------------------------------------------
495  // Data
496  //-----------------------------------------------------------------------
497 
502 
506  deque<node> qu;
507 
513  list<node> bfs_order;
514 
520  list<edge> tree;
521 
526 
531 
537  list<bfs_iterator> roots;
538 
539  //-----------------------------------------------------------------------
540  // Optional
541  //-----------------------------------------------------------------------
542 
549 
556 
563 
569  list<edge>* non_tree;
570 
577 };
578 
580 
581 #endif // GTL_BFS_H
582 
583 //--------------------------------------------------------------------------
584 // end of file
585 //--------------------------------------------------------------------------