Generated on Mon Aug 25 11:35:39 2008 for Gecode by doxygen 1.5.6

offset.icc

Go to the documentation of this file.
00001 /* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
00002 /*
00003  *  Main authors:
00004  *     Guido Tack <tack@gecode.org>
00005  *
00006  *  Contributing authors:
00007  *     Christian Schulte <schulte@gecode.org>
00008  *
00009  *  Copyright:
00010  *     Guido Tack, 2004, 2006
00011  *     Christian Schulte, 2004
00012  *
00013  *  Last modified:
00014  *     $Date: 2008-01-24 13:05:13 +0100 (Thu, 24 Jan 2008) $ by $Author: tack $
00015  *     $Revision: 5974 $
00016  *
00017  *  This file is part of Gecode, the generic constraint
00018  *  development environment:
00019  *     http://www.gecode.org
00020  *
00021  *  Permission is hereby granted, free of charge, to any person obtaining
00022  *  a copy of this software and associated documentation files (the
00023  *  "Software"), to deal in the Software without restriction, including
00024  *  without limitation the rights to use, copy, modify, merge, publish,
00025  *  distribute, sublicense, and/or sell copies of the Software, and to
00026  *  permit persons to whom the Software is furnished to do so, subject to
00027  *  the following conditions:
00028  *
00029  *  The above copyright notice and this permission notice shall be
00030  *  included in all copies or substantial portions of the Software.
00031  *
00032  *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
00033  *  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00034  *  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
00035  *  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
00036  *  LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
00037  *  OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
00038  *  WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
00039  *
00040  */
00041 
00042 namespace Gecode { namespace Set {
00043 
00044   template <class View>
00045   forceinline
00046   OffsetSetView<View>::OffsetSetView(void) {}
00047 
00048   template <class View>
00049   forceinline
00050   OffsetSetView<View>::OffsetSetView(View& s0, int k0)
00051     : DerivedViewBase<View>(s0), k(k0) {}
00052 
00053   template <class View>
00054   forceinline
00055   OffsetSetView<View>::OffsetSetView(Space* home,
00056                                      const Reflection::VarMap& vars,
00057                                      Reflection::Arg* arg)
00058   : DerivedViewBase<View>(View(home, vars, arg->second())), 
00059     k(arg->first()->toInt()) {}
00060 
00061   template <class View>
00062   forceinline bool
00063   OffsetSetView<View>::assigned(void) const { return view.assigned(); }
00064 
00065   template <class View>
00066   forceinline unsigned int
00067   OffsetSetView<View>::glbSize(void) const {
00068     return view.glbSize();
00069   }
00070 
00071   template <class View>
00072   forceinline unsigned int
00073   OffsetSetView<View>::lubSize(void) const {
00074     return view.lubSize();
00075   }
00076 
00077   template <class View>
00078   forceinline unsigned int
00079   OffsetSetView<View>::unknownSize(void) const {
00080     return view.unknownSize();
00081   }
00082 
00083   template <class View>
00084   forceinline int
00085   OffsetSetView<View>::offset(void) const {
00086     return k;
00087   }
00088 
00089   template <class View>
00090   forceinline bool
00091   OffsetSetView<View>::contains(int n) const {
00092     return view.contains(n-k);
00093   }
00094 
00095   template <class View>
00096   forceinline bool
00097   OffsetSetView<View>::notContains(int n) const {
00098     return view.notContains(n-k);
00099   }
00100 
00101   template <class View>
00102   forceinline unsigned int
00103   OffsetSetView<View>::cardMin() const {
00104     return view.cardMin();
00105   }
00106 
00107   template <class View>
00108   forceinline unsigned int
00109   OffsetSetView<View>::cardMax() const {
00110     return view.cardMax();
00111   }
00112 
00113   template <class View>
00114   forceinline int
00115   OffsetSetView<View>::lubMin() const {
00116     if (view.cardMax() == 0)
00117       return view.lubMin();
00118     return view.lubMin() + k;
00119   }
00120 
00121   template <class View>
00122   forceinline int
00123   OffsetSetView<View>::lubMax() const {
00124     if (view.cardMax() == 0)
00125       return view.lubMax();
00126     return view.lubMax() + k;
00127   }
00128 
00129   template <class View>
00130   forceinline int
00131   OffsetSetView<View>::glbMin() const {
00132     if (view.cardMax() == 0)
00133       return view.glbMin();
00134     return view.glbMin() + k;
00135   }
00136 
00137   template <class View>
00138   forceinline int
00139   OffsetSetView<View>::glbMax() const {
00140     if (view.cardMax() == 0)
00141       return view.glbMax();
00142     return view.glbMax() + k;
00143   }
00144 
00145   template <class View>
00146   forceinline ModEvent
00147   OffsetSetView<View>::cardMin(Space* home, unsigned int c) {
00148     return view.cardMin(home, c);
00149   }
00150 
00151   template <class View>
00152   forceinline ModEvent
00153   OffsetSetView<View>::cardMax(Space* home, unsigned int c) {
00154     return view.cardMax(home, c);
00155   }
00156 
00157   template <class View>
00158   forceinline ModEvent
00159   OffsetSetView<View>::include(Space* home, int c) {
00160     return view.include(home, c-k);
00161   }
00162 
00163   template <class View>
00164   forceinline ModEvent
00165   OffsetSetView<View>::exclude(Space* home, int c) {
00166     return view.exclude(home, c-k);
00167   }
00168 
00169   template <class View>
00170   forceinline ModEvent
00171   OffsetSetView<View>::intersect(Space* home, int c) {
00172     return view.intersect(home, c-k);
00173   }
00174 
00175   template <class View>
00176   forceinline ModEvent
00177   OffsetSetView<View>::intersect(Space* home, int i, int j) {
00178     return view.intersect(home, i-k, j-k);
00179   }
00180 
00181   template <class View>
00182   forceinline ModEvent
00183   OffsetSetView<View>::include(Space* home, int i, int j) {
00184     return view.include(home, i-k, j-k);
00185   }
00186 
00187   template <class View>
00188   forceinline ModEvent
00189   OffsetSetView<View>::exclude(Space* home, int i, int j) {
00190     return view.exclude(home, i-k, j-k);
00191   }
00192 
00193   template <class View>
00194   template <class I> ModEvent
00195   OffsetSetView<View>::excludeI(Space* home,I& iter) {
00196     Iter::Ranges::Offset<I> off(iter, -k);
00197     return view.excludeI(home, off);
00198   }
00199 
00200   template <class View>
00201   template <class I> ModEvent
00202   OffsetSetView<View>::includeI(Space* home,I& iter) {
00203     Iter::Ranges::Offset<I> off(iter, -k);
00204     return view.includeI(home, off);
00205   }
00206 
00207   template <class View>
00208   template <class I> ModEvent
00209   OffsetSetView<View>::intersectI(Space* home,I& iter) {
00210     Iter::Ranges::Offset<I> off(iter, -k);
00211     return view.intersectI(home, off);
00212   }
00213 
00214   template <class View>
00215   forceinline void
00216   OffsetSetView<View>::subscribe(Space* home, Propagator* p, PropCond pc,
00217                                   bool process) {
00218     view.subscribe(home,p, pc,process);
00219   }
00220 
00221   template <class View>
00222   forceinline void
00223   OffsetSetView<View>::cancel(Space* home, Propagator* p, PropCond pc) {
00224     view.cancel(home,p, pc);
00225   }
00226 
00227   template <class View>
00228   forceinline void
00229   OffsetSetView<View>::subscribe(Space* home, Advisor* a) {
00230     view.subscribe(home,a);
00231   }
00232 
00233   template <class View>
00234   forceinline void
00235   OffsetSetView<View>::cancel(Space* home, Advisor* a) {
00236     view.cancel(home,a);
00237   }
00238 
00239   template <class View>
00240   forceinline void
00241   OffsetSetView<View>::schedule(Space* home, Propagator* p, ModEvent me) {
00242     return View::schedule(home,p,me);
00243   }
00244   template <class View>
00245   forceinline ModEvent
00246   OffsetSetView<View>::me(ModEventDelta med) {
00247     return View::me(med);
00248   }
00249 
00250   template <class View>
00251   forceinline ModEventDelta
00252   OffsetSetView<View>::med(ModEvent me) {
00253     return View::med(me);
00254   }
00255 
00256   template <class View>
00257   forceinline void
00258   OffsetSetView<View>::update(Space* home, bool share, 
00259                                OffsetSetView& y) {
00260     k = y.k;
00261     view.update(home,share,y.view);
00262   }
00263 
00264   template <class View>
00265   forceinline Reflection::Arg*
00266   OffsetSetView<View>::spec(const Space* home, Reflection::VarMap& m) const {
00267     return Reflection::Arg::newPair(Reflection::Arg::newInt(k), 
00268                                     view.spec(home, m));
00269   }
00270 
00271   template <class View>
00272   inline Support::Symbol
00273   OffsetSetView<View>::type(void) {
00274     Support::Symbol t("Set::OffsetSetView<");
00275     t += View::type();
00276     t += ">";
00277     return t;
00278   }
00279 
00280   /*
00281    * Delta information for advisors
00282    *
00283    */
00284 
00285   template <class View>
00286   forceinline ModEvent
00287   OffsetSetView<View>::modevent(const Delta* d) {
00288     return View::modevent(d);
00289   }
00290   
00291   template <class View>
00292   forceinline int
00293   OffsetSetView<View>::glbMin(const Delta* d) const {
00294     return view.glbMin(d)+k;
00295   }
00296 
00297   template <class View>
00298   forceinline int
00299   OffsetSetView<View>::glbMax(const Delta* d) const {
00300     return view.glbMax(d)+k;
00301   }
00302 
00303   template <class View>
00304   forceinline bool
00305   OffsetSetView<View>::glbAny(const Delta* d) const {
00306     return view.glbAny(d);
00307   }
00308 
00309   template <class View>
00310   forceinline int
00311   OffsetSetView<View>::lubMin(const Delta* d) const {
00312     return view.lubMin(d)+k;
00313   }
00314 
00315   template <class View>
00316   forceinline int
00317   OffsetSetView<View>::lubMax(const Delta* d) const {
00318     return view.lubMax(d)+k;
00319   }
00320 
00321   template <class View>
00322   forceinline bool
00323   OffsetSetView<View>::lubAny(const Delta* d) const {
00324     return view.lubAny(d);
00325   }
00326 
00331   template <class View>
00332   class LubRanges<OffsetSetView<View> > : public Iter::Ranges::Offset<LubRanges<View> > {
00333   private:
00334     LubRanges<View> ub;
00335     Iter::Ranges::Offset<LubRanges<View> > ubo;
00336   public:
00338 
00339 
00340     LubRanges(void) {}
00342     LubRanges(const OffsetSetView<View>& x);
00344     void init(const OffsetSetView<View>& x);
00345 
00347 
00348 
00349     bool operator()(void) const;
00351     void operator++(void);
00353 
00355 
00356 
00357     int min(void) const;
00359     int max(void) const;
00361     unsigned int width(void) const;
00363   };
00364 
00365   template <class View>
00366   forceinline
00367   LubRanges<OffsetSetView<View> >::LubRanges(const OffsetSetView<View>& s)
00368     : ub(s.base()), ubo(ub, s.offset()) {}
00369 
00370   template <class View>
00371   forceinline void
00372   LubRanges<OffsetSetView<View> >::init(const OffsetSetView<View>& s) {
00373     ub.init(s.base());
00374     ubo.init(ub, s.offset());
00375   }
00376 
00377   template <class View>
00378   forceinline bool
00379   LubRanges<OffsetSetView<View> >::operator()(void) const { return ubo(); }
00380 
00381   template <class View>
00382   forceinline void
00383   LubRanges<OffsetSetView<View> >::operator++(void) { return ++ubo; }
00384 
00385   template <class View>
00386   forceinline int
00387   LubRanges<OffsetSetView<View> >::min(void) const { return ubo.min(); }
00388 
00389   template <class View>
00390   forceinline int
00391   LubRanges<OffsetSetView<View> >::max(void) const { return ubo.max(); }
00392 
00393   template <class View>
00394   forceinline unsigned int
00395   LubRanges<OffsetSetView<View> >::width(void) const { return ubo.width(); }
00396 
00397 
00402   template <class View>
00403   class GlbRanges<OffsetSetView<View> > {
00404   private:
00405     GlbRanges<View> lb;
00406     Iter::Ranges::Offset<GlbRanges<View> > lbo;
00407   public:
00409 
00410 
00411     GlbRanges(void) {}
00413     GlbRanges(const OffsetSetView<View> & x);
00415     void init(const OffsetSetView<View> & x);
00416 
00418 
00419 
00420     bool operator()(void) const;
00422     void operator++(void);
00424 
00426 
00427 
00428     int min(void) const;
00430     int max(void) const;
00432     unsigned int width(void) const;
00434   };
00435 
00436   template <class View>
00437   forceinline
00438   GlbRanges<OffsetSetView<View> >::GlbRanges(const OffsetSetView<View> & s)
00439     : lb(s.base()), lbo(lb, s.offset()) {}
00440 
00441   template <class View>
00442   forceinline void
00443   GlbRanges<OffsetSetView<View> >::init(const OffsetSetView<View> & s) {
00444     lb.init(s.base());
00445     lbo.init(lb, s.offset());
00446   }
00447 
00448   template <class View>
00449   forceinline bool
00450   GlbRanges<OffsetSetView<View> >::operator()(void) const { return lbo(); }
00451 
00452   template <class View>
00453   forceinline void
00454   GlbRanges<OffsetSetView<View> >::operator++(void) { return ++lbo; }
00455 
00456   template <class View>
00457   forceinline int
00458   GlbRanges<OffsetSetView<View> >::min(void) const { return lbo.min(); }
00459 
00460   template <class View>
00461   forceinline int
00462   GlbRanges<OffsetSetView<View> >::max(void) const { return lbo.max(); }
00463 
00464   template <class View>
00465   forceinline unsigned int
00466   GlbRanges<OffsetSetView<View> >::width(void) const { return lbo.width(); }
00467   
00468 }
00469 
00470 
00471   /*
00472    * Testing
00473    *
00474    */
00475   template <class View>
00476   forceinline bool
00477   same(const Set::OffsetSetView<View>& x, 
00478        const Set::OffsetSetView<View>& y) {
00479     return same(x.base(),y.base());
00480   }
00481   template <class View>
00482   forceinline bool
00483   before(const Set::OffsetSetView<View>& x, 
00484          const Set::OffsetSetView<View>& y) {
00485     return before(x.base(),y.base());
00486   }
00487 
00488 }
00489 
00490 template <class View>
00491 forceinline
00492 std::ostream&
00493 operator<<(std::ostream& os, const Gecode::Set::OffsetSetView<View>& s) {
00494   return os << "(" << s.base() << ")+"<<s.offset();
00495 }
00496 
00497 // STATISTICS: set-var