view.hpp /usr/include/gecode/kernel.hh Gecode::ConstView Gecode::VarImpView Gecode::DerivedView Gecode /*-*-mode:C++;c-basic-offset:2;indent-tabs-mode:nil-*-*/ /* *Mainauthors: *ChristianSchulte<schulte@gecode.org> * *Copyright: *ChristianSchulte,2005 * *Lastmodified: *$Date:2013-02-1821:53:58+0100(Mon,18Feb2013)$by$Author:schulte$ *$Revision:13310$ * *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<classView> classConstView{ public: typedeftypenameView::VarImpTypeVarImpType; typedeftypenameView::VarTypeVarType; unsignedintdegree(void)const; doubleafc(constSpace&home)const; staticboolvarderived(void); VarImpType*varimp(void)const; boolassigned(void)const; staticvoidschedule(Space&home,Propagator&p,ModEventme); staticModEventme(constModEventDelta&med); staticModEventDeltamed(ModEventme); voidsubscribe(Space&home,Propagator&p,PropCondpc,boolschedule=true); voidcancel(Space&home,Propagator&p,PropCondpc); voidsubscribe(Space&home,Advisor&a); voidcancel(Space&home,Advisor&a); staticModEventmodevent(constDelta&d); voidupdate(Space&home,boolshare,ConstView&y); }; template<classVar> classVarImpView{ public: typedefVarVarType; typedeftypenameVar::VarImpTypeVarImpType; protected: VarImpType*x; VarImpView(void); VarImpView(VarImpType*y); public: staticboolvarderived(void); VarImpType*varimp(void)const; unsignedintdegree(void)const; doubleafc(constSpace&home)const; boolassigned(void)const; staticvoidschedule(Space&home,Propagator&p,ModEventme); staticModEventme(constModEventDelta&med); staticModEventDeltamed(ModEventme); voidsubscribe(Space&home,Propagator&p,PropCondpc,boolschedule=true); voidcancel(Space&home,Propagator&p,PropCondpc); voidsubscribe(Space&home,Advisor&a); voidcancel(Space&home,Advisor&a); staticModEventmodevent(constDelta&d); voidupdate(Space&home,boolshare,VarImpView<Var>&y); }; template<classVarA,classVarB> boolsame(constVarImpView<VarA>&x,constVarImpView<VarB>&y); template<classViewA,classViewB> boolbefore(constViewA&x,constViewB&y); template<classView> classDerivedView{ public: typedeftypenameView::VarImpTypeVarImpType; typedeftypenameView::VarTypeVarType; protected: Viewx; DerivedView(void); DerivedView(constView&y); public: staticboolvarderived(void); VarImpType*varimp(void)const; Viewbase(void)const; unsignedintdegree(void)const; doubleafc(constSpace&home)const; boolassigned(void)const; staticvoidschedule(Space&home,Propagator&p,ModEventme); staticModEventme(constModEventDelta&med); staticModEventDeltamed(ModEvent); voidsubscribe(Space&home,Propagator&p,PropCondpc,boolschedule=true); voidcancel(Space&home,Propagator&p,PropCondpc); voidsubscribe(Space&home,Advisor&a); voidcancel(Space&home,Advisor&a); staticModEventmodevent(constDelta&d); voidupdate(Space&home,boolshare,DerivedView<View>&y); }; template<classViewA,classViewB> boolshared(constConstView<ViewA>&,constConstView<ViewB>&); template<classVar,classView> boolshared(constVarImpView<Var>&,constConstView<View>&); template<classViewA,classViewB> boolshared(constDerivedView<ViewA>&,constConstView<ViewB>&); template<classView,classVar> boolshared(constConstView<View>&,constVarImpView<Var>&); template<classViewA,classViewB> boolshared(constConstView<ViewA>&,constDerivedView<ViewB>&); template<classVarA,classVarB> boolshared(constVarImpView<VarA>&,constVarImpView<VarB>&); template<classVar,classView> boolshared(constVarImpView<Var>&,constDerivedView<View>&); template<classView,classVar> boolshared(constDerivedView<View>&,constVarImpView<Var>&); template<classViewA,classViewB> boolshared(constDerivedView<ViewA>&,constDerivedView<ViewB>&); /* *Constantview:hasnovariableimplementation * */ template<classView> forceinlineunsignedint ConstView<View>::degree(void)const{ return0; } template<classView> forceinlinedouble ConstView<View>::afc(constSpace&)const{ return0.0; } template<classView> forceinlinebool ConstView<View>::varderived(void){ returnfalse; } template<classView> forceinlinetypenameView::VarImpType* ConstView<View>::varimp(void)const{ returnNULL; } template<classView> forceinlinebool ConstView<View>::assigned(void)const{ returntrue; } template<classView> forceinlinevoid ConstView<View>::subscribe(Space&home,Propagator&p,PropCond, boolschedule){ if(schedule) View::schedule(home,p,ME_GEN_ASSIGNED); } template<classView> forceinlinevoid ConstView<View>::cancel(Space&,Propagator&,PropCond){ } template<classView> forceinlinevoid ConstView<View>::subscribe(Space&,Advisor&){ } template<classView> forceinlinevoid ConstView<View>::cancel(Space&,Advisor&){ } template<classView> forceinlinevoid ConstView<View>::schedule(Space&home,Propagator&p,ModEventme){ View::schedule(home,p,me); } template<classView> forceinlineModEvent ConstView<View>::me(constModEventDelta&med){ returnView::me(med); } template<classView> forceinlineModEventDelta ConstView<View>::med(ModEventme){ returnView::med(me); } template<classView> forceinlineModEvent ConstView<View>::modevent(constDelta&d){ (void)d; returnME_GEN_NONE; } template<classView> forceinlinevoid ConstView<View>::update(Space&,bool,ConstView<View>&){ } /* *Variableview:containsapointertoavariableimplementation * */ template<classVar> forceinline VarImpView<Var>::VarImpView(void) :x(NULL){} template<classVar> forceinline VarImpView<Var>::VarImpView(VarImpType*y) :x(y){} template<classVar> forceinlinebool VarImpView<Var>::varderived(void){ returntrue; } template<classVar> forceinlinetypenameVar::VarImpType* VarImpView<Var>::varimp(void)const{ returnx; } template<classVar> forceinlineunsignedint VarImpView<Var>::degree(void)const{ returnx->degree(); } template<classVar> forceinlinedouble VarImpView<Var>::afc(constSpace&home)const{ returnx->afc(home); } template<classVar> forceinlinebool VarImpView<Var>::assigned(void)const{ returnx->assigned(); } template<classVar> forceinlinevoid VarImpView<Var>::subscribe(Space&home,Propagator&p,PropCondpc, boolschedule){ x->subscribe(home,p,pc,schedule); } template<classVar> forceinlinevoid VarImpView<Var>::cancel(Space&home,Propagator&p,PropCondpc){ x->cancel(home,p,pc); } template<classVar> forceinlinevoid VarImpView<Var>::subscribe(Space&home,Advisor&a){ x->subscribe(home,a); } template<classVar> forceinlinevoid VarImpView<Var>::cancel(Space&home,Advisor&a){ x->cancel(home,a); } template<classVar> forceinlinevoid VarImpView<Var>::schedule(Space&home,Propagator&p,ModEventme){ VarImpType::schedule(home,p,me); } template<classVar> forceinlineModEvent VarImpView<Var>::me(constModEventDelta&med){ returnVarImpType::me(med); } template<classVar> forceinlineModEventDelta VarImpView<Var>::med(ModEventme){ returnVarImpType::med(me); } template<classVar> forceinlineModEvent VarImpView<Var>::modevent(constDelta&d){ returnVarImpType::modevent(d); } template<classVar> forceinlinevoid VarImpView<Var>::update(Space&home,boolshare,VarImpView<Var>&y){ x=y.x->copy(home,share); } /* *Derivedview:containthebaseviewfromwhichtheyarederived * */ template<classView> forceinline DerivedView<View>::DerivedView(void){} template<classView> forceinline DerivedView<View>::DerivedView(constView&y) :x(y){} template<classView> forceinlinebool DerivedView<View>::varderived(void){ returnView::varderived(); } template<classView> forceinlinetypenameView::VarImpType* DerivedView<View>::varimp(void)const{ returnx.varimp(); } template<classView> forceinlineView DerivedView<View>::base(void)const{ returnx; } template<classView> forceinlineunsignedint DerivedView<View>::degree(void)const{ returnx.degree(); } template<classView> forceinlinedouble DerivedView<View>::afc(constSpace&home)const{ returnx.afc(home); } template<classView> forceinlinebool DerivedView<View>::assigned(void)const{ returnx.assigned(); } template<classView> forceinlinevoid DerivedView<View>::schedule(Space&home,Propagator&p,ModEventme){ returnView::schedule(home,p,me); } template<classView> forceinlineModEvent DerivedView<View>::me(constModEventDelta&med){ returnView::me(med); } template<classView> forceinlineModEventDelta DerivedView<View>::med(ModEventme){ returnView::med(me); } template<classView> forceinlinevoid DerivedView<View>::subscribe(Space&home,Propagator&p,PropCondpc, boolschedule){ x.subscribe(home,p,pc,schedule); } template<classView> forceinlinevoid DerivedView<View>::cancel(Space&home,Propagator&p,PropCondpc){ x.cancel(home,p,pc); } template<classView> forceinlinevoid DerivedView<View>::subscribe(Space&home,Advisor&a){ x.subscribe(home,a); } template<classView> forceinlinevoid DerivedView<View>::cancel(Space&home,Advisor&a){ x.cancel(home,a); } template<classView> forceinlineModEvent DerivedView<View>::modevent(constDelta&d){ returnView::modevent(d); } template<classView> forceinlinevoid DerivedView<View>::update(Space&home,boolshare,DerivedView<View>&y){ x.update(home,share,y.x); } /* *Testswhethertwoviewsarethesame * */ template<classViewA,classViewB> forceinlinebool same(constConstView<ViewA>&,constConstView<ViewB>&){ returnfalse; } template<classVar,classView> forceinlinebool same(constVarImpView<Var>&,constConstView<View>&){ returnfalse; } template<classViewA,classViewB> forceinlinebool same(constConstView<ViewA>&,constDerivedView<ViewB>&){ returnfalse; } template<classVar,classView> forceinlinebool same(constVarImpView<Var>&,constDerivedView<View>&){ returnfalse; } template<classView,classVar> forceinlinebool same(constDerivedView<View>&,constVarImpView<Var>&){ returnfalse; } template<classVar> forceinlinebool same(constVarImpView<Var>&x,constVarImpView<Var>&y){ returnx.varimp()==y.varimp(); } template<classViewA,classViewB> forceinlinebool same(constDerivedView<ViewA>&x,constDerivedView<ViewB>&y){ returnsame(x.base(),y.base()); } /* *Testswhetheroneviewisbeforetheother * */ template<classViewA,classViewB> forceinlinebool before(constViewA&x,constViewB&y){ returnx.varimp()<y.varimp(); } /* *Testingwhethertwoviewssharethesamevariable * */ template<classViewA,classViewB> forceinlinebool shared(constConstView<ViewA>&,constConstView<ViewB>&){ returnfalse; } template<classVar,classView> forceinlinebool shared(constVarImpView<Var>&,constConstView<View>&){ returnfalse; } template<classViewA,classViewB> forceinlinebool shared(constDerivedView<ViewA>&,constConstView<ViewB>&){ returnfalse; } template<classView,classVar> forceinlinebool shared(constConstView<View>&,constVarImpView<Var>&){ returnfalse; } template<classViewA,classViewB> forceinlinebool shared(constConstView<ViewA>&,constDerivedView<ViewB>&){ returnfalse; } template<classVarA,classVarB> forceinlinebool shared(constVarImpView<VarA>&x,constVarImpView<VarB>&y){ return(static_cast<VarImpBase*>(x.varimp())== static_cast<VarImpBase*>(y.varimp())); } template<classVar,classView> forceinlinebool shared(constVarImpView<Var>&x,constDerivedView<View>&y){ return(View::varderived()&& static_cast<VarImpBase*>(x.varimp())== static_cast<VarImpBase*>(y.varimp())); } template<classView,classVar> forceinlinebool shared(constDerivedView<View>&x,constVarImpView<Var>&y){ return(View::varderived()&& static_cast<VarImpBase*>(x.varimp())== static_cast<VarImpBase*>(y.varimp())); } template<classViewA,classViewB> forceinlinebool shared(constDerivedView<ViewA>&x,constDerivedView<ViewB>&y){ return(ViewA::varderived()&&ViewB::varderived()&& static_cast<VarImpBase*>(x.varimp())== static_cast<VarImpBase*>(y.varimp())); } } //STATISTICS:kernel-var