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
00035
00036
00037
00038 #ifndef GECODE_GIST_SPACENODE_HH
00039 #define GECODE_GIST_SPACENODE_HH
00040
00041 #include <gecode/gist/node.hh>
00042 #include <gecode/kernel.hh>
00043
00044 namespace Gecode { namespace Gist {
00045
00047 enum NodeStatus {
00048 SOLVED,
00049 FAILED,
00050 BRANCH,
00051 UNDETERMINED,
00052 SPECIAL,
00053 STEP
00054 };
00055
00056 static const unsigned int FIRSTBIT = 5;
00057 static const unsigned int STATUSMASK = (1<<(FIRSTBIT-1))-1;
00058
00060 class StepDesc {
00061 public:
00062 int noOfSteps;
00063 bool debug;
00064 StepDesc(int steps);
00065 void toggleDebug(void);
00066 };
00067
00069 class SpecialDesc {
00070 public:
00071 const std::string vn;
00072 const int v;
00073 const int rel;
00074 SpecialDesc(std::string varName, int rel0, int v0);
00075 };
00076
00078 class Statistics : public StatusStatistics {
00079 public:
00081 int solutions;
00083 int failures;
00085 int choices;
00087 int undetermined;
00089 int maxDepth;
00090
00092 Statistics(void)
00093 : solutions(0), failures(0), choices(0), undetermined(1), maxDepth(0) {}
00094 };
00095
00096 class SpaceNode;
00097
00099 class BestNode {
00100 public:
00102 SpaceNode* s;
00104 BestNode(SpaceNode* s0);
00105 };
00106
00108 class SpaceNode : public Node {
00109 protected:
00111 Space* copy;
00113 Space* workingSpace;
00114 private:
00116 SpaceNode* ownBest;
00117 protected:
00118 union {
00120 const BranchingDesc* branch;
00122 const SpecialDesc* special;
00124 StepDesc* step;
00125 } desc;
00126
00128 unsigned int nstatus;
00129
00131 enum SpaceNodeFlags {
00132 HASOPENCHILDREN = FIRSTBIT,
00133 HASFAILEDCHILDREN,
00134 HASSOLVEDCHILDREN
00135 };
00137 static const int LASTBIT = HASSOLVEDCHILDREN;
00138
00139 private:
00141 void setHasOpenChildren(bool b);
00143 void setHasFailedChildren(bool b);
00145 void setHasSolvedChildren(bool b);
00147 void setStatus(NodeStatus s);
00148
00150 int recompute(BestNode* curBest, int c_d, int a_d);
00151
00153 void closeChild(bool hadFailures, bool hadSolutions);
00154 protected:
00156 void acquireSpace(BestNode* curBest, int c_d, int a_d);
00157 public:
00159 SpaceNode(void);
00161 SpaceNode(Space* root);
00163 ~SpaceNode(void);
00164
00166 Space* getSpace(BestNode* curBest, int c_d, int a_d);
00167
00169 const Space* getWorkingSpace(void) const;
00170
00172 void purge(void);
00173
00175 bool isCurrentBest(BestNode* curBest);
00176
00187 int getNumberOfChildNodes(NodeAllocator& na,
00188 BestNode* curBest,
00189 Statistics& stats,
00190 int c_d, int a_d);
00191
00193 NodeStatus getStatus(void) const;
00195 bool isStepNode(void);
00197 void setSpecialDesc(const SpecialDesc* d);
00199 void setStepDesc(StepDesc* d);
00201 StepDesc* getStepDesc(void);
00202
00204 bool isOpen(void);
00206 bool hasFailedChildren(void);
00208 bool hasSolvedChildren(void);
00210 bool hasOpenChildren(void);
00212 int getNoOfOpenChildren(void);
00214 void setNoOfOpenChildren(int n);
00216 bool hasCopy(void);
00218 bool hasWorkingSpace(void);
00219
00221 SpaceNode* getParent(void);
00223 SpaceNode* getChild(int i);
00225 int getAlternative(void);
00226 };
00227
00228 }}
00229
00230 #include <gecode/gist/spacenode.hpp>
00231
00232 #endif
00233
00234