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

- File List
- File Members

# /home/coin/svn-release/Blis-0.93.2/Bcps/src/BcpsObjectPool.h

Go to the documentation of this file.

    00001 /*===========================================================================*
    00002  * This file is part of the Branch, Constrain and Price Software (BiCePS)    *
    00003  *                                                                           *
    00004  * BiCePS 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  * Copyright (C) 2001-2011, Lehigh University, Yan Xu, and Ted Ralphs.       *
    00020  * All Rights Reserved.                                                      *
    00021  *===========================================================================*/
    00022
    00023 #ifndef BcpsObjectPool_h_
    00024 #define BcpsObjectPool_h_
    00025
    00026 #include <vector>
    00027
    00028 #include "AlpsKnowledgePool.h"
    00029
    00030 #include "BcpsObject.h"
    00031
    00032 //#############################################################################
    00034 //#############################################################################
    00035
    00036 class BcpsObjectPool : public AlpsKnowledgePool {
    00037
    00038  protected:
    00039
    00040     std::vector<AlpsKnowledge *> objects_;
    00041
    00042  public:
    00043
    00045     BcpsObjectPool() {}
    00046     virtual ~BcpsObjectPool() {
    00047         if (! objects_.empty()) {
    00048             freeGuts();
    00049         }
    00050     }
    00051
    00053     inline void freeGuts() {
    00054         for (int i = static_cast<int> (objects_.size() - 1); i > -1; --i) {
    00055             delete objects_[i];
    00056         }
    00057         objects_.clear();
    00058     }
    00059
    00061     inline void clear(){ objects_.clear(); }
    00062
    00064     virtual void addKnowledge(AlpsKnowledge * nk, double priority) {
    00065         objects_.push_back(nk);
    00066     }
    00067
    00069     virtual int getNumKnowledges() const {
    00070         return static_cast<int>(objects_.size());
    00071     }
    00072
    00074     virtual std::pair<AlpsKnowledge*, double> getKnowledge() const {
    00075         return std::make_pair(objects_[0], 0.0);
    00076     }
    00077
    00079     virtual bool hasKnowledge() const
    00080         { return objects_.empty() ? false : true; }
    00081
    00083     void deleteObject(int k) {
    00084         assert(k > -1 && k < ((int)objects_.size()));
    00085
    00086         AlpsKnowledge *objectK = getObject(k);
    00087         std::vector<AlpsKnowledge *>::iterator pos;
    00088         pos = objects_.begin() + k;
    00089         objects_.erase(pos);
    00090
    00091         // Free memory of object k.
    00092         delete objectK;
    00093     }
    00094
    00096     const std::vector<AlpsKnowledge *>& getObjects() const { return objects_; }
    00097
    00099     AlpsKnowledge *getObject(int k) const { return objects_[k]; }
    00100 };
    00101
    00102 //#############################################################################
    00103
    00104 class BcpsConstraintPool : public BcpsObjectPool {
    00105  public:
    00106     BcpsConstraintPool() {}
    00107     virtual ~BcpsConstraintPool() {}
    00108
    00110     void addConstraint(BcpsConstraint * con) { objects_.push_back(con); }
    00111
    00113     void deleteConstraint(int k) { deleteObject(k); }
    00114
    00116     int getNumConstraints() const { return getNumKnowledges(); }
    00117
    00119     const std::vector<AlpsKnowledge *>& getConstraints() const {return objects_;}
    00120
    00122     AlpsKnowledge *getConstraint(int k) const {return getObject(k);}
    00123 };
    00124
    00125 //#############################################################################
    00126
    00127 class BcpsVariablePool : public BcpsObjectPool {
    00128  public:
    00129     BcpsVariablePool() {}
    00130     virtual ~BcpsVariablePool() {}
    00131
    00133     void addVariable(BcpsVariable * var) { objects_.push_back(var); }
    00134
    00136     void deleteVariable(int k) { deleteObject(k); }
    00137
    00139     int getNumVariables() const { return getNumKnowledges(); }
    00140
    00142     const std::vector<AlpsKnowledge *>& getVariables() const {return objects_;}
    00143
    00145     AlpsKnowledge *getVariable(int k) const {return getObject(k);}
    00146 };
    00147
    00148 //#############################################################################
    00149
    00150 #endif // End of file