spacenode.hpp
Go to the documentation of this file.00001 /* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */ 00002 /* 00003 * Main authors: 00004 * Guido Tack <tack@gecode.org> 00005 * 00006 * Copyright: 00007 * Guido Tack, 2006 00008 * 00009 * Last modified: 00010 * $Date: 2009-01-21 11:36:29 +0100 (Wed, 21 Jan 2009) $ by $Author: schulte $ 00011 * $Revision: 8083 $ 00012 * 00013 * This file is part of Gecode, the generic constraint 00014 * development environment: 00015 * http://www.gecode.org 00016 * 00017 * Permission is hereby granted, free of charge, to any person obtaining 00018 * a copy of this software and associated documentation files (the 00019 * "Software"), to deal in the Software without restriction, including 00020 * without limitation the rights to use, copy, modify, merge, publish, 00021 * distribute, sublicense, and/or sell copies of the Software, and to 00022 * permit persons to whom the Software is furnished to do so, subject to 00023 * the following conditions: 00024 * 00025 * The above copyright notice and this permission notice shall be 00026 * included in all copies or substantial portions of the Software. 00027 * 00028 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 00029 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 00030 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 00031 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 00032 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 00033 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 00034 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 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::setHasOpenChildren(bool b) { 00052 if (b) 00053 nstatus |= 1<<(HASOPENCHILDREN-1); 00054 else 00055 nstatus &= ~(1<<(HASOPENCHILDREN-1)); 00056 } 00057 00058 forceinline void 00059 SpaceNode::setHasFailedChildren(bool b) { 00060 if (b) 00061 nstatus |= 1<<(HASFAILEDCHILDREN-1); 00062 else 00063 nstatus &= ~(1<<(HASFAILEDCHILDREN-1)); 00064 } 00065 00066 forceinline void 00067 SpaceNode::setHasSolvedChildren(bool b) { 00068 if (b) 00069 nstatus |= 1<<(HASSOLVEDCHILDREN-1); 00070 else 00071 nstatus &= ~(1<<(HASSOLVEDCHILDREN-1)); 00072 } 00073 00074 forceinline void 00075 SpaceNode::setStatus(NodeStatus s) { 00076 nstatus &= ~( STATUSMASK ); 00077 nstatus |= s; 00078 } 00079 00080 forceinline NodeStatus 00081 SpaceNode::getStatus(void) const { 00082 return static_cast<NodeStatus>(nstatus & STATUSMASK); 00083 } 00084 00085 forceinline 00086 SpaceNode::SpaceNode(void) 00087 : copy(NULL), workingSpace(NULL), ownBest(NULL) { 00088 desc.branch = NULL; 00089 setStatus(UNDETERMINED); 00090 setHasSolvedChildren(false); 00091 setHasFailedChildren(false); 00092 } 00093 00094 forceinline Space* 00095 SpaceNode::getSpace(BestNode* curBest, int c_d, int a_d) { 00096 acquireSpace(curBest,c_d,a_d); 00097 Space* ret = workingSpace; 00098 workingSpace = NULL; 00099 return ret; 00100 } 00101 00102 forceinline const Space* 00103 SpaceNode::getWorkingSpace(void) const { 00104 return workingSpace; 00105 } 00106 00107 forceinline void 00108 SpaceNode::purge(void) { 00109 if (getStatus() != SOLVED || ownBest == NULL) { 00110 // only delete working spaces from solutions if we are not in BAB 00111 delete workingSpace; 00112 workingSpace = NULL; 00113 } 00114 if (!isRoot()) { 00115 delete copy; 00116 copy = NULL; 00117 } 00118 } 00119 00120 00121 forceinline bool 00122 SpaceNode::isCurrentBest(BestNode* curBest) { 00123 return curBest != NULL && curBest->s == this; 00124 } 00125 00126 forceinline void 00127 SpaceNode::setSpecialDesc(const SpecialDesc* d) { 00128 desc.special = d; 00129 } 00130 00131 forceinline void 00132 SpaceNode::setStepDesc(StepDesc* d) { 00133 desc.step = d; 00134 } 00135 00136 forceinline bool 00137 SpaceNode::isStepNode(void) { 00138 return getStatus() == STEP; 00139 } 00140 00141 forceinline StepDesc* 00142 SpaceNode::getStepDesc(void) { 00143 return (isStepNode() ? desc.step : NULL); 00144 } 00145 00146 forceinline bool 00147 SpaceNode::isOpen(void) { 00148 return getStatus() == UNDETERMINED 00149 || (nstatus & (1<<(HASOPENCHILDREN-1))); 00150 } 00151 00152 forceinline bool 00153 SpaceNode::hasFailedChildren(void) { 00154 return nstatus & (1<<(HASFAILEDCHILDREN-1)); 00155 } 00156 00157 forceinline bool 00158 SpaceNode::hasSolvedChildren(void) { 00159 return nstatus & (1<<(HASSOLVEDCHILDREN-1)); 00160 } 00161 00162 forceinline bool 00163 SpaceNode::hasOpenChildren(void) { 00164 return nstatus & (1<<(HASOPENCHILDREN-1)); 00165 } 00166 00167 forceinline bool 00168 SpaceNode::hasCopy(void) { 00169 return copy != NULL; 00170 } 00171 00172 forceinline bool 00173 SpaceNode::hasWorkingSpace(void) { 00174 return workingSpace != NULL; 00175 } 00176 00177 forceinline int 00178 SpaceNode::getAlternative(void) { 00179 SpaceNode* p = getParent(); 00180 if (p) { 00181 for (int i=p->getNumberOfChildren(); i--;) 00182 if (p->getChild(i) == this) 00183 return i; 00184 } 00185 return -1; 00186 } 00187 00188 }} 00189 00190 // STATISTICS: gist-any
