task.hpp /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> *GuidoTack<tack@gecode.org> * *Copyright: *ChristianSchulte,2009 *GuidoTack,2010 * *Lastmodified: *$Date:2011-05-2516:56:41+0200(Wed,25May2011)$by$Author:schulte$ *$Revision:12022$ * *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{namespaceUnary{ /* *Mandatoryfixedtask */ forceinline ManFixPTask::ManFixPTask(void){} forceinline ManFixPTask::ManFixPTask(IntVars,intp):_s(s),_p(p){} forceinlinevoid ManFixPTask::init(IntVars,intp){ _s=s;_p=p; } forceinlinevoid ManFixPTask::init(constManFixPTask&t){ _s=t._s;_p=t._p; } forceinlineint ManFixPTask::est(void)const{ return_s.min(); } forceinlineint ManFixPTask::ect(void)const{ return_s.min()+_p; } forceinlineint ManFixPTask::lst(void)const{ return_s.max(); } forceinlineint ManFixPTask::lct(void)const{ return_s.max()+_p; } forceinlineint ManFixPTask::pmin(void)const{ return_p; } forceinlineint ManFixPTask::pmax(void)const{ return_p; } forceinlineIntVar ManFixPTask::st(void)const{ return_s; } forceinlinebool ManFixPTask::mandatory(void)const{ returntrue; } forceinlinebool ManFixPTask::excluded(void)const{ returnfalse; } forceinlinebool ManFixPTask::optional(void)const{ returnfalse; } forceinlinebool ManFixPTask::assigned(void)const{ return_s.assigned(); } forceinlineModEvent ManFixPTask::est(Space&home,intn){ return_s.gq(home,n); } forceinlineModEvent ManFixPTask::ect(Space&home,intn){ return_s.gq(home,n-_p); } forceinlineModEvent ManFixPTask::lst(Space&home,intn){ return_s.lq(home,n); } forceinlineModEvent ManFixPTask::lct(Space&home,intn){ return_s.lq(home,n-_p); } forceinlineModEvent ManFixPTask::norun(Space&home,inte,intl){ if(e<=l){ Iter::Ranges::Singletonr(e-_p+1,l); return_s.minus_r(home,r,false); }else{ returnInt::ME_INT_NONE; } } forceinlineModEvent ManFixPTask::mandatory(Space&){ returnInt::ME_INT_NONE; } forceinlineModEvent ManFixPTask::excluded(Space&){ returnInt::ME_INT_FAILED; } forceinlinevoid ManFixPTask::update(Space&home,boolshare,ManFixPTask&t){ _s.update(home,share,t._s);_p=t._p; } forceinlinevoid ManFixPTask::subscribe(Space&home,Propagator&p,PropCondpc){ _s.subscribe(home,p,pc); } forceinlinevoid ManFixPTask::cancel(Space&home,Propagator&p,PropCondpc){ _s.cancel(home,p,pc); } template<classChar,classTraits> std::basic_ostream<Char,Traits>& operator<<(std::basic_ostream<Char,Traits>&os,constManFixPTask&t){ std::basic_ostringstream<Char,Traits>s; s.copyfmt(os);s.width(0); s<<t.est()<<':'<<t.pmin()<<':'<<t.lct(); returnos<<s.str(); } /* *Mandatoryfixedtaskwithfixedprocessing,startorendtime */ forceinline ManFixPSETask::ManFixPSETask(void){} forceinline ManFixPSETask::ManFixPSETask(TaskTypet,IntVars,intp) :ManFixPTask(s,p),_t(t){} forceinlinevoid ManFixPSETask::init(TaskTypet,IntVars,intp){ ManFixPTask::init(s,p);_t=t; } forceinlinevoid ManFixPSETask::init(constManFixPSETask&t0){ ManFixPTask::init(t0);_t=t0._t; } forceinlineint ManFixPSETask::est(void)const{ return(_t==TT_FIXS)?_p:_s.min(); } forceinlineint ManFixPSETask::ect(void)const{ switch(_t){ caseTT_FIXP:return_s.min()+_p; caseTT_FIXS:return_s.min(); caseTT_FIXE:return_p; default:GECODE_NEVER; } return0; } forceinlineint ManFixPSETask::lst(void)const{ return(_t==TT_FIXS)?_p:_s.max(); } forceinlineint ManFixPSETask::lct(void)const{ switch(_t){ caseTT_FIXP:return_s.max()+_p; caseTT_FIXS:return_s.max(); caseTT_FIXE:return_p; default:GECODE_NEVER; } return0; } forceinlineint ManFixPSETask::pmin(void)const{ switch(_t){ caseTT_FIXP:return_p; caseTT_FIXS:return_s.min()-_p; caseTT_FIXE:return_p-_s.max(); default:GECODE_NEVER; } return0; } forceinlineint ManFixPSETask::pmax(void)const{ switch(_t){ caseTT_FIXP:return_p; caseTT_FIXS:return_s.max()-_p; caseTT_FIXE:return_p-_s.min(); default:GECODE_NEVER; } return0; } forceinlineModEvent ManFixPSETask::est(Space&home,intn){ switch(_t){ caseTT_FIXE://fallthrough caseTT_FIXP:return_s.gq(home,n); caseTT_FIXS:return(n<=_p)?Int::ME_INT_NONE:Int::ME_INT_FAILED; default:GECODE_NEVER; } returnInt::ME_INT_NONE; } forceinlineModEvent ManFixPSETask::ect(Space&home,intn){ switch(_t){ caseTT_FIXE:return(n<=_p)?Int::ME_INT_NONE:Int::ME_INT_FAILED; caseTT_FIXP:return_s.gq(home,n-_p); caseTT_FIXS:return_s.gq(home,n); default:GECODE_NEVER; } returnInt::ME_INT_NONE; } forceinlineModEvent ManFixPSETask::lst(Space&home,intn){ switch(_t){ caseTT_FIXE://fallthrough caseTT_FIXP:return_s.lq(home,n); caseTT_FIXS:return(n>=_p)?Int::ME_INT_NONE:Int::ME_INT_FAILED; default:GECODE_NEVER; } returnInt::ME_INT_NONE; } forceinlineModEvent ManFixPSETask::lct(Space&home,intn){ switch(_t){ caseTT_FIXE:return(n>=_p)?Int::ME_INT_NONE:Int::ME_INT_FAILED; caseTT_FIXP:return_s.lq(home,n-_p); caseTT_FIXS:return_s.lq(home,n); default:GECODE_NEVER; } returnInt::ME_INT_NONE; } forceinlineModEvent ManFixPSETask::norun(Space&home,inte,intl){ if(e<=l){ switch(_t){ caseTT_FIXP: { Iter::Ranges::Singletonr(e-_p+1,l); return_s.minus_r(home,r,false); } caseTT_FIXE: if(e<=_p) return_s.gr(home,l); break; caseTT_FIXS: if(l>=_p) return_s.lq(home,e); break; default: GECODE_NEVER; } returnInt::ME_INT_NONE; }else{ returnInt::ME_INT_NONE; } } forceinlinevoid ManFixPSETask::update(Space&home,boolshare,ManFixPSETask&t){ ManFixPTask::update(home,share,t);_t=t._t; } template<classChar,classTraits> std::basic_ostream<Char,Traits>& operator<<(std::basic_ostream<Char,Traits>&os,constManFixPSETask&t){ std::basic_ostringstream<Char,Traits>s; s.copyfmt(os);s.width(0); s<<t.est()<<':'<<t.pmin()<<':'<<t.lct(); returnos<<s.str(); } /* *Mandatoryflexibletask */ forceinline ManFlexTask::ManFlexTask(void){} forceinline ManFlexTask::ManFlexTask(IntVars,IntVarp,IntVare) :_s(s),_p(p),_e(e){} forceinlinevoid ManFlexTask::init(IntVars,IntVarp,IntVare){ _s=s;_p=p;_e=e; } forceinlinevoid ManFlexTask::init(constManFlexTask&t){ _s=t._s;_p=t._p;_e=t._e; } forceinlineint ManFlexTask::est(void)const{ return_s.min(); } forceinlineint ManFlexTask::ect(void)const{ return_e.min(); } forceinlineint ManFlexTask::lst(void)const{ return_s.max(); } forceinlineint ManFlexTask::lct(void)const{ return_e.max(); } forceinlineint ManFlexTask::pmin(void)const{ return_p.min(); } forceinlineint ManFlexTask::pmax(void)const{ return_p.max(); } forceinlineIntVar ManFlexTask::st(void)const{ return_s; } forceinlineIntVar ManFlexTask::p(void)const{ return_p; } forceinlineIntVar ManFlexTask::e(void)const{ return_e; } forceinlinebool ManFlexTask::mandatory(void)const{ returntrue; } forceinlinebool ManFlexTask::excluded(void)const{ returnfalse; } forceinlinebool ManFlexTask::optional(void)const{ returnfalse; } forceinlinebool ManFlexTask::assigned(void)const{ return_s.assigned()&&_p.assigned()&&_e.assigned(); } forceinlineModEvent ManFlexTask::est(Space&home,intn){ return_s.gq(home,n); } forceinlineModEvent ManFlexTask::ect(Space&home,intn){ return_e.gq(home,n); } forceinlineModEvent ManFlexTask::lst(Space&home,intn){ return_s.lq(home,n); } forceinlineModEvent ManFlexTask::lct(Space&home,intn){ return_e.lq(home,n); } forceinlineModEvent ManFlexTask::norun(Space&home,inte,intl){ if(e<=l){ Iter::Ranges::Singletonsr(e-_p.min()+1,l); if(me_failed(_s.minus_r(home,sr,false))) returnInt::ME_INT_FAILED; Iter::Ranges::Singletoner(e+1,_p.min()+l); return_e.minus_r(home,er,false); }else{ returnInt::ME_INT_NONE; } } forceinlineModEvent ManFlexTask::mandatory(Space&){ returnInt::ME_INT_NONE; } forceinlineModEvent ManFlexTask::excluded(Space&){ returnInt::ME_INT_FAILED; } forceinlinevoid ManFlexTask::update(Space&home,boolshare,ManFlexTask&t){ _s.update(home,share,t._s); _p.update(home,share,t._p); _e.update(home,share,t._e); } forceinlinevoid ManFlexTask::subscribe(Space&home,Propagator&p,PropCondpc){ _s.subscribe(home,p,pc); _p.subscribe(home,p,pc); _e.subscribe(home,p,pc); } forceinlinevoid ManFlexTask::cancel(Space&home,Propagator&p,PropCondpc){ _s.cancel(home,p,pc); _p.cancel(home,p,pc); _e.cancel(home,p,pc); } template<classChar,classTraits> std::basic_ostream<Char,Traits>& operator<<(std::basic_ostream<Char,Traits>&os,constManFlexTask&t){ std::basic_ostringstream<Char,Traits>s; s.copyfmt(os);s.width(0); s<<t.est()<<':'<<t.lst()<<':'<<t.pmin()<<':' <<t.pmax()<<':'<<t.ect()<<':'<<t.lct(); returnos<<s.str(); } /* *Optionalfixedtask */ forceinline OptFixPTask::OptFixPTask(void){} forceinline OptFixPTask::OptFixPTask(IntVars,intp,BoolVarm){ ManFixPTask::init(s,p);_m=m; } forceinlinevoid OptFixPTask::init(IntVars,intp,BoolVarm){ ManFixPTask::init(s,p);_m=m; } template<classChar,classTraits> std::basic_ostream<Char,Traits>& operator<<(std::basic_ostream<Char,Traits>&os,constOptFixPTask&t){ std::basic_ostringstream<Char,Traits>s; s.copyfmt(os);s.width(0); s<<t.est()<<':'<<t.pmin()<<':'<<t.lct()<<':' <<(t.mandatory()?'1':(t.optional()?'?':'0')); returnos<<s.str(); } /* *Optionalfixedtask */ forceinline OptFixPSETask::OptFixPSETask(void){} forceinline OptFixPSETask::OptFixPSETask(TaskTypet,IntVars,intp,BoolVarm){ ManFixPSETask::init(t,s,p);_m=m; } forceinlinevoid OptFixPSETask::init(TaskTypet,IntVars,intp,BoolVarm){ ManFixPSETask::init(t,s,p);_m=m; } template<classChar,classTraits> std::basic_ostream<Char,Traits>& operator<<(std::basic_ostream<Char,Traits>&os,constOptFixPSETask&t){ std::basic_ostringstream<Char,Traits>s; s.copyfmt(os);s.width(0); s<<t.est()<<':'<<t.pmin()<<':'<<t.lct()<<':' <<(t.mandatory()?'1':(t.optional()?'?':'0')); returnos<<s.str(); } /* *Optionalflexibletask */ forceinline OptFlexTask::OptFlexTask(void){} forceinline OptFlexTask::OptFlexTask(IntVars,IntVarp,IntVare,BoolVarm){ ManFlexTask::init(s,p,e);_m=m; } forceinlinevoid OptFlexTask::init(IntVars,IntVarp,IntVare,BoolVarm){ ManFlexTask::init(s,p,e);_m=m; } template<classChar,classTraits> std::basic_ostream<Char,Traits>& operator<<(std::basic_ostream<Char,Traits>&os,constOptFlexTask&t){ std::basic_ostringstream<Char,Traits>s; s.copyfmt(os);s.width(0); s<<t.est()<<':'<<t.lst()<<':'<<t.pmin()<<':' <<t.pmax()<<':'<<t.ect()<<':'<<t.lct()<<':' <<(t.mandatory()?'1':(t.optional()?'?':'0')); returnos<<s.str(); } }}} //STATISTICS:int-var