spacenode.hpp
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 namespace Gecode { namespace Gist {
00035
00036 forceinline void
00037 SpaceNode::setFlag(int flag, bool value) {
00038 if (value)
00039 nstatus |= 1<<(flag-1);
00040 else
00041 nstatus &= ~(1<<(flag-1));
00042 }
00043
00044 forceinline bool
00045 SpaceNode::getFlag(int flag) const {
00046 return (nstatus & (1<<(flag-1))) != 0;
00047 }
00048
00049 forceinline void
00050 SpaceNode::setHasOpenChildren(bool b) {
00051 setFlag(HASOPENCHILDREN, b);
00052 }
00053
00054 forceinline void
00055 SpaceNode::setHasFailedChildren(bool b) {
00056 setFlag(HASFAILEDCHILDREN, b);
00057 }
00058
00059 forceinline void
00060 SpaceNode::setHasSolvedChildren(bool b) {
00061 setFlag(HASSOLVEDCHILDREN, b);
00062 }
00063
00064 forceinline void
00065 SpaceNode::setStatus(NodeStatus s) {
00066 nstatus &= ~( STATUSMASK );
00067 nstatus |= s << 20;
00068 }
00069
00070 forceinline NodeStatus
00071 SpaceNode::getStatus(void) const {
00072 return static_cast<NodeStatus>((nstatus & STATUSMASK) >> 20);
00073 }
00074
00075 forceinline void
00076 SpaceNode::setDistance(unsigned int d) {
00077 if (d > MAXDISTANCE)
00078 d = MAXDISTANCE;
00079 nstatus &= ~( DISTANCEMASK );
00080 nstatus |= d;
00081 }
00082
00083 forceinline unsigned int
00084 SpaceNode::getDistance(void) const {
00085 return nstatus & DISTANCEMASK;
00086 }
00087
00088 forceinline
00089 SpaceNode::SpaceNode(int p)
00090 : Node(p), copy(NULL), nstatus(0) {
00091 choice = NULL;
00092 setStatus(UNDETERMINED);
00093 setHasSolvedChildren(false);
00094 setHasFailedChildren(false);
00095 }
00096
00097 forceinline Space*
00098 SpaceNode::getSpace(NodeAllocator& na,
00099 BestNode* curBest, int c_d, int a_d) {
00100 acquireSpace(na,curBest,c_d,a_d);
00101 Space* ret;
00102 if (Support::marked(copy)) {
00103 ret = static_cast<Space*>(Support::unmark(copy));
00104 copy = NULL;
00105 } else {
00106 ret = copy->clone();
00107 }
00108 return ret;
00109 }
00110
00111 forceinline const Space*
00112 SpaceNode::getWorkingSpace(void) const {
00113 assert(copy != NULL);
00114 if (Support::marked(copy))
00115 return static_cast<Space*>(Support::unmark(copy));
00116 return copy;
00117 }
00118
00119 forceinline void
00120 SpaceNode::purge(const NodeAllocator& na) {
00121 if (!isRoot() && (getStatus() != SOLVED || !na.bab())) {
00122
00123 if (Support::marked(copy))
00124 delete static_cast<Space*>(Support::unmark(copy));
00125 else
00126 delete copy;
00127 copy = NULL;
00128 }
00129 }
00130
00131
00132 forceinline bool
00133 SpaceNode::isCurrentBest(BestNode* curBest) {
00134 return curBest != NULL && curBest->s == this;
00135 }
00136
00137 forceinline bool
00138 SpaceNode::isOpen(void) {
00139 return ((getStatus() == UNDETERMINED) ||
00140 getFlag(HASOPENCHILDREN));
00141 }
00142
00143 forceinline bool
00144 SpaceNode::hasFailedChildren(void) {
00145 return getFlag(HASFAILEDCHILDREN);
00146 }
00147
00148 forceinline bool
00149 SpaceNode::hasSolvedChildren(void) {
00150 return getFlag(HASSOLVEDCHILDREN);
00151 }
00152
00153 forceinline bool
00154 SpaceNode::hasOpenChildren(void) {
00155 return getFlag(HASOPENCHILDREN);
00156 }
00157
00158 forceinline bool
00159 SpaceNode::hasCopy(void) {
00160 return copy != NULL;
00161 }
00162
00163 forceinline bool
00164 SpaceNode::hasWorkingSpace(void) {
00165 return copy != NULL && Support::marked(copy);
00166 }
00167
00168 forceinline int
00169 SpaceNode::getAlternative(const NodeAllocator& na) const {
00170 SpaceNode* p = getParent(na);
00171 if (p == NULL)
00172 return -1;
00173 for (int i=static_cast<int>(p->getNumberOfChildren()); i--;)
00174 if (p->getChild(na,i) == this)
00175 return i;
00176 GECODE_NEVER;
00177 return -1;
00178 }
00179
00180 forceinline const Choice*
00181 SpaceNode::getChoice(void) {
00182 return choice;
00183 }
00184
00185 }}
00186
00187