00001 #ifndef INDII_ML_AUX_PARTITIONTREENODE_HPP
00002 #define INDII_ML_AUX_PARTITIONTREENODE_HPP
00003
00004 #include "vector.hpp"
00005
00006 #include "boost/serialization/split_member.hpp"
00007
00008 namespace indii {
00009 namespace ml {
00010 namespace aux {
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 class PartitionTreeNode {
00024 public:
00025
00026
00027
00028
00029
00030
00031 PartitionTreeNode();
00032
00033
00034
00035
00036
00037
00038
00039 PartitionTreeNode(const unsigned int i, const unsigned int depth);
00040
00041
00042
00043
00044
00045
00046
00047 PartitionTreeNode(const std::vector<unsigned int>& is,
00048 const unsigned int depth);
00049
00050
00051
00052
00053
00054
00055
00056
00057 PartitionTreeNode(PartitionTreeNode* left, PartitionTreeNode* right,
00058 const unsigned int depth);
00059
00060
00061
00062
00063 PartitionTreeNode(const PartitionTreeNode& o);
00064
00065
00066
00067
00068 virtual ~PartitionTreeNode();
00069
00070
00071
00072
00073 PartitionTreeNode& operator=(const PartitionTreeNode& o);
00074
00075
00076
00077
00078
00079
00080 virtual PartitionTreeNode* clone() const = 0;
00081
00082
00083
00084
00085
00086
00087 unsigned int getDepth() const;
00088
00089
00090
00091
00092
00093
00094 bool isLeaf() const;
00095
00096
00097
00098
00099
00100
00101 bool isPrune() const;
00102
00103
00104
00105
00106
00107
00108 bool isInternal() const;
00109
00110
00111
00112
00113
00114
00115 unsigned int getSize() const;
00116
00117
00118
00119
00120
00121
00122 unsigned int getIndex() const;
00123
00124
00125
00126
00127
00128
00129 const std::vector<unsigned int>& getIndices() const;
00130
00131
00132
00133
00134
00135
00136 PartitionTreeNode* getLeft();
00137
00138
00139
00140
00141
00142
00143 PartitionTreeNode* getRight();
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155 virtual void difference(const vector& x, vector& result) const = 0;
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167 virtual void difference(const PartitionTreeNode& node, vector& result)
00168 const = 0;
00169
00170 private:
00171
00172
00173
00174 bool flagLeaf;
00175
00176
00177
00178
00179 bool flagPrune;
00180
00181
00182
00183
00184 bool flagInternal;
00185
00186
00187
00188
00189 unsigned int depth;
00190
00191
00192
00193
00194 unsigned int size;
00195
00196
00197
00198
00199 unsigned int i;
00200
00201
00202
00203
00204 std::vector<unsigned int> is;
00205
00206
00207
00208
00209 PartitionTreeNode* left;
00210
00211
00212
00213
00214 PartitionTreeNode* right;
00215
00216
00217
00218
00219 template<class Archive>
00220 void save(Archive& ar, const unsigned int version) const;
00221
00222
00223
00224
00225 template<class Archive>
00226 void load(Archive& ar, const unsigned int version);
00227
00228
00229
00230
00231 BOOST_SERIALIZATION_SPLIT_MEMBER()
00232 friend class boost::serialization::access;
00233
00234 };
00235
00236 }
00237 }
00238 }
00239
00240 inline unsigned int indii::ml::aux::PartitionTreeNode::getIndex() const {
00241
00242 assert (flagLeaf);
00243
00244 return i;
00245 }
00246
00247 inline const std::vector<unsigned int>&
00248 indii::ml::aux::PartitionTreeNode::getIndices() const {
00249 return is;
00250 }
00251
00252 inline indii::ml::aux::PartitionTreeNode*
00253 indii::ml::aux::PartitionTreeNode::getLeft() {
00254 return left;
00255 }
00256
00257 inline indii::ml::aux::PartitionTreeNode*
00258 indii::ml::aux::PartitionTreeNode::getRight() {
00259 return right;
00260 }
00261
00262 inline unsigned int indii::ml::aux::PartitionTreeNode::getDepth() const {
00263 return depth;
00264 }
00265
00266 inline unsigned int indii::ml::aux::PartitionTreeNode::getSize() const {
00267 return size;
00268 }
00269
00270 inline bool indii::ml::aux::PartitionTreeNode::isLeaf() const {
00271 return flagLeaf;
00272 }
00273
00274 inline bool indii::ml::aux::PartitionTreeNode::isPrune() const {
00275 return flagPrune;
00276 }
00277
00278 inline bool indii::ml::aux::PartitionTreeNode::isInternal() const {
00279 return flagInternal;
00280 }
00281
00282 template<class Archive>
00283 void indii::ml::aux::PartitionTreeNode::load(Archive& ar,
00284 const unsigned int version) {
00285 delete left;
00286 delete right;
00287
00288 ar & flagLeaf;
00289 ar & flagPrune;
00290 ar & flagInternal;
00291 ar & depth;
00292 ar & size;
00293 ar & i;
00294 ar & is;
00295 if (flagInternal) {
00296 ar & left;
00297 ar & right;
00298 } else {
00299 left = NULL;
00300 right = NULL;
00301 }
00302 }
00303
00304 template<class Archive>
00305 void indii::ml::aux::PartitionTreeNode::save(Archive& ar,
00306 const unsigned int version) const {
00307 ar & flagLeaf;
00308 ar & flagPrune;
00309 ar & flagInternal;
00310 ar & depth;
00311 ar & size;
00312 ar & i;
00313 ar & is;
00314 if (flagInternal) {
00315 ar & left;
00316 ar & right;
00317 }
00318 }
00319
00320 #endif
00321