brancher-merit.hpp /usr/include/gecode/kernel.hh Gecode::MeritBase Gecode::MeritFunction Gecode::MeritDegree Gecode::MeritAFC Gecode::MeritActivity Gecode /*-*-mode:C++;c-basic-offset:2;indent-tabs-mode:nil-*-*/ /* *Mainauthor: *ChristianSchulte<schulte@gecode.org> * *Copyright: *ChristianSchulte,2012 * *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<class_View,class_Val> classMeritBase{ public: typedef_ViewView; typedef_ValVal; MeritBase(Space&home,constVarBranch&vb); MeritBase(Space&home,boolshare,MeritBase&mb); boolnotice(void)const; voiddispose(Space&home); }; template<classView> classMeritFunction:publicMeritBase<View,double>{ public: typedeftypenameView::VarTypeVar; typedeftypenameBranchTraits<Var>::MeritFunction; protected: Functionf; public: MeritFunction(Space&home,constVarBranch&vb); MeritFunction(Space&home,boolshared,MeritFunction&mf); doubleoperator ()(constSpace&home,Viewx,inti); }; template<classView> classMeritDegree:publicMeritBase<View,unsignedint>{ public: MeritDegree(Space&home,constVarBranch&vb); MeritDegree(Space&home,boolshared,MeritDegree&md); unsignedintoperator ()(constSpace&home,Viewx,inti); }; template<classView> classMeritAFC:publicMeritBase<View,double>{ protected: AFCafc; public: MeritAFC(Space&home,constVarBranch&vb); MeritAFC(Space&home,boolshared,MeritAFC&ma); doubleoperator ()(constSpace&home,Viewx,inti); boolnotice(void)const; voiddispose(Space&home); }; template<classView> classMeritActivity:publicMeritBase<View,double>{ protected: Activityactivity; public: MeritActivity(Space&home,constVarBranch&vb); MeritActivity(Space&home,boolshared,MeritActivity&ma); doubleoperator ()(constSpace&home,Viewx,inti); boolnotice(void)const; voiddispose(Space&home); }; //Meritbaseclass template<classView,classVal> forceinline MeritBase<View,Val>::MeritBase(Space&,constVarBranch&){} template<classView,classVal> forceinline MeritBase<View,Val>::MeritBase(Space&,bool,MeritBase&){} template<classView,classVal> forceinlinebool MeritBase<View,Val>::notice(void)const{ returnfalse; } template<classView,classVal> forceinlinevoid MeritBase<View,Val>::dispose(Space&){} //User-definedfunctionmerit template<classView> forceinline MeritFunction<View>::MeritFunction(Space&home,constVarBranch&vb) :MeritBase<View,double>(home,vb), f(function_cast<Function>(vb.merit())){} template<classView> forceinline MeritFunction<View>::MeritFunction(Space&home,boolshared, MeritFunction&mf) :MeritBase<View,double>(home,shared,mf),f(mf.f){} template<classView> forceinlinedouble MeritFunction<View>::operator ()(constSpace&home,Viewx,inti){ typenameView::VarTypey(x.varimp()); returnf(home,y,i); } //Degreemerit template<classView> forceinline MeritDegree<View>::MeritDegree(Space&home,constVarBranch&vb) :MeritBase<View,unsignedint>(home,vb){} template<classView> forceinline MeritDegree<View>::MeritDegree(Space&home,boolshared, MeritDegree&md) :MeritBase<View,unsignedint>(home,shared,md){} template<classView> forceinlineunsignedint MeritDegree<View>::operator ()(constSpace&,Viewx,int){ returnx.degree(); } //AFCmerit template<classView> forceinline MeritAFC<View>::MeritAFC(Space&home,constVarBranch&vb) :MeritBase<View,double>(home,vb),afc(vb.afc()){} template<classView> forceinline MeritAFC<View>::MeritAFC(Space&home,boolshared, MeritAFC&ma) :MeritBase<View,double>(home,shared,ma){ afc.update(home,shared,ma.afc); } template<classView> forceinlinedouble MeritAFC<View>::operator ()(constSpace&home,Viewx,int){ returnx.afc(home); } template<classView> forceinlinebool MeritAFC<View>::notice(void)const{ returntrue; } template<classView> forceinlinevoid MeritAFC<View>::dispose(Space&){ afc.~AFC(); } //Acitivitymerit template<classView> forceinline MeritActivity<View>::MeritActivity(Space&home,constVarBranch&vb) :MeritBase<View,double>(home,vb),activity(vb.activity()){} template<classView> forceinline MeritActivity<View>::MeritActivity(Space&home,boolshared, MeritActivity&ma) :MeritBase<View,double>(home,shared,ma){ activity.update(home,shared,ma.activity); } template<classView> forceinlinedouble MeritActivity<View>::operator ()(constSpace&,View,inti){ returnactivity[i]; } template<classView> forceinlinebool MeritActivity<View>::notice(void)const{ returntrue; } template<classView> forceinlinevoid MeritActivity<View>::dispose(Space&){ activity.~Activity(); } } //STATISTICS:kernel-branch