spacenode.hpp /usr/include/gecode/gist/visualnode.hh Gecode Gecode::Gist /*-*-mode:C++;c-basic-offset:2;indent-tabs-mode:nil-*-*/ /* *Mainauthors: *GuidoTack<tack@gecode.org> * *Copyright: *GuidoTack,2006 * *Lastmodified: *$Date:2010-08-1211:02:06+0200(Thu,12Aug2010)$by$Author:tack$ *$Revision:11347$ * *ThisfileispartofGecode,thegenericconstraint *developmentenvironment: *http://www.gecode.org * *Permissionisherebygranted,freeofcharge,toanypersonobtaining *acopyofthissoftwareandassociateddocumentationfiles(the *"Software"),todealintheSoftwarewithoutrestriction,including *withoutlimitationtherightstouse,copy,modify,merge,publish, *distribute,sublicense,and/orsellcopiesoftheSoftware,andto *permitpersonstowhomtheSoftwareisfurnishedtodoso,subjectto *thefollowingconditions: * *Theabovecopyrightnoticeandthispermissionnoticeshallbe *includedinallcopiesorsubstantialportionsoftheSoftware. * *THESOFTWAREISPROVIDED"ASIS",WITHOUTWARRANTYOFANYKIND, *EXPRESSORIMPLIED,INCLUDINGBUTNOTLIMITEDTOTHEWARRANTIESOF *MERCHANTABILITY,FITNESSFORAPARTICULARPURPOSEAND *NONINFRINGEMENT.INNOEVENTSHALLTHEAUTHORSORCOPYRIGHTHOLDERSBE *LIABLEFORANYCLAIM,DAMAGESOROTHERLIABILITY,WHETHERINANACTION *OFCONTRACT,TORTOROTHERWISE,ARISINGFROM,OUTOFORINCONNECTION *WITHTHESOFTWAREORTHEUSEOROTHERDEALINGSINTHESOFTWARE. * */ namespaceGecode{namespaceGist{ forceinlinevoid SpaceNode::setFlag(intflag,boolvalue){ if(value) nstatus|=1<<(flag-1); else nstatus&=~(1<<(flag-1)); } forceinlinebool SpaceNode::getFlag(intflag)const{ return(nstatus&(1<<(flag-1)))!=0; } forceinlinevoid SpaceNode::setHasOpenChildren(boolb){ setFlag(HASOPENCHILDREN,b); } forceinlinevoid SpaceNode::setHasFailedChildren(boolb){ setFlag(HASFAILEDCHILDREN,b); } forceinlinevoid SpaceNode::setHasSolvedChildren(boolb){ setFlag(HASSOLVEDCHILDREN,b); } forceinlinevoid SpaceNode::setStatus(NodeStatuss){ nstatus&=~(STATUSMASK); nstatus|=s<<20; } forceinlineNodeStatus SpaceNode::getStatus(void)const{ returnstatic_cast<NodeStatus>((nstatus&STATUSMASK)>>20); } forceinlinevoid SpaceNode::setDistance(unsignedintd){ if(d>MAXDISTANCE) d=MAXDISTANCE; nstatus&=~(DISTANCEMASK); nstatus|=d; } forceinlineunsignedint SpaceNode::getDistance(void)const{ returnnstatus&DISTANCEMASK; } forceinline SpaceNode::SpaceNode(intp) :Node(p),copy(NULL),nstatus(0){ choice=NULL; setStatus(UNDETERMINED); setHasSolvedChildren(false); setHasFailedChildren(false); } forceinlineSpace* SpaceNode::getSpace(NodeAllocator&na, BestNode*curBest,intc_d,inta_d){ acquireSpace(na,curBest,c_d,a_d); Space*ret; if(Support::marked(copy)){ ret=static_cast<Space*>(Support::unmark(copy)); copy=NULL; }else{ ret=copy->clone(); } returnret; } forceinlineconstSpace* SpaceNode::getWorkingSpace(void)const{ assert(copy!=NULL); if(Support::marked(copy)) returnstatic_cast<Space*>(Support::unmark(copy)); returncopy; } forceinlinevoid SpaceNode::purge(constNodeAllocator&na){ if(!isRoot()&&(getStatus()!=SOLVED||!na.bab())){ //onlydeletecopiesfromsolutionsifwearenotinBAB if(Support::marked(copy)) deletestatic_cast<Space*>(Support::unmark(copy)); else deletecopy; copy=NULL; } } forceinlinebool SpaceNode::isCurrentBest(BestNode*curBest){ returncurBest!=NULL&&curBest->s==this; } forceinlinebool SpaceNode::isOpen(void){ return((getStatus()==UNDETERMINED)|| getFlag(HASOPENCHILDREN)); } forceinlinebool SpaceNode::hasFailedChildren(void){ returngetFlag(HASFAILEDCHILDREN); } forceinlinebool SpaceNode::hasSolvedChildren(void){ returngetFlag(HASSOLVEDCHILDREN); } forceinlinebool SpaceNode::hasOpenChildren(void){ returngetFlag(HASOPENCHILDREN); } forceinlinebool SpaceNode::hasCopy(void){ returncopy!=NULL; } forceinlinebool SpaceNode::hasWorkingSpace(void){ returncopy!=NULL&&Support::marked(copy); } forceinlineint SpaceNode::getAlternative(constNodeAllocator&na)const{ SpaceNode*p=getParent(na); if(p==NULL) return-1; for(inti=p->getNumberOfChildren();i--;) if(p->getChild(na,i)==this) returni; GECODE_NEVER; return-1; } forceinlineconstChoice* SpaceNode::getChoice(void){ returnchoice; } }} //STATISTICS:gist-any