00001
00002
00015
00016
00017 #ifndef polybori_BoolePolyRing_h_
00018 #define polybori_BoolePolyRing_h_
00019
00020
00021 # include <polybori/pbori_defs.h>
00022
00023
00024 #include "ring/CCuddCore.h"
00025 #include "except/PBoRiError.h"
00026 #include "common/CCheckedIdx.h"
00027 #include <boost/intrusive_ptr.hpp>
00028 #include "common/CWeakPtr.h"
00029 #include <list>
00030
00031 BEGIN_NAMESPACE_PBORI
00032
00033 class WeakRingPtr;
00034
00040 class BoolePolyRing:
00041 public CTypes::orderenums_type, public CTypes::compenums_type,
00042 public CTypes::auxtypes_type {
00043
00045 typedef BoolePolyRing self;
00046
00047 public:
00048
00050 friend class WeakRingPtr;
00051
00053 typedef class BooleExponent exp_type;
00054
00056 typedef class BooleMonomial monom_type;
00057
00059 typedef class BooleVariable var_type;
00060
00062 typedef class BooleSet dd_type;
00063
00065 typedef class BoolePolynomial poly_type;
00067
00068 typedef CTypes::ordercode_type ordercode_type;
00069 typedef CTypes::vartext_type vartext_type;
00071
00073 typedef CCheckedIdx checked_idx_type;
00074
00076 typedef CCuddCore core_type;
00077 typedef core_type::const_varname_reference const_varname_reference;
00079 typedef boost::intrusive_ptr<core_type> core_ptr;
00080
00082 typedef core_type::order_type order_type;
00083
00085 typedef core_type::order_ptr order_ptr;
00086
00088 typedef order_type& order_reference;
00089
00090 typedef DdManager mgr_type;
00092 using CTypes::orderenums_type::ordercodes;
00093
00095 typedef std::vector<idx_type> block_idx_type;
00096
00098 typedef block_idx_type::const_iterator block_iterator;
00099
00100 protected:
00101
00104 BoolePolyRing(const core_ptr& rhs): p_core(rhs) {}
00105
00107 explicit BoolePolyRing(const CWeakPtr<core_type>& rhs):
00108 p_core(rhs.operator->()) { PBORI_ASSERT(p_core != NULL); }
00109
00110 public:
00112 explicit BoolePolyRing(size_type nvars = 1,
00113 ordercode_type order = lp);
00114
00116 BoolePolyRing(size_type nvars, const order_ptr& order):
00117 p_core(new core_type(nvars, order)) {}
00118
00120 BoolePolyRing(const self& rhs): p_core(rhs.p_core) {}
00121
00123 ~BoolePolyRing() {}
00124
00126 size_type nVariables() const { return p_core->m_mgr.nVariables(); }
00127
00129 vartext_type getVariableName(checked_idx_type idx) const {
00130 return p_core->m_names[idx];
00131 }
00132
00134 void setVariableName(checked_idx_type idx, vartext_type varname) {
00135 p_core->m_names.set(idx, varname);
00136 }
00137
00139 void clearCache() { p_core->m_mgr.cacheFlush(); }
00140
00142 ostream_type& print(ostream_type&) const;
00143
00145 hash_type hash() const {
00146 return static_cast<hash_type>(reinterpret_cast<std::ptrdiff_t
00147 >(getManager()));
00148 }
00149
00151 hash_type id() const {
00152 return static_cast<hash_type>(reinterpret_cast<std::ptrdiff_t>(p_core.operator->()));
00153 }
00154
00156 order_reference ordering() const { return *(p_core->pOrder); }
00157
00159 mgr_type* getManager() const { return p_core->m_mgr.getManager(); }
00160
00162 self clone() const { return self(core_ptr(new core_type(*p_core))); }
00163
00165 void changeOrdering(ordercode_type);
00166
00168 poly_type coerce(const poly_type& rhs) const;
00169
00171 monom_type coerce(const monom_type& rhs) const;
00172
00174 var_type coerce(const var_type& rhs) const;
00175
00177 dd_type variableDiagram(checked_idx_type nvar) const;
00178
00180 var_type variable(checked_idx_type nvar) const;
00181
00183 dd_type zero() const;
00184
00186 dd_type one() const;
00187
00189 dd_type constant(bool is_one) const;
00190
00191 protected:
00193 core_ptr core() const { return p_core; };
00194
00196 core_ptr p_core;
00197 };
00198
00200 inline BoolePolyRing::ostream_type&
00201 operator<<(BoolePolyRing::ostream_type& os, const BoolePolyRing& ring) {
00202 return ring.print(os);
00203 }
00204
00205 END_NAMESPACE_PBORI
00206
00207
00208 #endif // of #ifndef polybori_BoolePolyRing_h_