Advertisement
Guest User

Untitled

a guest
Jul 19th, 2019
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.02 KB | None | 0 0
  1. #include <fstream>
  2. #include <iostream>
  3. #include <tdzdd/DdSpec.hpp>
  4. #include <tdzdd/DdStructure.hpp>
  5.  
  6. using namespace std;
  7.  
  8. const bool DEBUG_ENUM = false;
  9.  
  10. class Combination : public tdzdd::DdSpec<Combination, int, 2> {
  11. const int n;
  12. const int k;
  13. public:
  14. Combination(int __n, int __k) : n(__n), k(__k) {}
  15.  
  16. int getRoot(int& cnt) {
  17. cnt = 0;
  18. return n;
  19. }
  20.  
  21. int getChild(int& cnt, int level, int take) const {
  22. cnt += take;
  23. if (cnt > k)
  24. return 0;
  25. if (cnt + level - 1 < k)
  26. return 0;
  27. --level;
  28. return (level == 0) ? -1 : level;
  29. }
  30. };
  31.  
  32. class MaxNumItems: public tdzdd::DdEval<MaxNumItems, int> {
  33. public:
  34. void evalTerminal(int& n, bool one) const {
  35. n = one ? 0 : INT_MIN;
  36. }
  37. void evalNode(int& n, int, tdzdd::DdValues<int,2> const& values) const {
  38. n = std::max(values.get(0), values.get(1) + 1);
  39. }
  40. };
  41.  
  42. int main() {
  43. const int n = 10;
  44. const int k = 4;
  45. // ofstream output("comb.dot");
  46. // ofstream output_reduced("comb_reduced.dot");
  47. Combination comb(n, k);
  48. // comb.dumpDot(output);
  49. tdzdd::DdStructure<2> dd(comb);
  50. dd.zddReduce();
  51. // dd.dumpDot(output_reduced);
  52. cout << n << "C" << k << "=" << dd.zddCardinality() << endl;
  53.  
  54. // test iterator
  55. if (DEBUG_ENUM) {
  56. int count = 1;
  57. for (auto itemset : dd) {
  58. cout << (count++) << " [";
  59. for (auto v : itemset) { cout << v << " "; }
  60. cout << "]" << endl;
  61. }
  62. }
  63.  
  64. // traverse on ZDD
  65. // root's level
  66. auto root_node = dd.root();
  67. auto top_level = dd.topLevel();
  68. cout << "root node id = " << root_node << ", top leve = " << top_level << endl;
  69.  
  70. // topを1とする評価
  71. int max = dd.evaluate(MaxNumItems());
  72. cout << max << endl;
  73.  
  74. // get child
  75. auto c0 = dd.child(root_node, 0);
  76. auto c1 = dd.child(root_node, 1);
  77. cout << c0 << " " << c1 << endl;
  78.  
  79. // get 1-th sub zdd できない
  80. // ofstream oz1("comb_c1.dot");
  81. // c1.dumpDot(oz1);
  82. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement