52 #ifndef HAVOQGT_MPI_BREADTH_FIRST_SEARCH_HPP_INCLUDED
53 #define HAVOQGT_MPI_BREADTH_FIRST_SEARCH_HPP_INCLUDED
57 #include <boost/container/deque.hpp>
62 template <
typename Visitor>
67 std::priority_queue< Visitor, std::deque<Visitor>,
72 bool push(Visitor
const & task)
90 return m_data.size();;
95 return m_data.empty();
104 template <
typename Visitor>
109 typedef typename boost::container::deque<Visitor>::size_type
size_type;
116 bfs_queue() : m_vec_bfs_level_stack(20), m_cur_min_level(std::numeric_limits<level_number_type>::max()), m_size(0) { }
118 bool push(Visitor
const & task)
120 while(task.level() >= m_vec_bfs_level_stack.size()) {
121 m_vec_bfs_level_stack.push_back(boost::container::deque<Visitor>());
123 m_vec_bfs_level_stack[task.level()].push_back(task);
125 m_cur_min_level = std::min(m_cur_min_level, (uint32_t)task.level());
133 if(m_vec_bfs_level_stack[m_cur_min_level].
empty()) {
135 for(;m_cur_min_level < m_vec_bfs_level_stack.size(); ++
m_cur_min_level) {
136 if(!m_vec_bfs_level_stack[m_cur_min_level].
empty())
break;
153 return (m_size == 0);
158 for(
typename std::vector<boost::container::deque<Visitor> >::iterator itr = m_vec_bfs_level_stack.begin();
159 itr != m_vec_bfs_level_stack.end(); ++itr) {
163 m_cur_min_level = std::numeric_limits<level_number_type>::max();
169 template<
typename Graph,
typename LevelData,
typename ParentData>
174 bfs_visitor(vertex_locator _vertex, uint64_t _level, vertex_locator _parent)
193 template<
typename VisitorQueueHandle>
194 bool visit(Graph& g, VisitorQueueHandle vis_queue)
const {
199 typedef typename Graph::edge_iterator eitr_type;
200 for(eitr_type eitr = g.edges_begin(
vertex); eitr != g.edges_end(
vertex); ++eitr) {
201 vertex_locator neighbor = eitr.target();
205 vis_queue->queue_visitor(new_visitor);
234 static LevelData* data;
240 static ParentData* data;
247 } __attribute__ ((packed));
250 template <
typename TGraph,
typename LevelData,
typename ParentData>
252 LevelData& level_data,
253 ParentData& parent_data,
254 typename TGraph::vertex_locator s) {
257 visitor_type::set_level_data(&level_data);
258 visitor_type::set_parent_data(&parent_data);
261 visitor_queue_type vq(g);
262 vq.init_visitor_traversal(s);
272 #endif //HAVOQGT_MPI_BREADTH_FIRST_SEARCH_HPP_INCLUDED
static void set_parent_data(ParentData *_data)
static void set_level_data(LevelData *_data)
static LevelData *& level_data()
uint32_t level_number_type
friend bool operator>(const bfs_visitor &v1, const bfs_visitor &v2)
static ParentData *& parent_data()
std::vector< boost::container::deque< Visitor > > m_vec_bfs_level_stack
Graph::vertex_locator vertex_locator
bfs_visitor(vertex_locator _vertex)
bool push(Visitor const &task)
bfs_visitor(vertex_locator _vertex, uint64_t _level, vertex_locator _parent)
bool visit(Graph &g, VisitorQueueHandle vis_queue) const
std::priority_queue< Visitor, std::deque< Visitor >, std::greater< Visitor > > m_data
level_number_type m_cur_min_level
vertex_locator parent() const
void breadth_first_search(TGraph *g, LevelData &level_data, ParentData &parent_data, typename TGraph::vertex_locator s)
bool push(Visitor const &task)
boost::container::deque< Visitor >::size_type size_type