dom.hpp /usr/include/gecode/int/circuit.hh Gecode Gecode::Int Gecode::Int::Circuit /*-*-mode:C++;c-basic-offset:2;indent-tabs-mode:nil-*-*/ /* *Mainauthors: *ChristianSchulte<schulte@gecode.org> * *Copyright: *ChristianSchulte,2007 * *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. * */ namespaceGecode{namespaceInt{namespaceCircuit{ /* *Theactualpropagator * */ template<classView,classOffset> forceinline Dom<View,Offset>::Dom(Homehome,ViewArray<View>&x,Offset&o) :Base<View,Offset>(home,x,o){} template<classView,classOffset> forceinline Dom<View,Offset>::Dom(Space&home,boolshare,Dom<View,Offset>&p) :Base<View,Offset>(home,share,p){} template<classView,classOffset> Actor* Dom<View,Offset>::copy(Space&home,boolshare){ returnnew(home)Dom<View,Offset>(home,share,*this); } template<classView,classOffset> PropCost Dom<View,Offset>::cost(constSpace&,constModEventDelta&med)const{ if(View::me(med)==Int::ME_INT_VAL) returnPropCost::linear(PropCost::LO,x.size()); else returnPropCost::quadratic(PropCost::HI,x.size()); } template<classView,classOffset> ExecStatus Dom<View,Offset>::propagate(Space&home,constModEventDelta&med){ if(View::me(med)==Int::ME_INT_VAL){ GECODE_ES_CHECK((Int::Distinct::prop_val<View,true>(home,y))); ExecStatusescv=connected(home); if(escv!=ES_FIX) returnescv; if(y.size()<2) returnhome.ES_SUBSUMED(*this); returnhome.ES_FIX_PARTIAL(*this,View::med(Int::ME_INT_DOM)); } if(dc.available()){ GECODE_ES_CHECK(dc.sync(home)); }else{ GECODE_ES_CHECK(dc.init(home,y)); } boolassigned; GECODE_ES_CHECK(dc.propagate(home,assigned)); ExecStatusesc=connected(home); if(esc!=ES_FIX) returnesc; //Elminiateassignedviewsfromy,astheyhavebeenassigned //andpropagatedbydomainconsistentpropagation.Thisisrequired //asweneedtoknowhowmanyassignedviewsactuallyexist. if(assigned) for(inti=y.size();i--;) if(y[i].assigned()) y.move_lst(i); returnpath(home); } template<classView,classOffset> ExecStatus Dom<View,Offset>::post(Homehome,ViewArray<View>&x,Offset&o){ intn=x.size(); if(n==1){ GECODE_ME_CHECK(o(x[0]).eq(home,0)); }elseif(n==2){ GECODE_ME_CHECK(o(x[0]).eq(home,1)); GECODE_ME_CHECK(o(x[1]).eq(home,0)); }else{ for(inti=n;i--;){ GECODE_ME_CHECK(o(x[i]).gq(home,0)); GECODE_ME_CHECK(o(x[i]).le(home,n)); GECODE_ME_CHECK(o(x[i]).nq(home,i)); } (void)new(home)Dom<View,Offset>(home,x,o); } returnES_OK; } }}} //STATISTICS:int-prop