bab.hh gecode/search.hh gecode/search/support.hh gecode/search/worker.hh gecode/search/sequential/path.hh Gecode::Search::Sequential::BAB Gecode Gecode::Search Gecode::Search::Sequential /*-*-mode:C++;c-basic-offset:2;indent-tabs-mode:nil-*-*/ /* *Mainauthors: *ChristianSchulte<schulte@gecode.org> * *Contributingauthors: *GuidoTack<tack@gecode.org> * *Copyright: *ChristianSchulte,2004 *GuidoTack,2004 * *Lastmodified: *$Date:2013-10-2416:42:20+0200(Thu,24Oct2013)$by$Author:schulte$ *$Revision:14030$ * *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. * */ #ifndef__GECODE_SEARCH_SEQUENTIAL_BAB_HH__ #define__GECODE_SEARCH_SEQUENTIAL_BAB_HH__ #include<gecode/search.hh> #include<gecode/search/support.hh> #include<gecode/search/worker.hh> #include<gecode/search/sequential/path.hh> namespaceGecode{namespaceSearch{namespaceSequential{ classBAB:publicWorker{ private: Optionsopt; Pathpath; Space*cur; unsignedintd; intmark; Space*best; public: BAB(Space*s,constOptions&o); Space*next(void); Statisticsstatistics(void)const; voidreset(Space*s); NoGoods&nogoods(void); ~BAB(void); }; forceinline BAB::BAB(Space*s,constOptions&o) :opt(o),path(static_cast<int>(opt.nogoods_limit)), d(0),mark(0),best(NULL){ if((s==NULL)||(s->status(*this)==SS_FAILED)){ fail++; cur=NULL; if(!o.clone) deletes; }else{ cur=snapshot(s,opt); } } forceinlineSpace* BAB::next(void){ /* *Theinvariantmaintainedbytheengineis: *Forallnodesstoredatadepthlessthanmark,there *isnoguaranteeofbetterness.Forthoseabovethemark, *betternessisguaranteed. * *Theenginemaintainsthepathonthestackforthecurrent *nodetobeexplored. * */ start(); while(true){ while(cur){ if(stop(opt)) returnNULL; node++; switch(cur->status(*this)){ caseSS_FAILED: fail++; deletecur; cur=NULL; break; caseSS_SOLVED: //Deletesallpendingbranchers (void)cur->choice(); deletebest; best=cur; cur=NULL; mark=path.entries(); returnbest->clone(); caseSS_BRANCH: { Space*c; if((d==0)||(d>=opt.c_d)){ c=cur->clone(); d=1; }else{ c=NULL; d++; } constChoice*ch=path.push(*this,cur,c); cur->commit(*ch,0); break; } default: GECODE_NEVER; } } //Recomputeandaddconstraintifnecessary do{ if(!path.next()) returnNULL; cur=path.recompute(d,opt.a_d,*this,best,mark); }while(cur==NULL); } GECODE_NEVER; returnNULL; } forceinlineStatistics BAB::statistics(void)const{ return*this; } forceinlinevoid BAB::reset(Space*s){ deletebest; best=NULL; path.reset(); d=mark=0U; deletecur; if((s==NULL)||(s->status(*this)==SS_FAILED)){ cur=NULL; }else{ cur=s; } Worker::reset(); } forceinlineNoGoods& BAB::nogoods(void){ returnpath; } forceinline BAB::~BAB(void){ path.reset(); deletebest; deletecur; } }}} #endif //STATISTICS:search-sequential