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-2019, Lehigh University, Yan Xu, Aykut Bulut, and      *
22  *                          Ted Ralphs.                                      *
23  * All Rights Reserved.                                                      *
24  *===========================================================================*/
25 
26 
27 #ifndef AlpsSubTreePool_h_
28 #define AlpsSubTreePool_h_
29 
30 #include "AlpsHelperFunctions.h"
31 #include "AlpsPriorityQueue.h"
32 #include "AlpsKnowledgePool.h"
33 #include "AlpsSubTree.h"
34 /*!
35 
36   The subtree pool is used to store subtrees
37 
38 */
39 class AlpsSubTreePool: public AlpsKnowledgePool {
40   AlpsPriorityQueue<AlpsSubTree*> subTreeList_;
41 
42 public:
43   ///@name Constructor and destructor.
44   //@{
45   /// Default constructor.
46   AlpsSubTreePool();
47   /// Destructor.
48   virtual ~AlpsSubTreePool();
49   //@}
50 
51   ///@name Querry methods
52   //@{
53   /// Query the number of subtrees in the pool.
54   virtual int getNumKnowledges() const;
55   /// Get a subtree from subtree pool, doesn't remove it from the pool.
56   virtual std::pair<AlpsKnowledge*, double> getKnowledge() const;
57   /// Check whether there is a subtree in the subtree pool.
hasKnowledge()58   virtual bool hasKnowledge() const{ return ! (subTreeList_.empty()); }
59   /// Query the quantity limit of knowledges.
getMaxNumKnowledges()60   virtual int getMaxNumKnowledges() const { return INT_MAX; }
61   /// Query the best knowledge in the pool.
62   virtual std::pair<AlpsKnowledge*, double> getBestKnowledge() const;
63   /// Get a reference to all the knowledges in the pool.*/
64   virtual void getAllKnowledges (std::vector<std::pair<AlpsKnowledge*,
65                                  double> >& kls) const;
66   //@}
67 
68   ///@name Knowledge manipulation
69   //@{
70   /// Add a subtree to the subtree pool.
71   virtual void addKnowledge(AlpsKnowledge* subTree, double priority);
72   /// Remove a subtree from the pool.
popKnowledge()73   virtual void popKnowledge() { subTreeList_.pop(); }
74   //@}
75 
76   ///@name Other functions
77   //@{
78   /// Set the quantity limit of knowledges that can be stored in the pool.
79   virtual void setMaxNumKnowledges(int num);
80   //@}
81 
82   /// Return the container of subtrees.
83   virtual AlpsPriorityQueue< AlpsSubTree*> const & getSubTreeList() const;
84   /// Set comparison function and resort heap.
85   void setComparison(AlpsSearchStrategy<AlpsSubTree*>& compare);
86   /// Delete the subtrees in the pool.
87   void deleteGuts();
88   /// Get the quality of the best subtree.
89   double getBestQuality();
90 
91 private:
92   /// Disable copy constructor.
93   AlpsSubTreePool(AlpsSubTreePool const &);
94   /// Disable copy assignment operator.
95   AlpsSubTreePool& operator=(const AlpsSubTreePool &);
96 };
97 
98 #endif
99