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