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