Generated on Tue Jul 27 2010 21:59:13 for Gecode by doxygen 1.7.1

view.hpp

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: 2010-06-29 10:39:13 +0200 (Tue, 29 Jun 2010) $ by $Author: schulte $
00015  *     $Revision: 11118 $
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 #include <iostream>
00043 
00044 namespace Gecode { namespace Set {
00045 
00060   class SetView : public VarImpView<SetVarImp> {
00061   protected:
00062     using VarImpView<SetVarImp>::x;
00063   public:
00065 
00066 
00067     SetView(void);
00069     SetView(const SetVar& y);
00071     SetView(SetVarImp* y);
00073 
00075 
00076 
00078     unsigned int cardMin(void) const;
00080     unsigned int cardMax(void) const;
00082     int lubMin(void) const;
00084     int lubMax(void) const;
00086     int lubMinN(unsigned int n) const;
00088     int glbMin(void) const;
00090     int glbMax(void) const;
00091 
00093     unsigned int glbSize(void) const;
00095     unsigned int lubSize(void) const;
00097     unsigned int unknownSize(void) const;
00099 
00101 
00102 
00103     bool contains(int i) const;
00105     bool notContains(int i) const;
00107 
00108 
00110 
00111 
00112     ModEvent cardMin(Space& home, unsigned int m);
00114     ModEvent cardMax(Space& home, unsigned int m);
00119     ModEvent include(Space& home,int i,int j);
00124     ModEvent exclude(Space& home,int i,int j);
00126     ModEvent include(Space& home,int i);
00128     ModEvent exclude(Space& home,int i);
00133     ModEvent intersect(Space& home,int i,int j);
00135     ModEvent intersect(Space& home,int i);
00137 
00139 
00140 
00142     template<class I> ModEvent excludeI(Space& home, I& i);
00144     template<class I> ModEvent includeI(Space& home, I& i);
00146     template<class I> ModEvent intersectI(Space& home, I& iter);
00148 
00150 
00151 
00152     static ModEvent modevent(const Delta& d);
00154     int glbMin(const Delta& d) const;
00156     int glbMax(const Delta& d) const;
00158     bool glbAny(const Delta& d) const;
00160     int lubMin(const Delta& d) const;
00162     int lubMax(const Delta& d) const;
00164     bool lubAny(const Delta& d) const;
00166   };
00167 
00172   template<class Char, class Traits>
00173   std::basic_ostream<Char,Traits>&
00174   operator <<(std::basic_ostream<Char,Traits>& os, const SetView& x);
00175 
00176 
00177 
00178   // Forward declarations for friends
00179   class ConstSetView;
00180   bool same(const ConstSetView&, const ConstSetView&);
00181   bool before(const ConstSetView&, const ConstSetView&);
00182 
00190   class ConstSetView : public ConstView<SetView> {
00191     friend class LubRanges<ConstSetView>;
00192     friend class GlbRanges<ConstSetView>;
00193     friend bool Gecode::Set::same(const Gecode::Set::ConstSetView&,
00194                                   const Gecode::Set::ConstSetView&);
00195     friend bool Gecode::Set::before(const Gecode::Set::ConstSetView&,
00196                                     const Gecode::Set::ConstSetView&);
00197   private:
00198     int *ranges;
00199     int size;
00200     unsigned int domSize;
00201   public:
00203 
00204 
00205     ConstSetView(void);
00207     ConstSetView(Space& home, const IntSet& s);
00209 
00211 
00212 
00213     unsigned int cardMin(void) const;
00215     unsigned int cardMax(void) const;
00217     int lubMin(void) const;
00219     int lubMax(void) const;
00221     int lubMinN(unsigned int n) const;
00223     int glbMin(void) const;
00225     int glbMax(void) const;
00226 
00228     unsigned int glbSize(void) const;
00230     unsigned int lubSize(void) const;
00232     unsigned int unknownSize(void) const;
00234 
00236 
00237 
00238     bool contains(int i) const;
00240     bool notContains(int i) const;
00242 
00243 
00245 
00246 
00247     ModEvent cardMin(Space& home, unsigned int m);
00249     ModEvent cardMax(Space& home, unsigned int m);
00254     ModEvent include(Space& home,int i,int j);
00259     ModEvent exclude(Space& home,int i,int j);
00261     ModEvent include(Space& home,int i);
00263     ModEvent exclude(Space& home,int i);
00268     ModEvent intersect(Space& home,int i,int j);
00270     ModEvent intersect(Space& home,int i);
00272 
00274 
00275 
00277     template<class I> ModEvent excludeI(Space& home, I& i);
00279     template<class I> ModEvent includeI(Space& home, I& i);
00281     template<class I> ModEvent intersectI(Space& home, I& iter);
00283 
00285 
00286 
00287     void update(Space& home, bool share, ConstSetView& y);
00289 
00291 
00292 
00293     int glbMin(const Delta& d) const;
00295     int glbMax(const Delta& d) const;
00297     bool glbAny(const Delta& d) const;
00299     int lubMin(const Delta& d) const;
00301     int lubMax(const Delta& d) const;
00303     bool lubAny(const Delta& d) const;
00305 
00306   };
00307 
00312   template<class Char, class Traits>
00313   std::basic_ostream<Char,Traits>&
00314   operator <<(std::basic_ostream<Char,Traits>& os, const ConstSetView& x);
00315 
00320 
00321   bool same(const ConstSetView& x, const ConstSetView& y);
00323   bool before(const ConstSetView& x, const ConstSetView& y);
00325 
00326 
00335   class EmptyView : public ConstView<SetView> {
00336   public:
00338 
00339 
00340     EmptyView(void);
00342 
00344 
00345 
00346     unsigned int cardMin(void) const;
00348     unsigned int cardMax(void) const;
00350     int lubMin(void) const;
00352     int lubMax(void) const;
00354     int lubMinN(unsigned int n) const;
00356     int glbMin(void) const;
00358     int glbMax(void) const;
00359 
00361     unsigned int glbSize(void) const;
00363     unsigned int lubSize(void) const;
00365     unsigned int unknownSize(void) const;
00367 
00369 
00370 
00371     bool contains(int i) const;
00373     bool notContains(int i) const;
00375 
00376 
00378 
00379 
00380     ModEvent cardMin(Space& home, unsigned int m);
00382     ModEvent cardMax(Space& home, unsigned int m);
00387     ModEvent include(Space& home,int i,int j);
00392     ModEvent exclude(Space& home,int i,int j);
00394     ModEvent include(Space& home,int i);
00396     ModEvent exclude(Space& home,int i);
00401     ModEvent intersect(Space& home,int i,int j);
00403     ModEvent intersect(Space& home,int i);
00405 
00407 
00408 
00410     template<class I> ModEvent excludeI(Space& home, I& i);
00412     template<class I> ModEvent includeI(Space& home, I& i);
00414     template<class I> ModEvent intersectI(Space& home, I& iter);
00416 
00418 
00419 
00420     int glbMin(const Delta& d) const;
00422     int glbMax(const Delta& d) const;
00424     bool glbAny(const Delta& d) const;
00426     int lubMin(const Delta& d) const;
00428     int lubMax(const Delta& d) const;
00430     bool lubAny(const Delta& d) const;
00432 
00433   };
00434 
00439   template<class Char, class Traits>
00440   std::basic_ostream<Char,Traits>&
00441   operator <<(std::basic_ostream<Char,Traits>& os, const EmptyView& x);
00442 
00443 
00448 
00449   bool same(const EmptyView& x, const EmptyView& y);
00451 
00452 
00461   class UniverseView : public ConstView<SetView> {
00462   public:
00464 
00465 
00466     UniverseView(void);
00468 
00470 
00471 
00473     unsigned int cardMin(void) const;
00475     unsigned int cardMax(void) const;
00477     int lubMin(void) const;
00479     int lubMax(void) const;
00481     int lubMinN(unsigned int n) const;
00483     int glbMin(void) const;
00485     int glbMax(void) const;
00486 
00488     unsigned int glbSize(void) const;
00490     unsigned int lubSize(void) const;
00492     unsigned int unknownSize(void) const;
00494 
00496 
00497 
00498     bool contains(int i) const;
00500     bool notContains(int i) const;
00502 
00503 
00505 
00506 
00507     ModEvent cardMin(Space& home, unsigned int m);
00509     ModEvent cardMax(Space& home, unsigned int m);
00514     ModEvent include(Space& home,int i,int j);
00519     ModEvent exclude(Space& home,int i,int j);
00521     ModEvent include(Space& home,int i);
00523     ModEvent exclude(Space& home,int i);
00528     ModEvent intersect(Space& home,int i,int j);
00530     ModEvent intersect(Space& home,int i);
00532 
00534 
00535 
00537     template<class I> ModEvent excludeI(Space& home, I& i);
00539     template<class I> ModEvent includeI(Space& home, I& i);
00541     template<class I> ModEvent intersectI(Space& home, I& iter);
00543 
00545 
00546 
00547     int glbMin(const Delta& d) const;
00549     int glbMax(const Delta& d) const;
00551     bool glbAny(const Delta& d) const;
00553     int lubMin(const Delta& d) const;
00555     int lubMax(const Delta& d) const;
00557     bool lubAny(const Delta& d) const;
00559 
00560   };
00561 
00566   template<class Char, class Traits>
00567   std::basic_ostream<Char,Traits>&
00568   operator <<(std::basic_ostream<Char,Traits>& os, const UniverseView& x);
00569 
00570 
00575 
00576   bool same(const UniverseView& x, const UniverseView& y);
00578 
00579 
00580 
00589   class SingletonView :
00590     public DerivedView<Gecode::Int::IntView> {
00591   protected:
00592     using DerivedView<Gecode::Int::IntView>::x;
00593 
00595     static PropCond pc_settoint(PropCond pc);
00597     static ModEvent me_inttoset(ModEvent me);
00599     static ModEvent me_settoint(ModEvent me);
00600 
00601   public:
00603 
00604 
00605     SingletonView(void);
00607     SingletonView(Gecode::Int::IntView& y);
00609 
00611 
00612 
00614     unsigned int cardMin(void) const;
00616     unsigned int cardMax(void) const;
00618     int lubMin(void) const;
00620     int lubMax(void) const;
00622     int lubMinN(unsigned int n) const;
00624     int glbMin(void) const;
00626     int glbMax(void) const;
00627 
00629     unsigned int glbSize(void) const;
00631     unsigned int lubSize(void) const;
00633     unsigned int unknownSize(void) const;
00635 
00637 
00638 
00639     bool contains(int i) const;
00641     bool notContains(int i) const;
00643 
00644 
00646 
00647 
00648     ModEvent cardMin(Space& home, unsigned int m);
00650     ModEvent cardMax(Space& home, unsigned int m);
00655     ModEvent include(Space& home,int i,int j);
00660     ModEvent exclude(Space& home,int i,int j);
00662     ModEvent include(Space& home,int i);
00664     ModEvent exclude(Space& home,int i);
00669     ModEvent intersect(Space& home,int i,int j);
00671     ModEvent intersect(Space& home,int i);
00673 
00675 
00676 
00678     template<class I> ModEvent excludeI(Space& home, I& i);
00680     template<class I> ModEvent includeI(Space& home, I& i);
00682     template<class I> ModEvent intersectI(Space& home, I& iter);
00684 
00686 
00687 
00688     static void schedule(Space& home, Propagator& p, ModEvent me);
00690     static ModEvent me(const ModEventDelta& med);
00692     static ModEventDelta med(ModEvent);
00694 
00696 
00697 
00704     void subscribe(Space& home, Propagator& p, PropCond pc, bool schedule=true);
00706     void cancel(Space& home, Propagator& p, PropCond pc);
00708     void subscribe(Space& home, Advisor& a);
00710     void cancel(Space& home, Advisor& a);
00712 
00714 
00715 
00716     static ModEvent modevent(const Delta& d);
00718     int glbMin(const Delta& d) const;
00720     int glbMax(const Delta& d) const;
00722     bool glbAny(const Delta& d) const;
00724     int lubMin(const Delta& d) const;
00726     int lubMax(const Delta& d) const;
00728     bool lubAny(const Delta& d) const;
00730 
00731   };
00732 
00737   template<class Char, class Traits>
00738   std::basic_ostream<Char,Traits>&
00739   operator <<(std::basic_ostream<Char,Traits>& os, const SingletonView& x);
00740 
00741 
00751   template<class View>
00752   class ComplementView
00753     : public DerivedView<View> {
00754   protected:
00755     using DerivedView<View>::x;
00756 
00757   public:
00759     static PropCond pc_negateset(PropCond pc);
00761     static ModEvent me_negateset(ModEvent me);
00762 
00764 
00765 
00766     ComplementView(void);
00768     explicit ComplementView(View& y);
00770 
00772 
00773 
00775     unsigned int cardMin(void) const;
00777     unsigned int cardMax(void) const;
00779     int lubMin(void) const;
00781     int lubMax(void) const;
00783     int lubMinN(unsigned int n) const;
00785     int glbMin(void) const;
00787     int glbMax(void) const;
00788 
00790     unsigned int glbSize(void) const;
00792     unsigned int lubSize(void) const;
00794     unsigned int unknownSize(void) const;
00796 
00798 
00799 
00800     bool contains(int i) const;
00802     bool notContains(int i) const;
00804 
00805 
00807 
00808 
00809     ModEvent cardMin(Space& home, unsigned int m);
00811     ModEvent cardMax(Space& home, unsigned int m);
00816     ModEvent include(Space& home,int i,int j);
00821     ModEvent exclude(Space& home,int i,int j);
00823     ModEvent include(Space& home,int i);
00825     ModEvent exclude(Space& home,int i);
00830     ModEvent intersect(Space& home,int i,int j);
00832     ModEvent intersect(Space& home,int i);
00834 
00836 
00837 
00839     template<class I> ModEvent excludeI(Space& home, I& i);
00841     template<class I> ModEvent includeI(Space& home, I& i);
00843     template<class I> ModEvent intersectI(Space& home, I& iter);
00845 
00847 
00848 
00849     static void schedule(Space& home, Propagator& p, ModEvent me);
00851     static ModEvent me(const ModEventDelta& med);
00853     static ModEventDelta med(ModEvent);
00855 
00857 
00858 
00865     void subscribe(Space& home, Propagator& p, PropCond pc, bool schedule=true);
00867     void cancel(Space& home, Propagator& p, PropCond pc);
00869     void subscribe(Space& home, Advisor& a);
00871     void cancel(Space& home, Advisor& a);
00873 
00875 
00876 
00877     static ModEvent modevent(const Delta& d);
00879     int glbMin(const Delta& d) const;
00881     int glbMax(const Delta& d) const;
00883     bool glbAny(const Delta& d) const;
00885     int lubMin(const Delta& d) const;
00887     int lubMax(const Delta& d) const;
00889     bool lubAny(const Delta& d) const;
00891 
00892   };
00893 
00898   template<class Char, class Traits, class View>
00899   std::basic_ostream<Char,Traits>&
00900   operator <<(std::basic_ostream<Char,Traits>& os,
00901               const ComplementView<View>& x);
00902 
00903 }}
00904 
00905 #include <gecode/set/var/set.hpp>
00906 
00907 #include <gecode/set/view/set.hpp>
00908 
00909 #include <gecode/set/view/const.hpp>
00910 #include <gecode/set/view/singleton.hpp>
00911 #include <gecode/set/view/complement.hpp>
00912 
00913 #include <gecode/set/view/print.hpp>
00914 #include <gecode/set/var/print.hpp>
00915 
00916 // STATISTICS: set-var