00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #ifndef AlpsTreeNode_h_
00024 #define AlpsTreeNode_h_
00025
00026 #include <algorithm>
00027 #include <utility>
00028 #include <vector>
00029
00030 #include "CoinError.hpp"
00031 #include "CoinSort.hpp"
00032
00033 #include "Alps.h"
00034 #include "AlpsKnowledge.h"
00035 #include "AlpsNodeDesc.h"
00036
00037 typedef int AlpsNodeIndex_t;
00038
00039 class AlpsKnowledgeBroker;
00040 class AlpsSubTree;
00041
00042
00048
00049
00050 class AlpsTreeNode : public AlpsKnowledge {
00051 private:
00052 AlpsTreeNode(const AlpsTreeNode&);
00053 AlpsTreeNode& operator=(const AlpsTreeNode&);
00054
00055 protected:
00057
00058
00060 bool active_;
00061
00063 AlpsNodeIndex_t index_;
00064
00066 int depth_;
00067
00069 double solEstimate_;
00070
00072 double quality_;
00073
00075 AlpsTreeNode* parent_;
00076
00078 AlpsNodeIndex_t parentIndex_;
00079
00081 int numChildren_;
00082
00083 #if defined(ALPS_MAX_CHILD_NUM) // *FIXME* : Do we want ifdefs?
00084
00085 AlpsTreeNode* children_[ALPS_MAX_CHILD_NUM];
00086 #else
00087 AlpsTreeNode** children_;
00088 #endif
00089
00092 int explicit_;
00093
00095 AlpsNodeDesc* desc_;
00096
00098 AlpsNodeStatus status_;
00099
00102
00103 AlpsKnowledgeBroker* knowledgeBroker_;
00104
00106
00107 int sentMark_;
00108
00110 bool diving_;
00111
00112 public:
00113 AlpsTreeNode()
00114 :
00115 active_(false),
00116 index_(-1),
00117 depth_(-1),
00118 solEstimate_(ALPS_OBJ_MAX),
00119 quality_(ALPS_OBJ_MAX),
00120 parent_(0),
00121 parentIndex_(-1),
00122 numChildren_(0),
00123 #if defined(ALPS_MAX_CHILD_NUM)
00124
00125 #else
00126 children_(0),
00127 #endif
00128 explicit_(0),
00129 desc_(0),
00130 status_(AlpsNodeStatusCandidate),
00131 knowledgeBroker_(0),
00132 sentMark_(0),
00133 diving_(false)
00134 { setType(AlpsKnowledgeTypeNode); }
00135
00136 virtual ~AlpsTreeNode() {
00137 assert(numChildren_ == 0);
00138
00139 #if ! defined(ALPS_MAX_CHILD_NUM)
00140 if (children_ != 0) {
00141 delete [] children_;
00142 children_ = 0;
00143 }
00144 #endif
00145 if (desc_ != 0) {
00146 delete desc_;
00147 desc_ = 0;
00148 }
00149 }
00150
00151 bool operator<(const AlpsTreeNode& compNode)
00152 { return quality_ < compNode.getQuality(); }
00153
00155 AlpsNodeDesc* modifyDesc() { return desc_; }
00156 AlpsNodeDesc* getDesc() const { return desc_; }
00157 void setDesc(AlpsNodeDesc* desc) { desc_ = desc; }
00158
00160 inline AlpsKnowledgeBroker* getKnowledgeBroker() const
00161 { return knowledgeBroker_; }
00162 inline void setKnowledgeBroker(AlpsKnowledgeBroker* kb)
00163 { knowledgeBroker_ = kb; }
00164
00167
00168
00169
00170
00171
00172 virtual AlpsTreeNode* createNewTreeNode(AlpsNodeDesc*& desc) const = 0;
00173
00175
00176 inline AlpsNodeStatus getStatus() const { return status_; }
00177 inline void setStatus(const AlpsNodeStatus stat) { status_ = stat; }
00179
00181
00182 inline bool isCandidate() const {
00183 return status_ == AlpsNodeStatusCandidate; }
00184 inline bool isEvaluated() const {
00185 return status_ == AlpsNodeStatusEvaluated; }
00186 inline bool isPregnant() const {
00187 return status_ == AlpsNodeStatusPregnant; }
00188 inline bool isBranched() const {
00189 return status_ == AlpsNodeStatusBranched; }
00190 inline bool isFathomed() const {
00191 return status_ == AlpsNodeStatusFathomed; }
00193
00195
00196 inline bool isActive() const { return active_; }
00197 inline void setActive(const bool yesno) { active_ = yesno; }
00199
00201
00202 inline AlpsNodeIndex_t getIndex() const { return index_; }
00203 inline void setIndex(const AlpsNodeIndex_t index) { index_ = index; }
00205
00207
00208 inline int getDepth() const { return depth_; }
00209 inline void setDepth(const int depth) { depth_ = depth; }
00211
00213
00214 inline double getSolEstimate() const { return solEstimate_; }
00215 inline void setSolEstimate(double est) { solEstimate_ = est; }
00217
00219
00220 inline double getQuality() const { return quality_; }
00221 inline void setQuality(double quality) { quality_ = quality; }
00223
00225
00226 inline int getNumChildren() const { return numChildren_; }
00227 inline void setNumChildren(const int numChildren) {
00228 numChildren_ = numChildren;
00229 #if ! defined(ALPS_MAX_CHILD_NUM)
00230 if (children_ != 0) {
00231 delete [] children_;
00232 children_ = 0;
00233 }
00234 children_ = new AlpsTreeNode*[numChildren_];
00235 #endif
00236 }
00237
00238 inline void modifyNumChildren(const int s) { numChildren_ += s; }
00240
00241
00242
00243
00244
00245
00246
00248
00249 inline AlpsTreeNode* getChild(const int i) const { return children_[i]; }
00250
00251
00252
00253
00254
00255
00256 inline void setChild(const int i, AlpsTreeNode* node)
00257 { children_[i] = node; }
00259
00263 void removeChild(AlpsTreeNode*& child);
00264
00266 void addChild(AlpsTreeNode*& child);
00267
00271 void removeDescendants();
00272
00274
00275
00276
00278
00279 inline AlpsTreeNode* getParent() const { return parent_; }
00280 inline void setParent(AlpsTreeNode* parent) { parent_ = parent; }
00282
00284
00285 inline AlpsNodeIndex_t getParentIndex() const { return parentIndex_; }
00286 inline void setParentIndex(AlpsNodeIndex_t index)
00287 { parentIndex_ = index; }
00289
00292
00293 inline int getExplicit() const { return explicit_; }
00294 inline void setExplicit(int fp) { explicit_ = fp; }
00296
00298
00299 virtual void convertToExplicit() {}
00300 virtual void convertToRelative() {}
00302
00304
00305 inline int getDiving() const { return diving_; }
00306 inline void setDiving(const bool d) { diving_ = d; }
00308
00310
00311 inline int getSentMark() const { return sentMark_; }
00312 inline void setSentMark(const int tf) { sentMark_ = tf; }
00314
00343 virtual int process(bool isRoot = false, bool rampUp = false) = 0;
00344
00354 virtual std::vector< CoinTriple<AlpsNodeDesc*, AlpsNodeStatus, double> >
00355 branch() = 0;
00356
00357 protected:
00358
00360 AlpsReturnStatus encodeAlps(AlpsEncoded *encoded) const;
00361
00363 AlpsReturnStatus decodeAlps(AlpsEncoded &encoded);
00364
00365 };
00366 #endif