dom.hpp climits /usr/include/gecode/int/distinct.hh Gecode Gecode::Int Gecode::Int::Distinct /*-*-mode:C++;c-basic-offset:2;indent-tabs-mode:nil-*-*/ /* *Mainauthors: *ChristianSchulte<schulte@gecode.org> * *Copyright: *ChristianSchulte,2003 * *Lastmodified: *$Date:2011-09-0614:19:49+0200(Tue,06Sep2011)$by$Author:schulte$ *$Revision:12393$ * *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. * */ #include<climits> namespaceGecode{namespaceInt{namespaceDistinct{ template<classView> forceinline Dom<View>::Dom(Homehome,ViewArray<View>&x) :NaryPropagator<View,PC_INT_DOM>(home,x){} template<classView> ExecStatus Dom<View>::post(Homehome,ViewArray<View>&x){ if(x.size()==2) returnRel::Nq<View>::post(home,x[0],x[1]); if(x.size()==3) returnTerDom<View>::post(home,x[0],x[1],x[2]); if(x.size()>3){ //Doboundspropagationtomakeview-valuegraphsmaller GECODE_ES_CHECK(prop_bnd<View>(home,x)); (void)new(home)Dom<View>(home,x); } returnES_OK; } template<classView> forceinline Dom<View>::Dom(Space&home,boolshare,Dom<View>&p) :NaryPropagator<View,PC_INT_DOM>(home,share,p){} template<classView> PropCost Dom<View>::cost(constSpace&,constModEventDelta&med)const{ if(View::me(med)==ME_INT_VAL) returnPropCost::linear(PropCost::LO,x.size()); else returnPropCost::quadratic(PropCost::HI,x.size()); } template<classView> Actor* Dom<View>::copy(Space&home,boolshare){ returnnew(home)Dom<View>(home,share,*this); } template<classView> ExecStatus Dom<View>::propagate(Space&home,constModEventDelta&med){ if(View::me(med)==ME_INT_VAL){ ExecStatuses=prop_val<View,false>(home,x); GECODE_ES_CHECK(es); if(x.size()<2) returnhome.ES_SUBSUMED(*this); if(es==ES_FIX) returnhome.ES_FIX_PARTIAL(*this,View::med(ME_INT_DOM)); es=prop_bnd<View>(home,x); GECODE_ES_CHECK(es); if(x.size()<2) returnhome.ES_SUBSUMED(*this); es=prop_val<View,true>(home,x); GECODE_ES_CHECK(es); if(x.size()<2) returnhome.ES_SUBSUMED(*this); returnhome.ES_FIX_PARTIAL(*this,View::med(ME_INT_DOM)); } if(x.size()==2) GECODE_REWRITE(*this,Rel::Nq<View>::post(home(*this),x[0],x[1])); if(x.size()==3) GECODE_REWRITE(*this,TerDom<View>::post(home(*this),x[0],x[1],x[2])); if(dc.available()){ GECODE_ES_CHECK(dc.sync(home)); }else{ GECODE_ES_CHECK(dc.init(home,x)); } boolassigned; GECODE_ES_CHECK(dc.propagate(home,assigned)); returnES_FIX; } }}} //STATISTICS:int-prop