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