not-first-not-last.hpp algorithm /usr/include/gecode/int/unary.hh Gecode Gecode::Int Gecode::Int::Unary /*-*-mode:C++;c-basic-offset:2;indent-tabs-mode:nil-*-*/ /* *Mainauthors: *ChristianSchulte<schulte@gecode.org> * *Copyright: *ChristianSchulte,2009 * *Lastmodified: *$Date:2012-09-0717:31:22+0200(Fri,07Sep2012)$by$Author:schulte$ *$Revision:13068$ * *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<algorithm> namespaceGecode{namespaceInt{namespaceUnary{ template<classManTaskView> forceinlineExecStatus notlast(Space&home,TaskViewArray<ManTaskView>&t){ sort<ManTaskView,STO_LCT,true>(t); Regionr(home); OmegaTree<ManTaskView>o(r,t); TaskViewIter<ManTaskView,STO_LST,true>q(r,t); int*lct=r.alloc<int>(t.size()); for(inti=t.size();i--;) lct[i]=t[i].lct(); for(inti=0;i<t.size();i++){ intj=-1; while(q()&&(t[i].lct()>t[q.task()].lst())){ if((j>=0)&&(o.ect()>t[q.task()].lst())) lct[q.task()]=std::min(lct[q.task()],t[j].lst()); j=q.task(); o.insert(j);++q; } if((j>=0)&&(o.ect(i)>t[i].lst())) lct[i]=std::min(lct[i],t[j].lst()); } for(inti=t.size();i--;) GECODE_ME_CHECK(t[i].lct(home,lct[i])); returnES_OK; } template<classManTask> ExecStatus notfirstnotlast(Space&home,TaskArray<ManTask>&t){ TaskViewArray<typename TaskTraits<ManTask>::TaskViewFwd>f(t); GECODE_ES_CHECK(notlast(home,f)); TaskViewArray<typename TaskTraits<ManTask>::TaskViewBwd>b(t); returnnotlast(home,b); } template<classOptTaskView> forceinlineExecStatus notlast(Space&home,Propagator&p,TaskViewArray<OptTaskView>&t){ sort<OptTaskView,STO_LCT,true>(t); Regionr(home); OmegaTree<OptTaskView>o(r,t); ManTaskViewIter<OptTaskView,STO_LST,true>q(r,t); int*lct=r.alloc<int>(t.size()); for(inti=t.size();i--;) lct[i]=t[i].lct(); for(inti=0;i<t.size();i++){ intj=-1; while(q()&&(t[i].lct()>t[q.task()].lst())){ if((j>=0)&&(o.ect()>t[q.task()].lst())) lct[q.task()]=std::min(lct[q.task()],t[j].lst()); j=q.task(); o.insert(j);++q; } if((j>=0)&&(o.ect(i)>t[i].lst())) lct[i]=std::min(lct[i],t[j].lst()); } intn=t.size(); for(inti=n;i--;) if(t[i].mandatory()){ GECODE_ME_CHECK(t[i].lct(home,lct[i])); }elseif(lct[i]<t[i].ect()){ //GECODE_ME_CHECK(t[i].excluded(home)); //t[i].cancel(home,p);t[i]=t[--n]; } t.size(n); return(t.size()<2)?home.ES_SUBSUMED(p):ES_OK; } template<classOptTask> ExecStatus notfirstnotlast(Space&home,Propagator&p,TaskArray<OptTask>&t){ TaskViewArray<typename TaskTraits<OptTask>::TaskViewFwd>f(t); GECODE_ES_CHECK(notlast(home,p,f)); TaskViewArray<typename TaskTraits<OptTask>::TaskViewBwd>b(t); returnnotlast(home,p,b); } }}} //STATISTICS:int-prop