Alps  2.0.2
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  * Aykut Bulut, Lehigh University *
11  * Ted Ralphs, Lehigh University *
12  * *
13  * Conceptual Design: *
14  * *
15  * Yan Xu, Lehigh University *
16  * Ted Ralphs, Lehigh University *
17  * Laszlo Ladanyi, IBM T.J. Watson Research Center *
18  * Matthew Saltzman, Clemson University *
19  * *
20  * *
21  * Copyright (C) 2001-2023, Lehigh University, Yan Xu, Aykut Bulut, and *
22  * Ted Ralphs. *
23  * All Rights Reserved. *
24  *===========================================================================*/
25 
26 
27 #ifndef AlpsPriorityQueue_h_
28 #define AlpsPriorityQueue_h_
29 
30 #include <queue>
31 #include <vector>
32 #include "CoinHelperFunctions.hpp"
33 #include "AlpsSearchStrategyBase.h"
34 
35 //#############################################################################
36 
37 template<class T>
39  private:
42 
43  private:
44  std::vector<T> vec_;
45  AlpsCompare<T> comparison_; // Sort function for heap ordering.
46 
47  public:
49  AlpsPriorityQueue(AlpsSearchStrategy<T>& compare) {
50  setComparison(compare);
51  }
52 
54  const std::vector<T>& getContainer() const { return vec_; }
55 
57  void setComparison(AlpsSearchStrategy<T>& c) {
58  comparison_.strategy_ = &c;
59  std::make_heap(vec_.begin(), vec_.end(), comparison_);
60  }
61 
63  T top() const { return vec_.front(); }
64 
66  void push(T x) {
67  vec_.push_back(x);
68  std::push_heap(vec_.begin(), vec_.end(), comparison_);
69  }
70 
72  void pop() {
73  std::pop_heap(vec_.begin(), vec_.end(), comparison_);
74  vec_.pop_back();
75  }
76 
78  bool empty() const{
79  return vec_.empty();
80  }
81 
83  size_t size() const {
84  return vec_.size();
85  }
86 
88  void clear() { vec_.clear(); }
89 };
90 
91 //#############################################################################
92 
93 #if 0
94 template<class T,
95  class Container = std::vector<T>,
96  class Compare = std::less<typename Container::value_type> >
97 class AlpsPriorityQueue : public std::priority_queue<T, Container, Compare> {
98  public:
100  const Container& getContainer() const { return c; }
101 
103  // void cleanQueue(double cutoff){};
104 };
105 
106 #endif
107 
108 #endif // FILE
AlpsPriorityQueue::AlpsPriorityQueue
AlpsPriorityQueue(AlpsSearchStrategy< T > &compare)
Definition: AlpsPriorityQueue.h:49
AlpsPriorityQueue::operator=
AlpsPriorityQueue & operator=(const AlpsPriorityQueue &)
AlpsPriorityQueue::top
T top() const
Return the top element of the heap.
Definition: AlpsPriorityQueue.h:63
AlpsPriorityQueue::vec_
std::vector< T > vec_
Definition: AlpsPriorityQueue.h:44
AlpsSearchStrategyBase.h
AlpsPriorityQueue::pop
void pop()
Remove the top element from the heap.
Definition: AlpsPriorityQueue.h:72
AlpsPriorityQueue::AlpsPriorityQueue
AlpsPriorityQueue()
Definition: AlpsPriorityQueue.h:48
AlpsPriorityQueue::comparison_
AlpsCompare< T > comparison_
Definition: AlpsPriorityQueue.h:45
AlpsPriorityQueue::clear
void clear()
Remove all elements from the vector.
Definition: AlpsPriorityQueue.h:88
AlpsPriorityQueue::push
void push(T x)
Add a element to the heap.
Definition: AlpsPriorityQueue.h:66
AlpsPriorityQueue::empty
bool empty() const
Return true for an empty vector.
Definition: AlpsPriorityQueue.h:78
AlpsPriorityQueue::setComparison
void setComparison(AlpsSearchStrategy< T > &c)
Set comparison function and resort heap.
Definition: AlpsPriorityQueue.h:57
AlpsPriorityQueue::size
size_t size() const
Return the size of the vector.
Definition: AlpsPriorityQueue.h:83
AlpsPriorityQueue::getContainer
const std::vector< T > & getContainer() const
Return a const reference to the container.
Definition: AlpsPriorityQueue.h:54
AlpsPriorityQueue
Definition: AlpsPriorityQueue.h:38