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 #include <QHash>
00044 #include <QString>
00045
00046 namespace Gecode { namespace Gist {
00047
00048 class VisualNode;
00049
00051 template<class T>
00052 class NodeAllocatorBase {
00053 private:
00055 static const int NodeBlockSize = 1<<14;
00057 class Block {
00058 public:
00060 T b[NodeBlockSize];
00062 int best[NodeBlockSize];
00063 };
00065 Block** b;
00067 int n;
00069 int cur_b;
00071 int cur_t;
00073 void allocate(void);
00075 bool _bab;
00077 QHash<T*,QString> labels;
00078 public:
00080 NodeAllocatorBase(bool bab);
00082 ~NodeAllocatorBase(void);
00084 int allocate(int p);
00086 int allocate(Space* root);
00088 T* operator [](int i) const;
00090 T* best(int i) const;
00092 void setBest(int i, int b);
00094 bool bab(void) const;
00096 bool showLabels(void) const;
00098 void showLabels(bool b);
00100 bool hasLabel(T* n) const;
00102 void setLabel(T* n, const QString& l);
00104 void clearLabel(T* n);
00106 QString getLabel(T* n) const;
00107 };
00108
00110 class Node {
00111 private:
00113 enum {
00114 UNDET,
00115 LEAF,
00116 TWO_CHILDREN,
00117 MORE_CHILDREN
00118 };
00119
00121 void* childrenOrFirstChild;
00122
00126 int noOfChildren;
00127
00129 int parent;
00130
00132 unsigned int getTag(void) const;
00134 void setTag(unsigned int tag);
00136 void* getPtr(void) const;
00138 int getFirstChild(void) const;
00139
00140 protected:
00142 bool isUndetermined(void) const;
00143
00145 int getChild(int n) const;
00146 public:
00147 typedef NodeAllocatorBase<VisualNode> NodeAllocator;
00148
00150 Node(int p, bool failed = false);
00151
00153 int getParent(void) const;
00155 VisualNode* getParent(const NodeAllocator& na) const;
00157 VisualNode* getChild(const NodeAllocator& na, int n) const;
00158
00160 int getIndex(const NodeAllocator& na) const;
00161
00163 bool isRoot(void) const;
00164
00166 void setNumberOfChildren(unsigned int n, NodeAllocator& na);
00167
00169 unsigned int getNumberOfChildren(void) const;
00170
00171 };
00172
00173 }}
00174
00175 #endif
00176
00177