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

view.icc

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, 2005
00008  *
00009  *  Last modified:
00010  *     $Date: 2008-07-11 09:33:32 +0200 (Fri, 11 Jul 2008) $ by $Author: tack $
00011  *     $Revision: 7290 $
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 {
00039 
00044   class ConstViewBase {
00045   public:
00047 
00048 
00049     unsigned int degree(void) const;
00051     static bool varderived(void);
00053     VarImpBase* var(void) const;
00055   };
00056 
00057 
00058 
00063   template <class VarImp>
00064   class VarViewBase {
00065   protected:
00067     VarImp* varimp;
00069     VarViewBase(void);
00071     VarViewBase(VarImp* x);
00072   public:
00074 
00075 
00076     static bool varderived(void);
00078     VarImp* var(void) const;
00080     unsigned int degree(void) const;
00082 
00084 
00085 
00086     static void schedule(Space* home, Propagator* p, ModEvent me);
00088     static ModEvent me(ModEventDelta med);
00090     static ModEventDelta med(ModEvent me);
00092     static ModEvent me_combine(ModEvent me1, ModEvent me2);
00094 
00096 
00097 
00104     void subscribe(Space* home, Propagator* p, PropCond pc, bool process=true);
00106     void cancel(Space* home, Propagator* p, PropCond pc);
00108     void subscribe(Space* home, Advisor* a);
00110     void cancel(Space* home, Advisor* a);
00112   };
00113 
00118 
00119   template <class VarImp>
00120   bool same(const VarViewBase<VarImp>& x, const VarViewBase<VarImp>& y);
00122   template <class VarImp>
00123   bool before(const VarViewBase<VarImp>& x, const VarViewBase<VarImp>& y);
00125 
00126 
00131   template <class View>
00132   class DerivedViewBase {
00133   protected:
00135     View view;
00137     DerivedViewBase(void);
00139     DerivedViewBase(const View& x);
00140 
00141   public:
00143     typedef typename ViewVarImpTraits<View>::VarImp VarImp;
00144 
00146 
00147 
00148     static bool varderived(void);
00150     VarImp* var(void) const;
00152     View base(void) const;
00154     unsigned int degree(void) const;
00156   };
00157 
00158 
00163   bool shared(const ConstViewBase&, const ConstViewBase&);
00168   template <class VarImp>
00169   bool shared(const VarViewBase<VarImp>&, const ConstViewBase&);
00174   template <class ViewA>
00175   bool shared(const DerivedViewBase<ViewA>&, const ConstViewBase&);
00180   template <class VarImp>
00181   bool shared(const ConstViewBase&, const VarViewBase<VarImp>&);
00186   template <class ViewA>
00187   bool shared(const ConstViewBase&, const DerivedViewBase<ViewA>&);
00192   template <class VarImpA, class VarImpB>
00193   bool shared(const VarViewBase<VarImpA>&, const VarViewBase<VarImpB>&);
00198   template <class VarImpA, class ViewB>
00199   bool shared(const VarViewBase<VarImpA>&, const DerivedViewBase<ViewB>&);
00204   template <class ViewA, class VarImpB>
00205   bool shared(const DerivedViewBase<ViewA>&, const VarViewBase<VarImpB>&);
00210   template <class ViewA, class ViewB>
00211   bool shared(const DerivedViewBase<ViewA>&, const DerivedViewBase<ViewB>&);
00212 
00213 
00214   /*
00215    * Constant view: has no variable implementation
00216    *
00217    */
00218   forceinline unsigned int
00219   ConstViewBase::degree(void) const {
00220     return 0;
00221   }
00222   forceinline bool
00223   ConstViewBase::varderived(void) {
00224     return false;
00225   }
00226   forceinline VarImpBase*
00227   ConstViewBase::var(void) const {
00228     return NULL;
00229   }
00230 
00231   /*
00232    * Variable view: contains a pointer to a variable implementation
00233    *
00234    */
00235   template <class VarImp>
00236   forceinline
00237   VarViewBase<VarImp>::VarViewBase(void) {}
00238   template <class VarImp>
00239   forceinline
00240   VarViewBase<VarImp>::VarViewBase(VarImp* x)
00241     : varimp(x) {}
00242   template <class VarImp>
00243   forceinline bool
00244   VarViewBase<VarImp>::varderived(void) {
00245     return true;
00246   }
00247   template <class VarImp>
00248   forceinline VarImp*
00249   VarViewBase<VarImp>::var(void) const {
00250     return varimp;
00251   }
00252   template <class VarImp>
00253   forceinline unsigned int
00254   VarViewBase<VarImp>::degree(void) const {
00255     return varimp->degree();
00256   }
00257   template <class VarImp>
00258   forceinline void
00259   VarViewBase<VarImp>::subscribe(Space* home, Propagator* p, PropCond pc,
00260                                  bool process) {
00261     varimp->subscribe(home,p,pc,process);
00262   }
00263   template <class VarImp>
00264   forceinline void
00265   VarViewBase<VarImp>::cancel(Space* home, Propagator* p, PropCond pc) {
00266     varimp->cancel(home,p,pc);
00267   }
00268   template <class VarImp>
00269   forceinline void
00270   VarViewBase<VarImp>::subscribe(Space* home, Advisor* a) {
00271     varimp->subscribe(home,a);
00272   }
00273   template <class VarImp>
00274   forceinline void
00275   VarViewBase<VarImp>::cancel(Space* home, Advisor* a) {
00276     varimp->cancel(home,a);
00277   }
00278   template <class VarImp>
00279   forceinline void
00280   VarViewBase<VarImp>::schedule(Space* home, Propagator* p, ModEvent me) {
00281     return VarImp::schedule(home,p,me);
00282   }
00283   template <class VarImp>
00284   forceinline ModEvent
00285   VarViewBase<VarImp>::me(ModEventDelta med) {
00286     return VarImp::me(med);
00287   }
00288   template <class VarImp>
00289   forceinline ModEventDelta
00290   VarViewBase<VarImp>::med(ModEvent me) {
00291     return VarImp::med(me);
00292   }
00293   template <class VarImp>
00294   forceinline ModEvent
00295   VarViewBase<VarImp>::me_combine(ModEvent me1, ModEvent me2) {
00296     return VarImp::me_combine(me1,me2);
00297   }
00298 
00299   template <class VarImp>
00300   forceinline bool
00301   same(const VarViewBase<VarImp>& x, const VarViewBase<VarImp>& y) {
00302     return x.var() == y.var();
00303   }
00304   template <class VarImp>
00305   forceinline bool
00306   before(const VarViewBase<VarImp>& x, const VarViewBase<VarImp>& y) {
00307     return x.var() < y.var();
00308   }
00309 
00310   /*
00311    * Derived view: contain the base view from which they are derived
00312    *
00313    */
00314 
00315   template <class View>
00316   forceinline
00317   DerivedViewBase<View>::DerivedViewBase(void) {}
00318 
00319   template <class View>
00320   forceinline
00321   DerivedViewBase<View>::DerivedViewBase(const View& x)
00322     : view(x) {}
00323 
00324   template <class View>
00325   forceinline bool
00326   DerivedViewBase<View>::varderived(void) {
00327     return View::varderived();
00328   }
00329 
00330   template <class View>
00331   forceinline typename ViewVarImpTraits<View>::VarImp*
00332   DerivedViewBase<View>::var(void) const {
00333     return view.var();
00334   }
00335 
00336   template <class View>
00337   forceinline View
00338   DerivedViewBase<View>::base(void) const {
00339     return view;
00340   }
00341 
00342   template <class View>
00343   forceinline unsigned int
00344   DerivedViewBase<View>::degree(void) const {
00345     return view.degree();
00346   }
00347 
00348 
00349   /*
00350    * Testing whether two views share the same variable
00351    *
00352    */
00353 
00354   forceinline bool
00355   shared(const ConstViewBase&, const ConstViewBase&) {
00356     return false;
00357   }
00358 
00359   template <class VarImp>
00360   forceinline bool
00361   shared(const VarViewBase<VarImp>&, const ConstViewBase&) {
00362     return false;
00363   }
00364 
00365   template <class View>
00366   forceinline bool
00367   shared(const DerivedViewBase<View>&, const ConstViewBase&) {
00368     return false;
00369   }
00370 
00371   template <class VarImp>
00372   forceinline bool
00373   shared(const ConstViewBase&, const VarViewBase<VarImp>&) {
00374     return false;
00375   }
00376 
00377   template <class View>
00378   forceinline bool
00379   shared(const ConstViewBase&, const DerivedViewBase<View>&) {
00380     return false;
00381   }
00382 
00383   template <class VarImpA, class VarImpB>
00384   forceinline bool
00385   shared(const VarViewBase<VarImpA>& x, const VarViewBase<VarImpB>& y) {
00386     return (static_cast<VarImpBase*>(x.var()) ==
00387             static_cast<VarImpBase*>(y.var()));
00388   }
00389   template <class VarImpA, class ViewB>
00390   forceinline bool
00391   shared(const VarViewBase<VarImpA>& x, const DerivedViewBase<ViewB>& y) {
00392     return (ViewB::varderived() &&
00393             static_cast<VarImpBase*>(x.var()) ==
00394             static_cast<VarImpBase*>(y.var()));
00395   }
00396   template <class ViewA, class VarImpB>
00397   forceinline bool
00398   shared(const DerivedViewBase<ViewA>& x, const VarViewBase<VarImpB>& y) {
00399     return (ViewA::varderived() &&
00400             static_cast<VarImpBase*>(x.var()) ==
00401             static_cast<VarImpBase*>(y.var()));
00402   }
00403   template <class ViewA, class ViewB>
00404   forceinline bool
00405   shared(const DerivedViewBase<ViewA>& x, const DerivedViewBase<ViewB>& y) {
00406     return (ViewA::varderived() && ViewB::varderived() &&
00407             static_cast<VarImpBase*>(x.var()) ==
00408             static_cast<VarImpBase*>(y.var()));
00409   }
00410 
00411 }
00412 
00413 // STATISTICS: kernel-other