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

- File List
- File Members

# /home/coin/svn-release/Alps-1.4.8/Alps/src/AlpsSubTreePool.h

Go to the documentation of this file.

    00001 /*===========================================================================*
    00002  * This file is part of the Abstract Library for Parallel Search (ALPS).     *
    00003  *                                                                           *
    00004  * ALPS is distributed under the Eclipse Public License as part of the       *
    00005  * COIN-OR repository (http://www.coin-or.org).                              *
    00006  *                                                                           *
    00007  * Authors:                                                                  *
    00008  *                                                                           *
    00009  *          Yan Xu, Lehigh University                                        *
    00010  *          Ted Ralphs, Lehigh University                                    *
    00011  *                                                                           *
    00012  * Conceptual Design:                                                        *
    00013  *                                                                           *
    00014  *          Yan Xu, Lehigh University                                        *
    00015  *          Ted Ralphs, Lehigh University                                    *
    00016  *          Laszlo Ladanyi, IBM T.J. Watson Research Center                  *
    00017  *          Matthew Saltzman, Clemson University                             *
    00018  *                                                                           *
    00019  *                                                                           *
    00020  * Copyright (C) 2001-2013, Lehigh University, Yan Xu, and Ted Ralphs.       *
    00021  *===========================================================================*/
    00022
    00023 #ifndef AlpsSubTreePool_h_
    00024 #define AlpsSubTreePool_h_
    00025
    00026 #include "AlpsHelperFunctions.h"
    00027 #include "AlpsSubTree.h"
    00028
    00029 //#############################################################################
    00030
    00032 class AlpsSubTreePool : public AlpsKnowledgePool {
    00033
    00034  private:
    00035     AlpsSubTreePool(const AlpsSubTreePool&);
    00036     AlpsSubTreePool& operator=(const AlpsSubTreePool&);
    00037
    00038     AlpsPriorityQueue<AlpsSubTree*> subTreeList_;
    00039
    00040  public:
    00041     AlpsSubTreePool() {}
    00042     virtual ~AlpsSubTreePool() {
    00043         if (!subTreeList_.empty()) {
    00044             deleteGuts();
    00045         }
    00046     }
    00047
    00049     inline int getNumKnowledges() const { return static_cast<int> (subTreeList_.size()); }
    00050
    00052     inline bool hasKnowledge() const{ return ! (subTreeList_.empty()); }
    00053
    00055     inline std::pair<AlpsKnowledge*, double> getKnowledge() const {
    00056         return std::make_pair( static_cast<AlpsKnowledge *>
    00057                                (subTreeList_.top()),
    00058                                subTreeList_.top()->getQuality() );
    00059     }
    00060
    00062     inline void popKnowledge() {
    00063         subTreeList_.pop();
    00064     }
    00065
    00067     inline void addKnowledge(AlpsKnowledge* subTree, double priority) {
    00068         AlpsSubTree * st = dynamic_cast<AlpsSubTree* >(subTree);
    00069         subTreeList_.push(st);
    00070     }
    00071
    00073     inline const AlpsPriorityQueue< AlpsSubTree*>&
    00074         getSubTreeList() const { return subTreeList_; }
    00075
    00077     void setComparison(AlpsSearchStrategy<AlpsSubTree*>& compare) {
    00078         subTreeList_.setComparison(compare);
    00079     }
    00080
    00082     void deleteGuts() {
    00083         std::vector<AlpsSubTree* > treeVec = subTreeList_.getContainer();
    00084         std::for_each(treeVec.begin(), treeVec.end(), DeletePtrObject());
    00085         subTreeList_.clear();
    00086         assert(subTreeList_.size() == 0);
    00087     }
    00088
    00090     double getBestQuality() {
    00091         double quality = ALPS_OBJ_MAX;
    00092
    00093         std::vector<AlpsSubTree* > subTreeVec = subTreeList_.getContainer();
    00094
    00095         std::vector<AlpsSubTree* >::iterator pos1, pos2;
    00096
    00097         pos1 = subTreeVec.begin();
    00098         pos2 = subTreeVec.end();
    00099
    00100         for (; pos1 != pos2; ++pos1) {
    00101             (*pos1)->calculateQuality();
    00102             if ((*pos1)->getQuality() < quality) {
    00103                 quality = (*pos1)->getQuality();
    00104             }
    00105         }
    00106
    00107         return quality;
    00108     }
    00109 };
    00110
    00111 #endif