PolyBoRi
|
00001 // -*- c++ -*- 00002 //***************************************************************************** 00014 //***************************************************************************** 00015 00016 #ifndef polybori_BooleSet_h_ 00017 #define polybori_BooleSet_h_ 00018 00019 // include basic definitions 00020 #include <polybori/pbori_defs.h> 00021 00022 // include polybori functionals 00023 #include <polybori/routines/pbori_func.h> 00024 00025 #include <polybori/diagram/CCuddDDFacade.h> 00026 00027 #include "BoolePolyRing.h" 00028 00029 BEGIN_NAMESPACE_PBORI 00030 00032 class BooleMonomial; 00033 class BooleExponent; 00034 00035 template<class OrderType, class NavigatorType, class MonomType> 00036 class CGenericIter; 00037 // temporarily 00038 class LexOrder; 00039 00040 template<class OrderType, class NavigatorType, class MonomType> 00041 class CReverseIter; 00042 00043 00044 #define PBORI_CONST_DDFUNCS(func) \ 00045 self func(const self& rhs) const { return self(base::func(rhs.diagram())); } 00046 00047 #define PBORI_DDFUNCS(func) \ 00048 self& func(const self& rhs) { base::func(rhs.diagram()); return *this; } 00049 00050 #define PBORI_CONST_DDFUNCS_IDX(func) \ 00051 self func(idx_type idx) const { return self(base::func(idx)); } 00052 00053 #define PBORI_DDFUNCS_IDX(func) \ 00054 self& func(idx_type idx) { base::func(idx); return *this; } 00055 00056 00057 class BooleSet: 00058 public CCuddDDFacade<BoolePolyRing, BooleSet> { 00060 typedef BooleSet self; 00061 00062 public: 00064 typedef self dd_type; 00065 00067 typedef CCuddDDFacade<BoolePolyRing, BooleSet> base; 00068 00070 typedef BooleMonomial term_type; 00071 00073 typedef BooleExponent exp_type; 00074 00076 typedef BoolePolyRing ring_type; 00077 00079 typedef CGenericIter<LexOrder, navigator, term_type> const_iterator; 00080 00082 typedef CGenericIter<LexOrder, navigator, exp_type> exp_iterator; 00083 00085 typedef CReverseIter<LexOrder, navigator, exp_type> reverse_exp_iterator; 00086 00088 typedef CReverseIter<LexOrder, navigator, term_type> const_reverse_iterator; 00089 00090 public: 00092 BooleSet(const self& rhs): base(rhs) {} 00093 00095 BooleSet(const base& rhs): base(rhs) {} 00096 00098 BooleSet(idx_type idx, const self& first, const self& second): 00099 base(idx, first, second) { } 00100 00102 BooleSet(idx_type idx, navigator first, navigator second, 00103 const ring_type& ring): 00104 base(ring, idx, first, second) { } 00105 00107 BooleSet(const ring_type& ring, node_ptr node): 00108 base(ring, node) { } 00109 00111 BooleSet(const ring_type& ring, navigator navi): 00112 base(ring, navi.getNode()) { } 00113 00115 BooleSet(const ring_type& ring): 00116 base(ring.zero()) { }; 00117 00119 BooleSet(idx_type idx, const self& rhs): 00120 base(idx, rhs, rhs) { } 00121 00123 BooleSet(navigator navi, const ring_type& ring): 00124 base(ring, navi) { } 00125 00127 ~BooleSet() {} 00128 00130 const_iterator begin() const; 00131 00133 const_iterator end() const; 00134 00136 const_reverse_iterator rbegin() const; 00137 00139 const_reverse_iterator rend() const; 00140 00142 reverse_exp_iterator rExpBegin() const; 00143 00145 reverse_exp_iterator rExpEnd() const; 00146 00148 exp_iterator expBegin() const; 00149 00151 exp_iterator expEnd() const; 00152 00154 hash_type hash() const { 00155 return static_cast<hash_type>(reinterpret_cast<std::ptrdiff_t>(getNode())); 00156 } 00157 00159 hash_type stableHash() const { 00160 return stable_hash_range(navigation()); 00161 } 00162 00164 term_type usedVariables() const; 00165 00167 exp_type usedVariablesExp() const; 00168 00169 self change(idx_type idx) const { 00170 if PBORI_UNLIKELY(size_type(idx) >= ring().nVariables()) 00171 throw PBoRiError(CTypes::out_of_bounds); 00172 return base::change(idx); 00173 } 00174 00175 00177 self add(const term_type& rhs) const; 00178 00179 // Check whether rhs is included in *this 00180 bool_type owns(const term_type& rhs) const; 00181 00183 bool_type owns(const exp_type&) const; 00184 00186 term_type lastLexicographicalTerm() const; 00187 00189 self divisorsOf(const term_type& rhs) const; 00190 00192 self divisorsOf(const exp_type& rhs) const; 00193 00195 self firstDivisorsOf(const self& rhs) const; 00196 00198 self multiplesOf(const term_type& rhs) const; 00199 00201 self divide(const term_type& rhs) const; 00202 00205 bool_type hasTermOfVariables(const term_type& rhs) const; 00206 00208 self minimalElements() const; 00209 00211 bool_type ownsOne() const { return owns_one(navigation()); } 00212 00214 bool_type isSingleton() const { return dd_is_singleton(navigation()); } 00215 00217 bool_type isSingletonOrPair() const { 00218 return dd_is_singleton_or_pair(navigation()); 00219 } 00220 00222 bool_type isPair() const { return dd_is_pair(navigation()); } 00223 00228 self existAbstract(const term_type& rhs) const; 00229 00231 const self& diagram() const { return *this; } // to be removed 00232 00234 self cartesianProduct(const self& rhs) const { 00235 return unateProduct(rhs); 00236 }; 00237 00239 bool_type contains(const self& rhs) const { return rhs.implies(*this); } 00240 00242 size_type size() const { return count(); } 00243 00245 size_type length() const { return size(); } 00246 00248 size_type nVariables() const { return ring().nVariables(); } 00249 00251 double sizeDouble() const { return countDouble(); } 00252 00254 ostream_type& print(ostream_type&) const; 00255 00257 self emptyElement() const { return ring().zero(); } 00258 00260 size_type countIndex(idx_type idx) const; 00261 00263 double countIndexDouble(idx_type idx) const ; 00264 00266 bool_type containsDivisorsOfDecDeg(const term_type& rhs) const; 00267 00269 bool_type containsDivisorsOfDecDeg(const exp_type& rhs) const; 00270 }; 00271 00273 inline BooleSet::ostream_type& 00274 operator<<( BooleSet::ostream_type& os, const BooleSet& bset ) { 00275 return bset.print(os); 00276 } 00277 00278 00279 END_NAMESPACE_PBORI 00280 00281 #endif