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 
33 
34  private:
37 
39 
40  public:
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()),
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 
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());
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
virtual ~AlpsSubTreePool()
const std::vector< T > & getContainer() const
Return a const reference to the container.
void push(T x)
Add a element to the heap.
bool hasKnowledge() const
Check whether there is a subtree in the subtree pool.
void setComparison(AlpsSearchStrategy< AlpsSubTree * > &compare)
Set comparison function and resort 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.
This class contains the data pertaining to a particular subtree in the search tree.
Definition: AlpsSubTree.h:47
The subtree pool is used to store subtrees.
AlpsSubTreePool & operator=(const AlpsSubTreePool &)
std::pair< AlpsKnowledge *, double > getKnowledge() const
Get a subtree from subtree pool, doesn&#39;t remove it from the pool.
size_t size() const
Return the size of the vector.
double getQuality() const
Get the quality of this subtree.
Definition: AlpsSubTree.h:175
int getNumKnowledges() const
Query the number of subtrees in the pool.
void popKnowledge()
Remove a subtree from the pool.
#define ALPS_OBJ_MAX
Definition: Alps.h:145
double getBestQuality()
Get the quality of the best subtree.
AlpsPriorityQueue< AlpsSubTree * > subTreeList_
The abstract base class of any user-defined class that Alps has to know about in order to encode/deco...
Definition: AlpsKnowledge.h:51
void deleteGuts()
Delete the subtrees in the pool.
void addKnowledge(AlpsKnowledge *subTree, double priority)
Add a subtree to the subtree pool.
void clear()
Remove all elements from the vector.
T top() const
Return the top element of the heap.
const AlpsPriorityQueue< AlpsSubTree * > & getSubTreeList() const
Return the container of subtrees.