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 #ifndef GECODE_GIST_NODE_HH
00035 #define GECODE_GIST_NODE_HH
00036
00037 #include <gecode/kernel.hh>
00038
00039 #include <QHash>
00040 #include <QString>
00041
00042 namespace Gecode { namespace Gist {
00043
00044 class VisualNode;
00045
00047 template<class T>
00048 class NodeAllocatorBase {
00049 private:
00051 static const int NodeBlockSize = 1<<14;
00053 class Block {
00054 public:
00056 T b[NodeBlockSize];
00058 int best[NodeBlockSize];
00059 };
00061 Block** b;
00063 int n;
00065 int cur_b;
00067 int cur_t;
00069 void allocate(void);
00071 bool _bab;
00073 QHash<T*,QString> labels;
00074 public:
00076 NodeAllocatorBase(bool bab);
00078 ~NodeAllocatorBase(void);
00080 int allocate(int p);
00082 int allocate(Space* root);
00084 T* operator [](int i) const;
00086 T* best(int i) const;
00088 void setBest(int i, int b);
00090 bool bab(void) const;
00092 bool showLabels(void) const;
00094 void showLabels(bool b);
00096 bool hasLabel(T* n) const;
00098 void setLabel(T* n, const QString& l);
00100 void clearLabel(T* n);
00102 QString getLabel(T* n) const;
00103 };
00104
00106 class Node {
00107 private:
00109 enum {
00110 UNDET,
00111 LEAF,
00112 TWO_CHILDREN,
00113 MORE_CHILDREN
00114 };
00115
00117 void* childrenOrFirstChild;
00118
00122 int noOfChildren;
00123
00125 int parent;
00126
00128 unsigned int getTag(void) const;
00130 void setTag(unsigned int tag);
00132 void* getPtr(void) const;
00134 int getFirstChild(void) const;
00135
00136 protected:
00138 bool isUndetermined(void) const;
00139
00141 int getChild(int n) const;
00142 public:
00143 typedef NodeAllocatorBase<VisualNode> NodeAllocator;
00144
00146 Node(int p, bool failed = false);
00147
00149 int getParent(void) const;
00151 VisualNode* getParent(const NodeAllocator& na) const;
00153 VisualNode* getChild(const NodeAllocator& na, int n) const;
00154
00156 int getIndex(const NodeAllocator& na) const;
00157
00159 bool isRoot(void) const;
00160
00162 void setNumberOfChildren(unsigned int n, NodeAllocator& na);
00163
00165 unsigned int getNumberOfChildren(void) const;
00166
00167 };
00168
00169 }}
00170
00171 #endif
00172
00173