node.hh
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038 #ifndef GECODE_GIST_NODE_HH
00039 #define GECODE_GIST_NODE_HH
00040
00041 #include <gecode/kernel.hh>
00042
00043 namespace Gecode { namespace Gist {
00044
00045 class VisualNode;
00046
00048 template<class T>
00049 class NodeAllocatorBase {
00050 private:
00052 static const int NodeBlockSize = 1<<14;
00054 class Block {
00055 public:
00057 T b[NodeBlockSize];
00059 int best[NodeBlockSize];
00060 };
00062 Block** b;
00064 int n;
00066 int cur_b;
00068 int cur_t;
00070 void allocate(void);
00072 bool _bab;
00073 public:
00075 NodeAllocatorBase(bool bab);
00077 ~NodeAllocatorBase(void);
00079 int allocate(int p);
00081 int allocate(Space* root);
00083 T* operator [](int i) const;
00085 T* best(int i) const;
00087 void setBest(int i, int b);
00089 bool bab(void) const;
00090 };
00091
00093 class Node {
00094 private:
00096 enum {
00097 UNDET,
00098 LEAF,
00099 TWO_CHILDREN,
00100 MORE_CHILDREN
00101 };
00102
00104 void* childrenOrFirstChild;
00105
00109 int noOfChildren;
00110
00112 int parent;
00113
00115 unsigned int getTag(void) const;
00117 void setTag(unsigned int tag);
00119 void* getPtr(void) const;
00121 int getFirstChild(void) const;
00122
00123 protected:
00125 bool isUndetermined(void) const;
00126
00128 int getChild(int n) const;
00129 public:
00130 typedef NodeAllocatorBase<VisualNode> NodeAllocator;
00131
00133 Node(int p, bool failed = false);
00134
00136 int getParent(void) const;
00138 VisualNode* getParent(const NodeAllocator& na) const;
00140 VisualNode* getChild(const NodeAllocator& na, int n) const;
00141
00143 int getIndex(const NodeAllocator& na) const;
00144
00146 bool isRoot(void) const;
00147
00149 void setNumberOfChildren(unsigned int n, NodeAllocator& na);
00150
00152 unsigned int getNumberOfChildren(void) const;
00153
00154 };
00155
00156 }}
00157
00158 #endif
00159
00160