PolyBoRi
BooleSet.h
Go to the documentation of this file.
1 // -*- c++ -*-
2 //*****************************************************************************
14 //*****************************************************************************
15 
16 #ifndef polybori_BooleSet_h_
17 #define polybori_BooleSet_h_
18 
19 // include basic definitions
20 #include <polybori/pbori_defs.h>
21 
22 // include polybori functionals
24 
26 
27 #include "BoolePolyRing.h"
28 
30 
32 class BooleMonomial;
33 class BooleExponent;
34 
35 template<class OrderType, class NavigatorType, class MonomType>
36 class CGenericIter;
37 // temporarily
38 class LexOrder;
39 
40 template<class OrderType, class NavigatorType, class MonomType>
42 
43 
44 #define PBORI_CONST_DDFUNCS(func) \
45  self func(const self& rhs) const { return self(base::func(rhs.diagram())); }
46 
47 #define PBORI_DDFUNCS(func) \
48  self& func(const self& rhs) { base::func(rhs.diagram()); return *this; }
49 
50 #define PBORI_CONST_DDFUNCS_IDX(func) \
51  self func(idx_type idx) const { return self(base::func(idx)); }
52 
53 #define PBORI_DDFUNCS_IDX(func) \
54  self& func(idx_type idx) { base::func(idx); return *this; }
55 
56 
57 class BooleSet:
58  public CCuddDDFacade<BoolePolyRing, BooleSet> {
60  typedef BooleSet self;
61 
62 public:
64  typedef self dd_type;
65 
68 
71 
74 
77 
80 
83 
86 
89 
90 public:
92  BooleSet(const self& rhs): base(rhs) {}
93 
95  BooleSet(const base& rhs): base(rhs) {}
96 
98  BooleSet(idx_type idx, const self& first, const self& second):
99  base(idx, first, second) { }
100 
102  BooleSet(idx_type idx, navigator first, navigator second,
103  const ring_type& ring):
104  base(ring, idx, first, second) { }
105 
107  BooleSet(const ring_type& ring, node_ptr node):
108  base(ring, node) { }
109 
111  BooleSet(const ring_type& ring, navigator navi):
112  base(ring, navi.getNode()) { }
113 
115  BooleSet(const ring_type& ring):
116  base(ring.zero()) { };
117 
119  BooleSet(idx_type idx, const self& rhs):
120  base(idx, rhs, rhs) { }
121 
123  BooleSet(navigator navi, const ring_type& ring):
124  base(ring, navi) { }
125 
128 
130  const_iterator begin() const;
131 
133  const_iterator end() const;
134 
136  const_reverse_iterator rbegin() const;
137 
139  const_reverse_iterator rend() const;
140 
142  reverse_exp_iterator rExpBegin() const;
143 
145  reverse_exp_iterator rExpEnd() const;
146 
148  exp_iterator expBegin() const;
149 
151  exp_iterator expEnd() const;
152 
154  hash_type hash() const {
155  return static_cast<hash_type>(reinterpret_cast<std::ptrdiff_t>(getNode()));
156  }
157 
160  return stable_hash_range(navigation());
161  }
162 
164  term_type usedVariables() const;
165 
167  exp_type usedVariablesExp() const;
168 
169  self change(idx_type idx) const {
170  if PBORI_UNLIKELY(size_type(idx) >= ring().nVariables())
171  throw PBoRiError(CTypes::out_of_bounds);
172  return base::change(idx);
173  }
174 
175 
177  self add(const term_type& rhs) const;
178 
179  // Check whether rhs is included in *this
180  bool_type owns(const term_type& rhs) const;
181 
183  bool_type owns(const exp_type&) const;
184 
186  term_type lastLexicographicalTerm() const;
187 
189  self divisorsOf(const term_type& rhs) const;
190 
192  self divisorsOf(const exp_type& rhs) const;
193 
195  self firstDivisorsOf(const self& rhs) const;
196 
198  self multiplesOf(const term_type& rhs) const;
199 
201  self divide(const term_type& rhs) const;
202 
205  bool_type hasTermOfVariables(const term_type& rhs) const;
206 
208  self minimalElements() const;
209 
211  bool_type ownsOne() const { return owns_one(navigation()); }
212 
214  bool_type isSingleton() const { return dd_is_singleton(navigation()); }
215 
218  return dd_is_singleton_or_pair(navigation());
219  }
220 
222  bool_type isPair() const { return dd_is_pair(navigation()); }
223 
228  self existAbstract(const term_type& rhs) const;
229 
231  const self& diagram() const { return *this; } // to be removed
232 
234  self cartesianProduct(const self& rhs) const {
235  return unateProduct(rhs);
236  };
237 
239  bool_type contains(const self& rhs) const { return rhs.implies(*this); }
240 
242  size_type size() const { return count(); }
243 
245  size_type length() const { return size(); }
246 
248  size_type nVariables() const { return ring().nVariables(); }
249 
251  double sizeDouble() const { return countDouble(); }
252 
254  ostream_type& print(ostream_type&) const;
255 
257  self emptyElement() const { return ring().zero(); }
258 
260  size_type countIndex(idx_type idx) const;
261 
263  double countIndexDouble(idx_type idx) const ;
264 
266  bool_type containsDivisorsOfDecDeg(const term_type& rhs) const;
267 
269  bool_type containsDivisorsOfDecDeg(const exp_type& rhs) const;
270 };
271 
273 inline BooleSet::ostream_type&
275  return bset.print(os);
276 }
277 
278 
280 
281 #endif
BoolePolyRing ring_type
Type for Boolean polynomial rings (without ordering)
Definition: BooleSet.h:76
This class is just a wrapper for using variables for storing indices as interim data structure for Bo...
Definition: BooleExponent.h:34
#define END_NAMESPACE_PBORI
Finish project's namespace.
Definition: pbori_defs.h:77
bool dd_is_pair(NaviType navi)
Definition: pbori_algo.h:805
void stable_hash_range(HashType &seed, NaviType navi)
Definition: pbori_routines_hash.h:28
BooleSet(idx_type idx, navigator first, navigator second, const ring_type &ring)
Construct new node (using navigator nodes)
Definition: BooleSet.h:102
#define BEGIN_NAMESPACE_PBORI
Start project's namespace.
Definition: pbori_defs.h:74
BooleMonomial term_type
Type of terms.
Definition: BooleSet.h:70
const self & diagram() const
Access internal decision diagram.
Definition: BooleSet.h:231
bool_type contains(const self &rhs) const
Test containment.
Definition: BooleSet.h:239
bool_type isPair() const
Test, whether we have two terms only.
Definition: BooleSet.h:222
BooleExponent exp_type
Fix type for treatment of exponent vectors.
Definition: BooleSet.h:73
hash_type stableHash() const
Get stable hash value, which is reproducible.
Definition: BooleSet.h:159
size_type nVariables() const
Returns number of variables in manager.
Definition: BooleSet.h:248
BooleSet(const ring_type &ring, navigator navi)
Construct new node (using navigator nodes)
Definition: BooleSet.h:111
BooleSet(const base &rhs)
Copy constructor.
Definition: BooleSet.h:95
CGenericIter< LexOrder, navigator, exp_type > exp_iterator
Iterator type for iterating all exponent vectors.
Definition: BooleSet.h:82
This class reinterprets decicion diagram managers as Boolean polynomial rings, adds an ordering and v...
Definition: BoolePolyRing.h:40
std::ostream ostream_type
Type for out-stream.
Definition: pbori_defs.h:246
BooleSet::ostream_type & operator<<(BooleSet::ostream_type &os, const BooleSet &bset)
Stream output operator.
Definition: BooleSet.h:274
double sizeDouble() const
Approximation of number of terms.
Definition: BooleSet.h:251
std::size_t hash_type
Type for hashing.
Definition: pbori_defs.h:231
bool dd_is_singleton(NaviType navi)
Definition: pbori_algo.h:770
This template class defines a facade for decision diagrams.
Definition: CCuddDDFacade.h:103
This class is used for polybori's exception handling.
Definition: PBoRiError.h:31
size_type size() const
Returns number of terms.
Definition: BooleSet.h:242
CCuddDDFacade< BoolePolyRing, BooleSet > base
Generic access to base type.
Definition: BooleSet.h:67
BooleSet(navigator navi, const ring_type &ring)
Construct from navigator node.
Definition: BooleSet.h:123
bool_type isSingleton() const
Test, whether we have one term only.
Definition: BooleSet.h:214
BooleSet(const ring_type &ring, node_ptr node)
Construct new node (using nodes)
Definition: BooleSet.h:107
self emptyElement() const
Get corresponding zero element (may be removed in the future)
Definition: BooleSet.h:257
int idx_type
Type for indices.
Definition: pbori_defs.h:228
bool_type ownsOne() const
Test whether the empty set is included.
Definition: BooleSet.h:211
Definition: BooleSet.h:41
Definition: BoolePolynomial.h:70
self change(idx_type idx) const
Definition: BooleSet.h:169
BooleSet(const self &rhs)
Copy constructor.
Definition: BooleSet.h:92
bool_type isSingletonOrPair() const
Test, whether we have one or two terms only.
Definition: BooleSet.h:217
ostream_type & print(ostream_type &) const
Print current set to output stream.
Definition: BooleSet.cc:266
self cartesianProduct(const self &rhs) const
Cartesean product.
Definition: BooleSet.h:234
polybori::CTypes::idx_type idx_type
Definition: groebner_defs.h:44
std::size_t size_type
Type for lengths, dimensions, etc.
Definition: pbori_defs.h:219
This class defines an iterator for navigating through then and else branches of ZDDs.
Definition: CCuddNavigator.h:36
size_type length() const
Returns number of terms (deprecated)
Definition: BooleSet.h:245
BooleSet(const ring_type &ring)
Construct empty set in ring.
Definition: BooleSet.h:115
BooleSet(idx_type idx, const self &rhs)
Construct new node (using navigator for then and else-branches)
Definition: BooleSet.h:119
Definition: BooleSet.h:57
bool dd_is_singleton_or_pair(NaviType navi)
Definition: pbori_algo.h:798
CReverseIter< LexOrder, navigator, term_type > const_reverse_iterator
Iterator type for iterating all monomials.
Definition: BooleSet.h:88
This class is just a wrapper for using variables from cudd's decicion diagram.
Definition: BooleMonomial.h:50
self dd_type
Generic access to type of *this.
Definition: BooleSet.h:64
~BooleSet()
Destructor.
Definition: BooleSet.h:127
bool bool_type
Type for standard true/false statements.
Definition: pbori_defs.h:216
#define PBORI_UNLIKELY(expression)
Definition: pbori_defs.h:59
BooleSet(idx_type idx, const self &first, const self &second)
Construct new node.
Definition: BooleSet.h:98
CGenericIter< LexOrder, navigator, term_type > const_iterator
Iterator type for iterating all monomials.
Definition: BooleSet.h:79
CReverseIter< LexOrder, navigator, exp_type > reverse_exp_iterator
Iterator type for iterating all exponent vectors.
Definition: BooleSet.h:85
hash_type hash() const
Get unique hash value (valid only per runtime)
Definition: BooleSet.h:154
DdNode * node_ptr
Definition: CApplyNodeFacade.h:50
bool owns_one(NaviType navi)
Test whether the empty set is included.
Definition: pbori_algo.h:318