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

- File List
- File Members

AlpsSubTreePool.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 AlpsSubTreePool_h_
24 #define AlpsSubTreePool_h_
25
26 #include "AlpsHelperFunctions.h"
27 #include "AlpsSubTree.h"
28
29 //#############################################################################
30
32 class AlpsSubTreePool : public AlpsKnowledgePool {
33
34 private:
35 AlpsSubTreePool(const AlpsSubTreePool&);
36 AlpsSubTreePool& operator=(const AlpsSubTreePool&);
37
38 AlpsPriorityQueue<AlpsSubTree*> subTreeList_;
39
40 public:
41 AlpsSubTreePool() {}
42 virtual ~AlpsSubTreePool() {
43 if (!subTreeList_.empty()) {
44 deleteGuts();
45 }
46 }
47
49 inline int getNumKnowledges() const { return static_cast<int> (subTreeList_.size()); }
50
52 inline bool hasKnowledge() const{ return ! (subTreeList_.empty()); }
53
55 inline std::pair<AlpsKnowledge*, double> getKnowledge() const {
56 return std::make_pair( static_cast<AlpsKnowledge *>
57 (subTreeList_.top()),
58 subTreeList_.top()->getQuality() );
59 }
60
62 inline void popKnowledge() {
63 subTreeList_.pop();
64 }
65
67 inline void addKnowledge(AlpsKnowledge* subTree, double priority) {
68 AlpsSubTree * st = dynamic_cast<AlpsSubTree* >(subTree);
69 subTreeList_.push(st);
70 }
71
73 inline const AlpsPriorityQueue< AlpsSubTree*>&
74 getSubTreeList() const { return subTreeList_; }
75
77 void setComparison(AlpsSearchStrategy<AlpsSubTree*>& compare) {
78 subTreeList_.setComparison(compare);
79 }
80
82 void deleteGuts() {
83 std::vector<AlpsSubTree* > treeVec = subTreeList_.getContainer();
84 std::for_each(treeVec.begin(), treeVec.end(), DeletePtrObject());
85 subTreeList_.clear();
86 assert(subTreeList_.size() == 0);
87 }
88
90 double getBestQuality() {
91 double quality = ALPS_OBJ_MAX;
92
93 std::vector<AlpsSubTree* > subTreeVec = subTreeList_.getContainer();
94
95 std::vector<AlpsSubTree* >::iterator pos1, pos2;
96
97 pos1 = subTreeVec.begin();
98 pos2 = subTreeVec.end();
99
100 for (; pos1 != pos2; ++pos1) {
101 (*pos1)->calculateQuality();
102 if ((*pos1)->getQuality() < quality) {
103 quality = (*pos1)->getQuality();
104 }
105 }
106
107 return quality;
108 }
109 };
110
111 #endif
AlpsPriorityQueue< AlpsSubTree * >
AlpsSubTreePool::~AlpsSubTreePool
virtual ~AlpsSubTreePool()
Definition: AlpsSubTreePool.h:42
AlpsHelperFunctions.h
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
AlpsSubTreePool::hasKnowledge
bool hasKnowledge() const
Check whether there is a subtree in the subtree pool.
Definition: AlpsSubTreePool.h:52
AlpsSubTreePool::setComparison
void setComparison(AlpsSearchStrategy< AlpsSubTree * > &compare)
Set comparison function and resort heap.
Definition: AlpsSubTreePool.h:77
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
AlpsSubTree
This class contains the data pertaining to a particular subtree in the search tree.
Definition: AlpsSubTree.h:47
AlpsSubTreePool
The subtree pool is used to store subtrees.
Definition: AlpsSubTreePool.h:32
AlpsSubTreePool::operator=
AlpsSubTreePool & operator=(const AlpsSubTreePool &)
AlpsSubTreePool::getKnowledge
std::pair< AlpsKnowledge *, double > getKnowledge() const
Get a subtree from subtree pool, doesn&#39;t remove it from the pool.
Definition: AlpsSubTreePool.h:55
AlpsSubTreePool::AlpsSubTreePool
AlpsSubTreePool()
Definition: AlpsSubTreePool.h:41
AlpsPriorityQueue::size
size_t size() const
Return the size of the vector.
Definition: AlpsPriorityQueue.h:79
AlpsSubTree::getQuality
double getQuality() const
Get the quality of this subtree.
Definition: AlpsSubTree.h:178
AlpsSubTreePool::getNumKnowledges
int getNumKnowledges() const
Query the number of subtrees in the pool.
Definition: AlpsSubTreePool.h:49
DeletePtrObject
Definition: AlpsHelperFunctions.h:62
AlpsSubTreePool::popKnowledge
void popKnowledge()
Remove a subtree from the pool.
Definition: AlpsSubTreePool.h:62
ALPS_OBJ_MAX
#define ALPS_OBJ_MAX
Definition: Alps.h:145
AlpsKnowledgePool
Definition: AlpsKnowledgePool.h:36
AlpsSubTreePool::getBestQuality
double getBestQuality()
Get the quality of the best subtree.
Definition: AlpsSubTreePool.h:90
AlpsSubTreePool::subTreeList_
AlpsPriorityQueue< AlpsSubTree * > subTreeList_
Definition: AlpsSubTreePool.h:38
AlpsKnowledge
The abstract base class of any user-defined class that Alps has to know about in order to encode/deco...
Definition: AlpsKnowledge.h:51
AlpsSubTree.h
AlpsSubTreePool::deleteGuts
void deleteGuts()
Delete the subtrees in the pool.
Definition: AlpsSubTreePool.h:82
AlpsSubTreePool::addKnowledge
void addKnowledge(AlpsKnowledge *subTree, double priority)
Add a subtree to the subtree pool.
Definition: AlpsSubTreePool.h:67
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
AlpsSubTreePool::getSubTreeList
const AlpsPriorityQueue< AlpsSubTree * > & getSubTreeList() const
Return the container of subtrees.
Definition: AlpsSubTreePool.h:74