PolyBoRi
BooleSet.h
Go to the documentation of this file.
00001 // -*- c++ -*-
00002 //*****************************************************************************
00014 //*****************************************************************************
00015 
00016 // include basic definitions
00017 #include "pbori_defs.h"
00018 
00019 
00020 
00021 // include polybori functionals
00022 #include "pbori_func.h"
00023 
00024 #include "CCuddDDFacade.h"
00025 
00026 #include "BoolePolyRing.h"
00027 
00028 
00029 #ifndef BooleSet_h_
00030 #define BooleSet_h_
00031 
00032   //#include "BoolePolyRing.h"
00033 BEGIN_NAMESPACE_PBORI
00034 
00036 class BooleMonomial;
00037 class BooleExponent;
00038 
00039 template<class OrderType, class NavigatorType, class MonomType>
00040 class CGenericIter;
00041 // temporarily
00042 class LexOrder;
00043 
00044 template<class OrderType, class NavigatorType, class MonomType>
00045 class CReverseIter;
00046 
00047 
00048 #define PBORI_CONST_DDFUNCS(func)   \
00049   self func(const self& rhs) const { return self(base::func(rhs.diagram())); }
00050 
00051 #define PBORI_DDFUNCS(func) \
00052   self& func(const self& rhs) { base::func(rhs.diagram()); return *this; }
00053 
00054 #define PBORI_CONST_DDFUNCS_IDX(func) \
00055   self func(idx_type idx) const { return self(base::func(idx)); }
00056 
00057 #define PBORI_DDFUNCS_IDX(func) \
00058   self& func(idx_type idx) { base::func(idx); return *this; }
00059 
00060 
00061 class BooleSet:
00062   public CCuddDDFacade<BoolePolyRing, BooleSet> {
00064   typedef BooleSet self;
00065 
00066 public:
00068   typedef self dd_type;
00069 
00071   typedef CCuddDDFacade<BoolePolyRing, BooleSet> base;
00072 
00074   typedef BooleMonomial term_type;
00075 
00077   typedef BooleExponent exp_type; 
00078 
00080   typedef BoolePolyRing ring_type;
00081 
00083   typedef CGenericIter<LexOrder, navigator, term_type> const_iterator;
00084 
00086   typedef CGenericIter<LexOrder, navigator, exp_type> exp_iterator;
00087 
00089   typedef CReverseIter<LexOrder, navigator, term_type> const_reverse_iterator;
00090 
00092   BooleSet();
00093 
00095   BooleSet(const self& rhs): base(rhs) {}
00096 
00098   BooleSet(const base& rhs): base(rhs) {}
00099 
00101   BooleSet(idx_type idx, const self& first, const self& second):
00102     base(idx, first, second) { }
00103 
00105   BooleSet(idx_type idx, navigator first, navigator second, 
00106            const ring_type& ring): 
00107     base(ring, idx, first, second) { }
00108  
00110   BooleSet(const ring_type& ring, node_ptr node): 
00111     base(ring, node) { }
00112 
00113   BooleSet(const ring_type& ring, navigator navi): 
00114     base(ring, navi.getNode()) { }
00115 
00117   BooleSet(idx_type idx, const self& rhs):
00118     base(idx, rhs, rhs) { }
00119 
00121   BooleSet(navigator navi, const ring_type& ring):
00122     base(ring, navi) { }
00123 
00125   ~BooleSet() {}
00126 
00128   const_iterator begin() const;
00129 
00131   const_iterator end() const;
00132 
00134   const_reverse_iterator rbegin() const;
00135 
00137   const_reverse_iterator rend() const;
00138 
00140   exp_iterator expBegin() const;
00141 
00143   exp_iterator expEnd() const;
00144 
00146   hash_type hash() const { 
00147     return static_cast<hash_type>(reinterpret_cast<std::ptrdiff_t>(getNode()));
00148   }
00149 
00151   hash_type stableHash() const { 
00152     return stable_hash_range(navigation());
00153   }
00154 
00156   term_type usedVariables() const;
00157 
00159   exp_type usedVariablesExp() const;
00160 
00161   self change(idx_type idx) const {
00162     if UNLIKELY(idx >= ring().nVariables())
00163       throw PBoRiError(CTypes::out_of_bounds);
00164     return base::change(idx);
00165   }
00166 
00167 
00169   self add(const term_type& rhs) const;
00170 
00171   // Check whether rhs is included in *this
00172   bool_type owns(const term_type& rhs) const;
00173 
00175   bool_type owns(const exp_type&) const;
00176 
00178   term_type lastLexicographicalTerm() const; 
00179 
00181   self divisorsOf(const term_type& rhs) const;
00182   
00184   self divisorsOf(const exp_type& rhs) const;
00185 
00187   self firstDivisorsOf(const self& rhs) const;
00188 
00190   self multiplesOf(const term_type& rhs) const;
00191   
00193   self divide(const term_type& rhs) const;
00194 
00197   bool_type hasTermOfVariables(const term_type& rhs) const;
00198 
00200   self minimalElements() const;
00201 
00203   bool_type ownsOne() const { return owns_one(navigation()); }
00204 
00206   bool_type isSingleton() const { return dd_is_singleton(navigation()); }
00207 
00209   bool_type isSingletonOrPair() const { 
00210     return dd_is_singleton_or_pair(navigation()); 
00211   }
00212 
00214   bool_type isPair() const { return dd_is_pair(navigation()); }
00215 
00220   self existAbstract(const term_type& rhs) const;
00221 
00223   const self& diagram() const { return *this; }  //  to be removed
00224 
00226   self cartesianProduct(const self& rhs) const {
00227     return unateProduct(rhs);
00228   };
00229 
00231   bool_type contains(const self& rhs) const { return rhs.implies(*this); }
00232 
00234   size_type size() const { return count(); }
00235 
00237   size_type length() const { return size(); }
00238 
00240   size_type nVariables() const { return ring().nVariables(); }
00241 
00243   double sizeDouble() const { return countDouble(); }
00244 
00246   ostream_type& print(ostream_type&) const;
00247 
00249   self emptyElement() const { return ring().zero(); }
00250 
00252   size_type countIndex(idx_type idx) const;
00253 
00255   double countIndexDouble(idx_type idx) const ;
00256 
00258   bool_type containsDivisorsOfDecDeg(const term_type& rhs) const;
00259 
00261   bool_type containsDivisorsOfDecDeg(const exp_type& rhs) const;
00262 };
00263 
00265 inline BooleSet::ostream_type& 
00266 operator<<( BooleSet::ostream_type& os, const BooleSet& bset ) {
00267   return bset.print(os);
00268 }
00269 
00270 
00271 END_NAMESPACE_PBORI
00272 
00273 #endif