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

complement.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
00011  *     Christian Schulte, 2004
00012  *
00013  *  Last modified:
00014  *     $Date: 2008-07-11 10:24:32 +0200 (Fri, 11 Jul 2008) $ by $Author: tack $
00015  *     $Revision: 7328 $
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   ComplementView<View>::ComplementView(void) {}
00047 
00048   template <class View>
00049   forceinline
00050   ComplementView<View>::ComplementView(View& s0)
00051     : DerivedViewBase<View>(s0) {}
00052 
00053   template <class View>
00054   forceinline
00055   ComplementView<View>::ComplementView(Space* home,
00056                                        const Reflection::VarMap& vars,
00057                                        Reflection::Arg* arg)
00058   : DerivedViewBase<View>(View(home, vars, arg)) {}
00059 
00060   template <class View>
00061   forceinline ModEvent
00062   ComplementView<View>::me_negateset(ModEvent me) {
00063     switch(me) {
00064     case ME_SET_LUB : return ME_SET_GLB;
00065     case ME_SET_GLB : return ME_SET_LUB;
00066     case ME_SET_CLUB : return ME_SET_CGLB;
00067     case ME_SET_CGLB : return ME_SET_CLUB;
00068     default: return me;
00069     }
00070   }
00071 
00072   template <class View>
00073   forceinline PropCond
00074   ComplementView<View>::pc_negateset(PropCond pc) {
00075     switch(pc) {
00076     case PC_SET_CLUB  : return PC_SET_CGLB;
00077     case PC_SET_CGLB  : return PC_SET_CLUB;
00078     default: return pc;
00079     }
00080   }
00081 
00082   template <class View>
00083   forceinline bool
00084   ComplementView<View>::assigned(void) const { return view.assigned(); }
00085 
00086   template <class View>
00087   forceinline unsigned int
00088   ComplementView<View>::glbSize(void) const {
00089     return Limits::card - view.lubSize();
00090   }
00091 
00092   template <class View>
00093   forceinline unsigned int
00094   ComplementView<View>::lubSize(void) const {
00095     return Limits::card - view.glbSize();
00096   }
00097 
00098   template <class View>
00099   forceinline unsigned int
00100   ComplementView<View>::unknownSize(void) const {
00101     return lubSize() - glbSize();
00102   }
00103 
00104   template <class View>
00105   forceinline bool
00106   ComplementView<View>::contains(int n) const { return view.notContains(n); }
00107 
00108   template <class View>
00109   forceinline bool
00110   ComplementView<View>::notContains(int n) const { return view.contains(n); }
00111 
00112   template <class View>
00113   forceinline unsigned int
00114   ComplementView<View>::cardMin() const {
00115     return Limits::card - view.cardMax();
00116   }
00117 
00118   template <class View>
00119   forceinline unsigned int
00120   ComplementView<View>::cardMax() const {
00121     return Limits::card - view.cardMin();
00122   }
00123 
00124   template <class View>
00125   forceinline int
00126   ComplementView<View>::lubMin() const {
00127     GlbRanges<View> lb(view);
00128     RangesCompl<GlbRanges<View> > lbc(lb);
00129     if (lbc()) {
00130       return lbc.min();
00131     } else {
00132       return BndSet::MIN_OF_EMPTY;
00133     }
00134   }
00135 
00136   template <class View>
00137   forceinline int
00138   ComplementView<View>::lubMax() const {
00139     GlbRanges<View> lb(view);
00140     RangesCompl<GlbRanges<View> > lbc(lb);
00141     if (lbc()) {
00142       while(lbc()) ++lbc;
00143       return lbc.max();
00144     } else {
00145       return BndSet::MAX_OF_EMPTY;
00146     }
00147   }
00148 
00149   template <class View>
00150   forceinline int
00151   ComplementView<View>::glbMin() const {
00152     LubRanges<View> ub(view);
00153     RangesCompl<LubRanges<View> > ubc(ub);
00154     if (ubc()) {
00155       return ubc.min();
00156     } else {
00157       return BndSet::MIN_OF_EMPTY;
00158     }
00159   }
00160 
00161   template <class View>
00162   forceinline int
00163   ComplementView<View>::glbMax() const {
00164     LubRanges<View> ub(view);
00165     RangesCompl<LubRanges<View> > ubc(ub);
00166     if (ubc()) {
00167       while(ubc()) ++ubc;
00168       return ubc.max();
00169     } else {
00170       return BndSet::MAX_OF_EMPTY;
00171     }
00172   }
00173 
00174   template <class View>
00175   forceinline ModEvent
00176   ComplementView<View>::cardMin(Space* home, unsigned int c) {
00177     if (c < Limits::card)
00178       return me_negateset(view.cardMax(home, Limits::card - c));
00179     return ME_SET_NONE;
00180   }
00181 
00182   template <class View>
00183   forceinline ModEvent
00184   ComplementView<View>::cardMax(Space* home, unsigned int c) {
00185     if (c < Limits::card)
00186       return me_negateset(view.cardMin(home, Limits::card - c));
00187     return ME_SET_NONE;
00188   }
00189 
00190   template <class View>
00191   forceinline ModEvent
00192   ComplementView<View>::include(Space* home, int c) {
00193     return me_negateset((view.exclude(home, c)));
00194   }
00195 
00196   template <class View>
00197   forceinline ModEvent
00198   ComplementView<View>::exclude(Space* home, int c) {
00199     return me_negateset((view.include(home, c)));
00200   }
00201 
00202   template <class View>
00203   forceinline ModEvent
00204   ComplementView<View>::intersect(Space* home, int c) {
00205     Iter::Ranges::Singleton si(c,c);
00206     RangesCompl<Iter::Ranges::Singleton> csi(si);
00207     return me_negateset((view.includeI(home, csi)));
00208   }
00209 
00210   template <class View>
00211   forceinline ModEvent
00212   ComplementView<View>::intersect(Space* home, int i, int j) {
00213     Iter::Ranges::Singleton si(i,j);
00214     RangesCompl<Iter::Ranges::Singleton> csi(si);
00215     return me_negateset((view.includeI(home, csi)));
00216   }
00217 
00218   template <class View>
00219   forceinline ModEvent
00220   ComplementView<View>::include(Space* home, int j, int k) {
00221     return me_negateset(view.exclude(home,j,k));
00222   }
00223 
00224   template <class View>
00225   forceinline ModEvent
00226   ComplementView<View>::exclude(Space* home, int j, int k) {
00227     return me_negateset(view.include(home,j,k));
00228   }
00229 
00230   template <class View>
00231   template <class I> ModEvent
00232   ComplementView<View>::excludeI(Space* home,I& iter) {
00233     return me_negateset(view.includeI(home,iter));
00234   }
00235 
00236   template <class View>
00237   template <class I> ModEvent
00238   ComplementView<View>::includeI(Space* home,I& iter) {
00239     return me_negateset(view.excludeI(home,iter));
00240   }
00241 
00242   template <class View>
00243   template <class I> ModEvent
00244   ComplementView<View>::intersectI(Space* home,I& iter) {
00245     RangesCompl<I> c(iter);
00246     return me_negateset(view.includeI(home,c));
00247   }
00248 
00249   template <class View>
00250   forceinline void
00251   ComplementView<View>::subscribe(Space* home, Propagator* p, PropCond pc,
00252                                   bool process) {
00253     view.subscribe(home,p, pc_negateset(pc),process);
00254   }
00255 
00256   template <class View>
00257   forceinline void
00258   ComplementView<View>::cancel(Space* home, Propagator* p, PropCond pc) {
00259     view.cancel(home,p, pc_negateset(pc));
00260   }
00261 
00262   template <class View>
00263   forceinline void
00264   ComplementView<View>::subscribe(Space* home, Advisor* a) {
00265     view.subscribe(home,a);
00266   }
00267 
00268   template <class View>
00269   forceinline void
00270   ComplementView<View>::cancel(Space* home, Advisor* a) {
00271     view.cancel(home,a);
00272   }
00273 
00274   template <class View>
00275   forceinline void
00276   ComplementView<View>::schedule(Space* home, Propagator* p, ModEvent me) {
00277     return View::schedule(home,p,me_negateset(me));
00278   }
00279   template <class View>
00280   forceinline ModEvent
00281   ComplementView<View>::me(ModEventDelta med) {
00282     return me_negateset(View::me(med));
00283   }
00284 
00285   template <class View>
00286   forceinline ModEventDelta
00287   ComplementView<View>::med(ModEvent me) {
00288     return me_negateset(View::med(me));
00289   }
00290 
00291   template <class View>
00292   forceinline void
00293   ComplementView<View>::update(Space* home, bool share, 
00294                                ComplementView& y) {
00295     view.update(home,share,y.view);
00296   }
00297 
00298   template <class View>
00299   forceinline Reflection::Arg*
00300   ComplementView<View>::spec(const Space* home, Reflection::VarMap& m) const {
00301     return view.spec(home, m);
00302   }
00303 
00304   template <class View>
00305   inline Support::Symbol
00306   ComplementView<View>::type(void) {
00307     Support::Symbol t("Set::ComplementView<");
00308     t += View::type();
00309     t += ">";
00310     return t;
00311   }
00312 
00313   /*
00314    * Delta information for advisors
00315    *
00316    */
00317 
00318   template <class View>
00319   forceinline ModEvent
00320   ComplementView<View>::modevent(const Delta* d) {
00321     return me_negateset(View::modevent(d));
00322   }
00323   
00324   template <class View>
00325   forceinline int
00326   ComplementView<View>::glbMin(const Delta* d) const {
00327     return view.lubMin(d);
00328   }
00329 
00330   template <class View>
00331   forceinline int
00332   ComplementView<View>::glbMax(const Delta* d) const {
00333     return view.lubMax(d);
00334   }
00335 
00336   template <class View>
00337   forceinline bool
00338   ComplementView<View>::glbAny(const Delta* d) const {
00339     return view.lubAny(d);
00340   }
00341 
00342   template <class View>
00343   forceinline int
00344   ComplementView<View>::lubMin(const Delta* d) const {
00345     return view.glbMin(d);
00346   }
00347 
00348   template <class View>
00349   forceinline int
00350   ComplementView<View>::lubMax(const Delta* d) const {
00351     return view.glbMax(d);
00352   }
00353 
00354   template <class View>
00355   forceinline bool
00356   ComplementView<View>::lubAny(const Delta* d) const {
00357     return view.glbAny(d);
00358   }
00359 
00360 
00365   template <class View>
00366   class LubRanges<ComplementView<View> > {
00367   private:
00368     GlbRanges<View> lb;
00369     RangesCompl<GlbRanges<View> > lbc;
00370   public:
00372 
00373 
00374     LubRanges(void) {}
00376     LubRanges(const ComplementView<View>& x);
00378     void init(const ComplementView<View>& x);
00379 
00381 
00382 
00383     bool operator()(void) const;
00385     void operator++(void);
00387 
00389 
00390 
00391     int min(void) const;
00393     int max(void) const;
00395     unsigned int width(void) const;
00397   };
00398 
00399   template <class View>
00400   forceinline
00401   LubRanges<ComplementView<View> >::LubRanges(const ComplementView<View>& s)
00402     : lb(s.base()), lbc(lb) {}
00403 
00404   template <class View>
00405   forceinline void
00406   LubRanges<ComplementView<View> >::init(const ComplementView<View>& s) {
00407     lb.init(s.base());
00408     lbc.init(lb);
00409   }
00410 
00411   template <class View>
00412   forceinline bool
00413   LubRanges<ComplementView<View> >::operator()(void) const { return lbc(); }
00414 
00415   template <class View>
00416   forceinline void
00417   LubRanges<ComplementView<View> >::operator++(void) { return ++lbc; }
00418 
00419   template <class View>
00420   forceinline int
00421   LubRanges<ComplementView<View> >::min(void) const { return lbc.min(); }
00422 
00423   template <class View>
00424   forceinline int
00425   LubRanges<ComplementView<View> >::max(void) const { return lbc.max(); }
00426 
00427   template <class View>
00428   forceinline unsigned int
00429   LubRanges<ComplementView<View> >::width(void) const { return lbc.width(); }
00430 
00439   template <class View>
00440   class LubRanges<ComplementView<ComplementView<View> > > :
00441   public LubRanges<View> {
00442   public:
00444 
00445 
00446     LubRanges(void) {}
00448     LubRanges(const ComplementView<ComplementView<View> >& x);
00450     void init(const ComplementView<ComplementView<View> >& x);
00452   };
00453 
00454   template <class View>
00455   forceinline
00456   LubRanges<ComplementView<ComplementView<View> > >::
00457   LubRanges(const ComplementView<ComplementView<View> >& x) :
00458   LubRanges<View>(x) {}
00459 
00460   template <class View>
00461   forceinline void
00462   LubRanges<ComplementView<ComplementView<View> > >::
00463   init(const ComplementView<ComplementView<View> >& x) {
00464     LubRanges<View>::init(x);
00465   }
00466 
00471   template <class View>
00472   class GlbRanges<ComplementView<View> > {
00473   private:
00474     LubRanges<View> ub;
00475     RangesCompl<LubRanges<View> > ubc;
00476   public:
00478 
00479 
00480     GlbRanges(void) {}
00482     GlbRanges(const ComplementView<View> & x);
00484     void init(const ComplementView<View> & x);
00485 
00487 
00488 
00489     bool operator()(void) const;
00491     void operator++(void);
00493 
00495 
00496 
00497     int min(void) const;
00499     int max(void) const;
00501     unsigned int width(void) const;
00503   };
00504 
00505   template <class View>
00506   forceinline
00507   GlbRanges<ComplementView<View> >::GlbRanges(const ComplementView<View> & s)
00508     : ub(s.base()), ubc(ub) {}
00509 
00510   template <class View>
00511   forceinline void
00512   GlbRanges<ComplementView<View> >::init(const ComplementView<View> & s) {
00513     ub.init(s.base());
00514     ubc.init(ub);
00515   }
00516 
00517   template <class View>
00518   forceinline bool
00519   GlbRanges<ComplementView<View> >::operator()(void) const { return ubc(); }
00520 
00521   template <class View>
00522   forceinline void
00523   GlbRanges<ComplementView<View> >::operator++(void) { return ++ubc; }
00524 
00525   template <class View>
00526   forceinline int
00527   GlbRanges<ComplementView<View> >::min(void) const { return ubc.min(); }
00528 
00529   template <class View>
00530   forceinline int
00531   GlbRanges<ComplementView<View> >::max(void) const { return ubc.max(); }
00532 
00533   template <class View>
00534   forceinline unsigned int
00535   GlbRanges<ComplementView<View> >::width(void) const { return ubc.width(); }
00536   
00545   template <class View>
00546   class GlbRanges<ComplementView<ComplementView<View> > > :
00547   public GlbRanges<View> {
00548   public:
00550 
00551 
00552     GlbRanges(void) {}
00554     GlbRanges(const ComplementView<ComplementView<View> >& x);
00556     void init(const ComplementView<ComplementView<View> >& x);
00558   };
00559 
00560   template <class View>
00561   forceinline
00562   GlbRanges<ComplementView<ComplementView<View> > >::
00563   GlbRanges(const ComplementView<ComplementView<View> >& x) :
00564   GlbRanges<View>(x) {}
00565 
00566   template <class View>
00567   forceinline void
00568   GlbRanges<ComplementView<ComplementView<View> > >::
00569   init(const ComplementView<ComplementView<View> >& x) {
00570     GlbRanges<View>::init(x);
00571   }
00572 
00573 }
00574 
00575 
00576   /*
00577    * Testing
00578    *
00579    */
00580   template <class View>
00581   forceinline bool
00582   same(const Set::ComplementView<View>& x, 
00583        const Set::ComplementView<View>& y) {
00584     return same(x.base(),y.base());
00585   }
00586   template <class View>
00587   forceinline bool
00588   before(const Set::ComplementView<View>& x, 
00589          const Set::ComplementView<View>& y) {
00590     return before(x.base(),y.base());
00591   }
00592   template <class View>
00593   forceinline bool
00594   same(const Set::ComplementView<Set::ComplementView<View> >& x, 
00595        const Set::ComplementView<Set::ComplementView<View> >& y) {
00596     return same(x,y);
00597   }
00598   template <class View>
00599   forceinline bool
00600   before(const Set::ComplementView<Set::ComplementView<View> >& x, 
00601          const Set::ComplementView<Set::ComplementView<View> >& y) {
00602     return before(x,y);
00603   }
00604 
00605 }
00606 
00607 template <class View>
00608 forceinline
00609 std::ostream&
00610 operator<<(std::ostream& os, const Gecode::Set::ComplementView<View>& s) {
00611   return os << "(" << s.base() << ")^C";
00612 }
00613 
00614 // STATISTICS: set-var