PolyBoRi
BoolePolyRing.h
Go to the documentation of this file.
1 // -*- c++ -*-
2 //*****************************************************************************
15 //*****************************************************************************
16 
17 #ifndef polybori_BoolePolyRing_h_
18 #define polybori_BoolePolyRing_h_
19 
20 // load PolyBoRi settings
21 # include <polybori/pbori_defs.h>
22 
23 // include basic decision diagram manager interface
24 #include "ring/CCuddCore.h"
25 #include "except/PBoRiError.h"
26 #include "common/CCheckedIdx.h"
27 #include <boost/intrusive_ptr.hpp>
28 #include "common/CWeakPtr.h"
29 #include <list>
30 
32 
33 class WeakRingPtr; // forward declaration
34 
42  public CTypes::auxtypes_type {
43 
45  typedef BoolePolyRing self;
46 
47  public:
48 
50  friend class WeakRingPtr;
51 
53  typedef class BooleExponent exp_type;
54 
56  typedef class BooleMonomial monom_type;
57 
59  typedef class BooleVariable var_type;
60 
62  typedef class BooleSet dd_type;
63 
65  typedef class BoolePolynomial poly_type;
67 
71 
74 
79  typedef boost::intrusive_ptr<core_type> core_ptr;
80 
83 
86 
89 
93 
95  typedef std::vector<idx_type> block_idx_type;
96 
98  typedef block_idx_type::const_iterator block_iterator;
99 
100 protected:
101 
104  BoolePolyRing(const core_ptr& rhs): p_core(rhs) {}
105 
107  explicit BoolePolyRing(const CWeakPtr<core_type>& rhs):
108  p_core(rhs.operator->()) { PBORI_ASSERT(p_core != NULL); }
109 
110 public:
112  explicit BoolePolyRing(size_type nvars = 1,
113  ordercode_type order = lp);
114 
116  BoolePolyRing(size_type nvars, const order_ptr& order):
117  p_core(new core_type(nvars, order)) {}
118 
120  BoolePolyRing(const self& rhs): p_core(rhs.p_core) {}
121 
124 
126  size_type nVariables() const { return p_core->m_mgr.nVariables(); }
127 
130  return p_core->m_names[idx];
131  }
132 
135  p_core->m_names.set(idx, varname);
136  }
137 
139  void clearCache() { p_core->m_mgr.cacheFlush(); }
140 
142  ostream_type& print(ostream_type&) const;
143 
145  hash_type hash() const {
146  return static_cast<hash_type>(reinterpret_cast<std::ptrdiff_t
147  >(getManager()));
148  }
149 
151  hash_type id() const {
152  return static_cast<hash_type>(reinterpret_cast<std::ptrdiff_t>(p_core.operator->()));
153  }
154 
156  order_reference ordering() const { return *(p_core->pOrder); }
157 
159  mgr_type* getManager() const { return p_core->m_mgr.getManager(); }
160 
162  self clone() const { return self(core_ptr(new core_type(*p_core))); }
163 
165  void changeOrdering(ordercode_type);
166 
168  poly_type coerce(const poly_type& rhs) const;
169 
171  monom_type coerce(const monom_type& rhs) const;
172 
174  var_type coerce(const var_type& rhs) const;
175 
177  dd_type variableDiagram(checked_idx_type nvar) const;
178 
180  var_type variable(checked_idx_type nvar) const;
181 
183  dd_type zero() const;
184 
186  dd_type one() const;
187 
189  dd_type constant(bool is_one) const;
190 
191 protected:
193  core_ptr core() const { return p_core; };
194 
196  core_ptr p_core;
197 };
198 
200 inline BoolePolyRing::ostream_type&
201 operator<<(BoolePolyRing::ostream_type& os, const BoolePolyRing& ring) {
202  return ring.print(os);
203 }
204 
206 
207 
208 #endif // of #ifndef polybori_BoolePolyRing_h_