spacenode.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_SPACENODE_HH
00035 #define GECODE_GIST_SPACENODE_HH
00036
00037 #include <gecode/gist/node.hh>
00038 #include <gecode/kernel.hh>
00039
00040 namespace Gecode { namespace Gist {
00041
00044 enum NodeStatus {
00045 SOLVED,
00046 FAILED,
00047 BRANCH,
00048 UNDETERMINED,
00049 STOP,
00050 UNSTOP,
00051 };
00052
00053 static const unsigned int FIRSTBIT = 24;
00054 static const unsigned int STATUSMASK = 7<<20;
00055 static const unsigned int MAXDISTANCE = (1<<20)-1;
00056 static const unsigned int DISTANCEMASK = (1<<20)-1;
00057
00059 class Statistics : public StatusStatistics {
00060 public:
00062 int solutions;
00064 int failures;
00066 int choices;
00068 int undetermined;
00070 int maxDepth;
00071
00073 Statistics(void)
00074 : solutions(0), failures(0), choices(0), undetermined(1), maxDepth(0) {}
00075 };
00076
00077 class SpaceNode;
00078
00080 class BestNode {
00081 public:
00083 SpaceNode* s;
00085 BestNode(SpaceNode* s0);
00086 };
00087
00089 class SpaceNode : public Node {
00090 protected:
00096 Space* copy;
00097 protected:
00098 const Choice* choice;
00099
00106 unsigned int nstatus;
00107
00109 void setDistance(unsigned int d);
00110
00112 unsigned int getDistance(void) const;
00113
00115 void setFlag(int flag, bool value);
00116
00118 bool getFlag(int flag) const;
00119
00121 enum SpaceNodeFlags {
00122 HASOPENCHILDREN = FIRSTBIT,
00123 HASFAILEDCHILDREN,
00124 HASSOLVEDCHILDREN
00125 };
00127 static const int LASTBIT = HASSOLVEDCHILDREN;
00128
00129 private:
00131 void setHasOpenChildren(bool b);
00133 void setHasFailedChildren(bool b);
00135 void setHasSolvedChildren(bool b);
00136
00138 int recompute(NodeAllocator& na,
00139 BestNode* curBest, int c_d, int a_d);
00140
00142 void closeChild(const NodeAllocator& na,
00143 bool hadFailures, bool hadSolutions);
00144 protected:
00146 void setStatus(NodeStatus s);
00148 void acquireSpace(NodeAllocator& na,
00149 BestNode* curBest, int c_d, int a_d);
00150 public:
00152 SpaceNode(int p);
00154 SpaceNode(Space* root);
00155
00157 Space* getSpace(NodeAllocator& na,
00158 BestNode* curBest, int c_d, int a_d);
00159
00161 const Space* getWorkingSpace(void) const;
00162
00164 void purge(const NodeAllocator& na);
00165
00167 void dispose(void);
00168
00170 bool isCurrentBest(BestNode* curBest);
00171
00182 int getNumberOfChildNodes(NodeAllocator& na,
00183 BestNode* curBest,
00184 Statistics& stats,
00185 int c_d, int a_d);
00186
00188 NodeStatus getStatus(void) const;
00189
00191 bool isOpen(void);
00193 bool hasFailedChildren(void);
00195 bool hasSolvedChildren(void);
00197 bool hasOpenChildren(void);
00199 int getNoOfOpenChildren(const NodeAllocator& na);
00201 void setNoOfOpenChildren(int n);
00203 bool hasCopy(void);
00205 bool hasWorkingSpace(void);
00206
00208 int getAlternative(const NodeAllocator& na) const;
00210 const Choice* getChoice(void);
00211 };
00212
00213 }}
00214
00215 #endif
00216
00217