AlpsPriorityQueue.h
Go to the documentation of this file.
1 /*===========================================================================*
2  * This file is part of the Abstract Library for Parallel Search (ALPS). *
3  * *
4  * ALPS is distributed under the Eclipse Public License as part of the *
5  * COIN-OR repository (http://www.coin-or.org). *
6  * *
7  * Authors: *
8  * *
9  * Yan Xu, Lehigh University *
10  * Ted Ralphs, Lehigh University *
11  * *
12  * Conceptual Design: *
13  * *
14  * Yan Xu, Lehigh University *
15  * Ted Ralphs, Lehigh University *
16  * Laszlo Ladanyi, IBM T.J. Watson Research Center *
17  * Matthew Saltzman, Clemson University *
18  * *
19  * *
20  * Copyright (C) 2001-2013, Lehigh University, Yan Xu, and Ted Ralphs. *
21  *===========================================================================*/
22 
23 #ifndef AlpsPriorityQueue_h_
24 #define AlpsPriorityQueue_h_
25 
26 #include <queue>
27 #include <vector>
28 #include "CoinHelperFunctions.hpp"
29 #include "AlpsSearchStrategyBase.h"
30 
31 //#############################################################################
32 
33 template<class T>
35  private:
38 
39  private:
40  std::vector<T> vec_;
41  AlpsCompare<T> comparison_; // Sort function for heap ordering.
42 
43  public:
45  AlpsPriorityQueue(AlpsSearchStrategy<T>& compare) {
46  setComparison(compare);
47  }
48 
50  const std::vector<T>& getContainer() const { return vec_; }
51 
53  void setComparison(AlpsSearchStrategy<T>& c) {
54  comparison_.strategy_ = &c;
55  std::make_heap(vec_.begin(), vec_.end(), comparison_);
56  }
57 
59  T top() const { return vec_.front(); }
60 
62  void push(T x) {
63  vec_.push_back(x);
64  std::push_heap(vec_.begin(), vec_.end(), comparison_);
65  }
66 
68  void pop() {
69  std::pop_heap(vec_.begin(), vec_.end(), comparison_);
70  vec_.pop_back();
71  }
72 
74  bool empty() const{
75  return vec_.empty();
76  }
77 
79  size_t size() const {
80  return vec_.size();
81  }
82 
84  void clear() { vec_.clear(); }
85 };
86 
87 //#############################################################################
88 
89 #if 0
90 template<class T,
91  class Container = std::vector<T>,
92  class Compare = std::less<typename Container::value_type> >
93 class AlpsPriorityQueue : public std::priority_queue<T, Container, Compare> {
94  public:
96  const Container& getContainer() const { return c; }
97 
99  // void cleanQueue(double cutoff){};
100 };
101 
102 #endif
103 
104 #endif // FILE
AlpsPriorityQueue(AlpsSearchStrategy< T > &compare)
const std::vector< T > & getContainer() const
Return a const reference to the container.
void push(T x)
Add a element to the heap.
void setComparison(AlpsSearchStrategy< T > &c)
Set comparison function and resort heap.
void pop()
Remove the top element from the heap.
bool empty() const
Return true for an empty vector.
AlpsCompare< T > comparison_
size_t size() const
Return the size of the vector.
std::vector< T > vec_
void clear()
Remove all elements from the vector.
T top() const
Return the top element of the heap.
AlpsPriorityQueue & operator=(const AlpsPriorityQueue &)