00001 // This is brl/bbas/bgrl/bgrl_search_func.h 00002 #ifndef bgrl_search_func_h_ 00003 #define bgrl_search_func_h_ 00004 //: 00005 // \file 00006 // \brief A set of search functions to search through a graph 00007 // \author Matt Leotta, (mleotta@lems.brown.edu) 00008 // \date March 24, 2004 00009 // 00010 // \verbatim 00011 // Modifications 00012 // 10-sep-2004 Peter Vanroose Added copy ctor with explicit vbl_ref_count init 00013 // \endverbatim 00014 00015 #include <vbl/vbl_ref_count.h> 00016 #include <bgrl/bgrl_vertex_sptr.h> 00017 #include <bgrl/bgrl_edge_sptr.h> 00018 #include <vcl_deque.h> 00019 #include <vcl_set.h> 00020 00021 00022 //: The abstract base class for search functions 00023 class bgrl_search_func : public vbl_ref_count 00024 { 00025 public: 00026 // Constructor 00027 bgrl_search_func(const bgrl_vertex_sptr& init_vertex = NULL) 00028 : curr_vertex_(init_vertex) {} 00029 00030 // Copy constructor 00031 bgrl_search_func(bgrl_search_func const& f) 00032 : vbl_ref_count(), curr_vertex_(f.curr_vertex_) {} 00033 00034 // Destructor 00035 ~bgrl_search_func() {} 00036 00037 bgrl_vertex_sptr curr_vertex() const { return curr_vertex_; } 00038 00039 //: Returns the edge to the next vertex in the search 00040 virtual bgrl_edge_sptr next_vertex() = 0; 00041 00042 protected: 00043 bgrl_vertex_sptr curr_vertex_; 00044 }; 00045 00046 //================================================================ 00047 00048 //: A search function for breadth first search 00049 class bgrl_breadth_search : public bgrl_search_func 00050 { 00051 public: 00052 //: Constructor 00053 bgrl_breadth_search(const bgrl_vertex_sptr& init_vertex = NULL) 00054 : bgrl_search_func(init_vertex) {visited_.insert(init_vertex);} 00055 00056 //: Destructor 00057 ~bgrl_breadth_search(){} 00058 00059 //: Returns the edge to the next vertex in the search 00060 virtual bgrl_edge_sptr next_vertex(); 00061 00062 protected: 00063 //: The queue of nodes to be evaluated 00064 vcl_deque<bgrl_edge_sptr> eval_queue_; 00065 //: The set of visited nodes 00066 vcl_set<bgrl_vertex_sptr> visited_; 00067 }; 00068 00069 //================================================================ 00070 00071 //: A search function for depth first search 00072 class bgrl_depth_search : public bgrl_search_func 00073 { 00074 public: 00075 //: Constructor 00076 bgrl_depth_search(const bgrl_vertex_sptr& init_vertex = NULL) 00077 : bgrl_search_func(init_vertex) {visited_.insert(init_vertex);} 00078 00079 //: Destructor 00080 ~bgrl_depth_search(){} 00081 00082 //: Returns the edge to the next vertex in the search 00083 virtual bgrl_edge_sptr next_vertex(); 00084 00085 protected: 00086 //: The queue of nodes to be evaluated 00087 vcl_deque<bgrl_edge_sptr> eval_queue_; 00088 //: The set of visited nodes 00089 vcl_set<bgrl_vertex_sptr> visited_; 00090 }; 00091 00092 #endif // bgrl_search_func_h_