man-prop.hpp /usr/include/gecode/int/cumulative.hh Gecode Gecode::Int Gecode::Int::Cumulative /*-*-mode:C++;c-basic-offset:2;indent-tabs-mode:nil-*-*/ /* *Mainauthors: *ChristianSchulte<schulte@gecode.org> *GuidoTack<tack@gecode.org> * *Copyright: *ChristianSchulte,2009 *GuidoTack,2010 * *Lastmodified: *$Date:2011-07-1322:44:50+0200(Wed,13Jul2011)$by$Author:tack$ *$Revision:12202$ * *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{namespaceCumulative{ template<classManTask,classCap> forceinline ManProp<ManTask,Cap>::ManProp(Homehome,Capc0,TaskArray<ManTask>&t) :TaskProp<ManTask,Int::PC_INT_DOM>(home,t),c(c0){ c.subscribe(home,*this,Int::PC_INT_BND); } template<classManTask,classCap> forceinline ManProp<ManTask,Cap>::ManProp(Space&home,boolshared, ManProp<ManTask,Cap>&p) :TaskProp<ManTask,Int::PC_INT_DOM>(home,shared,p){ c.update(home,shared,p.c); } template<classManTask,classCap> forceinlineExecStatus ManProp<ManTask,Cap>::post(Homehome,Capc,TaskArray<ManTask>&t){ //Capacitymustbenonnegative GECODE_ME_CHECK(c.gq(home,0)); //Checkthattasksdonotoverloadresource for(inti=t.size();i--;) if(t[i].c()>c.max()) returnES_FAILED; if(t.size()==1) GECODE_ME_CHECK(c.gq(home,t[0].c())); if(t.size()>1){ if(c.assigned()&&c.val()==1){ TaskArray<typename TaskTraits<ManTask>::UnaryTask>mt(home,t.size()); for(inti=t.size();i--;) mt[i]=t[i]; returnUnary::ManProp<typename TaskTraits<ManTask>::UnaryTask> ::post(home,mt); }else{ (void)new(home)ManProp<ManTask,Cap>(home,c,t); } } returnES_OK; } template<classManTask,classCap> Actor* ManProp<ManTask,Cap>::copy(Space&home,boolshare){ returnnew(home)ManProp<ManTask,Cap>(home,share,*this); } template<classManTask,classCap> forceinlinesize_t ManProp<ManTask,Cap>::dispose(Space&home){ (void)TaskProp<ManTask,Int::PC_INT_DOM>::dispose(home); c.cancel(home,*this,PC_INT_BND); returnsizeof(*this); } template<classManTask,classCap> ExecStatus ManProp<ManTask,Cap>::propagate(Space&home,constModEventDelta&med){ //Onlyboundschanges? if(Int::IntView::me(med)!=Int::ME_INT_DOM) GECODE_ES_CHECK(overload(home,c.max(),t)); GECODE_ES_CHECK(edgefinding(home,c.max(),t)); boolsubsumed; ExecStatuses=basic(home,subsumed,c,t); GECODE_ES_CHECK(es); if(subsumed) returnhome.ES_SUBSUMED(*this); if(Cap::varderived()&&c.assigned()&&c.val()==1){ //Checkthattasksdonotoverloadresource for(inti=t.size();i--;) if(t[i].c()>1) returnES_FAILED; //Rewritetounaryresourceconstraint TaskArray<typename TaskTraits<ManTask>::UnaryTask>ut(home,t.size()); for(inti=t.size();i--;) ut[i]=t[i]; GECODE_REWRITE(*this, (Unary::ManProp<typenameTaskTraits<ManTask>::UnaryTask> ::post(home(*this),ut))); }else{ returnes; } } }}} //STATISTICS:int-prop