brancher-view-val.hpp /usr/include/gecode/kernel.hh Gecode::PosValChoice Gecode::ViewValNGL Gecode::ViewValBrancher Gecode /*-*-mode:C++;c-basic-offset:2;indent-tabs-mode:nil-*-*/ /* *Mainauthors: *ChristianSchulte<schulte@gecode.org> * *Copyright: *ChristianSchulte,2012 * *Lastmodified: *$Date:2013-07-0817:25:13+0200(Mon,08Jul2013)$by$Author:schulte$ *$Revision:13825$ * *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{ template<classVal> classGECODE_VTABLE_EXPORTPosValChoice:publicPosChoice{ private: constVal_val; public: PosValChoice(constBrancher&b,unsignedinta,constPos&p,constVal&n); constVal&val(void)const; virtualsize_tsize(void)const; virtualvoidarchive(Archive&e)const; }; template<classView,classVal,PropCondpc> classViewValNGL:publicNGL{ protected: Viewx; Valn; public: ViewValNGL(Space&home,Viewx,Valn); ViewValNGL(Space&home,boolshare,ViewValNGL&ngl); virtualvoidsubscribe(Space&home,Propagator&p); virtualvoidcancel(Space&home,Propagator&p); virtualsize_tdispose(Space&home); }; template<classView,intn,classVal,unsignedinta> classViewValBrancher:publicViewBrancher<View,n>{ typedeftypenameViewBrancher<View,n>::BranchFilterBranchFilter; protected: usingViewBrancher<View,n>::vs; usingViewBrancher<View,n>::x; ValSelCommitBase<View,Val>*vsc; typedefvoid(*VarValPrint)(constSpace&home,constBrancherHandle&bh, unsignedintb, typenameView::VarTypex,inti, constVal&m, std::ostream&o); VarValPrintvvp; ViewValBrancher(Space&home,boolshare,ViewValBrancher&b); ViewValBrancher(Homehome, ViewArray<View>&x, ViewSel<View>*vs[n], ValSelCommitBase<View,Val>*vsc, BranchFilterbf, VarValPrintvvp); public: virtualconstChoice*choice(Space&home); virtualconstChoice*choice(constSpace&home,Archive&e); virtualExecStatuscommit(Space&home,constChoice&c,unsignedintb); virtualNGL*ngl(Space&home,constChoice&c,unsignedintb)const; virtualvoidprint(constSpace&home,constChoice&c,unsignedintb, std::ostream&o)const; virtualActor*copy(Space&home,boolshare); virtualsize_tdispose(Space&home); staticBrancherHandlepost(Homehome, ViewArray<View>&x, ViewSel<View>*vs[n], ValSelCommitBase<View,Val>*vsc, BranchFilterbf, VarValPrintvvp); }; /* *%Choicewithpositionandvalue * */ template<classVal> forceinline PosValChoice<Val>::PosValChoice(constBrancher&b,unsignedinta, constPos&p,constVal&n) :PosChoice(b,a,p),_val(n){} template<classVal> forceinlineconstVal& PosValChoice<Val>::val(void)const{ return_val; } template<classVal> forceinlinesize_t PosValChoice<Val>::size(void)const{ returnsizeof(PosValChoice<Val>); } template<classVal> forceinlinevoid PosValChoice<Val>::archive(Archive&e)const{ PosChoice::archive(e); e<<_val; } /* *View-valueno-goodliteral * */ template<classView,classVal,PropCondpc> forceinline ViewValNGL<View,Val,pc>::ViewValNGL(Space&home,Viewx0,Valn0) :NGL(home),x(x0),n(n0){} template<classView,classVal,PropCondpc> forceinline ViewValNGL<View,Val,pc>::ViewValNGL(Space&home,boolshare,ViewValNGL&ngl) :NGL(home,share,ngl),n(ngl.n){ x.update(home,share,ngl.x); } template<classView,classVal,PropCondpc> void ViewValNGL<View,Val,pc>::subscribe(Space&home,Propagator&p){ x.subscribe(home,p,pc); } template<classView,classVal,PropCondpc> void ViewValNGL<View,Val,pc>::cancel(Space&home,Propagator&p){ x.cancel(home,p,pc); } template<classView,classVal,PropCondpc> size_t ViewValNGL<View,Val,pc>::dispose(Space&home){ (void)NGL::dispose(home); returnsizeof(*this); } /* *Genericbrancherbasedonvariable/valueselection * */ template<classView,intn,classVal,unsignedinta> forceinline ViewValBrancher<View,n,Val,a>:: ViewValBrancher(Homehome, ViewArray<View>&x, ViewSel<View>*vs[n], ValSelCommitBase<View,Val>*vsc0, BranchFilterbf, VarValPrintvvp0) :ViewBrancher<View,n>(home,x,vs,bf),vsc(vsc0),vvp(vvp0){ if(vsc->notice()) home.notice(*this,AP_DISPOSE,true); } template<classView,intn,classVal,unsignedinta> forceinlineBrancherHandle ViewValBrancher<View,n,Val,a>:: post(Homehome,ViewArray<View>&x, ViewSel<View>*vs[n],ValSelCommitBase<View,Val>*vsc, BranchFilterbf, VarValPrintvvp){ return*new(home)ViewValBrancher<View,n,Val,a>(home,x,vs,vsc,bf,vvp); } template<classView,intn,classVal,unsignedinta> forceinline ViewValBrancher<View,n,Val,a>:: ViewValBrancher(Space&home,boolshared,ViewValBrancher<View,n,Val,a>&b) :ViewBrancher<View,n>(home,shared,b), vsc(b.vsc->copy(home,shared)),vvp(b.vvp){} template<classView,intn,classVal,unsignedinta> Actor* ViewValBrancher<View,n,Val,a>::copy(Space&home,boolshared){ returnnew(home)ViewValBrancher<View,n,Val,a>(home,shared,*this); } template<classView,intn,classVal,unsignedinta> constChoice* ViewValBrancher<View,n,Val,a>::choice(Space&home){ Posp=ViewBrancher<View,n>::pos(home); Viewv=ViewBrancher<View,n>::view(p); returnnewPosValChoice<Val>(*this,a,p,vsc->val(home,v,p.pos)); } template<classView,intn,classVal,unsignedinta> constChoice* ViewValBrancher<View,n,Val,a>::choice(constSpace&home,Archive&e){ (void)home; intp;e>>p; Valv;e>>v; returnnewPosValChoice<Val>(*this,a,p,v); } template<classView,intn,classVal,unsignedinta> ExecStatus ViewValBrancher<View,n,Val,a> ::commit(Space&home,constChoice&c,unsignedintb){ constPosValChoice<Val>&pvc =static_cast<constPosValChoice<Val>&>(c); returnme_failed(vsc->commit(home,b, ViewBrancher<View,n>::view(pvc.pos()), pvc.pos().pos, pvc.val())) ?ES_FAILED:ES_OK; } template<classView,intn,classVal,unsignedinta> NGL* ViewValBrancher<View,n,Val,a> ::ngl(Space&home,constChoice&c,unsignedintb)const{ constPosValChoice<Val>&pvc =static_cast<constPosValChoice<Val>&>(c); returnvsc->ngl(home,b, ViewBrancher<View,n>::view(pvc.pos()),pvc.val()); } template<classView,intn,classVal,unsignedinta> void ViewValBrancher<View,n,Val,a> ::print(constSpace&home,constChoice&c,unsignedintb, std::ostream&o)const{ constPosValChoice<Val>&pvc =static_cast<constPosValChoice<Val>&>(c); Viewxi=ViewBrancher<View,n>::view(pvc.pos()); typenameView::VarTypey(ViewBrancher<View,n>::view(pvc.pos()).varimp()); if(vvp!=NULL) vvp(home,*this,b,y,pvc.pos().pos,pvc.val(),o); else vsc->print(home,b,xi,pvc.pos().pos,pvc.val(),o); } template<classView,intn,classVal,unsignedinta> forceinlinesize_t ViewValBrancher<View,n,Val,a>::dispose(Space&home){ if(vsc->notice()) home.ignore(*this,AP_DISPOSE,true); vsc->dispose(home); (void)ViewBrancher<View,n>::dispose(home); returnsizeof(ViewValBrancher<View,n,Val,a>); } } //STATISTICS:kernel-branch