30 #include "../DdEval.hpp" 31 #include "../util/BigNumber.hpp" 32 #include "../util/MemoryPool.hpp" 33 #include "../util/MyVector.hpp" 37 template<
typename E,
typename T,
int ARITY,
bool BDD>
38 class CardinalityBase:
public DdEval<E,T> {
43 CardinalityBase(
int numVars = 0) :
48 void initialize(
int level) {
52 void evalTerminal(T& n,
bool one)
const {
56 void evalNode(T& n,
int i, DdValues<T,ARITY>
const& values)
const {
59 for (
int b = 0; b < ARITY; ++b) {
60 T tmp = values.get(b);
61 int ii = values.getLevel(b);
70 for (
int b = 0; b < ARITY; ++b) {
76 T getValue(T
const& n) {
79 for (
int i = topLevel; i < numVars; ++i) {
90 template<
typename E,
int ARITY,
bool BDD>
91 class CardinalityBase<E,std::string,ARITY,BDD> :
public DdEval<E,BigNumber,
101 CardinalityBase(
int numVars = 0) :
106 void initialize(
int level) {
108 pools.resize(topLevel + 1);
110 int max = ceil(
double(topLevel) * log2(
double(ARITY)) / 63.0) + 1;
111 tmp1.setArray(pools[topLevel].
template allocate<uint64_t>(max));
112 tmp2.setArray(pools[topLevel].
template allocate<uint64_t>(max));
113 tmp3.setArray(pools[topLevel].
template allocate<uint64_t>(max));
116 void evalTerminal(BigNumber& n,
int value) {
117 n.setArray(pools[0].
template allocate<uint64_t>(1));
121 void evalNode(BigNumber& n,
123 DdValues<BigNumber,ARITY>
const& values) {
124 assert(0 <= i &&
size_t(i) <= pools.size());
126 size_t w = tmp1.store(0);
127 for (
int b = 0; b < ARITY; ++b) {
128 tmp2.store(values.get(b));
129 int k = i - values.getLevel(b) - 1;
136 for (
int b = 1; b < ARITY; ++b) {
143 n.setArray(pools[i].
template allocate<uint64_t>(w));
152 w = tmp1.store(values.get(0));
153 for (
int b = 1; b < ARITY; ++b) {
154 w = tmp1.add(values.get(b));
157 n.setArray(pools[i].
template allocate<uint64_t>(w));
162 std::string getValue(BigNumber
const& n) {
165 int k = numVars - topLevel;
172 for (
int b = 1; b < ARITY; ++b) {
184 void destructLevel(
int i) {
195 template<
typename T = std::
string,
int AR = 2>
198 CardinalityBase<BddCardinality<T,AR>,T,AR,
true>(numVars) {
208 template<
typename T = std::
string,
int AR = 2>
ZDD evaluator that counts the number of elements.
BDD evaluator that counts the number of elements.