Generated on Mon May 10 06:46:44 2010 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  *
00006  *  Copyright:
00007  *     Christian Schulte, 2009
00008  *
00009  *  Last modified:
00010  *     $Date: 2010-02-15 13:56:19 +0100 (Mon, 15 Feb 2010) $ by $Author: schulte $
00011  *     $Revision: 10284 $
00012  *
00013  *  This file is part of Gecode, the generic constraint
00014  *  development environment:
00015  *     http://www.gecode.org
00016  *
00017  *  Permission is hereby granted, free of charge, to any person obtaining
00018  *  a copy of this software and associated documentation files (the
00019  *  "Software"), to deal in the Software without restriction, including
00020  *  without limitation the rights to use, copy, modify, merge, publish,
00021  *  distribute, sublicense, and/or sell copies of the Software, and to
00022  *  permit persons to whom the Software is furnished to do so, subject to
00023  *  the following conditions:
00024  *
00025  *  The above copyright notice and this permission notice shall be
00026  *  included in all copies or substantial portions of the Software.
00027  *
00028  *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
00029  *  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00030  *  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
00031  *  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
00032  *  LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
00033  *  OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
00034  *  WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
00035  *
00036  */
00037 
00038 namespace Gecode { namespace Scheduling { namespace Unary {
00039 
00040   /*
00041    * Mandatory fixed task
00042    */
00043 
00044   forceinline
00045   ManFixTask::ManFixTask(void) {}
00046   forceinline
00047   ManFixTask::ManFixTask(IntVar s, int p) : _s(s), _p(p) {}
00048   forceinline void
00049   ManFixTask::init(IntVar s, int p) {
00050     _s=s; _p=p;
00051   }
00052 
00053   forceinline int 
00054   ManFixTask::est(void) const {
00055     return _s.min();
00056   }
00057   forceinline int
00058   ManFixTask::ect(void) const {
00059     return _s.min()+_p;
00060   }
00061   forceinline int
00062   ManFixTask::lst(void) const {
00063     return _s.max();
00064   }
00065   forceinline int
00066   ManFixTask::lct(void) const {
00067     return _s.max()+_p;
00068   }
00069   forceinline IntVar
00070   ManFixTask::st(void) const {
00071     return _s;
00072   }
00073   forceinline int
00074   ManFixTask::p(void) const {
00075     return _p;
00076   }
00077 
00078   forceinline bool
00079   ManFixTask::mandatory(void) const {
00080     return true;
00081   }
00082   forceinline bool
00083   ManFixTask::excluded(void) const {
00084     return false;
00085   }
00086   forceinline bool
00087   ManFixTask::optional(void) const {
00088     return false;
00089   }
00090 
00091   forceinline bool
00092   ManFixTask::assigned(void) const {
00093     return _s.assigned();
00094   }
00095 
00096   forceinline ModEvent 
00097   ManFixTask::est(Space& home, int n) {
00098     return _s.gq(home,n);
00099   }
00100   forceinline ModEvent
00101   ManFixTask::ect(Space& home, int n) {
00102     return _s.gq(home,n-_p);
00103   }
00104   forceinline ModEvent
00105   ManFixTask::lst(Space& home, int n) {
00106     return _s.lq(home,n);
00107   }
00108   forceinline ModEvent
00109   ManFixTask::lct(Space& home, int n) {
00110     return _s.lq(home,n-_p);
00111   }
00112   forceinline ModEvent
00113   ManFixTask::norun(Space& home, int e, int l) {
00114     assert(e <= l);
00115     Iter::Ranges::Singleton r(e-_p+1,l);
00116     return _s.minus_r(home,r,false);
00117   }
00118 
00119 
00120   forceinline ModEvent
00121   ManFixTask::mandatory(Space&) {
00122     return Int::ME_INT_NONE;
00123   }
00124   forceinline ModEvent
00125   ManFixTask::excluded(Space&) {
00126     return Int::ME_INT_FAILED;
00127   }
00128 
00129   forceinline void
00130   ManFixTask::update(Space& home, bool share, ManFixTask& t) {
00131     _s.update(home,share,t._s); _p=t._p;
00132   }
00133 
00134   forceinline void
00135   ManFixTask::subscribe(Space& home, Propagator& p, PropCond pc) {
00136     _s.subscribe(home, p, pc);
00137   }
00138   forceinline void
00139   ManFixTask::cancel(Space& home, Propagator& p, PropCond pc) {
00140     _s.cancel(home, p, pc);
00141   }
00142 
00143   template<class Char, class Traits>
00144   std::basic_ostream<Char,Traits>&
00145   operator <<(std::basic_ostream<Char,Traits>& os, const ManFixTask& t) {
00146     std::basic_ostringstream<Char,Traits> s;
00147     s.copyfmt(os); s.width(0);
00148     s << t.est() << ':' << t.p() << ':' << t.lct();
00149     return os << s.str();
00150   }
00151     
00152 
00153   /*
00154    * Optional fixed task
00155    */
00156 
00157   forceinline
00158   OptFixTask::OptFixTask(void) {}
00159   forceinline
00160   OptFixTask::OptFixTask(IntVar s, int p, BoolVar m) {
00161     ManFixTask::init(s,p); _m=m;
00162   }
00163   forceinline void
00164   OptFixTask::init(IntVar s, int p, BoolVar m) {
00165     ManFixTask::init(s,p); _m=m;
00166   }
00167 
00168   template<class Char, class Traits>
00169   std::basic_ostream<Char,Traits>&
00170   operator <<(std::basic_ostream<Char,Traits>& os, const OptFixTask& t) {
00171     std::basic_ostringstream<Char,Traits> s;
00172     s.copyfmt(os); s.width(0);
00173     s << t.est() << ':' << t.p() << ':' << t.lct() << ':'
00174       << (t.mandatory() ? '1' : (t.optional() ? '?' : '0'));
00175     return os << s.str();
00176   }
00177     
00178 }}}
00179 
00180 // STATISTICS: scheduling-var