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