Generated on Tue Apr 18 10:21:51 2017 for Gecode by doxygen 1.6.3

task.hpp

Go to the documentation of this file.
00001 /* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
00002 /*
00003  *  Main authors:
00004  *     Christian Schulte <schulte@gecode.org>
00005  *     Guido Tack <tack@gecode.org>
00006  *
00007  *  Copyright:
00008  *     Christian Schulte, 2009
00009  *     Guido Tack, 2010
00010  *
00011  *  Last modified:
00012  *     $Date: 2016-06-29 17:28:17 +0200 (Wed, 29 Jun 2016) $ by $Author: schulte $
00013  *     $Revision: 15137 $
00014  *
00015  *  This file is part of Gecode, the generic constraint
00016  *  development environment:
00017  *     http://www.gecode.org
00018  *
00019  *  Permission is hereby granted, free of charge, to any person obtaining
00020  *  a copy of this software and associated documentation files (the
00021  *  "Software"), to deal in the Software without restriction, including
00022  *  without limitation the rights to use, copy, modify, merge, publish,
00023  *  distribute, sublicense, and/or sell copies of the Software, and to
00024  *  permit persons to whom the Software is furnished to do so, subject to
00025  *  the following conditions:
00026  *
00027  *  The above copyright notice and this permission notice shall be
00028  *  included in all copies or substantial portions of the Software.
00029  *
00030  *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
00031  *  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00032  *  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
00033  *  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
00034  *  LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
00035  *  OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
00036  *  WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
00037  *
00038  */
00039 
00040 namespace Gecode { namespace Int { namespace Unary {
00041 
00042   /*
00043    * Mandatory fixed task
00044    */
00045 
00046   forceinline
00047   ManFixPTask::ManFixPTask(void) {}
00048   forceinline
00049   ManFixPTask::ManFixPTask(IntVar s, int p) : _s(s), _p(p) {}
00050   forceinline void
00051   ManFixPTask::init(IntVar s, int p) {
00052     _s=s; _p=p;
00053   }
00054   forceinline void
00055   ManFixPTask::init(const ManFixPTask& t) {
00056     _s=t._s; _p=t._p;
00057   }
00058 
00059   forceinline int
00060   ManFixPTask::est(void) const {
00061     return _s.min();
00062   }
00063   forceinline int
00064   ManFixPTask::ect(void) const {
00065     return _s.min()+_p;
00066   }
00067   forceinline int
00068   ManFixPTask::lst(void) const {
00069     return _s.max();
00070   }
00071   forceinline int
00072   ManFixPTask::lct(void) const {
00073     return _s.max()+_p;
00074   }
00075   forceinline int
00076   ManFixPTask::pmin(void) const {
00077     return _p;
00078   }
00079   forceinline int
00080   ManFixPTask::pmax(void) const {
00081     return _p;
00082   }
00083   forceinline IntVar
00084   ManFixPTask::st(void) const {
00085     return _s;
00086   }
00087 
00088   forceinline bool
00089   ManFixPTask::mandatory(void) const {
00090     return true;
00091   }
00092   forceinline bool
00093   ManFixPTask::excluded(void) const {
00094     return false;
00095   }
00096   forceinline bool
00097   ManFixPTask::optional(void) const {
00098     return false;
00099   }
00100 
00101   forceinline bool
00102   ManFixPTask::assigned(void) const {
00103     return _s.assigned();
00104   }
00105 
00106   forceinline ModEvent
00107   ManFixPTask::est(Space& home, int n) {
00108     return _s.gq(home,n);
00109   }
00110   forceinline ModEvent
00111   ManFixPTask::ect(Space& home, int n) {
00112     return _s.gq(home,n-_p);
00113   }
00114   forceinline ModEvent
00115   ManFixPTask::lst(Space& home, int n) {
00116     return _s.lq(home,n);
00117   }
00118   forceinline ModEvent
00119   ManFixPTask::lct(Space& home, int n) {
00120     return _s.lq(home,n-_p);
00121   }
00122   forceinline ModEvent
00123   ManFixPTask::norun(Space& home, int e, int l) {
00124     if (e <= l) {
00125       Iter::Ranges::Singleton r(e-_p+1,l);
00126       return _s.minus_r(home,r,false);
00127     } else {
00128       return ME_INT_NONE;
00129     }
00130   }
00131 
00132 
00133   forceinline ModEvent
00134   ManFixPTask::mandatory(Space&) {
00135     return ME_INT_NONE;
00136   }
00137   forceinline ModEvent
00138   ManFixPTask::excluded(Space&) {
00139     return ME_INT_FAILED;
00140   }
00141 
00142   forceinline void
00143   ManFixPTask::update(Space& home, bool share, ManFixPTask& t) {
00144     _s.update(home,share,t._s); _p=t._p;
00145   }
00146 
00147   forceinline void
00148   ManFixPTask::subscribe(Space& home, Propagator& p, PropCond pc) {
00149     _s.subscribe(home, p, pc);
00150   }
00151   forceinline void
00152   ManFixPTask::cancel(Space& home, Propagator& p, PropCond pc) {
00153     _s.cancel(home, p, pc);
00154   }
00155   forceinline void
00156   ManFixPTask::reschedule(Space& home, Propagator& p, PropCond pc) {
00157     _s.reschedule(home, p, pc);
00158   }
00159 
00160   template<class Char, class Traits>
00161   std::basic_ostream<Char,Traits>&
00162   operator <<(std::basic_ostream<Char,Traits>& os, const ManFixPTask& t) {
00163     std::basic_ostringstream<Char,Traits> s;
00164     s.copyfmt(os); s.width(0);
00165     s << t.est() << ':' << t.pmin() << ':' << t.lct();
00166     return os << s.str();
00167   }
00168 
00169   /*
00170    * Mandatory fixed task with fixed processing, start or end time
00171    */
00172 
00173   forceinline
00174   ManFixPSETask::ManFixPSETask(void) {}
00175   forceinline
00176   ManFixPSETask::ManFixPSETask(TaskType t, IntVar s, int p)
00177     : ManFixPTask(s,p), _t(t) {}
00178   forceinline void
00179   ManFixPSETask::init(TaskType t, IntVar s, int p) {
00180     ManFixPTask::init(s,p); _t=t;
00181   }
00182   forceinline void
00183   ManFixPSETask::init(const ManFixPSETask& t0) {
00184     ManFixPTask::init(t0); _t = t0._t;
00185   }
00186 
00187   forceinline int
00188   ManFixPSETask::est(void) const {
00189     return (_t == TT_FIXS) ? _p : _s.min();
00190   }
00191   forceinline int
00192   ManFixPSETask::ect(void) const {
00193     switch (_t) {
00194     case TT_FIXP: return _s.min()+_p;
00195     case TT_FIXS: return _s.min();
00196     case TT_FIXE: return _p;
00197     default: GECODE_NEVER;
00198     }
00199     return 0;
00200   }
00201   forceinline int
00202   ManFixPSETask::lst(void) const {
00203     return (_t == TT_FIXS) ? _p : _s.max();
00204   }
00205   forceinline int
00206   ManFixPSETask::lct(void) const {
00207     switch (_t) {
00208     case TT_FIXP: return _s.max()+_p;
00209     case TT_FIXS: return _s.max();
00210     case TT_FIXE: return _p;
00211     default: GECODE_NEVER;
00212     }
00213     return 0;
00214   }
00215   forceinline int
00216   ManFixPSETask::pmin(void) const {
00217     switch (_t) {
00218     case TT_FIXP: return _p;
00219     case TT_FIXS: return _s.min()-_p;
00220     case TT_FIXE: return _p-_s.max();
00221     default: GECODE_NEVER;
00222     }
00223     return 0;
00224   }
00225   forceinline int
00226   ManFixPSETask::pmax(void) const {
00227     switch (_t) {
00228     case TT_FIXP: return _p;
00229     case TT_FIXS: return _s.max()-_p;
00230     case TT_FIXE: return _p-_s.min();
00231     default: GECODE_NEVER;
00232     }
00233     return 0;
00234   }
00235 
00236   forceinline ModEvent
00237   ManFixPSETask::est(Space& home, int n) {
00238     switch (_t) {
00239     case TT_FIXE: // fall through
00240     case TT_FIXP: return _s.gq(home,n);
00241     case TT_FIXS: return (n <= _p) ? ME_INT_NONE : ME_INT_FAILED;
00242     default: GECODE_NEVER;
00243     }
00244     return ME_INT_NONE;
00245   }
00246   forceinline ModEvent
00247   ManFixPSETask::ect(Space& home, int n) {
00248     switch (_t) {
00249     case TT_FIXE: return (n <= _p) ? ME_INT_NONE : ME_INT_FAILED;
00250     case TT_FIXP: return _s.gq(home,n-_p);
00251     case TT_FIXS: return _s.gq(home,n);
00252     default: GECODE_NEVER;
00253     }
00254     return ME_INT_NONE;
00255   }
00256   forceinline ModEvent
00257   ManFixPSETask::lst(Space& home, int n) {
00258     switch (_t) {
00259     case TT_FIXE: // fall through
00260     case TT_FIXP: return _s.lq(home,n);
00261     case TT_FIXS: return (n >= _p) ? ME_INT_NONE : ME_INT_FAILED;
00262     default: GECODE_NEVER;
00263     }
00264     return ME_INT_NONE;
00265   }
00266   forceinline ModEvent
00267   ManFixPSETask::lct(Space& home, int n) {
00268     switch (_t) {
00269     case TT_FIXE: return (n >= _p) ? ME_INT_NONE : ME_INT_FAILED;
00270     case TT_FIXP: return _s.lq(home,n-_p);
00271     case TT_FIXS: return _s.lq(home,n);
00272     default: GECODE_NEVER;
00273     }
00274     return ME_INT_NONE;
00275   }
00276   forceinline ModEvent
00277   ManFixPSETask::norun(Space& home, int e, int l) {
00278     if (e <= l) {
00279       switch (_t) {
00280       case TT_FIXP:
00281         {
00282           Iter::Ranges::Singleton r(e-_p+1,l);
00283           return _s.minus_r(home,r,false);
00284         }
00285       case TT_FIXE:
00286         if (e <= _p)
00287           return _s.gr(home,l);
00288         break;
00289       case TT_FIXS:
00290         if (l >= _p)
00291           return _s.lq(home,e);
00292         break;
00293       default:
00294         GECODE_NEVER;
00295       }
00296       return ME_INT_NONE;
00297     } else {
00298       return ME_INT_NONE;
00299     }
00300   }
00301 
00302   forceinline void
00303   ManFixPSETask::update(Space& home, bool share, ManFixPSETask& t) {
00304     ManFixPTask::update(home,share,t); _t=t._t;
00305   }
00306 
00307   template<class Char, class Traits>
00308   std::basic_ostream<Char,Traits>&
00309   operator <<(std::basic_ostream<Char,Traits>& os, const ManFixPSETask& t) {
00310     std::basic_ostringstream<Char,Traits> s;
00311     s.copyfmt(os); s.width(0);
00312     s << t.est() << ':' << t.pmin() << ':' << t.lct();
00313     return os << s.str();
00314   }
00315 
00316   /*
00317    * Mandatory flexible task
00318    */
00319 
00320   forceinline
00321   ManFlexTask::ManFlexTask(void) {}
00322   forceinline
00323   ManFlexTask::ManFlexTask(IntVar s, IntVar p, IntVar e)
00324     : _s(s), _p(p), _e(e) {}
00325   forceinline void
00326   ManFlexTask::init(IntVar s, IntVar p, IntVar e) {
00327     _s=s; _p=p; _e=e;
00328   }
00329   forceinline void
00330   ManFlexTask::init(const ManFlexTask& t) {
00331     _s=t._s; _p=t._p; _e=t._e;
00332   }
00333 
00334   forceinline int
00335   ManFlexTask::est(void) const {
00336     return _s.min();
00337   }
00338   forceinline int
00339   ManFlexTask::ect(void) const {
00340     return _e.min();
00341   }
00342   forceinline int
00343   ManFlexTask::lst(void) const {
00344     return _s.max();
00345   }
00346   forceinline int
00347   ManFlexTask::lct(void) const {
00348     return _e.max();
00349   }
00350   forceinline int
00351   ManFlexTask::pmin(void) const {
00352     return _p.min();
00353   }
00354   forceinline int
00355   ManFlexTask::pmax(void) const {
00356     return _p.max();
00357   }
00358   forceinline IntVar
00359   ManFlexTask::st(void) const {
00360     return _s;
00361   }
00362   forceinline IntVar
00363   ManFlexTask::p(void) const {
00364     return _p;
00365   }
00366   forceinline IntVar
00367   ManFlexTask::e(void) const {
00368     return _e;
00369   }
00370 
00371   forceinline bool
00372   ManFlexTask::mandatory(void) const {
00373     return true;
00374   }
00375   forceinline bool
00376   ManFlexTask::excluded(void) const {
00377     return false;
00378   }
00379   forceinline bool
00380   ManFlexTask::optional(void) const {
00381     return false;
00382   }
00383 
00384   forceinline bool
00385   ManFlexTask::assigned(void) const {
00386     return _s.assigned() && _p.assigned() && _e.assigned();
00387   }
00388 
00389   forceinline ModEvent
00390   ManFlexTask::est(Space& home, int n) {
00391     return _s.gq(home,n);
00392   }
00393   forceinline ModEvent
00394   ManFlexTask::ect(Space& home, int n) {
00395     return _e.gq(home,n);
00396   }
00397   forceinline ModEvent
00398   ManFlexTask::lst(Space& home, int n) {
00399     return _s.lq(home,n);
00400   }
00401   forceinline ModEvent
00402   ManFlexTask::lct(Space& home, int n) {
00403     return _e.lq(home,n);
00404   }
00405   forceinline ModEvent
00406   ManFlexTask::norun(Space& home, int e, int l) {
00407     if (e <= l) {
00408       Iter::Ranges::Singleton sr(e-_p.min()+1,l);
00409       if (me_failed(_s.minus_r(home,sr,false)))
00410         return ME_INT_FAILED;
00411       Iter::Ranges::Singleton er(e+1,_p.min()+l);
00412       return _e.minus_r(home,er,false);
00413     } else {
00414       return ME_INT_NONE;
00415     }
00416   }
00417 
00418 
00419   forceinline ModEvent
00420   ManFlexTask::mandatory(Space&) {
00421     return ME_INT_NONE;
00422   }
00423   forceinline ModEvent
00424   ManFlexTask::excluded(Space&) {
00425     return ME_INT_FAILED;
00426   }
00427 
00428   forceinline void
00429   ManFlexTask::update(Space& home, bool share, ManFlexTask& t) {
00430     _s.update(home,share,t._s);
00431     _p.update(home,share,t._p);
00432     _e.update(home,share,t._e);
00433   }
00434 
00435   forceinline void
00436   ManFlexTask::subscribe(Space& home, Propagator& p, PropCond pc) {
00437     _s.subscribe(home, p, pc);
00438     _p.subscribe(home, p, pc);
00439     _e.subscribe(home, p, pc);
00440   }
00441   forceinline void
00442   ManFlexTask::cancel(Space& home, Propagator& p, PropCond pc) {
00443     _s.cancel(home, p, pc);
00444     _p.cancel(home, p, pc);
00445     _e.cancel(home, p, pc);
00446   }
00447   forceinline void
00448   ManFlexTask::reschedule(Space& home, Propagator& p, PropCond pc) {
00449     _s.reschedule(home, p, pc);
00450     _p.reschedule(home, p, pc);
00451     _e.reschedule(home, p, pc);
00452   }
00453 
00454   template<class Char, class Traits>
00455   std::basic_ostream<Char,Traits>&
00456   operator <<(std::basic_ostream<Char,Traits>& os, const ManFlexTask& t) {
00457     std::basic_ostringstream<Char,Traits> s;
00458     s.copyfmt(os); s.width(0);
00459     s << t.est() << ':' << t.lst() << ':' << t.pmin() << ':'
00460       << t.pmax() << ':' << t.ect() << ':' << t.lct();
00461     return os << s.str();
00462   }
00463 
00464   /*
00465    * Optional fixed task
00466    */
00467 
00468   forceinline
00469   OptFixPTask::OptFixPTask(void) {}
00470   forceinline
00471   OptFixPTask::OptFixPTask(IntVar s, int p, BoolVar m) {
00472     ManFixPTask::init(s,p); _m=m;
00473   }
00474   forceinline void
00475   OptFixPTask::init(IntVar s, int p, BoolVar m) {
00476     ManFixPTask::init(s,p); _m=m;
00477   }
00478 
00479   template<class Char, class Traits>
00480   std::basic_ostream<Char,Traits>&
00481   operator <<(std::basic_ostream<Char,Traits>& os, const OptFixPTask& t) {
00482     std::basic_ostringstream<Char,Traits> s;
00483     s.copyfmt(os); s.width(0);
00484     s << t.est() << ':' << t.pmin() << ':' << t.lct() << ':'
00485       << (t.mandatory() ? '1' : (t.optional() ? '?' : '0'));
00486     return os << s.str();
00487   }
00488 
00489   /*
00490    * Optional fixed task
00491    */
00492 
00493   forceinline
00494   OptFixPSETask::OptFixPSETask(void) {}
00495   forceinline
00496   OptFixPSETask::OptFixPSETask(TaskType t,IntVar s,int p,BoolVar m) {
00497     ManFixPSETask::init(t,s,p); _m=m;
00498   }
00499   forceinline void
00500   OptFixPSETask::init(TaskType t, IntVar s, int p, BoolVar m) {
00501     ManFixPSETask::init(t,s,p); _m=m;
00502   }
00503 
00504   template<class Char, class Traits>
00505   std::basic_ostream<Char,Traits>&
00506   operator <<(std::basic_ostream<Char,Traits>& os, const OptFixPSETask& t) {
00507     std::basic_ostringstream<Char,Traits> s;
00508     s.copyfmt(os); s.width(0);
00509     s << t.est() << ':' << t.pmin() << ':' << t.lct() << ':'
00510       << (t.mandatory() ? '1' : (t.optional() ? '?' : '0'));
00511     return os << s.str();
00512   }
00513 
00514   /*
00515    * Optional flexible task
00516    */
00517 
00518   forceinline
00519   OptFlexTask::OptFlexTask(void) {}
00520   forceinline
00521   OptFlexTask::OptFlexTask(IntVar s, IntVar p, IntVar e, BoolVar m) {
00522     ManFlexTask::init(s,p,e); _m=m;
00523   }
00524   forceinline void
00525   OptFlexTask::init(IntVar s, IntVar p, IntVar e, BoolVar m) {
00526     ManFlexTask::init(s,p,e); _m=m;
00527   }
00528 
00529   template<class Char, class Traits>
00530   std::basic_ostream<Char,Traits>&
00531   operator <<(std::basic_ostream<Char,Traits>& os, const OptFlexTask& t) {
00532     std::basic_ostringstream<Char,Traits> s;
00533     s.copyfmt(os); s.width(0);
00534     s << t.est() << ':' << t.lst() << ':' << t.pmin() << ':'
00535       << t.pmax() << ':' << t.ect() << ':' << t.lct() << ':'
00536       << (t.mandatory() ? '1' : (t.optional() ? '?' : '0'));
00537     return os << s.str();
00538   }
00539 
00540 }}}
00541 
00542 // STATISTICS: int-var