- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

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>
34 class AlpsPriorityQueue {
35 private:
36 AlpsPriorityQueue(const AlpsPriorityQueue&);
37 AlpsPriorityQueue& operator=(const AlpsPriorityQueue&);
38
39 private:
40 std::vector<T> vec_;
41 AlpsCompare<T> comparison_; // Sort function for heap ordering.
42
43 public:
44 AlpsPriorityQueue() {}
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
Definition: AlpsPriorityQueue.h:34
AlpsPriorityQueue::AlpsPriorityQueue
AlpsPriorityQueue(AlpsSearchStrategy< T > &compare)
Definition: AlpsPriorityQueue.h:45
AlpsPriorityQueue::getContainer
const std::vector< T > & getContainer() const
Return a const reference to the container.
Definition: AlpsPriorityQueue.h:50
AlpsPriorityQueue::push
void push(T x)
Add a element to the heap.
Definition: AlpsPriorityQueue.h:62
AlpsPriorityQueue::AlpsPriorityQueue
AlpsPriorityQueue()
Definition: AlpsPriorityQueue.h:44
AlpsPriorityQueue::setComparison
void setComparison(AlpsSearchStrategy< T > &c)
Set comparison function and resort heap.
Definition: AlpsPriorityQueue.h:53
AlpsPriorityQueue::pop
void pop()
Remove the top element from the heap.
Definition: AlpsPriorityQueue.h:68
AlpsPriorityQueue::empty
bool empty() const
Return true for an empty vector.
Definition: AlpsPriorityQueue.h:74
CoinHelperFunctions.hpp
AlpsPriorityQueue::comparison_
AlpsCompare< T > comparison_
Definition: AlpsPriorityQueue.h:41
AlpsPriorityQueue::size
size_t size() const
Return the size of the vector.
Definition: AlpsPriorityQueue.h:79
AlpsSearchStrategyBase.h
AlpsPriorityQueue::vec_
std::vector< T > vec_
Definition: AlpsPriorityQueue.h:40
AlpsPriorityQueue::clear
void clear()
Remove all elements from the vector.
Definition: AlpsPriorityQueue.h:84
AlpsPriorityQueue::top
T top() const
Return the top element of the heap.
Definition: AlpsPriorityQueue.h:59
AlpsPriorityQueue::operator=
AlpsPriorityQueue & operator=(const AlpsPriorityQueue &)