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 desc.branch = 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 void
00144 SpaceNode::setSpecialDesc(const SpecialDesc* d) {
00145 desc.special = d;
00146 }
00147
00148 forceinline void
00149 SpaceNode::setStepDesc(StepDesc* d) {
00150 desc.step = d;
00151 }
00152
00153 forceinline bool
00154 SpaceNode::isStepNode(void) {
00155 return getStatus() == STEP;
00156 }
00157
00158 forceinline StepDesc*
00159 SpaceNode::getStepDesc(void) {
00160 return (isStepNode() ? desc.step : NULL);
00161 }
00162
00163 forceinline bool
00164 SpaceNode::isOpen(void) {
00165 return ((getStatus() == UNDETERMINED) ||
00166 getFlag(HASOPENCHILDREN));
00167 }
00168
00169 forceinline bool
00170 SpaceNode::hasFailedChildren(void) {
00171 return getFlag(HASFAILEDCHILDREN);
00172 }
00173
00174 forceinline bool
00175 SpaceNode::hasSolvedChildren(void) {
00176 return getFlag(HASSOLVEDCHILDREN);
00177 }
00178
00179 forceinline bool
00180 SpaceNode::hasOpenChildren(void) {
00181 return getFlag(HASOPENCHILDREN);
00182 }
00183
00184 forceinline bool
00185 SpaceNode::hasCopy(void) {
00186 return copy != NULL;
00187 }
00188
00189 forceinline bool
00190 SpaceNode::hasWorkingSpace(void) {
00191 return workingSpace != NULL;
00192 }
00193
00194 forceinline int
00195 SpaceNode::getAlternative(void) {
00196 SpaceNode* p = getParent();
00197 if (p) {
00198 for (int i=p->getNumberOfChildren(); i--;)
00199 if (p->getChild(i) == this)
00200 return i;
00201 }
00202 return -1;
00203 }
00204
00205 }}
00206
00207