CAL  3.0.0
An External Memory Decision Diagram Library
calObj.hh
1 
39 #ifndef _CALOBJ
40 #define _CALOBJ
41 
42 extern "C" {
43 #include "cal.h"
44 #include "calInt.h"
45 }
46 
47 #include <vector>
48 #include <sstream>
49 #include <string>
50 
51 class BDD;
52 class Cal;
53 
57 
62 
72 class BDD
73 {
74  friend Cal;
75 
77  // Types
78 public:
83  using Id_t = Cal_BddId_t;
84 
89  using Index_t = Cal_BddIndex_t;
90 
92  // Members
93 private:
95  Cal_BddManager _bddManager;
96 
98  Cal_Bdd _bdd;
99 
101  // Constructors
102 protected:
103 
110  BDD(Cal_BddManager bddManager, Cal_Bdd bdd)
111  : _bddManager(bddManager), _bdd(bdd)
112  { }
113 
114 public:
118  BDD()
119  : _bddManager(NULL), _bdd(Cal_BddNull(NULL))
120  { }
121 
125  BDD(const BDD &other)
126  : _bddManager(other._bddManager), _bdd(other._bdd)
127  {
128  this->UnFree();
129  }
130 
134  BDD& operator= (const BDD &other)
135  {
136  this->Free();
137 
138  this->_bdd = other._bdd;
139  this->_bddManager = other._bddManager;
140 
141  this->UnFree();
142 
143  return *this;
144  }
145 
149  BDD(BDD &&other)
150  : _bddManager(other._bddManager), _bdd(other._bdd)
151  {
152  other._bdd = Cal_BddNull(other._bddManager);
153  }
154 
158  BDD& operator= (BDD &&other)
159  {
160  this->Free();
161 
162  this->_bdd = other._bdd;
163  this->_bddManager = other._bddManager;
164 
165  other._bdd = Cal_BddNull(other._bddManager);
166 
167  return *this;
168  }
169 
174  {
175  this->Free();
176  }
177 
179  // Predicates
180 public:
181 
187  bool IsOne() const
188  { return Cal_BddIsBddOne(this->_bddManager, this->_bdd); }
189 
195  bool IsZero() const
196  { return Cal_BddIsBddZero(this->_bddManager, this->_bdd); }
197 
201  bool IsNull() const
202  { return BDD::IsNull(this->_bddManager, this->_bdd); }
203 
210  bool IsConst() const
211  { return Cal_BddIsBddConst(this->_bddManager, this->_bdd); }
212 
216  bool IsCube() const
217  { return Cal_BddIsCube(this->_bddManager, this->_bdd); }
218 
222  bool IsEqualTo(const BDD &other) const
223  { return Cal_BddIsEqual(this->_bddManager, this->_bdd, other._bdd); }
224 
230  bool operator== (const BDD &other) const
231  { return this->IsEqualTo(other); }
232 
238  bool operator!= (const BDD &other) const
239  { return !(*this == other); }
240 
244  bool DependsOn(const BDD &var) const
245  { return Cal_BddDependsOn(this->_bddManager, this->_bdd, var._bdd); }
246 
248  // Node traversal and Information
249 public:
250 
256  BDD If() const
257  { return BDD(this->_bddManager, Cal_BddIf(this->_bddManager, this->_bdd)); }
258 
264  Id_t Id() const
265  { return Cal_BddGetIfId(this->_bddManager, this->_bdd); }
266 
272  Index_t Index() const
273  { return Cal_BddGetIfIndex(this->_bddManager, this->_bdd); }
274 
279  BDD Then() const
280  { return BDD(this->_bddManager, Cal_BddThen(this->_bddManager, this->_bdd)); }
281 
285  BDD Else() const
286  { return BDD(this->_bddManager, Cal_BddElse(this->_bddManager, this->_bdd)); }
287 
293  enum Type_t
294  {
296  Zero = CAL_BDD_TYPE_ZERO,
298  One = CAL_BDD_TYPE_ONE,
300  Constant = CAL_BDD_TYPE_CONSTANT,
302  Posvar = CAL_BDD_TYPE_POSVAR,
304  Negvar = CAL_BDD_TYPE_NEGVAR,
306  Overflow = CAL_BDD_TYPE_OVERFLOW,
308  NonTerminal = CAL_BDD_TYPE_NONTERMINAL
309  };
310 
314  Type_t Type() const
315  { return static_cast<Type_t>(Cal_BddType(this->_bddManager, this->_bdd)); }
316 
323  unsigned long Size(bool negout = true) const
324  { return Cal_BddSize(this->_bddManager, this->_bdd, negout); }
325 
332  double SatisfyingFraction() const
333  { return Cal_BddSatisfyingFraction(this->_bddManager, this->_bdd); }
334 
336  // Operations
337 public:
338 
344  BDD Identity() const
345  { return BDD(this->_bddManager, Cal_BddIdentity(this->_bddManager, this->_bdd)); }
346 
352  BDD Regular() const
353  {
354  // Unlike other BDD operations of CAL, `Cal_BddGetRegular` does not
355  // increment the reference count of its output. Hence, we have to do so here
356  // to compensate for the `Free(...)` in `~BDD()`.
357  BDD res(this->_bddManager, Cal_BddGetRegular(this->_bddManager, this->_bdd));
358  BDD::UnFree(res._bddManager, res._bdd);
359  return res;
360  }
361 
365  BDD Not() const
366  { return BDD(this->_bddManager, Cal_BddNot(this->_bddManager, this->_bdd)); }
367 
371  BDD operator~ () const
372  { return this->Not(); }
373 
381  BDD Compose(const BDD &g, const BDD &h) const
382  { return BDD(this->_bddManager, Cal_BddCompose(this->_bddManager, this->_bdd, g._bdd, h._bdd)); }
383 
389  BDD Intersects(const BDD &g) const
390  { return BDD(this->_bddManager, Cal_BddIntersects(this->_bddManager, this->_bdd, g._bdd)); }
391 
397  BDD Implies(const BDD &g) const
398  { return BDD(this->_bddManager, Cal_BddImplies(this->_bddManager, this->_bdd, g._bdd)); }
399 
409  BDD ITE(const BDD &g, const BDD &h) const
410  { return BDD(this->_bddManager, Cal_BddITE(this->_bddManager, this->_bdd, g._bdd, h._bdd)); }
411 
415  BDD And(const BDD &g) const
416  { return BDD(this->_bddManager, Cal_BddAnd(this->_bddManager, this->_bdd, g._bdd)); }
417 
421  BDD operator& (const BDD &other) const
422  { return this->And(other); }
423 
427  BDD& operator&= (const BDD &other)
428  { return (*this = (*this) & other); }
429 
433  BDD Nand(const BDD &g) const
434  { return BDD(this->_bddManager, Cal_BddNand(this->_bddManager, this->_bdd, g._bdd)); }
435 
439  BDD Or(const BDD &g) const
440  { return BDD(this->_bddManager, Cal_BddOr(this->_bddManager, this->_bdd, g._bdd)); }
441 
445  BDD operator| (const BDD &other) const
446  { return this->Or(other); }
447 
451  BDD& operator|= (const BDD &other)
452  { return (*this = (*this) | other); }
453 
457  BDD Nor(const BDD &g) const
458  { return BDD(this->_bddManager, Cal_BddNor(this->_bddManager, this->_bdd, g._bdd)); }
459 
463  BDD Xor(const BDD &g) const
464  { return BDD(this->_bddManager, Cal_BddXor(this->_bddManager, this->_bdd, g._bdd)); }
465 
469  BDD operator^ (const BDD &other) const
470  { return this->Xor(other); }
471 
475  BDD& operator^= (const BDD &other)
476  { return (*this = (*this) ^ other); }
477 
481  BDD Xnor(const BDD &g) const
482  { return BDD(this->_bddManager, Cal_BddXnor(this->_bddManager, this->_bdd, g._bdd)); }
483 
487  BDD Diff(const BDD &g) const
488  { return *this & ~g; }
489 
493  BDD operator- (const BDD &other) const
494  { return this->Diff(other); }
495 
499  BDD& operator-= (const BDD &other)
500  { return (*this = (*this) - other); }
501 
508  BDD Satisfy() const
509  { return BDD(this->_bddManager, Cal_BddSatisfy(this->_bddManager, this->_bdd)); }
510 
520  { return BDD(this->_bddManager, Cal_BddSatisfySupport(this->_bddManager, this->_bdd)); }
521 
530  BDD SwapVars(const BDD &g, const BDD &h) const
531  { return BDD(this->_bddManager, Cal_BddSwapVars(this->_bddManager, this->_bdd, g._bdd, h._bdd)); }
532 
535  // BDD Exists(...) const
536 
539  // BDD ForAll(...) const
540 
543  // BDD RelProd(const BDD &g) const
544 
553  BDD Cofactor(const BDD &c) const
554  { return BDD(this->_bddManager, Cal_BddCofactor(this->_bddManager, this->_bdd, c._bdd)); }
555 
567  BDD Reduce(const BDD &c) const
568  { return BDD(this->_bddManager, Cal_BddReduce(this->_bddManager, this->_bdd, c._bdd)); }
569 
571  // Debugging
572 public:
573 
577  void Print(FILE *fp = stdout) const
578  {
579  // TODO: Extend to use your own NamingFn and TerminalIdFn
580  // (and their environment).
581  Cal_BddPrintBdd(this->_bddManager, this->_bdd,
583  fp);
584  }
585 
589  void FunctionPrint(std::string &name) const
590  { Cal_BddFunctionPrint(this->_bddManager, this->_bdd, name.data()); }
591 
598  std::vector<long> Profile(bool negout = true) const
599  {
600  std::vector<long> results;
601  results.reserve(Cal_BddVars(this->_bddManager)+1);
602  Cal_BddProfile(this->_bddManager, this->_bdd, results.data(), negout);
603  return results;
604  }
605 
613  void PrintProfile(int lineLength = 79, FILE *fp = stdout) const
614  {
615  // TODO: Extend to use your own NamingFn (and its environment).
616  Cal_BddPrintProfile(this->_bddManager, this->_bdd,
617  Cal_BddNamingFnNone, NULL,
618  lineLength, fp);
619  }
620 
630  std::vector<long> FunctionProfile() const
631  {
632  std::vector<long> results;
633  results.reserve(Cal_BddVars(this->_bddManager)+1);
634  Cal_BddFunctionProfile(this->_bddManager, this->_bdd, results.data());
635  return results;
636  }
637 
638 
647  void PrintFunctionProfile(int lineLength = 79, FILE *fp = stdout) const
648  {
649  // TODO: Extend to use your own NamingFn (and its environment).
650  Cal_BddPrintFunctionProfile(this->_bddManager, this->_bdd,
651  Cal_BddNamingFnNone, NULL,
652  lineLength, fp);
653  }
654 
662  int RefCount() const
663  {
664  if (this->IsNull()) {
665  return 255; // <-- Simulate NULL has fixed MAX reference count.
666  }
667 
668  CalBddNode_t *internal_node = CAL_BDD_POINTER(this->_bdd);
669 
670  int res;
671  CalBddNodeGetRefCount(internal_node, res);
672 
673  return res;
674  }
675 
679  std::string ToString() const
680  {
681  if (this->IsNull()) { return "NULL"; }
682  if (this->IsZero()) { return "(0)"; }
683  if (this->IsOne()) { return "(1)"; }
684 
685  std::stringstream ss;
686  ss << "("
687  << this->Id() << ", "
688  << this->Then()._bdd << ", "
689  << this->Else()._bdd
690  << ")";
691 
692  return ss.str();
693  }
694 
696  // Conversion back and from C null-terminated arrays.
697 protected:
698 
700 
708  template<typename IT>
709  static std::vector<Cal_Bdd>
710  C_Bdd_vector(Cal_BddManager bddManager, IT begin, IT end)
711  {
712  // TODO: tidy up with template overloading
713 
714  std::vector<Cal_Bdd> out;
715  out.reserve(std::distance(begin, end));
716 
717  while (begin != end) {
718  const typename IT::value_type &x = *(begin++);
719 
720  if constexpr (std::is_same_v<typename IT::value_type, BDD>) {
721  // TODO: assert same 'bddManager'...
722 
723  BDD::UnFree(x._bddManager, x._bdd);
724  out.push_back(x._bdd);
725  } else if constexpr (std::is_same_v<typename IT::value_type, int>) {
726  out.push_back(Cal_BddManagerGetVarWithId(bddManager, x));
727  }
728  }
729 
730  out.push_back(Cal_BddNull(bddManager));
731 
732  return out;
733  }
734 
739  static std::vector<BDD>
740  From_C_Array(Cal_BddManager bddManager, Cal_Bdd * bddArray)
741  {
742  std::vector<BDD> res;
743 
744  for (int i = 0; Cal_BddIsBddNull(bddManager, bddArray[i]) == 0; i++){
745  if (CalBddPreProcessing(bddManager, 1, bddArray[i]) == 0){
746  return std::vector<BDD>();
747  }
748  res.push_back(BDD(bddManager, bddArray[i]));
749  }
750 
751  return res;
752  }
753 
755 
757  // Memory Management
758 private:
759 
761 
762  // TODO: move further down
763 
765  static inline bool
766  IsNull(Cal_BddManager bddManager, Cal_Bdd f)
767  { return Cal_BddIsBddNull(bddManager, f); }
768 
770  static inline void
771  Free(Cal_BddManager bddManager, Cal_Bdd f)
772  { if (!BDD::IsNull(bddManager, f)) Cal_BddFree(bddManager, f); }
773 
775  inline void
776  Free()
777  { BDD::Free(this->_bddManager, this->_bdd); }
778 
780  template<typename IT>
781  static inline void
782  Free(IT begin, IT end)
783  {
784  static_assert(std::is_same_v<typename IT::value_type, BDD>,
785  "Must be called with iterator for BDD");
786 
787  while (begin != end) (begin++)->Free();
788  }
789 
791  template<typename IT>
792  static inline void
793  Free(Cal_BddManager bddManager, IT begin, IT end)
794  {
795  static_assert(std::is_same_v<typename IT::value_type, Cal_Bdd>,
796  "Must be called with iterator for Cal_Bdd");
797 
798  while (begin != end) BDD::Free(bddManager, *(begin++));
799  }
800 
802  static inline void
803  UnFree(Cal_BddManager bddManager, Cal_Bdd f)
804  { if (!BDD::IsNull(bddManager, f)) Cal_BddUnFree(bddManager, f); }
805 
807  inline void
808  UnFree()
809  { BDD::UnFree(this->_bddManager, this->_bdd); }
810 
812 };
813 
822 class Cal
823 {
824  friend BDD;
825 
827  // Types
828 
832  using Bdd_t = BDD;
833 
838  using Id_t = BDD::Id_t;
839 
844  using Index_t = BDD::Index_t;
845 
846  // ---------------------------------------------------------------------------
847  // Fields
848  // TODO -----------------------------------------------
849  // Multiple Cal objects for the same Cal_BddManager
850  // ----------------------------------------------- TODO
851  //
852  // Use a 'std::shared_ptr' for reference counting this 'Cal_BddManager'
853  // pointer. The 'Cal_BddManagerQuit' function is then the managed pointer's
854  // deleter.
855  //
856  // NOTE -------------------------------------------- NOTE
857  //
858  // If so, should all BDD objects also be part of this reference counting?
859  // Otherwise, if a BDD object survives for longer than the BDD manager, then
860  // it will result in Segmentation Faults. Arguably this is already an
861  // issue...
862  Cal_BddManager _bddManager;
863 
865  // Constructors
866 public:
867 
871  Cal()
872  : _bddManager(Cal_BddManagerInit())
873  { }
874 
878  Cal(unsigned int numVars)
879  : Cal()
880  {
881  // Create variables
882  for (Id_t i = 0; i < numVars; ++i) {
883  this->CreateNewVarLast();
884  }
885  }
886 
888  // TODO: Copy constructor (requires reference counting)
889  Cal(const Cal &o) = delete;
890 
894  Cal(Cal &&o)
895  : _bddManager(o._bddManager)
896  {
897  o._bddManager = nullptr;
898  }
899 
907  {
908  if (this->_bddManager)
909  Cal_BddManagerQuit(this->_bddManager);
910  }
911 
913  // Settings + Statistics
914 
930  void SetParameters(long reorderingThreshold,
931  long maxForwardedNodes,
932  double repackAfterGCThreshold,
933  double tableRepackThreshold)
934  {
935  return Cal_BddManagerSetParameters(this->_bddManager,
936  reorderingThreshold,
937  maxForwardedNodes,
938  repackAfterGCThreshold,
939  tableRepackThreshold);
940  }
941 
947  unsigned long Nodes() const
948  { return Cal_BddManagerGetNumNodes(this->_bddManager); }
949 
953  long Vars() const
954  { return Cal_BddVars(this->_bddManager); }
955 
963  bool Overflow() const
964  { return Cal_BddOverflow(this->_bddManager); }
965 
971  unsigned long TotalSize() const
972  { return Cal_BddTotalSize(this->_bddManager); }
973 
977  void Stats(FILE* fp = stdout) const
978  { Cal_BddStats(this->_bddManager, fp); }
979 
980  // TODO: obtain error
981 
983  // Memory and Garbage Collection
984 
992  long NodeLimit(long newLimit)
993  { return Cal_BddNodeLimit(this->_bddManager, newLimit); }
994 
998  void SetGCMode(bool enableGC)
999  { Cal_BddSetGCMode(this->_bddManager, enableGC); }
1000 
1011  void SetGCLimit()
1012  { Cal_BddManagerSetGCLimit(this->_bddManager); }
1013 
1021  void GC()
1022  { Cal_BddManagerGC(this->_bddManager); }
1023 
1025  // Reordering
1026 
1033  None = CAL_REORDER_NONE,
1034  Sift = CAL_REORDER_SIFT,
1035  Window = CAL_REORDER_WINDOW
1036  };
1037 
1045  BF = CAL_REORDER_METHOD_BF,
1046  DF = CAL_REORDER_METHOD_DF
1047  };
1048 
1054  void DynamicReordering(ReorderTechnique technique, ReorderMethod method = ReorderMethod::DF)
1055  {
1056  Cal_BddDynamicReordering(this->_bddManager, technique, method);
1057  }
1058 
1066  void Reorder()
1067  { Cal_BddReorder(this->_bddManager); }
1068 
1070  // Association List
1071 
1072  // TODO: use RAII to hide association identifiers
1073  // TODO: container-based functions
1074 
1093  template<typename IT>
1094  int AssociationInit(IT begin, IT end, const bool pairs = false)
1095  {
1096  std::vector<Cal_Bdd> c_arg =
1097  BDD::C_Bdd_vector(this->_bddManager, std::move(begin), std::move(end));
1098 
1099  const int res = Cal_AssociationInit(this->_bddManager, c_arg.data(), pairs);
1100 
1101  BDD::Free(this->_bddManager, c_arg.begin(), c_arg.end());
1102 
1103  return res;
1104  }
1105 
1118  { return Cal_AssociationSetCurrent(this->_bddManager, i); }
1119 
1128  void AssociationQuit(int i)
1129  { Cal_AssociationQuit(this->_bddManager, i); }
1130 
1142  template<typename IT>
1143  void TempAssociationInit(IT begin, const IT end, const bool pairs = false)
1144  {
1145  std::vector<Cal_Bdd> c_arg =
1146  BDD::C_Bdd_vector(this->_bddManager, std::move(begin), std::move(end));
1147 
1148  Cal_TempAssociationInit(this->_bddManager, c_arg.data(), pairs);
1149 
1150  BDD::Free(this->_bddManager, c_arg.begin(), c_arg.end());
1151  }
1152 
1164  template<typename IT>
1165  void TempAssociationAugment(IT begin, const IT end, const bool pairs = false)
1166  {
1167  std::vector<Cal_Bdd> c_arg =
1168  BDD::C_Bdd_vector(this->_bddManager, std::move(begin), std::move(end));
1169 
1170  Cal_TempAssociationAugment(this->_bddManager, c_arg.data(), pairs);
1171 
1172  BDD::Free(this->_bddManager, c_arg.begin(), c_arg.end());
1173  }
1174 
1181  { Cal_TempAssociationQuit(this->_bddManager); }
1182 
1184  // Save / Load BDDs
1185 
1186  // BDD UndumpBdd(IT vars_begin, IT vars_end, FILE *f, int &error)
1187  // BDD DumpBdd(const BDD &f, IT vars_begin, IT vars_end, FILE *f, int &error)
1188 
1190  // BDD Constructors
1191 
1195  BDD Null() const
1196  { return BDD(this->_bddManager, Cal_BddNull(this->_bddManager)); }
1197 
1203  BDD One() const
1204  { return BDD(this->_bddManager, Cal_BddOne(this->_bddManager)); }
1205 
1211  BDD Zero() const
1212  { return BDD(this->_bddManager, Cal_BddZero(this->_bddManager)); }
1213 
1219  BDD Id(Id_t id) const
1220  { return BDD(this->_bddManager, Cal_BddManagerGetVarWithId(this->_bddManager, id)); }
1221 
1228  BDD Index(Index_t idx) const
1229  { return BDD(this->_bddManager, Cal_BddManagerGetVarWithIndex(this->_bddManager, idx)); }
1230 
1235  { return BDD(this->_bddManager, Cal_BddManagerCreateNewVarFirst(this->_bddManager)); }
1236 
1241  { return BDD(this->_bddManager, Cal_BddManagerCreateNewVarLast(this->_bddManager)); }
1242 
1248  { return BDD(this->_bddManager, Cal_BddManagerCreateNewVarBefore(this->_bddManager, x._bdd)); }
1249 
1255  { return BDD(this->_bddManager, Cal_BddManagerCreateNewVarAfter(this->_bddManager, x._bdd)); }
1256 
1258  // BDD Predicates
1259 
1263  bool IsNull(const BDD &f) const
1264  { return f.IsNull(); }
1265 
1271  bool IsOne(const BDD &f) const
1272  { return f.IsOne(); }
1273 
1279  bool IsZero(const BDD &f) const
1280  { return f.IsZero(); }
1281 
1288  bool IsConst(const BDD &f) const
1289  { return f.IsConst(); }
1290 
1294  bool IsCube(const BDD &f) const
1295  { return f.IsCube(); }
1296 
1302  bool IsEqual(const BDD &f, const BDD &g) const
1303  { return f.IsEqualTo(g); }
1304 
1310  bool DependsOn(const BDD &f, const BDD &var) const
1311  { return f.DependsOn(var); }
1312 
1314  // BDD Information
1315 
1322  double SatisfyingFraction(const BDD &f)
1323  { return f.SatisfyingFraction(); }
1324 
1333  unsigned long Size(const BDD &f, bool negout = true)
1334  { return f.Size(negout); }
1335 
1347  template<typename IT>
1348  unsigned long Size(IT begin, IT end, bool negout = true)
1349  {
1350  static_assert(std::is_same_v<typename IT::value_type, BDD>,
1351  "Must be called with iterator for BDD");
1352 
1353  std::vector<Cal_Bdd> c_arg =
1354  BDD::C_Bdd_vector(this->_bddManager, std::move(begin), std::move(end));
1355 
1356  const unsigned long res = Cal_BddSizeMultiple(this->_bddManager, c_arg.data(), negout);
1357 
1358  BDD::Free(this->_bddManager, c_arg.begin(), c_arg.end());
1359 
1360  return res;
1361  }
1362 
1372  template<typename Container>
1373  unsigned long Size(Container c, bool negout = true)
1374  { return Size(std::begin(c), std::end(c), negout); }
1375 
1378  // container_t<BDD> Support(const BDD &f);
1379 
1381  // Manipulation
1382 
1388  BDD Identity(const BDD &f)
1389  { return f.Identity(); }
1390 
1396  BDD Regular(const BDD &f)
1397  { return f.Regular(); }
1398 
1402  BDD Not(const BDD &f)
1403  { return f.Not(); }
1404 
1410  BDD Compose(const BDD &f, const BDD &g, const BDD &h)
1411  { return f.Compose(g, h); }
1412 
1418  BDD Intersects(const BDD &f, const BDD &g)
1419  { return f.Intersects(g); }
1420 
1426  BDD Implies(const BDD &f, const BDD &g)
1427  { return f.Implies(g); }
1428 
1434  BDD ITE(const BDD &f, const BDD &g, const BDD &h)
1435  { return f.ITE(g, h); }
1436 
1442  BDD And(const BDD &f, const BDD &g)
1443  { return f.And(g); }
1444 
1458  template<typename IT>
1459  BDD And(IT begin, IT end)
1460  {
1461  std::vector<Cal_Bdd> c_arg =
1462  BDD::C_Bdd_vector(this->_bddManager, std::move(begin), std::move(end));
1463 
1464  const BDD res(this->_bddManager, Cal_BddMultiwayAnd(this->_bddManager, c_arg.data()));
1465 
1466  BDD::Free(this->_bddManager, c_arg.begin(), c_arg.end());
1467 
1468  return res;
1469  }
1470 
1482  template<typename Container>
1483  BDD And(const Container &c)
1484  { return And(std::begin(c), std::end(c)); }
1485 
1491  BDD Nand(const BDD &f, const BDD &g)
1492  { return f.Nand(g); }
1493 
1497  BDD Or(const BDD &f, const BDD &g)
1498  { return f.Or(g); }
1499 
1513  template<typename IT>
1514  BDD Or(IT begin, IT end)
1515  {
1516  std::vector<Cal_Bdd> c_arg =
1517  BDD::C_Bdd_vector(this->_bddManager, std::move(begin), std::move(end));
1518 
1519  const BDD res(this->_bddManager, Cal_BddMultiwayOr(this->_bddManager, c_arg.data()));
1520 
1521  BDD::Free(this->_bddManager, c_arg.begin(), c_arg.end());
1522 
1523  return res;
1524  }
1525 
1537  template<typename Container>
1538  BDD Or(const Container &c)
1539  { return Or(std::begin(c), std::end(c)); }
1540 
1546  BDD Nor(const BDD &f, const BDD &g)
1547  { return f.Nor(g); }
1548 
1552  BDD Xor(const BDD &f, const BDD &g)
1553  { return f.Xor(g); }
1554 
1568  template<typename IT>
1569  BDD Xor(IT begin, IT end)
1570  {
1571  std::vector<Cal_Bdd> c_arg =
1572  BDD::C_Bdd_vector(this->_bddManager, std::move(begin), std::move(end));
1573 
1574  const BDD res(this->_bddManager, Cal_BddMultiwayXor(this->_bddManager, c_arg.data()));
1575 
1576  BDD::Free(this->_bddManager, c_arg.begin(), c_arg.end());
1577 
1578  return res;
1579  }
1580 
1592  template<typename Container>
1593  BDD Xor(const Container &c)
1594  { return Xor(std::begin(c), std::end(c)); }
1595 
1599  BDD Xnor(const BDD &f, const BDD &g)
1600  { return f.Xnor(g); }
1601 
1615  template<typename IT>
1616  std::vector<BDD>
1617  PairwiseAnd(IT begin, IT end)
1618  {
1619  std::vector<Cal_Bdd> c_arg =
1620  BDD::C_Bdd_vector(this->_bddManager, std::move(begin), std::move(end));
1621 
1622  std::vector<BDD> res =
1623  BDD::From_C_Array(this->_bddManager, Cal_BddPairwiseAnd(this->_bddManager, c_arg.data()));
1624 
1625  BDD::Free(this->_bddManager, c_arg.begin(), c_arg.end());
1626 
1627  return res;
1628  }
1629 
1641  template<typename Container>
1642  std::vector<BDD>
1643  PairwiseAnd(const Container &c)
1644  { return PairwiseAnd(std::begin(c), std::end(c)); }
1645 
1659  template<typename IT>
1660  std::vector<BDD>
1661  PairwiseOr(IT begin, IT end)
1662  {
1663  std::vector<Cal_Bdd> c_arg =
1664  BDD::C_Bdd_vector(this->_bddManager, std::move(begin), std::move(end));
1665 
1666  std::vector<BDD> res =
1667  BDD::From_C_Array(this->_bddManager, Cal_BddPairwiseOr(this->_bddManager, c_arg.data()));
1668 
1669  BDD::Free(this->_bddManager, c_arg.begin(), c_arg.end());
1670 
1671  return res;
1672  }
1673 
1685  template<typename Container>
1686  std::vector<BDD>
1687  PairwiseOr(const Container &c)
1688  { return PairwiseOr(std::begin(c), std::end(c)); }
1689 
1696  template<typename IT>
1697  std::vector<BDD>
1698  PairwiseXor(IT begin, IT end)
1699  {
1700  std::vector<Cal_Bdd> c_arg =
1701  BDD::C_Bdd_vector(this->_bddManager, std::move(begin), std::move(end));
1702 
1703  std::vector<BDD> res =
1704  BDD::From_C_Array(this->_bddManager, Cal_BddPairwiseXor(this->_bddManager, c_arg.data()));
1705 
1706  BDD::Free(this->_bddManager, c_arg.begin(), c_arg.end());
1707 
1708  return res;
1709  }
1710 
1720  template<typename Container>
1721  std::vector<BDD>
1722  PairwiseXor(const Container &c)
1723  { return PairwiseXor(std::begin(c), std::end(c)); }
1724 
1732  BDD Satisfy(const BDD &f)
1733  { return f.Satisfy(); }
1734 
1743  { return f.SatisfySupport(); }
1744 
1755  BDD Substitute(const BDD &f)
1756  { return BDD(this->_bddManager, Cal_BddSubstitute(this->_bddManager, f._bdd)); }
1757 
1759  // \brief Substitute a set of variables by set of another variables.
1760  //
1761  // \details Returns a BDD for `f` using the substitution defined by current
1762  // variable association. It is assumed that each variable is replaced by
1763  // another variable.
1764  //
1765  // \remark For the substitution of a variable by a function, use
1766  // `Cal_BddSubstitute` instead.
1767  //
1768  // \see Cal::Substitute(), Cal::AssociationInit(), Cal::TempAssociationInit()
1770  BDD VarSubstitute(const BDD &f)
1771  { return BDD(this->_bddManager, Cal_BddVarSubstitute(this->_bddManager, f._bdd)); }
1772 
1781  BDD SwapVars(const BDD &f, const BDD &g, const BDD &h)
1782  { return f.SwapVars(g, h); }
1783 
1793  BDD Exists(const BDD &f)
1794  { return BDD(this->_bddManager, Cal_BddExists(this->_bddManager, f._bdd)); }
1795 
1805  BDD ForAll(const BDD &f)
1806  { return BDD(this->_bddManager, Cal_BddForAll(this->_bddManager, f._bdd)); }
1807 
1817  BDD RelProd(const BDD &f, const BDD &g)
1818  { return BDD(this->_bddManager, Cal_BddRelProd(this->_bddManager, f._bdd, g._bdd)); }
1819 
1829  BDD Cofactor(const BDD &f, const BDD &c)
1830  { return f.Cofactor(c); }
1831 
1842  BDD Reduce(const BDD &f, const BDD &c)
1843  { return f.Reduce(c); }
1844 
1855  BDD Between(const BDD &fMin, const BDD &fMax)
1856  { return BDD(this->_bddManager, Cal_BddBetween(this->_bddManager, fMin._bdd, fMax._bdd)); }
1857 
1859  // BDD Node Access / Traversal
1860 
1866  BDD If(const BDD &f) const
1867  { return f.If(); }
1868 
1874  Id_t IfId(const BDD &f) const
1875  { return f.Id(); }
1876 
1882  Index_t IfIndex(const BDD &f) const
1883  { return f.Index(); }
1884 
1891  BDD Then(const BDD &f)
1892  { return f.Then(); }
1893 
1900  BDD Else(const BDD &f)
1901  { return f.Else(); }
1902 
1904  // Debugging
1905 
1915  void Print(const BDD &f, FILE *fp = stdout) const
1916  { f.Print(fp); }
1917 
1923  void FunctionPrint(const BDD &f, std::string &name) const
1924  { f.FunctionPrint(name); }
1925 
1936  std::vector<long> Profile(const BDD &f, bool negout = true) const
1937  { return f.Profile(negout); }
1938 
1952  template<typename IT>
1953  std::vector<long> Profile(IT begin, IT end, bool negout = true) const
1954  {
1955  std::vector<Cal_Bdd> c_arg =
1956  BDD::C_Bdd_vector(this->_bddManager, std::move(begin), std::move(end));
1957 
1958  std::vector<long> levelCounts;
1959  levelCounts.reserve(this->Vars()+1);
1960 
1961  Cal_BddProfileMultiple(this->_bddManager,
1962  c_arg.data(),
1963  levelCounts.data(),
1964  negout);
1965 
1966  BDD::Free(this->_bddManager, c_arg.begin(), c_arg.end());
1967 
1968  return levelCounts;
1969  }
1970 
1982  template<typename Container>
1983  std::vector<long> Profile(const Container &c, bool negout = true) const
1984  { return Profile(c.begin(), c.end(), negout); }
1985 
1995  void PrintProfile(const BDD &f, int lineLength = 79, FILE *fp = stdout) const
1996  { return f.PrintProfile(lineLength, fp); }
1997 
2010  template<typename IT>
2011  void PrintProfile(IT begin, IT end,
2012  int lineLength = 79,
2013  FILE *fp = stdout) const
2014  {
2015  std::vector<Cal_Bdd> c_arg =
2016  BDD::C_Bdd_vector(this->_bddManager, std::move(begin), std::move(end));
2017 
2018  // TODO: Extend to use your own NamingFn (and its environment).
2019  Cal_BddPrintProfileMultiple(this->_bddManager, c_arg.data(),
2020  Cal_BddNamingFnNone, NULL,
2021  lineLength, fp);
2022 
2023  BDD::Free(this->_bddManager, c_arg.begin(), c_arg.end());
2024  }
2025 
2036  template<typename Container>
2037  void PrintProfile(const Container &c,
2038  int lineLength = 79,
2039  FILE *fp = stdout) const
2040  { PrintProfile(c.begin(), c.end(), lineLength, fp); }
2041 
2050  std::vector<long> FunctionProfile(const BDD &f) const
2051  { return f.FunctionProfile(); }
2052 
2063  template<typename IT>
2064  std::vector<long> FunctionProfile(IT begin, IT end) const
2065  {
2066  std::vector<Cal_Bdd> c_arg =
2067  BDD::C_Bdd_vector(this->_bddManager, std::move(begin), std::move(end));
2068 
2069  std::vector<long> funcCounts;
2070  funcCounts.reserve(Vars()+1);
2071 
2072  Cal_BddFunctionProfileMultiple(this->_bddManager, c_arg.data(), funcCounts.data());
2073 
2074  BDD::Free(this->_bddManager, c_arg.begin(), c_arg.end());
2075 
2076  return funcCounts;
2077  }
2078 
2087  template<typename Container>
2088  std::vector<long> FunctionProfile(const Container &c) const
2089  { return FunctionProfile(c.begin(), c.end()); }
2090 
2103  void PrintFunctionProfile(const BDD &f,
2104  int lineLength = 79,
2105  FILE *fp = stdout) const
2106  { return f.PrintFunctionProfile(lineLength, fp); }
2107 
2108 
2123  template<typename IT>
2124  void PrintFunctionProfile(IT begin, IT end,
2125  int lineLength = 79,
2126  FILE *fp = stdout) const
2127  {
2128  std::vector<Cal_Bdd> c_arg =
2129  BDD::C_Bdd_vector(this->_bddManager, std::move(begin), std::move(end));
2130 
2131  // TODO: Extend to use your own NamingFn (and its environment).
2132  Cal_BddPrintFunctionProfileMultiple(this->_bddManager, c_arg.data(),
2133  Cal_BddNamingFnNone, NULL,
2134  lineLength, fp);
2135 
2136  BDD::Free(this->_bddManager, c_arg.begin(), c_arg.end());
2137  }
2138 
2151  template<typename Container>
2152  void PrintFunctionProfile(const Container &c,
2153  int lineLength = 79,
2154  FILE *fp = stdout) const
2155  { PrintFunctionProfile(c.begin(), c.end(), lineLength, fp); }
2156 
2158  // BDD Pipelining
2159 
2160  // TODO: class Pipeline using RAII and operator overloading
2161 
2163  // NOTE: These should never be exposed (hidden inside of the BDD class)
2164 
2165  // void Free();
2166  // void UnFree();
2167 };
2168 
2171 
2172 #endif /* _CALOBJ */
C++ wrapper for Cal_Bdd, managing reference count with RAII.
Definition: calObj.hh:73
BDD Regular() const
Returns a BDD in positive form (regardless of this BDDs phase).
Definition: calObj.hh:352
BDD ITE(const BDD &g, const BDD &h) const
Logical If-Then-Else.
Definition: calObj.hh:409
BDD Then() const
The positive cofactor of this BDD with respect to its top variable.
Definition: calObj.hh:279
Id_t Id() const
Returns the id of this BDD's top variable.
Definition: calObj.hh:264
bool IsNull() const
true if the this BDD is NULL, false otherwise.
Definition: calObj.hh:201
std::string ToString() const
String representation of this BDD node.
Definition: calObj.hh:679
Cal_BddIndex_t Index_t
Type of BDD indices, i.e. their placement in the current variable ordering.
Definition: calObj.hh:89
unsigned long Size(bool negout=true) const
This BDD's size.
Definition: calObj.hh:323
bool operator!=(const BDD &other) const
false if argument BDDs are equal, true otherwise.
Definition: calObj.hh:238
bool IsCube() const
true if the this BDD is a cube, false otherwise.
Definition: calObj.hh:216
bool IsConst() const
true if the this BDD is either constant one or constant zero, otherwise returns false.
Definition: calObj.hh:210
BDD(BDD &&other)
Move ownership of another BDD.
Definition: calObj.hh:149
void PrintProfile(int lineLength=79, FILE *fp=stdout) const
Prints a BDD in the human readable form.
Definition: calObj.hh:613
BDD & operator|=(const BDD &other)
Definition: calObj.hh:451
BDD Intersects(const BDD &g) const
Computes a BDD that implies conjunction of this and g.
Definition: calObj.hh:389
void FunctionPrint(std::string &name) const
Prints the function implemented by this BDD.
Definition: calObj.hh:589
BDD SwapVars(const BDD &g, const BDD &h) const
The function obtained by swapping two variables.
Definition: calObj.hh:530
BDD & operator^=(const BDD &other)
Definition: calObj.hh:475
std::vector< long > FunctionProfile() const
The number of subfunctions of this which may be obtained by restricting variables with an index lower...
Definition: calObj.hh:630
BDD & operator=(const BDD &other)
Copy ownership of another BDD during assignment.
Definition: calObj.hh:134
BDD Identity() const
Duplicate of this BDD.
Definition: calObj.hh:344
BDD Reduce(const BDD &c) const
A function that agrees with this for all valuations which satisfy c.
Definition: calObj.hh:567
BDD(const BDD &other)
Copies ownership of another BDD.
Definition: calObj.hh:125
bool IsZero() const
true if the this BDD is constant zero, falseotherwise.
Definition: calObj.hh:195
void PrintFunctionProfile(int lineLength=79, FILE *fp=stdout) const
Similar to BDD::PrintProfile() but displays a function profile for this.
Definition: calObj.hh:647
Index_t Index() const
Returns the index of this BDD's top variable.
Definition: calObj.hh:272
BDD operator~() const
Definition: calObj.hh:371
Type_t
Possible types a BDD can be.
Definition: calObj.hh:294
@ Negvar
Definition: calObj.hh:304
@ One
Definition: calObj.hh:298
@ Posvar
Definition: calObj.hh:302
@ Constant
Definition: calObj.hh:300
@ Overflow
Definition: calObj.hh:306
@ Zero
Definition: calObj.hh:296
@ NonTerminal
Definition: calObj.hh:308
BDD Diff(const BDD &g) const
Logical Difference operation.
Definition: calObj.hh:487
BDD Nand(const BDD &g) const
Logical Negated AND operation.
Definition: calObj.hh:433
BDD & operator-=(const BDD &other)
Definition: calObj.hh:499
BDD operator-(const BDD &other) const
Definition: calObj.hh:493
bool IsEqualTo(const BDD &other) const
true if this BDD is equal to other, false otherwise.
Definition: calObj.hh:222
~BDD()
Decrement reference count upon leaving scope.
Definition: calObj.hh:173
BDD And(const BDD &g) const
Logical AND operation.
Definition: calObj.hh:415
BDD SatisfySupport() const
Returns a special cube contained in this.
Definition: calObj.hh:519
BDD operator&(const BDD &other) const
Definition: calObj.hh:421
bool DependsOn(const BDD &var) const
true if this depends on var, false otherwise.
Definition: calObj.hh:244
BDD & operator&=(const BDD &other)
Definition: calObj.hh:427
BDD Satisfy() const
A satisfying assignment of this BDD.
Definition: calObj.hh:508
double SatisfyingFraction() const
Fraction of valuations which make this BDD true.
Definition: calObj.hh:332
Type_t Type() const
The BDD type (0, 1, +var, -var, overflow, nonterminal).
Definition: calObj.hh:314
BDD operator|(const BDD &other) const
Definition: calObj.hh:445
BDD Not() const
Complement of this BDD.
Definition: calObj.hh:365
BDD()
The NULL BDD.
Definition: calObj.hh:118
bool operator==(const BDD &other) const
true if argument BDDs are equal, false otherwise.
Definition: calObj.hh:230
BDD Xnor(const BDD &g) const
Logical Negated XOR operation.
Definition: calObj.hh:481
BDD Cofactor(const BDD &c) const
Generalized cofactor of this with respect to c.
Definition: calObj.hh:553
BDD operator^(const BDD &other) const
Definition: calObj.hh:469
bool IsOne() const
true if the this BDD is constant one, falseotherwise.
Definition: calObj.hh:187
BDD(Cal_BddManager bddManager, Cal_Bdd bdd)
Wrap C API Cal_Bdd to be managed by this new BDD object.
Definition: calObj.hh:110
BDD Implies(const BDD &g) const
Computes a BDD that implies conjunction of this and g.Not().
Definition: calObj.hh:397
BDD Else() const
The negative cofactor of this BDD with respect to its top variable.
Definition: calObj.hh:285
BDD Compose(const BDD &g, const BDD &h) const
Substitute a BDD variable by a function.
Definition: calObj.hh:381
Cal_BddId_t Id_t
Type of BDD identifiers, i.e. the variable name independent of the current variable ordering.
Definition: calObj.hh:83
BDD Xor(const BDD &g) const
Logical XOR operation.
Definition: calObj.hh:463
BDD Or(const BDD &g) const
Logical OR operation.
Definition: calObj.hh:439
BDD Nor(const BDD &g) const
Logical Negated OR operation.
Definition: calObj.hh:457
std::vector< long > Profile(bool negout=true) const
Obtain a vector with the number of nodes at each level in f.
Definition: calObj.hh:598
void Print(FILE *fp=stdout) const
Prints this BDD in the human readable form.
Definition: calObj.hh:577
int RefCount() const
The reference count of this BDD.
Definition: calObj.hh:662
BDD If() const
BDD corresponding to the top variable of the this BDD.
Definition: calObj.hh:256
Core Manager of everything BDDs, variables, and more.
Definition: calObj.hh:823
BDD Or(const BDD &f, const BDD &g)
Logical OR operation.
Definition: calObj.hh:1497
std::vector< BDD > PairwiseOr(const Container &c)
Pairwise OR of BDDs or ints within a container.
Definition: calObj.hh:1687
double SatisfyingFraction(const BDD &f)
Fraction of valuations which make this BDD true.
Definition: calObj.hh:1322
void PrintFunctionProfile(const BDD &f, int lineLength=79, FILE *fp=stdout) const
Similar to Cal::PrintProfile() but displays a function profile for the given BDD.
Definition: calObj.hh:2103
BDD CreateNewVarAfter(const BDD &x)
Create and obtain a new variable after the specified one in the variable order.
Definition: calObj.hh:1254
bool IsCube(const BDD &f) const
true if the given BDD is a cube, false otherwise.
Definition: calObj.hh:1294
BDD And(IT begin, IT end)
Logical AND of iterator of BDD or int.
Definition: calObj.hh:1459
BDD ForAll(const BDD &f)
Universal quantification of some variables from the given BDD.
Definition: calObj.hh:1805
void PrintProfile(const BDD &f, int lineLength=79, FILE *fp=stdout) const
Prints a BDD in the human readable form.
Definition: calObj.hh:1995
bool IsZero(const BDD &f) const
true if the given BDD is constant zero, falseotherwise.
Definition: calObj.hh:1279
BDD Not(const BDD &f)
Complement of the given BDD.
Definition: calObj.hh:1402
std::vector< long > FunctionProfile(const Container &c) const
Similar to Cal::FunctionProfile for a container of BDDs. But, this accounts for sharing of nodes.
Definition: calObj.hh:2088
BDD Between(const BDD &fMin, const BDD &fMax)
Function that contains fMin and is contained in fMax.
Definition: calObj.hh:1855
BDD Or(IT begin, IT end)
Logical OR of iterator of BDD or int.
Definition: calObj.hh:1514
void SetParameters(long reorderingThreshold, long maxForwardedNodes, double repackAfterGCThreshold, double tableRepackThreshold)
Sets appropriate fields of BDD Manager.
Definition: calObj.hh:930
void SetGCLimit()
Sets the limit of the garbage collection.
Definition: calObj.hh:1011
BDD Exists(const BDD &f)
Existentially quantification of some variables from the given BDD.
Definition: calObj.hh:1793
void PrintFunctionProfile(IT begin, IT end, int lineLength=79, FILE *fp=stdout) const
Similar to Cal::PrintFunctionProfile for an iterator of BDDs. But, this accounts for sharing of nodes...
Definition: calObj.hh:2124
std::vector< BDD > PairwiseOr(IT begin, IT end)
Pairwise OR of BDDs or ints provided by an iterator.
Definition: calObj.hh:1661
unsigned long Nodes() const
The number of BDD nodes.
Definition: calObj.hh:947
BDD Reduce(const BDD &f, const BDD &c)
Function that agrees with f for all valuations that satisfy c.
Definition: calObj.hh:1842
void AssociationQuit(int i)
Deletes the variable association given by id.
Definition: calObj.hh:1128
std::vector< BDD > PairwiseAnd(IT begin, IT end)
Pairwise AND of BDDs or ints provided by an iterator.
Definition: calObj.hh:1617
BDD Substitute(const BDD &f)
Substitute a set of variables by functions.
Definition: calObj.hh:1755
std::vector< long > FunctionProfile(IT begin, IT end) const
Similar to Cal::FunctionProfile for an iterator of BDDs. But, this accounts for sharing of nodes.
Definition: calObj.hh:2064
BDD Nand(const BDD &f, const BDD &g)
Logical Negated AND operation.
Definition: calObj.hh:1491
BDD Identity(const BDD &f)
Duplicate of given BDD.
Definition: calObj.hh:1388
bool DependsOn(const BDD &f, const BDD &var) const
true if the BDD f depends on var, false otherwise.
Definition: calObj.hh:1310
BDD Xor(IT begin, IT end)
Logical XOR of iterator of BDD or int.
Definition: calObj.hh:1569
bool Overflow() const
true if the node limit has been exceeded, false otherwise.
Definition: calObj.hh:963
int AssociationInit(IT begin, IT end, const bool pairs=false)
Creates or finds a variable association.
Definition: calObj.hh:1094
BDD SatisfySupport(const BDD &f)
Returns a special cube contained in this.
Definition: calObj.hh:1742
BDD One() const
The BDD for the constant one.
Definition: calObj.hh:1203
unsigned long Size(Container c, bool negout=true)
Similar to Cal::Size() for a container of BDDs. But, this accounts for sharing of nodes.
Definition: calObj.hh:1373
std::vector< long > FunctionProfile(const BDD &f) const
The number of subfunctions of the given BDD which may be obtained by restricting variables with an in...
Definition: calObj.hh:2050
long NodeLimit(long newLimit)
Sets the node limit to newLimit and returns the previous limit.
Definition: calObj.hh:992
BDD Id(Id_t id) const
The variable with the specified id, null if no such variable exists.
Definition: calObj.hh:1219
BDD Xnor(const BDD &f, const BDD &g)
Logical Negated XOR operation.
Definition: calObj.hh:1599
Cal(unsigned int numVars)
Initialize a new BDD Manager with variables [1, numVars].
Definition: calObj.hh:878
BDD And(const BDD &f, const BDD &g)
Logical AND operation.
Definition: calObj.hh:1442
unsigned long TotalSize() const
The number of nodes in the Unique table.
Definition: calObj.hh:971
BDD Nor(const BDD &f, const BDD &g)
Logical Negated OR operation.
Definition: calObj.hh:1546
BDD Then(const BDD &f)
The positive cofactor of the given BDD with respect to its top variable.
Definition: calObj.hh:1891
void PrintProfile(IT begin, IT end, int lineLength=79, FILE *fp=stdout) const
Similar to Cal::PrintProfile() for an iterator of BDDs. But, this accounts for sharing of nodes.
Definition: calObj.hh:2011
unsigned long Size(const BDD &f, bool negout=true)
This BDD's size.
Definition: calObj.hh:1333
std::vector< BDD > PairwiseXor(IT begin, IT end)
Pairwise XOR of BDDs or ints provided by an iterator.
Definition: calObj.hh:1698
BDD And(const Container &c)
Logical AND of container with BDDs or ints.
Definition: calObj.hh:1483
BDD Xor(const BDD &f, const BDD &g)
Logical XOR operation.w.
Definition: calObj.hh:1552
void SetGCMode(bool enableGC)
Enable or Disable garbage collection.
Definition: calObj.hh:998
void TempAssociationInit(IT begin, const IT end, const bool pairs=false)
Sets the temporary variable association.
Definition: calObj.hh:1143
long Vars() const
The number of BDD variables.
Definition: calObj.hh:953
void FunctionPrint(const BDD &f, std::string &name) const
Prints the function implemented by the given BDD.
Definition: calObj.hh:1923
BDD Compose(const BDD &f, const BDD &g, const BDD &h)
Substitute a BDD variable by a function, i.e. f[h/g].
Definition: calObj.hh:1410
void Stats(FILE *fp=stdout) const
Prints miscellaneous BDD statistics.
Definition: calObj.hh:977
Cal(Cal &&o)
Move ownership of C object.
Definition: calObj.hh:894
BDD RelProd(const BDD &f, const BDD &g)
Logical AND of the argument BDDs and existentially quantifying some variables from the product.
Definition: calObj.hh:1817
std::vector< long > Profile(const BDD &f, bool negout=true) const
Obtain a vector with the number of nodes at each level in f.
Definition: calObj.hh:1936
BDD ITE(const BDD &f, const BDD &g, const BDD &h)
Logical If-Then-Else.
Definition: calObj.hh:1434
bool IsOne(const BDD &f) const
true if the given BDD is constant one, falseotherwise.
Definition: calObj.hh:1271
BDD Zero() const
The BDD for the constant zero.
Definition: calObj.hh:1211
BDD SwapVars(const BDD &f, const BDD &g, const BDD &h)
The function obtained by swapping two variables.
Definition: calObj.hh:1781
std::vector< BDD > PairwiseXor(const Container &c)
Pairwise XOR of BDDs or ints within a container.
Definition: calObj.hh:1722
BDD Regular(const BDD &f)
The given BDD in positive form (regardless of its phase).
Definition: calObj.hh:1396
BDD CreateNewVarBefore(const BDD &x)
Create and obtain a new variable before the specified one in the variable order.
Definition: calObj.hh:1247
void GC()
Invokes the garbage collection at the manager level.
Definition: calObj.hh:1021
void TempAssociationQuit()
Cleans up temporary association.
Definition: calObj.hh:1180
BDD Intersects(const BDD &f, const BDD &g)
Computes a BDD that implies the conjunction of both BDDs.
Definition: calObj.hh:1418
std::vector< BDD > PairwiseAnd(const Container &c)
Pairwise AND of BDDs or ints within a container.
Definition: calObj.hh:1643
BDD If(const BDD &f) const
BDD corresponding to the top variable of the given BDD.
Definition: calObj.hh:1866
void TempAssociationAugment(IT begin, const IT end, const bool pairs=false)
Adds to the temporary variable association.
Definition: calObj.hh:1165
BDD Cofactor(const BDD &f, const BDD &c)
Generalized cofactor of f with respect to c.
Definition: calObj.hh:1829
void Reorder()
Invoke the current dynamic reodering method.
Definition: calObj.hh:1066
BDD CreateNewVarLast()
Create and obtain a new variable at the end of the variable order.
Definition: calObj.hh:1240
Cal()
Initialize a new BDD Manager.
Definition: calObj.hh:871
std::vector< long > Profile(const Container &c, bool negout=true) const
Similar to Cal::Profile() for a container of BDDs. But, this accounts for sharing of nodes.
Definition: calObj.hh:1983
ReorderMethod
The possible technique to be used to execute each method (c.f. Cal::ReorderTechnique).
Definition: calObj.hh:1044
BDD Satisfy(const BDD &f)
A satisfying assignment of this BDD.
Definition: calObj.hh:1732
void PrintFunctionProfile(const Container &c, int lineLength=79, FILE *fp=stdout) const
Similar to Cal::PrintFunctionProfile for a container of BDDs. But, this accounts for sharing of nodes...
Definition: calObj.hh:2152
bool IsConst(const BDD &f) const
true if the given BDD is either constant one or constant zero, otherwise returns false.
Definition: calObj.hh:1288
void DynamicReordering(ReorderTechnique technique, ReorderMethod method=ReorderMethod::DF)
Specify dynamic reordering technique and method.
Definition: calObj.hh:1054
BDD Else(const BDD &f)
The negative cofactor of the given BDD with respect to its top variable.
Definition: calObj.hh:1900
BDD Implies(const BDD &f, const BDD &g)
Computes a BDD that implies the conjunction of f and g.Not().
Definition: calObj.hh:1426
void PrintProfile(const Container &c, int lineLength=79, FILE *fp=stdout) const
Similar to Cal::PrintProfile for a container of BDDs. But, this accounts for sharing of nodes....
Definition: calObj.hh:2037
int AssociationSetCurrent(int i)
Sets the current variable association to the one given.
Definition: calObj.hh:1117
bool IsEqual(const BDD &f, const BDD &g) const
true if the two BDDs are equal, false otherwise.
Definition: calObj.hh:1302
std::vector< long > Profile(IT begin, IT end, bool negout=true) const
Similar to Cal::Profile() for an iterator of BDDs. But, this accounts for sharing of nodes.
Definition: calObj.hh:1953
Id_t IfId(const BDD &f) const
Returns the id of the given BDD's top variable.
Definition: calObj.hh:1874
BDD Xor(const Container &c)
Logical XOR of container with BDDs or ints.
Definition: calObj.hh:1593
Index_t IfIndex(const BDD &f) const
Returns the index of this BDD's top variable.
Definition: calObj.hh:1882
BDD Null() const
The NULL BDD.
Definition: calObj.hh:1195
unsigned long Size(IT begin, IT end, bool negout=true)
Similar to Cal::Size() for an iterator of BDDs. But, this accounts for sharing of nodes.
Definition: calObj.hh:1348
void Print(const BDD &f, FILE *fp=stdout) const
Prints a BDD in the human readable form.
Definition: calObj.hh:1915
BDD Index(Index_t idx) const
The variable with the specified index, null if no such variable exists.
Definition: calObj.hh:1228
~Cal()
Clear memory of BDD Manager.
Definition: calObj.hh:906
bool IsNull(const BDD &f) const
true if the given BDD is NULL, false otherwise.
Definition: calObj.hh:1263
ReorderTechnique
The possible methods (algorithms) for variable reordering.
Definition: calObj.hh:1032
BDD CreateNewVarFirst()
Create and obtain a new variable at the start of the variable order.
Definition: calObj.hh:1234
BDD Or(const Container &c)
Logical OR of container with BDDs or ints.
Definition: calObj.hh:1538
EXTERN Cal_Bdd Cal_BddElse(Cal_BddManager bddManager, Cal_Bdd userBdd)
The negative cofactor of the argument BDD with respect to its top variable.
EXTERN void Cal_BddUnFree(Cal_BddManager bddManager, Cal_Bdd userBdd)
Unfrees the argument BDD.
EXTERN double Cal_BddSatisfyingFraction(Cal_BddManager bddManager, Cal_Bdd fUserBdd)
Fraction of valuations which make f true.
EXTERN void Cal_BddStats(Cal_BddManager bddManager, FILE *fp)
Prints miscellaneous BDD statistics.
EXTERN Cal_BddId_t Cal_BddGetIfId(Cal_BddManager bddManager, Cal_Bdd userBdd)
Returns the id of the top variable of the argument BDD.
EXTERN Cal_Bdd Cal_BddManagerGetVarWithIndex(Cal_BddManager bddManager, Cal_BddIndex_t index)
The variable with the specified index, null if no such variable exists.
EXTERN Cal_Bdd * Cal_BddPairwiseXor(Cal_BddManager bddManager, Cal_Bdd *userBddArray)
Logical XOR of BDD pairs in argument null-termiinated array of BDDs.
EXTERN int Cal_BddIsBddConst(Cal_BddManager bddManager, Cal_Bdd userBdd)
Returns 1 if the argument BDD is either constant one or constant zero, otherwise returns 0.
EXTERN Cal_Bdd Cal_BddSatisfySupport(Cal_BddManager bddManager, Cal_Bdd fUserBdd)
Returns a special cube contained in f.
EXTERN int Cal_BddManagerGC(Cal_BddManager bddManager)
Invokes the garbage collection at the manager level.
EXTERN Cal_Bdd Cal_BddXor(Cal_BddManager bddManager, Cal_Bdd fUserBdd, Cal_Bdd gUserBdd)
Logical XOR of argument BDDs.
EXTERN Cal_Bdd * Cal_BddPairwiseAnd(Cal_BddManager bddManager, Cal_Bdd *userBddArray)
Logical AND of BDD pairs in argument null-termiinated array of BDDs.
EXTERN void Cal_BddFree(Cal_BddManager bddManager, Cal_Bdd userBdd)
Frees the argument BDD.
EXTERN long Cal_BddSizeMultiple(Cal_BddManager bddManager, Cal_Bdd *fUserBddArray, int negout)
Similar to Cal_BddSize for a null-terminated array of BDDs and accounting for sharing of nodes.
EXTERN int Cal_BddIsEqual(Cal_BddManager bddManager, Cal_Bdd userBdd1, Cal_Bdd userBdd2)
Returns 1 if argument BDDs are equal, 0 otherwise.
EXTERN Cal_Bdd Cal_BddCompose(Cal_BddManager bddManager, Cal_Bdd fUserBdd, Cal_Bdd gUserBdd, Cal_Bdd hUserBdd)
Substitute a BDD variable by a function.
EXTERN Cal_Bdd Cal_BddIdentity(Cal_BddManager bddManager, Cal_Bdd userBdd)
Duplicate of the argument BDD.
#define Cal_BddTerminalIdFnNone
Default BDD terminal naming function.
Definition: cal.h:146
EXTERN void Cal_BddPrintFunctionProfileMultiple(Cal_BddManager bddManager, Cal_Bdd *userBdds, Cal_VarNamingFn_t varNamingProc, char *env, int lineLength, FILE *fp)
Similar to Cal_BddPrintFunctionProfile but displays a function profile for a set of BDDs.
EXTERN void Cal_TempAssociationQuit(Cal_BddManager bddManager)
Cleans up temporary association.
EXTERN void Cal_BddFunctionProfile(Cal_BddManager bddManager, Cal_Bdd fUserBdd, long *funcCounts)
The number of subfunctions of f which may be obtained by restricting variables with an index lower th...
EXTERN int Cal_AssociationInit(Cal_BddManager bddManager, Cal_Bdd *associationInfoUserBdds, int pairs)
Creates or finds a variable association.
EXTERN Cal_Bdd Cal_BddMultiwayXor(Cal_BddManager bddManager, Cal_Bdd *userBddArray)
Logical XOR of BDDs in argument null-terminated array of BDDs.
EXTERN void Cal_BddPrintBdd(Cal_BddManager bddManager, Cal_Bdd fUserBdd, Cal_VarNamingFn_t VarNamingFn, Cal_TerminalIdFn_t TerminalIdFn, Cal_Pointer_t env, FILE *fp)
Prints a BDD in the human readable form.
EXTERN Cal_Bdd Cal_BddCofactor(Cal_BddManager bddManager, Cal_Bdd fUserBdd, Cal_Bdd cUserBdd)
Generalized cofactor of f with respect to c.
EXTERN void Cal_BddProfileMultiple(Cal_BddManager bddManager, Cal_Bdd *fUserBddArray, long *levelCounts, int negout)
Similar to Cal_BddProfile for a null-terminated array of BDDs and accounting for sharing of nodes.
EXTERN Cal_Bdd Cal_BddMultiwayAnd(Cal_BddManager bddManager, Cal_Bdd *userBddArray)
Logical AND of BDDs in argument null-terminated array of BDDs.
EXTERN Cal_Bdd Cal_BddVarSubstitute(Cal_BddManager bddManager, Cal_Bdd fUserBdd)
Substitute a set of variables by set of another variables.
EXTERN Cal_Bdd Cal_BddSubstitute(Cal_BddManager bddManager, Cal_Bdd fUserBdd)
Substitute a set of variables by functions.
EXTERN void Cal_BddDynamicReordering(Cal_BddManager bddManager, int technique, int method)
Specify dynamic reordering technique and method.
EXTERN long Cal_BddNodeLimit(Cal_BddManager bddManager, long newLimit)
Sets the node limit to new_limit and returns the old limit.
EXTERN Cal_Bdd Cal_BddManagerCreateNewVarLast(Cal_BddManager bddManager)
Create and obtain a new variable at the end of the variable order.
EXTERN void Cal_BddPrintFunctionProfile(Cal_BddManager bddManager, Cal_Bdd f, Cal_VarNamingFn_t varNamingProc, char *env, int lineLength, FILE *fp)
Similar to Cal_BddPrintProfile but displays a function profile for f.
EXTERN Cal_Bdd Cal_BddManagerGetVarWithId(Cal_BddManager bddManager, Cal_BddId_t id)
The variable with the specified id, null if no such variable exists.
EXTERN void Cal_TempAssociationInit(Cal_BddManager bddManager, Cal_Bdd *associationInfoUserBdds, int pairs)
Sets the temporary variable association.
EXTERN void Cal_BddFunctionPrint(Cal_BddManager bddManager, Cal_Bdd userBdd, char *name)
Prints the function implemented by the argument BDD.
EXTERN Cal_Bdd Cal_BddManagerCreateNewVarAfter(Cal_BddManager bddManager, Cal_Bdd userBdd)
Create and obtain a new variable after the specified one in the variable order.
EXTERN Cal_Bdd Cal_BddNand(Cal_BddManager bddManager, Cal_Bdd fUserBdd, Cal_Bdd gUserBdd)
Logical NAND of argument BDDs.
EXTERN Cal_Bdd Cal_BddOne(Cal_BddManager bddManager)
The BDD for the constant one.
EXTERN void Cal_BddManagerSetGCLimit(Cal_BddManager manager)
Sets the limit of the garbage collection.
EXTERN Cal_BddId_t Cal_BddGetIfIndex(Cal_BddManager bddManager, Cal_Bdd userBdd)
Returns the index of the top variable of the argument BDD.
EXTERN Cal_Bdd Cal_BddExists(Cal_BddManager bddManager, Cal_Bdd fUserBdd)
Existentially quantification of some variables from the given BDD.
EXTERN Cal_Bdd Cal_BddNot(Cal_BddManager bddManager, Cal_Bdd userBdd)
Complement of the argument BDD.
EXTERN int Cal_BddIsBddOne(Cal_BddManager bddManager, Cal_Bdd userBdd)
Returns 1 if the argument BDD is constant one, 0 otherwise.
EXTERN Cal_Bdd Cal_BddIntersects(Cal_BddManager bddManager, Cal_Bdd fUserBdd, Cal_Bdd gUserBdd)
Computes a BDD that implies conjunction of f and g.
EXTERN void Cal_BddProfile(Cal_BddManager bddManager, Cal_Bdd fUserBdd, long *levelCounts, int negout)
The number of nodes at each level in f.
EXTERN int Cal_BddOverflow(Cal_BddManager bddManager)
Returns 1 if the node limit has been exceeded, 0 otherwise.
EXTERN void Cal_BddPrintProfile(Cal_BddManager bddManager, Cal_Bdd fUserBdd, Cal_VarNamingFn_t varNamingProc, char *env, int lineLength, FILE *fp)
Displays the node profile for f on fp.
EXTERN unsigned long Cal_BddTotalSize(Cal_BddManager bddManager)
Returns the number of nodes in the Unique table.
EXTERN Cal_Bdd Cal_BddManagerCreateNewVarBefore(Cal_BddManager bddManager, Cal_Bdd userBdd)
Create and obtain a new variable before the specified one in the variable order.
EXTERN long Cal_BddSize(Cal_BddManager bddManager, Cal_Bdd fUserBdd, int negout)
BDD size of fUserBdd.
EXTERN void Cal_BddPrintProfileMultiple(Cal_BddManager bddManager, Cal_Bdd *userBdds, Cal_VarNamingFn_t varNamingProc, char *env, int lineLength, FILE *fp)
Similar to Cal_BddPrintProfile but displays the profile for a set of BDDs.
EXTERN Cal_Bdd * Cal_BddPairwiseOr(Cal_BddManager bddManager, Cal_Bdd *userBddArray)
Logical OR of BDD pairs in argument null-termiinated array of BDDs.
EXTERN Cal_Bdd Cal_BddIf(Cal_BddManager bddManager, Cal_Bdd userBdd)
A BDD corresponding to the top variable of the given BDD.
EXTERN Cal_Bdd Cal_BddZero(Cal_BddManager bddManager)
The BDD for the constant zero.
EXTERN unsigned long Cal_BddManagerGetNumNodes(Cal_BddManager bddManager)
Returns the number of BDD nodes.
EXTERN Cal_Bdd Cal_BddManagerCreateNewVarFirst(Cal_BddManager bddManager)
Create and obtain a new variable at the start of the variable order.
EXTERN Cal_Bdd Cal_BddReduce(Cal_BddManager bddManager, Cal_Bdd fUserBdd, Cal_Bdd cUserBdd)
A function that agrees with f for all valuations which satisfy c.
EXTERN Cal_BddManager Cal_BddManagerInit()
Creates and initializes a new BDD manager.
EXTERN Cal_Bdd Cal_BddSatisfy(Cal_BddManager bddManager, Cal_Bdd fUserBdd)
A satisfying assignment of f.
EXTERN void Cal_AssociationQuit(Cal_BddManager bddManager, int associationId)
Deletes the variable association given by id.
EXTERN Cal_Bdd Cal_BddBetween(Cal_BddManager bddManager, Cal_Bdd fMinUserBdd, Cal_Bdd fMaxUserBdd)
A function that contains fMin and is contained in fMax.
EXTERN int Cal_BddType(Cal_BddManager bddManager, Cal_Bdd fUserBdd)
The type of the given BDD (0, 1, +var, -var, overflow, nonterminal).
#define Cal_BddNamingFnNone
Default BDD variable naming function.
Definition: cal.h:141
EXTERN Cal_Bdd Cal_BddGetRegular(Cal_BddManager bddManager, Cal_Bdd userBdd)
Returns a BDD with positive from a given BDD with arbitrary phase.
EXTERN int Cal_AssociationSetCurrent(Cal_BddManager bddManager, int associationId)
Sets the current variable association to the one given.
EXTERN long Cal_BddVars(Cal_BddManager bddManager)
Returns the number of BDD variables.
EXTERN Cal_Bdd Cal_BddXnor(Cal_BddManager bddManager, Cal_Bdd fUserBdd, Cal_Bdd gUserBdd)
Logical XNOR of argument BDDs.
EXTERN void Cal_BddSetGCMode(Cal_BddManager bddManager, int gcMode)
Sets the garbage collection mode.
EXTERN void Cal_BddFunctionProfileMultiple(Cal_BddManager bddManager, Cal_Bdd *fUserBddArray, long *funcCounts)
Similar to Cal_BddFunctionProfile for a null-terminated array of BDDs and accounting for sharing of n...
EXTERN Cal_Bdd Cal_BddITE(Cal_BddManager bddManager, Cal_Bdd fUserBdd, Cal_Bdd gUserBdd, Cal_Bdd hUserBdd)
Logical If-Then-Else.
EXTERN void Cal_BddReorder(Cal_BddManager bddManager)
Invoke the current dynamic reodering method.
EXTERN int Cal_BddIsBddZero(Cal_BddManager bddManager, Cal_Bdd userBdd)
Returns 1 if the argument BDD is constant zero, 0 otherwise.
EXTERN Cal_Bdd Cal_BddRelProd(Cal_BddManager bddManager, Cal_Bdd fUserBdd, Cal_Bdd gUserBdd)
Logical AND of the argument BDDs and existentially quantifying some variables from the product.
EXTERN Cal_Bdd Cal_BddThen(Cal_BddManager bddManager, Cal_Bdd userBdd)
The positive cofactor of the argument BDD with respect to its top variable.
EXTERN int Cal_BddDependsOn(Cal_BddManager bddManager, Cal_Bdd fUserBdd, Cal_Bdd varUserBdd)
Returns 1 if f depends on var and returns 0 otherwise.
EXTERN int Cal_BddIsCube(Cal_BddManager bddManager, Cal_Bdd fUserBdd)
Returns 1 if the argument BDD is a cube, 0 otherwise.
EXTERN int Cal_BddManagerQuit(Cal_BddManager bddManager)
Frees the BDD manager and all the associated allocations.
EXTERN void Cal_TempAssociationAugment(Cal_BddManager bddManager, Cal_Bdd *associationInfoUserBdds, int pairs)
Adds to the temporary variable association.
EXTERN Cal_Bdd Cal_BddForAll(Cal_BddManager bddManager, Cal_Bdd fUserBdd)
Universal quantification of some variables from the given BDD.
EXTERN Cal_Bdd Cal_BddNor(Cal_BddManager bddManager, Cal_Bdd fUserBdd, Cal_Bdd gUserBdd)
Logical NOR of argument BDDs.
EXTERN Cal_Bdd Cal_BddImplies(Cal_BddManager bddManager, Cal_Bdd fUserBdd, Cal_Bdd gUserBdd)
Computes a BDD that implies conjunction of f and Cal_BddNot(g).
EXTERN Cal_Bdd Cal_BddOr(Cal_BddManager bddManager, Cal_Bdd fUserBdd, Cal_Bdd gUserBdd)
Logical Or of argument BDDs.
EXTERN Cal_Bdd Cal_BddMultiwayOr(Cal_BddManager bddManager, Cal_Bdd *userBddArray)
Logical OR of BDDs in argument null-terminated array of BDDs.
EXTERN Cal_Bdd Cal_BddNull(Cal_BddManager bddManager)
Returns the NULL BDD.
EXTERN int Cal_BddIsBddNull(Cal_BddManager bddManager, Cal_Bdd userBdd)
1 if the argument BDD is NULL, 0 otherwise.
EXTERN Cal_Bdd Cal_BddSwapVars(Cal_BddManager bddManager, Cal_Bdd fUserBdd, Cal_Bdd gUserBdd, Cal_Bdd hUserBdd)
The function obtained by swapping two variables.
EXTERN Cal_Bdd Cal_BddAnd(Cal_BddManager bddManager, Cal_Bdd fUserBdd, Cal_Bdd gUserBdd)
Logical AND of argument BDDs.
EXTERN void Cal_BddManagerSetParameters(Cal_BddManager bddManager, long reorderingThreshold, long maxForwardedNodes, double repackAfterGCThreshold, double tableRepackThreshold)
Sets appropriate fields of BDD Manager.