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

- File List
- File Members

# /home/coin/svn-release/Alps-1.4.6/Alps/src/AlpsNodePool.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 AlpsNodePool_h_
    00024 #define AlpsNodePool_h_
    00025
    00026 #include <vector>
    00027
    00028 #include "AlpsHelperFunctions.h"
    00029 #include "AlpsPriorityQueue.h"
    00030 #include "AlpsTreeNode.h"
    00031 #include "AlpsKnowledgePool.h"
    00032
    00033 //#############################################################################
    00035 //#############################################################################
    00036
    00037 class AlpsNodePool : public AlpsKnowledgePool {
    00038
    00039  private:
    00040     AlpsNodePool(const AlpsNodePool&);
    00041     AlpsNodePool& operator=(const AlpsNodePool&);
    00042
    00043     AlpsPriorityQueue<AlpsTreeNode*> candidateList_;
    00044
    00045  public:
    00046     AlpsNodePool() {}
    00047     virtual ~AlpsNodePool() {
    00048         //std::cout << "- delete nodes pool, size = " << getNumKnowledges() << std::endl;
    00049         if (!candidateList_.empty()) {
    00050             deleteGuts();
    00051         }
    00052     }
    00053
    00055     inline int getNumKnowledges() const { return static_cast<int> (candidateList_.size()); }
    00056
    00058     inline double getBestKnowledgeValue() const {
    00059         const std::vector<AlpsTreeNode *>& pool=candidateList_.getContainer();
    00060         int k;
    00061         int size = static_cast<int> (pool.size());
    00062         double bestQuality = ALPS_OBJ_MAX;
    00063         AlpsTreeNode * node = NULL;
    00064         for (k = 0; k < size; ++k) {
    00065             node = pool[k];
    00066             if (node->getQuality() < bestQuality) {
    00067                 bestQuality = node->getQuality();
    00068             }
    00069         }
    00070         return bestQuality;
    00071     }
    00072
    00074     inline AlpsTreeNode *getBestNode() const {
    00075         const std::vector<AlpsTreeNode *>& pool=candidateList_.getContainer();
    00076         int k;
    00077         int size = static_cast<int> (pool.size());
    00078         double bestQuality = ALPS_OBJ_MAX;
    00079         AlpsTreeNode * bestNode = NULL;
    00080         AlpsTreeNode * node = NULL;
    00081
    00082         for (k = 0; k < size; ++k) {
    00083             node = pool[k];
    00084             if (node->getQuality() < bestQuality) {
    00085                 bestQuality = node->getQuality();
    00086                 bestNode = node;
    00087             }
    00088         }
    00089         return bestNode;
    00090     }
    00091
    00093     inline bool hasKnowledge() const{ return ! (candidateList_.empty()); }
    00094
    00096     inline std::pair<AlpsKnowledge*, double> getKnowledge() const {
    00097         return std::make_pair( static_cast<AlpsKnowledge *>
    00098                                (candidateList_.top()),
    00099                                candidateList_.top()->getQuality() );
    00100     }
    00101
    00103     inline void popKnowledge() {
    00104         candidateList_.pop();
    00105     }
    00106
    00110     inline void addKnowledge(AlpsKnowledge* node, double priority) {
    00111         AlpsTreeNode * nn = dynamic_cast<AlpsTreeNode*>(node);
    00112         //     if(!nn) {
    00113         //AlpsTreeNode * nonnn = const_cast<AlpsTreeNode*>(nn);
    00114         candidateList_.push(nn);
    00115         //     }
    00116         //    else
    00117         // std::cout << "Add node failed\n";
    00118         //     else
    00119         // throw CoinError();
    00120     }
    00121
    00123     inline const AlpsPriorityQueue<AlpsTreeNode*>&
    00124         getCandidateList() const { return candidateList_; }
    00125
    00127     void setNodeSelection(AlpsSearchStrategy<AlpsTreeNode*>& compare) {
    00128         candidateList_.setComparison(compare);
    00129     }
    00130
    00132     void deleteGuts() {
    00133         std::vector<AlpsTreeNode* > nodeVec = candidateList_.getContainer();
    00134         std::for_each(nodeVec.begin(), nodeVec.end(), DeletePtrObject());
    00135         candidateList_.clear();
    00136         assert(candidateList_.size() == 0);
    00137
    00138         //std::cout << "-- delete nodes in pool" << std::endl;
    00139     }
    00140
    00142     void clear() {
    00143         candidateList_.clear();
    00144     }
    00145 };
    00146
    00147 #endif
    00148
    00149