You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

4893 lines
136 KiB

  1. /**CFile***********************************************************************
  2. FileName [cuddAPI.c]
  3. PackageName [cudd]
  4. Synopsis [Application interface functions.]
  5. Description [External procedures included in this module:
  6. <ul>
  7. <li> Cudd_addNewVar()
  8. <li> Cudd_addNewVarAtLevel()
  9. <li> Cudd_bddNewVar()
  10. <li> Cudd_bddNewVarAtLevel()
  11. <li> Cudd_addIthVar()
  12. <li> Cudd_bddIthVar()
  13. <li> Cudd_zddIthVar()
  14. <li> Cudd_zddVarsFromBddVars()
  15. <li> Cudd_addConst()
  16. <li> Cudd_IsNonConstant()
  17. <li> Cudd_ReadStartTime()
  18. <li> Cudd_ReadElapsedTime()
  19. <li> Cudd_SetStartTime()
  20. <li> Cudd_ResetStartTime()
  21. <li> Cudd_ReadTimeLimit()
  22. <li> Cudd_SetTimeLimit()
  23. <li> Cudd_UpdateTimeLimit()
  24. <li> Cudd_IncreaseTimeLimit()
  25. <li> Cudd_UnsetTimeLimit()
  26. <li> Cudd_TimeLimited()
  27. <li> Cudd_AutodynEnable()
  28. <li> Cudd_AutodynDisable()
  29. <li> Cudd_ReorderingStatus()
  30. <li> Cudd_AutodynEnableZdd()
  31. <li> Cudd_AutodynDisableZdd()
  32. <li> Cudd_ReorderingStatusZdd()
  33. <li> Cudd_zddRealignmentEnabled()
  34. <li> Cudd_zddRealignEnable()
  35. <li> Cudd_zddRealignDisable()
  36. <li> Cudd_bddRealignmentEnabled()
  37. <li> Cudd_bddRealignEnable()
  38. <li> Cudd_bddRealignDisable()
  39. <li> Cudd_ReadOne()
  40. <li> Cudd_ReadZddOne()
  41. <li> Cudd_ReadZero()
  42. <li> Cudd_ReadLogicZero()
  43. <li> Cudd_ReadPlusInfinity()
  44. <li> Cudd_ReadMinusInfinity()
  45. <li> Cudd_ReadBackground()
  46. <li> Cudd_SetBackground()
  47. <li> Cudd_ReadCacheSlots()
  48. <li> Cudd_ReadCacheUsedSlots()
  49. <li> Cudd_ReadCacheLookUps()
  50. <li> Cudd_ReadCacheHits()
  51. <li> Cudd_ReadMinHit()
  52. <li> Cudd_SetMinHit()
  53. <li> Cudd_ReadLooseUpTo()
  54. <li> Cudd_SetLooseUpTo()
  55. <li> Cudd_ReadMaxCache()
  56. <li> Cudd_ReadMaxCacheHard()
  57. <li> Cudd_SetMaxCacheHard()
  58. <li> Cudd_ReadSize()
  59. <li> Cudd_ReadSlots()
  60. <li> Cudd_ReadUsedSlots()
  61. <li> Cudd_ExpectedUsedSlots()
  62. <li> Cudd_ReadKeys()
  63. <li> Cudd_ReadDead()
  64. <li> Cudd_ReadMinDead()
  65. <li> Cudd_ReadReorderings()
  66. <li> Cudd_ReadMaxReorderings()
  67. <li> Cudd_SetMaxReorderings()
  68. <li> Cudd_ReadReorderingTime()
  69. <li> Cudd_ReadGarbageCollections()
  70. <li> Cudd_ReadGarbageCollectionTime()
  71. <li> Cudd_ReadNodesFreed()
  72. <li> Cudd_ReadNodesDropped()
  73. <li> Cudd_ReadUniqueLookUps()
  74. <li> Cudd_ReadUniqueLinks()
  75. <li> Cudd_ReadSiftMaxVar()
  76. <li> Cudd_SetSiftMaxVar()
  77. <li> Cudd_ReadMaxGrowth()
  78. <li> Cudd_SetMaxGrowth()
  79. <li> Cudd_ReadMaxGrowthAlternate()
  80. <li> Cudd_SetMaxGrowthAlternate()
  81. <li> Cudd_ReadReorderingCycle()
  82. <li> Cudd_SetReorderingCycle()
  83. <li> Cudd_ReadTree()
  84. <li> Cudd_SetTree()
  85. <li> Cudd_FreeTree()
  86. <li> Cudd_ReadZddTree()
  87. <li> Cudd_SetZddTree()
  88. <li> Cudd_FreeZddTree()
  89. <li> Cudd_NodeReadIndex()
  90. <li> Cudd_ReadPerm()
  91. <li> Cudd_ReadInvPerm()
  92. <li> Cudd_ReadVars()
  93. <li> Cudd_ReadEpsilon()
  94. <li> Cudd_SetEpsilon()
  95. <li> Cudd_ReadGroupCheck()
  96. <li> Cudd_SetGroupcheck()
  97. <li> Cudd_GarbageCollectionEnabled()
  98. <li> Cudd_EnableGarbageCollection()
  99. <li> Cudd_DisableGarbageCollection()
  100. <li> Cudd_DeadAreCounted()
  101. <li> Cudd_TurnOnCountDead()
  102. <li> Cudd_TurnOffCountDead()
  103. <li> Cudd_ReadRecomb()
  104. <li> Cudd_SetRecomb()
  105. <li> Cudd_ReadSymmviolation()
  106. <li> Cudd_SetSymmviolation()
  107. <li> Cudd_ReadArcviolation()
  108. <li> Cudd_SetArcviolation()
  109. <li> Cudd_ReadPopulationSize()
  110. <li> Cudd_SetPopulationSize()
  111. <li> Cudd_ReadNumberXovers()
  112. <li> Cudd_SetNumberXovers()
  113. <li> Cudd_ReadOrderRandomization()
  114. <li> Cudd_SetOrderRandomization()
  115. <li> Cudd_ReadMemoryInUse()
  116. <li> Cudd_PrintInfo()
  117. <li> Cudd_ReadPeakNodeCount()
  118. <li> Cudd_ReadPeakLiveNodeCount()
  119. <li> Cudd_ReadNodeCount()
  120. <li> Cudd_zddReadNodeCount()
  121. <li> Cudd_AddHook()
  122. <li> Cudd_RemoveHook()
  123. <li> Cudd_IsInHook()
  124. <li> Cudd_StdPreReordHook()
  125. <li> Cudd_StdPostReordHook()
  126. <li> Cudd_EnableReorderingReporting()
  127. <li> Cudd_DisableReorderingReporting()
  128. <li> Cudd_ReorderingReporting()
  129. <li> Cudd_PrintGroupedOrder()
  130. <li> Cudd_EnableOrderingMonitoring()
  131. <li> Cudd_DisableOrderingMonitoring()
  132. <li> Cudd_OrderingMonitoring()
  133. <li> Cudd_ReadErrorCode()
  134. <li> Cudd_ClearErrorCode()
  135. <li> Cudd_ReadStdout()
  136. <li> Cudd_SetStdout()
  137. <li> Cudd_ReadStderr()
  138. <li> Cudd_SetStderr()
  139. <li> Cudd_ReadNextReordering()
  140. <li> Cudd_SetNextReordering()
  141. <li> Cudd_ReadSwapSteps()
  142. <li> Cudd_ReadMaxLive()
  143. <li> Cudd_SetMaxLive()
  144. <li> Cudd_ReadMaxMemory()
  145. <li> Cudd_SetMaxMemory()
  146. <li> Cudd_bddBindVar()
  147. <li> Cudd_bddUnbindVar()
  148. <li> Cudd_bddVarIsBound()
  149. <li> Cudd_bddSetPiVar()
  150. <li> Cudd_bddSetPsVar()
  151. <li> Cudd_bddSetNsVar()
  152. <li> Cudd_bddIsPiVar()
  153. <li> Cudd_bddIsPsVar()
  154. <li> Cudd_bddIsNsVar()
  155. <li> Cudd_bddSetPairIndex()
  156. <li> Cudd_bddReadPairIndex()
  157. <li> Cudd_bddSetVarToBeGrouped()
  158. <li> Cudd_bddSetVarHardGroup()
  159. <li> Cudd_bddResetVarToBeGrouped()
  160. <li> Cudd_bddIsVarToBeGrouped()
  161. <li> Cudd_bddSetVarToBeUngrouped()
  162. <li> Cudd_bddIsVarToBeUngrouped()
  163. <li> Cudd_bddIsVarHardGroup()
  164. </ul>
  165. Static procedures included in this module:
  166. <ul>
  167. <li> fixVarTree()
  168. </ul>]
  169. SeeAlso []
  170. Author [Fabio Somenzi]
  171. Copyright [Copyright (c) 1995-2012, Regents of the University of Colorado
  172. All rights reserved.
  173. Redistribution and use in source and binary forms, with or without
  174. modification, are permitted provided that the following conditions
  175. are met:
  176. Redistributions of source code must retain the above copyright
  177. notice, this list of conditions and the following disclaimer.
  178. Redistributions in binary form must reproduce the above copyright
  179. notice, this list of conditions and the following disclaimer in the
  180. documentation and/or other materials provided with the distribution.
  181. Neither the name of the University of Colorado nor the names of its
  182. contributors may be used to endorse or promote products derived from
  183. this software without specific prior written permission.
  184. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  185. "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  186. LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  187. FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  188. COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  189. INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  190. BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  191. LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  192. CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  193. LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
  194. ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  195. POSSIBILITY OF SUCH DAMAGE.]
  196. ******************************************************************************/
  197. #include "util.h"
  198. #include "cuddInt.h"
  199. /*---------------------------------------------------------------------------*/
  200. /* Constant declarations */
  201. /*---------------------------------------------------------------------------*/
  202. /*---------------------------------------------------------------------------*/
  203. /* Stucture declarations */
  204. /*---------------------------------------------------------------------------*/
  205. /*---------------------------------------------------------------------------*/
  206. /* Type declarations */
  207. /*---------------------------------------------------------------------------*/
  208. /*---------------------------------------------------------------------------*/
  209. /* Variable declarations */
  210. /*---------------------------------------------------------------------------*/
  211. #ifndef lint
  212. static char rcsid[] DD_UNUSED = "$Id: cuddAPI.c,v 1.64 2012/02/05 01:07:18 fabio Exp $";
  213. #endif
  214. /*---------------------------------------------------------------------------*/
  215. /* Macro declarations */
  216. /*---------------------------------------------------------------------------*/
  217. /**AutomaticStart*************************************************************/
  218. /*---------------------------------------------------------------------------*/
  219. /* Static function prototypes */
  220. /*---------------------------------------------------------------------------*/
  221. static void fixVarTree (MtrNode *treenode, int *perm, int size);
  222. static int addMultiplicityGroups (DdManager *dd, MtrNode *treenode, int multiplicity, char *vmask, char *lmask);
  223. /**AutomaticEnd***************************************************************/
  224. /*---------------------------------------------------------------------------*/
  225. /* Definition of exported functions */
  226. /*---------------------------------------------------------------------------*/
  227. /**Function********************************************************************
  228. Synopsis [Returns a new ADD variable.]
  229. Description [Creates a new ADD variable. The new variable has an
  230. index equal to the largest previous index plus 1. Returns a
  231. pointer to the new variable if successful; NULL otherwise.
  232. An ADD variable differs from a BDD variable because it points to the
  233. arithmetic zero, instead of having a complement pointer to 1. ]
  234. SideEffects [None]
  235. SeeAlso [Cudd_bddNewVar Cudd_addIthVar Cudd_addConst
  236. Cudd_addNewVarAtLevel]
  237. ******************************************************************************/
  238. DdNode *
  239. Cudd_addNewVar(
  240. DdManager * dd)
  241. {
  242. DdNode *res;
  243. if ((unsigned int) dd->size >= CUDD_MAXINDEX - 1) return(NULL);
  244. do {
  245. dd->reordered = 0;
  246. res = cuddUniqueInter(dd,dd->size,DD_ONE(dd),DD_ZERO(dd));
  247. } while (dd->reordered == 1);
  248. return(res);
  249. } /* end of Cudd_addNewVar */
  250. /**Function********************************************************************
  251. Synopsis [Returns a new ADD variable at a specified level.]
  252. Description [Creates a new ADD variable. The new variable has an
  253. index equal to the largest previous index plus 1 and is positioned at
  254. the specified level in the order. Returns a pointer to the new
  255. variable if successful; NULL otherwise.]
  256. SideEffects [None]
  257. SeeAlso [Cudd_addNewVar Cudd_addIthVar Cudd_bddNewVarAtLevel]
  258. ******************************************************************************/
  259. DdNode *
  260. Cudd_addNewVarAtLevel(
  261. DdManager * dd,
  262. int level)
  263. {
  264. DdNode *res;
  265. if ((unsigned int) dd->size >= CUDD_MAXINDEX - 1) return(NULL);
  266. if (level >= dd->size) return(Cudd_addIthVar(dd,level));
  267. if (!cuddInsertSubtables(dd,1,level)) return(NULL);
  268. do {
  269. dd->reordered = 0;
  270. res = cuddUniqueInter(dd,dd->size - 1,DD_ONE(dd),DD_ZERO(dd));
  271. } while (dd->reordered == 1);
  272. return(res);
  273. } /* end of Cudd_addNewVarAtLevel */
  274. /**Function********************************************************************
  275. Synopsis [Returns a new BDD variable.]
  276. Description [Creates a new BDD variable. The new variable has an
  277. index equal to the largest previous index plus 1. Returns a
  278. pointer to the new variable if successful; NULL otherwise.]
  279. SideEffects [None]
  280. SeeAlso [Cudd_addNewVar Cudd_bddIthVar Cudd_bddNewVarAtLevel]
  281. ******************************************************************************/
  282. DdNode *
  283. Cudd_bddNewVar(
  284. DdManager * dd)
  285. {
  286. DdNode *res;
  287. if ((unsigned int) dd->size >= CUDD_MAXINDEX - 1) return(NULL);
  288. res = cuddUniqueInter(dd,dd->size,dd->one,Cudd_Not(dd->one));
  289. return(res);
  290. } /* end of Cudd_bddNewVar */
  291. /**Function********************************************************************
  292. Synopsis [Returns a new BDD variable at a specified level.]
  293. Description [Creates a new BDD variable. The new variable has an
  294. index equal to the largest previous index plus 1 and is positioned at
  295. the specified level in the order. Returns a pointer to the new
  296. variable if successful; NULL otherwise.]
  297. SideEffects [None]
  298. SeeAlso [Cudd_bddNewVar Cudd_bddIthVar Cudd_addNewVarAtLevel]
  299. ******************************************************************************/
  300. DdNode *
  301. Cudd_bddNewVarAtLevel(
  302. DdManager * dd,
  303. int level)
  304. {
  305. DdNode *res;
  306. if ((unsigned int) dd->size >= CUDD_MAXINDEX - 1) return(NULL);
  307. if (level >= dd->size) return(Cudd_bddIthVar(dd,level));
  308. if (!cuddInsertSubtables(dd,1,level)) return(NULL);
  309. res = dd->vars[dd->size - 1];
  310. return(res);
  311. } /* end of Cudd_bddNewVarAtLevel */
  312. /**Function********************************************************************
  313. Synopsis [Returns the ADD variable with index i.]
  314. Description [Retrieves the ADD variable with index i if it already
  315. exists, or creates a new ADD variable. Returns a pointer to the
  316. variable if successful; NULL otherwise. An ADD variable differs from
  317. a BDD variable because it points to the arithmetic zero, instead of
  318. having a complement pointer to 1. ]
  319. SideEffects [None]
  320. SeeAlso [Cudd_addNewVar Cudd_bddIthVar Cudd_addConst
  321. Cudd_addNewVarAtLevel]
  322. ******************************************************************************/
  323. DdNode *
  324. Cudd_addIthVar(
  325. DdManager * dd,
  326. int i)
  327. {
  328. DdNode *res;
  329. if ((unsigned int) i >= CUDD_MAXINDEX - 1) return(NULL);
  330. do {
  331. dd->reordered = 0;
  332. res = cuddUniqueInter(dd,i,DD_ONE(dd),DD_ZERO(dd));
  333. } while (dd->reordered == 1);
  334. return(res);
  335. } /* end of Cudd_addIthVar */
  336. /**Function********************************************************************
  337. Synopsis [Returns the BDD variable with index i.]
  338. Description [Retrieves the BDD variable with index i if it already
  339. exists, or creates a new BDD variable. Returns a pointer to the
  340. variable if successful; NULL otherwise.]
  341. SideEffects [None]
  342. SeeAlso [Cudd_bddNewVar Cudd_addIthVar Cudd_bddNewVarAtLevel
  343. Cudd_ReadVars]
  344. ******************************************************************************/
  345. DdNode *
  346. Cudd_bddIthVar(
  347. DdManager * dd,
  348. int i)
  349. {
  350. DdNode *res;
  351. if ((unsigned int) i >= CUDD_MAXINDEX - 1) return(NULL);
  352. if (i < dd->size) {
  353. res = dd->vars[i];
  354. } else {
  355. res = cuddUniqueInter(dd,i,dd->one,Cudd_Not(dd->one));
  356. }
  357. return(res);
  358. } /* end of Cudd_bddIthVar */
  359. /**Function********************************************************************
  360. Synopsis [Returns the ZDD variable with index i.]
  361. Description [Retrieves the ZDD variable with index i if it already
  362. exists, or creates a new ZDD variable. Returns a pointer to the
  363. variable if successful; NULL otherwise.]
  364. SideEffects [None]
  365. SeeAlso [Cudd_bddIthVar Cudd_addIthVar]
  366. ******************************************************************************/
  367. DdNode *
  368. Cudd_zddIthVar(
  369. DdManager * dd,
  370. int i)
  371. {
  372. DdNode *res;
  373. DdNode *zvar;
  374. DdNode *lower;
  375. int j;
  376. if ((unsigned int) i >= CUDD_MAXINDEX - 1) return(NULL);
  377. /* The i-th variable function has the following structure:
  378. ** at the level corresponding to index i there is a node whose "then"
  379. ** child points to the universe, and whose "else" child points to zero.
  380. ** Above that level there are nodes with identical children.
  381. */
  382. /* First we build the node at the level of index i. */
  383. lower = (i < dd->sizeZ - 1) ? dd->univ[dd->permZ[i]+1] : DD_ONE(dd);
  384. do {
  385. dd->reordered = 0;
  386. zvar = cuddUniqueInterZdd(dd, i, lower, DD_ZERO(dd));
  387. } while (dd->reordered == 1);
  388. if (zvar == NULL)
  389. return(NULL);
  390. cuddRef(zvar);
  391. /* Now we add the "filler" nodes above the level of index i. */
  392. for (j = dd->permZ[i] - 1; j >= 0; j--) {
  393. do {
  394. dd->reordered = 0;
  395. res = cuddUniqueInterZdd(dd, dd->invpermZ[j], zvar, zvar);
  396. } while (dd->reordered == 1);
  397. if (res == NULL) {
  398. Cudd_RecursiveDerefZdd(dd,zvar);
  399. return(NULL);
  400. }
  401. cuddRef(res);
  402. Cudd_RecursiveDerefZdd(dd,zvar);
  403. zvar = res;
  404. }
  405. cuddDeref(zvar);
  406. return(zvar);
  407. } /* end of Cudd_zddIthVar */
  408. /**Function********************************************************************
  409. Synopsis [Creates one or more ZDD variables for each BDD variable.]
  410. Description [Creates one or more ZDD variables for each BDD
  411. variable. If some ZDD variables already exist, only the missing
  412. variables are created. Parameter multiplicity allows the caller to
  413. control how many variables are created for each BDD variable in
  414. existence. For instance, if ZDDs are used to represent covers, two
  415. ZDD variables are required for each BDD variable. The order of the
  416. BDD variables is transferred to the ZDD variables. If a variable
  417. group tree exists for the BDD variables, a corresponding ZDD
  418. variable group tree is created by expanding the BDD variable
  419. tree. In any case, the ZDD variables derived from the same BDD
  420. variable are merged in a ZDD variable group. If a ZDD variable group
  421. tree exists, it is freed. Returns 1 if successful; 0 otherwise.]
  422. SideEffects [None]
  423. SeeAlso [Cudd_bddNewVar Cudd_bddIthVar Cudd_bddNewVarAtLevel]
  424. ******************************************************************************/
  425. int
  426. Cudd_zddVarsFromBddVars(
  427. DdManager * dd /* DD manager */,
  428. int multiplicity /* how many ZDD variables are created for each BDD variable */)
  429. {
  430. int res;
  431. int i, j;
  432. int allnew;
  433. int *permutation;
  434. if (multiplicity < 1) return(0);
  435. allnew = dd->sizeZ == 0;
  436. if (dd->size * multiplicity > dd->sizeZ) {
  437. res = cuddResizeTableZdd(dd,dd->size * multiplicity - 1);
  438. if (res == 0) return(0);
  439. }
  440. /* Impose the order of the BDD variables to the ZDD variables. */
  441. if (allnew) {
  442. for (i = 0; i < dd->size; i++) {
  443. for (j = 0; j < multiplicity; j++) {
  444. dd->permZ[i * multiplicity + j] =
  445. dd->perm[i] * multiplicity + j;
  446. dd->invpermZ[dd->permZ[i * multiplicity + j]] =
  447. i * multiplicity + j;
  448. }
  449. }
  450. for (i = 0; i < dd->sizeZ; i++) {
  451. dd->univ[i]->index = dd->invpermZ[i];
  452. }
  453. } else {
  454. permutation = ALLOC(int,dd->sizeZ);
  455. if (permutation == NULL) {
  456. dd->errorCode = CUDD_MEMORY_OUT;
  457. return(0);
  458. }
  459. for (i = 0; i < dd->size; i++) {
  460. for (j = 0; j < multiplicity; j++) {
  461. permutation[i * multiplicity + j] =
  462. dd->invperm[i] * multiplicity + j;
  463. }
  464. }
  465. for (i = dd->size * multiplicity; i < dd->sizeZ; i++) {
  466. permutation[i] = i;
  467. }
  468. res = Cudd_zddShuffleHeap(dd, permutation);
  469. FREE(permutation);
  470. if (res == 0) return(0);
  471. }
  472. /* Copy and expand the variable group tree if it exists. */
  473. if (dd->treeZ != NULL) {
  474. Cudd_FreeZddTree(dd);
  475. }
  476. if (dd->tree != NULL) {
  477. dd->treeZ = Mtr_CopyTree(dd->tree, multiplicity);
  478. if (dd->treeZ == NULL) return(0);
  479. } else if (multiplicity > 1) {
  480. dd->treeZ = Mtr_InitGroupTree(0, dd->sizeZ);
  481. if (dd->treeZ == NULL) return(0);
  482. dd->treeZ->index = dd->invpermZ[0];
  483. }
  484. /* Create groups for the ZDD variables derived from the same BDD variable.
  485. */
  486. if (multiplicity > 1) {
  487. char *vmask, *lmask;
  488. vmask = ALLOC(char, dd->size);
  489. if (vmask == NULL) {
  490. dd->errorCode = CUDD_MEMORY_OUT;
  491. return(0);
  492. }
  493. lmask = ALLOC(char, dd->size);
  494. if (lmask == NULL) {
  495. dd->errorCode = CUDD_MEMORY_OUT;
  496. return(0);
  497. }
  498. for (i = 0; i < dd->size; i++) {
  499. vmask[i] = lmask[i] = 0;
  500. }
  501. res = addMultiplicityGroups(dd,dd->treeZ,multiplicity,vmask,lmask);
  502. FREE(vmask);
  503. FREE(lmask);
  504. if (res == 0) return(0);
  505. }
  506. return(1);
  507. } /* end of Cudd_zddVarsFromBddVars */
  508. /**Function********************************************************************
  509. Synopsis [Returns the ADD for constant c.]
  510. Description [Retrieves the ADD for constant c if it already
  511. exists, or creates a new ADD. Returns a pointer to the
  512. ADD if successful; NULL otherwise.]
  513. SideEffects [None]
  514. SeeAlso [Cudd_addNewVar Cudd_addIthVar]
  515. ******************************************************************************/
  516. DdNode *
  517. Cudd_addConst(
  518. DdManager * dd,
  519. CUDD_VALUE_TYPE c)
  520. {
  521. return(cuddUniqueConst(dd,c));
  522. } /* end of Cudd_addConst */
  523. /**Function********************************************************************
  524. Synopsis [Returns 1 if a DD node is not constant.]
  525. Description [Returns 1 if a DD node is not constant. This function is
  526. useful to test the results of Cudd_bddIteConstant, Cudd_addIteConstant,
  527. Cudd_addEvalConst. These results may be a special value signifying
  528. non-constant. In the other cases the macro Cudd_IsConstant can be used.]
  529. SideEffects [None]
  530. SeeAlso [Cudd_IsConstant Cudd_bddIteConstant Cudd_addIteConstant
  531. Cudd_addEvalConst]
  532. ******************************************************************************/
  533. int
  534. Cudd_IsNonConstant(
  535. DdNode *f)
  536. {
  537. return(f == DD_NON_CONSTANT || !Cudd_IsConstant(f));
  538. } /* end of Cudd_IsNonConstant */
  539. /**Function********************************************************************
  540. Synopsis [Returns the start time of the manager.]
  541. Description [Returns the start time of the manager. This is initially set
  542. to the number of milliseconds since the program started, but may be reset by
  543. the application.]
  544. SideEffects [None]
  545. SeeAlso [Cudd_SetStartTime Cudd_ResetStartTime Cudd_ReadTimeLimit]
  546. ******************************************************************************/
  547. unsigned long
  548. Cudd_ReadStartTime(
  549. DdManager * unique)
  550. {
  551. return unique->startTime;
  552. } /* end of Cudd_ReadStartTime */
  553. /**Function********************************************************************
  554. Synopsis [Returns the time elapsed since the start time of the manager.]
  555. Description [Returns the time elapsed since the start time of the manager.]
  556. SideEffects [None]
  557. SeeAlso [Cudd_ReadStartTime Cudd_SetStartTime]
  558. ******************************************************************************/
  559. unsigned long
  560. Cudd_ReadElapsedTime(
  561. DdManager * unique)
  562. {
  563. return util_cpu_time() - unique->startTime;
  564. } /* end of Cudd_ReadElapsedTime */
  565. /**Function********************************************************************
  566. Synopsis [Sets the start time of the manager.]
  567. Description [Sets the start time of the manager.]
  568. SideEffects [None]
  569. SeeAlso [Cudd_ReadStartTime Cudd_ResetStartTime Cudd_ReadElapsedTime
  570. Cudd_SetTimeLimit]
  571. ******************************************************************************/
  572. void
  573. Cudd_SetStartTime(
  574. DdManager * unique,
  575. unsigned long st)
  576. {
  577. unique->startTime = st;
  578. } /* end of Cudd_SetStartTime */
  579. /**Function********************************************************************
  580. Synopsis [Resets the start time of the manager.]
  581. Description [Resets the start time of the manager.]
  582. SideEffects [None]
  583. SeeAlso [Cudd_ReadStartTime Cudd_SetStartTime Cudd_SetTimeLimit]
  584. ******************************************************************************/
  585. void
  586. Cudd_ResetStartTime(
  587. DdManager * unique)
  588. {
  589. unique->startTime = util_cpu_time();
  590. } /* end of Cudd_ResetStartTime */
  591. /**Function********************************************************************
  592. Synopsis [Returns the time limit for the manager.]
  593. Description [Returns the time limit for the manager. This is initially set
  594. to a very large number, but may be reset by the application.]
  595. SideEffects [None]
  596. SeeAlso [Cudd_SetTimeLimit Cudd_UpdateTimeLimit Cudd_UnsetTimeLimit
  597. Cudd_IncreaseTimeLimit Cudd_TimeLimited Cudd_ReadStartTime]
  598. ******************************************************************************/
  599. unsigned long
  600. Cudd_ReadTimeLimit(
  601. DdManager * unique)
  602. {
  603. return unique->timeLimit;
  604. } /* end of Cudd_ReadTimeLimit */
  605. /**Function********************************************************************
  606. Synopsis [Sets the time limit for the manager.]
  607. Description [Sets the time limit for the manager.]
  608. SideEffects [None]
  609. SeeAlso [Cudd_ReadTimeLimit Cudd_UnsetTimeLimit Cudd_UpdateTimeLimit
  610. Cudd_IncreaseTimeLimit Cudd_TimeLimited Cudd_SetStartTime]
  611. ******************************************************************************/
  612. void
  613. Cudd_SetTimeLimit(
  614. DdManager * unique,
  615. unsigned long tl)
  616. {
  617. unique->timeLimit = tl;
  618. } /* end of Cudd_SetTimeLimit */
  619. /**Function********************************************************************
  620. Synopsis [Updates the time limit for the manager.]
  621. Description [Updates the time limit for the manager by subtracting the
  622. elapsed time from it.]
  623. SideEffects [None]
  624. SeeAlso [Cudd_ReadTimeLimit Cudd_SetTimeLimit Cudd_UnsetTimeLimit
  625. Cudd_IncreaseTimeLimit Cudd_TimeLimited Cudd_SetStartTime]
  626. ******************************************************************************/
  627. void
  628. Cudd_UpdateTimeLimit(
  629. DdManager * unique)
  630. {
  631. unsigned long elapsed;
  632. if (unique->timeLimit == ~0UL)
  633. return;
  634. elapsed = util_cpu_time() - unique->startTime;
  635. if (unique->timeLimit >= elapsed) {
  636. unique->timeLimit -= elapsed;
  637. } else {
  638. unique->timeLimit = 0;
  639. }
  640. } /* end of Cudd_UpdateTimeLimit */
  641. /**Function********************************************************************
  642. Synopsis [Increases the time limit for the manager.]
  643. Description [Increases the time limit for the manager.]
  644. SideEffects [None]
  645. SeeAlso [Cudd_ReadTimeLimit Cudd_SetTimeLimit Cudd_UnsetTimeLimit
  646. Cudd_UpdateTimeLimit Cudd_TimeLimited Cudd_SetStartTime]
  647. ******************************************************************************/
  648. void
  649. Cudd_IncreaseTimeLimit(
  650. DdManager * unique,
  651. unsigned long increase)
  652. {
  653. if (unique->timeLimit == ~0UL)
  654. unique->timeLimit = increase;
  655. else
  656. unique->timeLimit += increase;
  657. } /* end of Cudd_IncreaseTimeLimit */
  658. /**Function********************************************************************
  659. Synopsis [Unsets the time limit for the manager.]
  660. Description [Unsets the time limit for the manager. Actually, sets it to
  661. a very large value.]
  662. SideEffects [None]
  663. SeeAlso [Cudd_ReadTimeLimit Cudd_SetTimeLimit Cudd_UpdateTimeLimit
  664. Cudd_IncreaseTimeLimit Cudd_TimeLimited Cudd_SetStartTime]
  665. ******************************************************************************/
  666. void
  667. Cudd_UnsetTimeLimit(
  668. DdManager * unique)
  669. {
  670. unique->timeLimit = ~0UL;
  671. } /* end of Cudd_UnsetTimeLimit */
  672. /**Function********************************************************************
  673. Synopsis [Returns true if the time limit for the manager is set.]
  674. Description [Returns true if the time limit for the manager is set.]
  675. SideEffects [None]
  676. SeeAlso [Cudd_ReadTimeLimit Cudd_SetTimeLimit Cudd_UpdateTimeLimit
  677. Cudd_UnsetTimeLimit Cudd_IncreaseTimeLimit]
  678. ******************************************************************************/
  679. int
  680. Cudd_TimeLimited(
  681. DdManager * unique)
  682. {
  683. return unique->timeLimit != ~0UL;
  684. } /* end of Cudd_TimeLimited */
  685. /**Function********************************************************************
  686. Synopsis [Enables automatic dynamic reordering of BDDs and ADDs.]
  687. Description [Enables automatic dynamic reordering of BDDs and
  688. ADDs. Parameter method is used to determine the method used for
  689. reordering. If CUDD_REORDER_SAME is passed, the method is
  690. unchanged.]
  691. SideEffects [None]
  692. SeeAlso [Cudd_AutodynDisable Cudd_ReorderingStatus
  693. Cudd_AutodynEnableZdd]
  694. ******************************************************************************/
  695. void
  696. Cudd_AutodynEnable(
  697. DdManager * unique,
  698. Cudd_ReorderingType method)
  699. {
  700. unique->autoDyn = 1;
  701. if (method != CUDD_REORDER_SAME) {
  702. unique->autoMethod = method;
  703. }
  704. #ifndef DD_NO_DEATH_ROW
  705. /* If reordering is enabled, using the death row causes too many
  706. ** invocations. Hence, we shrink the death row to just one entry.
  707. */
  708. cuddClearDeathRow(unique);
  709. unique->deathRowDepth = 1;
  710. unique->deadMask = unique->deathRowDepth - 1;
  711. if ((unsigned) unique->nextDead > unique->deadMask) {
  712. unique->nextDead = 0;
  713. }
  714. unique->deathRow = REALLOC(DdNodePtr, unique->deathRow,
  715. unique->deathRowDepth);
  716. #endif
  717. return;
  718. } /* end of Cudd_AutodynEnable */
  719. /**Function********************************************************************
  720. Synopsis [Disables automatic dynamic reordering.]
  721. Description []
  722. SideEffects [None]
  723. SeeAlso [Cudd_AutodynEnable Cudd_ReorderingStatus
  724. Cudd_AutodynDisableZdd]
  725. ******************************************************************************/
  726. void
  727. Cudd_AutodynDisable(
  728. DdManager * unique)
  729. {
  730. unique->autoDyn = 0;
  731. return;
  732. } /* end of Cudd_AutodynDisable */
  733. /**Function********************************************************************
  734. Synopsis [Reports the status of automatic dynamic reordering of BDDs
  735. and ADDs.]
  736. Description [Reports the status of automatic dynamic reordering of
  737. BDDs and ADDs. Parameter method is set to the reordering method
  738. currently selected. Returns 1 if automatic reordering is enabled; 0
  739. otherwise.]
  740. SideEffects [Parameter method is set to the reordering method currently
  741. selected.]
  742. SeeAlso [Cudd_AutodynEnable Cudd_AutodynDisable
  743. Cudd_ReorderingStatusZdd]
  744. ******************************************************************************/
  745. int
  746. Cudd_ReorderingStatus(
  747. DdManager * unique,
  748. Cudd_ReorderingType * method)
  749. {
  750. *method = unique->autoMethod;
  751. return(unique->autoDyn);
  752. } /* end of Cudd_ReorderingStatus */
  753. /**Function********************************************************************
  754. Synopsis [Enables automatic dynamic reordering of ZDDs.]
  755. Description [Enables automatic dynamic reordering of ZDDs. Parameter
  756. method is used to determine the method used for reordering ZDDs. If
  757. CUDD_REORDER_SAME is passed, the method is unchanged.]
  758. SideEffects [None]
  759. SeeAlso [Cudd_AutodynDisableZdd Cudd_ReorderingStatusZdd
  760. Cudd_AutodynEnable]
  761. ******************************************************************************/
  762. void
  763. Cudd_AutodynEnableZdd(
  764. DdManager * unique,
  765. Cudd_ReorderingType method)
  766. {
  767. unique->autoDynZ = 1;
  768. if (method != CUDD_REORDER_SAME) {
  769. unique->autoMethodZ = method;
  770. }
  771. return;
  772. } /* end of Cudd_AutodynEnableZdd */
  773. /**Function********************************************************************
  774. Synopsis [Disables automatic dynamic reordering of ZDDs.]
  775. Description []
  776. SideEffects [None]
  777. SeeAlso [Cudd_AutodynEnableZdd Cudd_ReorderingStatusZdd
  778. Cudd_AutodynDisable]
  779. ******************************************************************************/
  780. void
  781. Cudd_AutodynDisableZdd(
  782. DdManager * unique)
  783. {
  784. unique->autoDynZ = 0;
  785. return;
  786. } /* end of Cudd_AutodynDisableZdd */
  787. /**Function********************************************************************
  788. Synopsis [Reports the status of automatic dynamic reordering of ZDDs.]
  789. Description [Reports the status of automatic dynamic reordering of
  790. ZDDs. Parameter method is set to the ZDD reordering method currently
  791. selected. Returns 1 if automatic reordering is enabled; 0
  792. otherwise.]
  793. SideEffects [Parameter method is set to the ZDD reordering method currently
  794. selected.]
  795. SeeAlso [Cudd_AutodynEnableZdd Cudd_AutodynDisableZdd
  796. Cudd_ReorderingStatus]
  797. ******************************************************************************/
  798. int
  799. Cudd_ReorderingStatusZdd(
  800. DdManager * unique,
  801. Cudd_ReorderingType * method)
  802. {
  803. *method = unique->autoMethodZ;
  804. return(unique->autoDynZ);
  805. } /* end of Cudd_ReorderingStatusZdd */
  806. /**Function********************************************************************
  807. Synopsis [Tells whether the realignment of ZDD order to BDD order is
  808. enabled.]
  809. Description [Returns 1 if the realignment of ZDD order to BDD order is
  810. enabled; 0 otherwise.]
  811. SideEffects [None]
  812. SeeAlso [Cudd_zddRealignEnable Cudd_zddRealignDisable
  813. Cudd_bddRealignEnable Cudd_bddRealignDisable]
  814. ******************************************************************************/
  815. int
  816. Cudd_zddRealignmentEnabled(
  817. DdManager * unique)
  818. {
  819. return(unique->realign);
  820. } /* end of Cudd_zddRealignmentEnabled */
  821. /**Function********************************************************************
  822. Synopsis [Enables realignment of ZDD order to BDD order.]
  823. Description [Enables realignment of the ZDD variable order to the
  824. BDD variable order after the BDDs and ADDs have been reordered. The
  825. number of ZDD variables must be a multiple of the number of BDD
  826. variables for realignment to make sense. If this condition is not met,
  827. Cudd_ReduceHeap will return 0. Let <code>M</code> be the
  828. ratio of the two numbers. For the purpose of realignment, the ZDD
  829. variables from <code>M*i</code> to <code>(M+1)*i-1</code> are
  830. reagarded as corresponding to BDD variable <code>i</code>. Realignment
  831. is initially disabled.]
  832. SideEffects [None]
  833. SeeAlso [Cudd_ReduceHeap Cudd_zddRealignDisable
  834. Cudd_zddRealignmentEnabled Cudd_bddRealignDisable
  835. Cudd_bddRealignmentEnabled]
  836. ******************************************************************************/
  837. void
  838. Cudd_zddRealignEnable(
  839. DdManager * unique)
  840. {
  841. unique->realign = 1;
  842. return;
  843. } /* end of Cudd_zddRealignEnable */
  844. /**Function********************************************************************
  845. Synopsis [Disables realignment of ZDD order to BDD order.]
  846. Description []
  847. SideEffects [None]
  848. SeeAlso [Cudd_zddRealignEnable Cudd_zddRealignmentEnabled
  849. Cudd_bddRealignEnable Cudd_bddRealignmentEnabled]
  850. ******************************************************************************/
  851. void
  852. Cudd_zddRealignDisable(
  853. DdManager * unique)
  854. {
  855. unique->realign = 0;
  856. return;
  857. } /* end of Cudd_zddRealignDisable */
  858. /**Function********************************************************************
  859. Synopsis [Tells whether the realignment of BDD order to ZDD order is
  860. enabled.]
  861. Description [Returns 1 if the realignment of BDD order to ZDD order is
  862. enabled; 0 otherwise.]
  863. SideEffects [None]
  864. SeeAlso [Cudd_bddRealignEnable Cudd_bddRealignDisable
  865. Cudd_zddRealignEnable Cudd_zddRealignDisable]
  866. ******************************************************************************/
  867. int
  868. Cudd_bddRealignmentEnabled(
  869. DdManager * unique)
  870. {
  871. return(unique->realignZ);
  872. } /* end of Cudd_bddRealignmentEnabled */
  873. /**Function********************************************************************
  874. Synopsis [Enables realignment of BDD order to ZDD order.]
  875. Description [Enables realignment of the BDD variable order to the
  876. ZDD variable order after the ZDDs have been reordered. The
  877. number of ZDD variables must be a multiple of the number of BDD
  878. variables for realignment to make sense. If this condition is not met,
  879. Cudd_zddReduceHeap will return 0. Let <code>M</code> be the
  880. ratio of the two numbers. For the purpose of realignment, the ZDD
  881. variables from <code>M*i</code> to <code>(M+1)*i-1</code> are
  882. reagarded as corresponding to BDD variable <code>i</code>. Realignment
  883. is initially disabled.]
  884. SideEffects [None]
  885. SeeAlso [Cudd_zddReduceHeap Cudd_bddRealignDisable
  886. Cudd_bddRealignmentEnabled Cudd_zddRealignDisable
  887. Cudd_zddRealignmentEnabled]
  888. ******************************************************************************/
  889. void
  890. Cudd_bddRealignEnable(
  891. DdManager * unique)
  892. {
  893. unique->realignZ = 1;
  894. return;
  895. } /* end of Cudd_bddRealignEnable */
  896. /**Function********************************************************************
  897. Synopsis [Disables realignment of ZDD order to BDD order.]
  898. Description []
  899. SideEffects [None]
  900. SeeAlso [Cudd_bddRealignEnable Cudd_bddRealignmentEnabled
  901. Cudd_zddRealignEnable Cudd_zddRealignmentEnabled]
  902. ******************************************************************************/
  903. void
  904. Cudd_bddRealignDisable(
  905. DdManager * unique)
  906. {
  907. unique->realignZ = 0;
  908. return;
  909. } /* end of Cudd_bddRealignDisable */
  910. /**Function********************************************************************
  911. Synopsis [Returns the one constant of the manager.]
  912. Description [Returns the one constant of the manager. The one
  913. constant is common to ADDs and BDDs.]
  914. SideEffects [None]
  915. SeeAlso [Cudd_ReadZero Cudd_ReadLogicZero Cudd_ReadZddOne]
  916. ******************************************************************************/
  917. DdNode *
  918. Cudd_ReadOne(
  919. DdManager * dd)
  920. {
  921. return(dd->one);
  922. } /* end of Cudd_ReadOne */
  923. /**Function********************************************************************
  924. Synopsis [Returns the ZDD for the constant 1 function.]
  925. Description [Returns the ZDD for the constant 1 function.
  926. The representation of the constant 1 function as a ZDD depends on
  927. how many variables it (nominally) depends on. The index of the
  928. topmost variable in the support is given as argument <code>i</code>.]
  929. SideEffects [None]
  930. SeeAlso [Cudd_ReadOne]
  931. ******************************************************************************/
  932. DdNode *
  933. Cudd_ReadZddOne(
  934. DdManager * dd,
  935. int i)
  936. {
  937. if (i < 0)
  938. return(NULL);
  939. return(i < dd->sizeZ ? dd->univ[i] : DD_ONE(dd));
  940. } /* end of Cudd_ReadZddOne */
  941. /**Function********************************************************************
  942. Synopsis [Returns the zero constant of the manager.]
  943. Description [Returns the zero constant of the manager. The zero
  944. constant is the arithmetic zero, rather than the logic zero. The
  945. latter is the complement of the one constant.]
  946. SideEffects [None]
  947. SeeAlso [Cudd_ReadOne Cudd_ReadLogicZero]
  948. ******************************************************************************/
  949. DdNode *
  950. Cudd_ReadZero(
  951. DdManager * dd)
  952. {
  953. return(DD_ZERO(dd));
  954. } /* end of Cudd_ReadZero */
  955. /**Function********************************************************************
  956. Synopsis [Returns the logic zero constant of the manager.]
  957. Description [Returns the zero constant of the manager. The logic zero
  958. constant is the complement of the one constant, and is distinct from
  959. the arithmetic zero.]
  960. SideEffects [None]
  961. SeeAlso [Cudd_ReadOne Cudd_ReadZero]
  962. ******************************************************************************/
  963. DdNode *
  964. Cudd_ReadLogicZero(
  965. DdManager * dd)
  966. {
  967. return(Cudd_Not(DD_ONE(dd)));
  968. } /* end of Cudd_ReadLogicZero */
  969. /**Function********************************************************************
  970. Synopsis [Reads the plus-infinity constant from the manager.]
  971. Description []
  972. SideEffects [None]
  973. ******************************************************************************/
  974. DdNode *
  975. Cudd_ReadPlusInfinity(
  976. DdManager * dd)
  977. {
  978. return(dd->plusinfinity);
  979. } /* end of Cudd_ReadPlusInfinity */
  980. /**Function********************************************************************
  981. Synopsis [Reads the minus-infinity constant from the manager.]
  982. Description []
  983. SideEffects [None]
  984. ******************************************************************************/
  985. DdNode *
  986. Cudd_ReadMinusInfinity(
  987. DdManager * dd)
  988. {
  989. return(dd->minusinfinity);
  990. } /* end of Cudd_ReadMinusInfinity */
  991. /**Function********************************************************************
  992. Synopsis [Reads the background constant of the manager.]
  993. Description []
  994. SideEffects [None]
  995. ******************************************************************************/
  996. DdNode *
  997. Cudd_ReadBackground(
  998. DdManager * dd)
  999. {
  1000. return(dd->background);
  1001. } /* end of Cudd_ReadBackground */
  1002. /**Function********************************************************************
  1003. Synopsis [Sets the background constant of the manager.]
  1004. Description [Sets the background constant of the manager. It assumes
  1005. that the DdNode pointer bck is already referenced.]
  1006. SideEffects [None]
  1007. ******************************************************************************/
  1008. void
  1009. Cudd_SetBackground(
  1010. DdManager * dd,
  1011. DdNode * bck)
  1012. {
  1013. dd->background = bck;
  1014. } /* end of Cudd_SetBackground */
  1015. /**Function********************************************************************
  1016. Synopsis [Reads the number of slots in the cache.]
  1017. Description []
  1018. SideEffects [None]
  1019. SeeAlso [Cudd_ReadCacheUsedSlots]
  1020. ******************************************************************************/
  1021. unsigned int
  1022. Cudd_ReadCacheSlots(
  1023. DdManager * dd)
  1024. {
  1025. return(dd->cacheSlots);
  1026. } /* end of Cudd_ReadCacheSlots */
  1027. /**Function********************************************************************
  1028. Synopsis [Reads the fraction of used slots in the cache.]
  1029. Description [Reads the fraction of used slots in the cache. The unused
  1030. slots are those in which no valid data is stored. Garbage collection,
  1031. variable reordering, and cache resizing may cause used slots to become
  1032. unused.]
  1033. SideEffects [None]
  1034. SeeAlso [Cudd_ReadCacheSlots]
  1035. ******************************************************************************/
  1036. double
  1037. Cudd_ReadCacheUsedSlots(
  1038. DdManager * dd)
  1039. {
  1040. unsigned long used = 0;
  1041. int slots = dd->cacheSlots;
  1042. DdCache *cache = dd->cache;
  1043. int i;
  1044. for (i = 0; i < slots; i++) {
  1045. used += cache[i].h != 0;
  1046. }
  1047. return((double)used / (double) dd->cacheSlots);
  1048. } /* end of Cudd_ReadCacheUsedSlots */
  1049. /**Function********************************************************************
  1050. Synopsis [Returns the number of cache look-ups.]
  1051. Description [Returns the number of cache look-ups.]
  1052. SideEffects [None]
  1053. SeeAlso [Cudd_ReadCacheHits]
  1054. ******************************************************************************/
  1055. double
  1056. Cudd_ReadCacheLookUps(
  1057. DdManager * dd)
  1058. {
  1059. return(dd->cacheHits + dd->cacheMisses +
  1060. dd->totCachehits + dd->totCacheMisses);
  1061. } /* end of Cudd_ReadCacheLookUps */
  1062. /**Function********************************************************************
  1063. Synopsis [Returns the number of cache hits.]
  1064. Description []
  1065. SideEffects [None]
  1066. SeeAlso [Cudd_ReadCacheLookUps]
  1067. ******************************************************************************/
  1068. double
  1069. Cudd_ReadCacheHits(
  1070. DdManager * dd)
  1071. {
  1072. return(dd->cacheHits + dd->totCachehits);
  1073. } /* end of Cudd_ReadCacheHits */
  1074. /**Function********************************************************************
  1075. Synopsis [Returns the number of recursive calls.]
  1076. Description [Returns the number of recursive calls if the package is
  1077. compiled with DD_COUNT defined.]
  1078. SideEffects [None]
  1079. SeeAlso []
  1080. ******************************************************************************/
  1081. double
  1082. Cudd_ReadRecursiveCalls(
  1083. DdManager * dd)
  1084. {
  1085. #ifdef DD_COUNT
  1086. return(dd->recursiveCalls);
  1087. #else
  1088. return(-1.0);
  1089. #endif
  1090. } /* end of Cudd_ReadRecursiveCalls */
  1091. /**Function********************************************************************
  1092. Synopsis [Reads the hit rate that causes resizinig of the computed
  1093. table.]
  1094. Description []
  1095. SideEffects [None]
  1096. SeeAlso [Cudd_SetMinHit]
  1097. ******************************************************************************/
  1098. unsigned int
  1099. Cudd_ReadMinHit(
  1100. DdManager * dd)
  1101. {
  1102. /* Internally, the package manipulates the ratio of hits to
  1103. ** misses instead of the ratio of hits to accesses. */
  1104. return((unsigned int) (0.5 + 100 * dd->minHit / (1 + dd->minHit)));
  1105. } /* end of Cudd_ReadMinHit */
  1106. /**Function********************************************************************
  1107. Synopsis [Sets the hit rate that causes resizinig of the computed
  1108. table.]
  1109. Description [Sets the minHit parameter of the manager. This
  1110. parameter controls the resizing of the computed table. If the hit
  1111. rate is larger than the specified value, and the cache is not
  1112. already too large, then its size is doubled.]
  1113. SideEffects [None]
  1114. SeeAlso [Cudd_ReadMinHit]
  1115. ******************************************************************************/
  1116. void
  1117. Cudd_SetMinHit(
  1118. DdManager * dd,
  1119. unsigned int hr)
  1120. {
  1121. /* Internally, the package manipulates the ratio of hits to
  1122. ** misses instead of the ratio of hits to accesses. */
  1123. dd->minHit = (double) hr / (100.0 - (double) hr);
  1124. } /* end of Cudd_SetMinHit */
  1125. /**Function********************************************************************
  1126. Synopsis [Reads the looseUpTo parameter of the manager.]
  1127. Description []
  1128. SideEffects [None]
  1129. SeeAlso [Cudd_SetLooseUpTo Cudd_ReadMinHit Cudd_ReadMinDead]
  1130. ******************************************************************************/
  1131. unsigned int
  1132. Cudd_ReadLooseUpTo(
  1133. DdManager * dd)
  1134. {
  1135. return(dd->looseUpTo);
  1136. } /* end of Cudd_ReadLooseUpTo */
  1137. /**Function********************************************************************
  1138. Synopsis [Sets the looseUpTo parameter of the manager.]
  1139. Description [Sets the looseUpTo parameter of the manager. This
  1140. parameter of the manager controls the threshold beyond which no fast
  1141. growth of the unique table is allowed. The threshold is given as a
  1142. number of slots. If the value passed to this function is 0, the
  1143. function determines a suitable value based on the available memory.]
  1144. SideEffects [None]
  1145. SeeAlso [Cudd_ReadLooseUpTo Cudd_SetMinHit]
  1146. ******************************************************************************/
  1147. void
  1148. Cudd_SetLooseUpTo(
  1149. DdManager * dd,
  1150. unsigned int lut)
  1151. {
  1152. if (lut == 0) {
  1153. unsigned long datalimit = getSoftDataLimit();
  1154. lut = (unsigned int) (datalimit / (sizeof(DdNode) *
  1155. DD_MAX_LOOSE_FRACTION));
  1156. }
  1157. dd->looseUpTo = lut;
  1158. } /* end of Cudd_SetLooseUpTo */
  1159. /**Function********************************************************************
  1160. Synopsis [Returns the soft limit for the cache size.]
  1161. Description [Returns the soft limit for the cache size.]
  1162. SideEffects [None]
  1163. SeeAlso [Cudd_ReadMaxCacheHard]
  1164. ******************************************************************************/
  1165. unsigned int
  1166. Cudd_ReadMaxCache(
  1167. DdManager * dd)
  1168. {
  1169. return(2 * dd->cacheSlots + dd->cacheSlack);
  1170. } /* end of Cudd_ReadMaxCache */
  1171. /**Function********************************************************************
  1172. Synopsis [Reads the maxCacheHard parameter of the manager.]
  1173. Description []
  1174. SideEffects [None]
  1175. SeeAlso [Cudd_SetMaxCacheHard Cudd_ReadMaxCache]
  1176. ******************************************************************************/
  1177. unsigned int
  1178. Cudd_ReadMaxCacheHard(
  1179. DdManager * dd)
  1180. {
  1181. return(dd->maxCacheHard);
  1182. } /* end of Cudd_ReadMaxCache */
  1183. /**Function********************************************************************
  1184. Synopsis [Sets the maxCacheHard parameter of the manager.]
  1185. Description [Sets the maxCacheHard parameter of the manager. The
  1186. cache cannot grow larger than maxCacheHard entries. This parameter
  1187. allows an application to control the trade-off of memory versus
  1188. speed. If the value passed to this function is 0, the function
  1189. determines a suitable maximum cache size based on the available memory.]
  1190. SideEffects [None]
  1191. SeeAlso [Cudd_ReadMaxCacheHard Cudd_SetMaxCache]
  1192. ******************************************************************************/
  1193. void
  1194. Cudd_SetMaxCacheHard(
  1195. DdManager * dd,
  1196. unsigned int mc)
  1197. {
  1198. if (mc == 0) {
  1199. unsigned long datalimit = getSoftDataLimit();
  1200. mc = (unsigned int) (datalimit / (sizeof(DdCache) *
  1201. DD_MAX_CACHE_FRACTION));
  1202. }
  1203. dd->maxCacheHard = mc;
  1204. } /* end of Cudd_SetMaxCacheHard */
  1205. /**Function********************************************************************
  1206. Synopsis [Returns the number of BDD variables in existance.]
  1207. Description []
  1208. SideEffects [None]
  1209. SeeAlso [Cudd_ReadZddSize]
  1210. ******************************************************************************/
  1211. int
  1212. Cudd_ReadSize(
  1213. DdManager * dd)
  1214. {
  1215. return(dd->size);
  1216. } /* end of Cudd_ReadSize */
  1217. /**Function********************************************************************
  1218. Synopsis [Returns the number of ZDD variables in existance.]
  1219. Description []
  1220. SideEffects [None]
  1221. SeeAlso [Cudd_ReadSize]
  1222. ******************************************************************************/
  1223. int
  1224. Cudd_ReadZddSize(
  1225. DdManager * dd)
  1226. {
  1227. return(dd->sizeZ);
  1228. } /* end of Cudd_ReadZddSize */
  1229. /**Function********************************************************************
  1230. Synopsis [Returns the total number of slots of the unique table.]
  1231. Description [Returns the total number of slots of the unique table.
  1232. This number ismainly for diagnostic purposes.]
  1233. SideEffects [None]
  1234. ******************************************************************************/
  1235. unsigned int
  1236. Cudd_ReadSlots(
  1237. DdManager * dd)
  1238. {
  1239. return(dd->slots);
  1240. } /* end of Cudd_ReadSlots */
  1241. /**Function********************************************************************
  1242. Synopsis [Reads the fraction of used slots in the unique table.]
  1243. Description [Reads the fraction of used slots in the unique
  1244. table. The unused slots are those in which no valid data is
  1245. stored. Garbage collection, variable reordering, and subtable
  1246. resizing may cause used slots to become unused.]
  1247. SideEffects [None]
  1248. SeeAlso [Cudd_ReadSlots]
  1249. ******************************************************************************/
  1250. double
  1251. Cudd_ReadUsedSlots(
  1252. DdManager * dd)
  1253. {
  1254. unsigned long used = 0;
  1255. int i, j;
  1256. int size = dd->size;
  1257. DdNodePtr *nodelist;
  1258. DdSubtable *subtable;
  1259. DdNode *node;
  1260. DdNode *sentinel = &(dd->sentinel);
  1261. /* Scan each BDD/ADD subtable. */
  1262. for (i = 0; i < size; i++) {
  1263. subtable = &(dd->subtables[i]);
  1264. nodelist = subtable->nodelist;
  1265. for (j = 0; (unsigned) j < subtable->slots; j++) {
  1266. node = nodelist[j];
  1267. if (node != sentinel) {
  1268. used++;
  1269. }
  1270. }
  1271. }
  1272. /* Scan the ZDD subtables. */
  1273. size = dd->sizeZ;
  1274. for (i = 0; i < size; i++) {
  1275. subtable = &(dd->subtableZ[i]);
  1276. nodelist = subtable->nodelist;
  1277. for (j = 0; (unsigned) j < subtable->slots; j++) {
  1278. node = nodelist[j];
  1279. if (node != NULL) {
  1280. used++;
  1281. }
  1282. }
  1283. }
  1284. /* Constant table. */
  1285. subtable = &(dd->constants);
  1286. nodelist = subtable->nodelist;
  1287. for (j = 0; (unsigned) j < subtable->slots; j++) {
  1288. node = nodelist[j];
  1289. if (node != NULL) {
  1290. used++;
  1291. }
  1292. }
  1293. return((double)used / (double) dd->slots);
  1294. } /* end of Cudd_ReadUsedSlots */
  1295. /**Function********************************************************************
  1296. Synopsis [Computes the expected fraction of used slots in the unique
  1297. table.]
  1298. Description [Computes the fraction of slots in the unique table that
  1299. should be in use. This expected value is based on the assumption
  1300. that the hash function distributes the keys randomly; it can be
  1301. compared with the result of Cudd_ReadUsedSlots to monitor the
  1302. performance of the unique table hash function.]
  1303. SideEffects [None]
  1304. SeeAlso [Cudd_ReadSlots Cudd_ReadUsedSlots]
  1305. ******************************************************************************/
  1306. double
  1307. Cudd_ExpectedUsedSlots(
  1308. DdManager * dd)
  1309. {
  1310. int i;
  1311. int size = dd->size;
  1312. DdSubtable *subtable;
  1313. double empty = 0.0;
  1314. /* To each subtable we apply the corollary to Theorem 8.5 (occupancy
  1315. ** distribution) from Sedgewick and Flajolet's Analysis of Algorithms.
  1316. ** The corollary says that for a table with M buckets and a load ratio
  1317. ** of r, the expected number of empty buckets is asymptotically given
  1318. ** by M * exp(-r).
  1319. */
  1320. /* Scan each BDD/ADD subtable. */
  1321. for (i = 0; i < size; i++) {
  1322. subtable = &(dd->subtables[i]);
  1323. empty += (double) subtable->slots *
  1324. exp(-(double) subtable->keys / (double) subtable->slots);
  1325. }
  1326. /* Scan the ZDD subtables. */
  1327. size = dd->sizeZ;
  1328. for (i = 0; i < size; i++) {
  1329. subtable = &(dd->subtableZ[i]);
  1330. empty += (double) subtable->slots *
  1331. exp(-(double) subtable->keys / (double) subtable->slots);
  1332. }
  1333. /* Constant table. */
  1334. subtable = &(dd->constants);
  1335. empty += (double) subtable->slots *
  1336. exp(-(double) subtable->keys / (double) subtable->slots);
  1337. return(1.0 - empty / (double) dd->slots);
  1338. } /* end of Cudd_ExpectedUsedSlots */
  1339. /**Function********************************************************************
  1340. Synopsis [Returns the number of nodes in the unique table.]
  1341. Description [Returns the total number of nodes currently in the unique
  1342. table, including the dead nodes.]
  1343. SideEffects [None]
  1344. SeeAlso [Cudd_ReadDead]
  1345. ******************************************************************************/
  1346. unsigned int
  1347. Cudd_ReadKeys(
  1348. DdManager * dd)
  1349. {
  1350. return(dd->keys);
  1351. } /* end of Cudd_ReadKeys */
  1352. /**Function********************************************************************
  1353. Synopsis [Returns the number of dead nodes in the unique table.]
  1354. Description []
  1355. SideEffects [None]
  1356. SeeAlso [Cudd_ReadKeys]
  1357. ******************************************************************************/
  1358. unsigned int
  1359. Cudd_ReadDead(
  1360. DdManager * dd)
  1361. {
  1362. return(dd->dead);
  1363. } /* end of Cudd_ReadDead */
  1364. /**Function********************************************************************
  1365. Synopsis [Reads the minDead parameter of the manager.]
  1366. Description [Reads the minDead parameter of the manager. The minDead
  1367. parameter is used by the package to decide whether to collect garbage
  1368. or resize a subtable of the unique table when the subtable becomes
  1369. too full. The application can indirectly control the value of minDead
  1370. by setting the looseUpTo parameter.]
  1371. SideEffects [None]
  1372. SeeAlso [Cudd_ReadDead Cudd_ReadLooseUpTo Cudd_SetLooseUpTo]
  1373. ******************************************************************************/
  1374. unsigned int
  1375. Cudd_ReadMinDead(
  1376. DdManager * dd)
  1377. {
  1378. return(dd->minDead);
  1379. } /* end of Cudd_ReadMinDead */
  1380. /**Function********************************************************************
  1381. Synopsis [Returns the number of times reordering has occurred.]
  1382. Description [Returns the number of times reordering has occurred in the
  1383. manager. The number includes both the calls to Cudd_ReduceHeap from
  1384. the application program and those automatically performed by the
  1385. package. However, calls that do not even initiate reordering are not
  1386. counted. A call may not initiate reordering if there are fewer than
  1387. minsize live nodes in the manager, or if CUDD_REORDER_NONE is specified
  1388. as reordering method. The calls to Cudd_ShuffleHeap are not counted.]
  1389. SideEffects [None]
  1390. SeeAlso [Cudd_ReduceHeap Cudd_ReadReorderingTime]
  1391. ******************************************************************************/
  1392. unsigned int
  1393. Cudd_ReadReorderings(
  1394. DdManager * dd)
  1395. {
  1396. return(dd->reorderings);
  1397. } /* end of Cudd_ReadReorderings */
  1398. /**Function********************************************************************
  1399. Synopsis [Returns the maximum number of times reordering may be invoked.]
  1400. Description [Returns the maximum number of times reordering may be invoked in
  1401. this manager.]
  1402. SideEffects [None]
  1403. SeeAlso [Cudd_ReadReorderings Cudd_SetMaxReorderings Cudd_ReduceHeap]
  1404. ******************************************************************************/
  1405. unsigned int
  1406. Cudd_ReadMaxReorderings(
  1407. DdManager * dd)
  1408. {
  1409. return(dd->maxReorderings);
  1410. } /* end of Cudd_ReadMaxReorderings */
  1411. /**Function********************************************************************
  1412. Synopsis [Sets the maximum number of times reordering may be invoked.]
  1413. Description [Sets the maximum number of times reordering may be invoked in
  1414. this manager. The default value is (practically) infinite.]
  1415. SideEffects [None]
  1416. SeeAlso [Cudd_ReadReorderings Cudd_ReadMaxReorderings Cudd_ReduceHeap]
  1417. ******************************************************************************/
  1418. void
  1419. Cudd_SetMaxReorderings(
  1420. DdManager * dd, unsigned int mr)
  1421. {
  1422. dd->maxReorderings = mr;
  1423. } /* end of Cudd_SetMaxReorderings */
  1424. /**Function********************************************************************
  1425. Synopsis [Returns the time spent in reordering.]
  1426. Description [Returns the number of milliseconds spent reordering
  1427. variables since the manager was initialized. The time spent in collecting
  1428. garbage before reordering is included.]
  1429. SideEffects [None]
  1430. SeeAlso [Cudd_ReadReorderings]
  1431. ******************************************************************************/
  1432. long
  1433. Cudd_ReadReorderingTime(
  1434. DdManager * dd)
  1435. {
  1436. return(dd->reordTime);
  1437. } /* end of Cudd_ReadReorderingTime */
  1438. /**Function********************************************************************
  1439. Synopsis [Returns the number of times garbage collection has occurred.]
  1440. Description [Returns the number of times garbage collection has
  1441. occurred in the manager. The number includes both the calls from
  1442. reordering procedures and those caused by requests to create new
  1443. nodes.]
  1444. SideEffects [None]
  1445. SeeAlso [Cudd_ReadGarbageCollectionTime]
  1446. ******************************************************************************/
  1447. int
  1448. Cudd_ReadGarbageCollections(
  1449. DdManager * dd)
  1450. {
  1451. return(dd->garbageCollections);
  1452. } /* end of Cudd_ReadGarbageCollections */
  1453. /**Function********************************************************************
  1454. Synopsis [Returns the time spent in garbage collection.]
  1455. Description [Returns the number of milliseconds spent doing garbage
  1456. collection since the manager was initialized.]
  1457. SideEffects [None]
  1458. SeeAlso [Cudd_ReadGarbageCollections]
  1459. ******************************************************************************/
  1460. long
  1461. Cudd_ReadGarbageCollectionTime(
  1462. DdManager * dd)
  1463. {
  1464. return(dd->GCTime);
  1465. } /* end of Cudd_ReadGarbageCollectionTime */
  1466. /**Function********************************************************************
  1467. Synopsis [Returns the number of nodes freed.]
  1468. Description [Returns the number of nodes returned to the free list if the
  1469. keeping of this statistic is enabled; -1 otherwise. This statistic is
  1470. enabled only if the package is compiled with DD_STATS defined.]
  1471. SideEffects [None]
  1472. SeeAlso [Cudd_ReadNodesDropped]
  1473. ******************************************************************************/
  1474. double
  1475. Cudd_ReadNodesFreed(
  1476. DdManager * dd)
  1477. {
  1478. #ifdef DD_STATS
  1479. return(dd->nodesFreed);
  1480. #else
  1481. return(-1.0);
  1482. #endif
  1483. } /* end of Cudd_ReadNodesFreed */
  1484. /**Function********************************************************************
  1485. Synopsis [Returns the number of nodes dropped.]
  1486. Description [Returns the number of nodes killed by dereferencing if the
  1487. keeping of this statistic is enabled; -1 otherwise. This statistic is
  1488. enabled only if the package is compiled with DD_STATS defined.]
  1489. SideEffects [None]
  1490. SeeAlso [Cudd_ReadNodesFreed]
  1491. ******************************************************************************/
  1492. double
  1493. Cudd_ReadNodesDropped(
  1494. DdManager * dd)
  1495. {
  1496. #ifdef DD_STATS
  1497. return(dd->nodesDropped);
  1498. #else
  1499. return(-1.0);
  1500. #endif
  1501. } /* end of Cudd_ReadNodesDropped */
  1502. /**Function********************************************************************
  1503. Synopsis [Returns the number of look-ups in the unique table.]
  1504. Description [Returns the number of look-ups in the unique table if the
  1505. keeping of this statistic is enabled; -1 otherwise. This statistic is
  1506. enabled only if the package is compiled with DD_UNIQUE_PROFILE defined.]
  1507. SideEffects [None]
  1508. SeeAlso [Cudd_ReadUniqueLinks]
  1509. ******************************************************************************/
  1510. double
  1511. Cudd_ReadUniqueLookUps(
  1512. DdManager * dd)
  1513. {
  1514. #ifdef DD_UNIQUE_PROFILE
  1515. return(dd->uniqueLookUps);
  1516. #else
  1517. return(-1.0);
  1518. #endif
  1519. } /* end of Cudd_ReadUniqueLookUps */
  1520. /**Function********************************************************************
  1521. Synopsis [Returns the number of links followed in the unique table.]
  1522. Description [Returns the number of links followed during look-ups in the
  1523. unique table if the keeping of this statistic is enabled; -1 otherwise.
  1524. If an item is found in the first position of its collision list, the
  1525. number of links followed is taken to be 0. If it is in second position,
  1526. the number of links is 1, and so on. This statistic is enabled only if
  1527. the package is compiled with DD_UNIQUE_PROFILE defined.]
  1528. SideEffects [None]
  1529. SeeAlso [Cudd_ReadUniqueLookUps]
  1530. ******************************************************************************/
  1531. double
  1532. Cudd_ReadUniqueLinks(
  1533. DdManager * dd)
  1534. {
  1535. #ifdef DD_UNIQUE_PROFILE
  1536. return(dd->uniqueLinks);
  1537. #else
  1538. return(-1.0);
  1539. #endif
  1540. } /* end of Cudd_ReadUniqueLinks */
  1541. /**Function********************************************************************
  1542. Synopsis [Reads the siftMaxVar parameter of the manager.]
  1543. Description [Reads the siftMaxVar parameter of the manager. This
  1544. parameter gives the maximum number of variables that will be sifted
  1545. for each invocation of sifting.]
  1546. SideEffects [None]
  1547. SeeAlso [Cudd_ReadSiftMaxSwap Cudd_SetSiftMaxVar]
  1548. ******************************************************************************/
  1549. int
  1550. Cudd_ReadSiftMaxVar(
  1551. DdManager * dd)
  1552. {
  1553. return(dd->siftMaxVar);
  1554. } /* end of Cudd_ReadSiftMaxVar */
  1555. /**Function********************************************************************
  1556. Synopsis [Sets the siftMaxVar parameter of the manager.]
  1557. Description [Sets the siftMaxVar parameter of the manager. This
  1558. parameter gives the maximum number of variables that will be sifted
  1559. for each invocation of sifting.]
  1560. SideEffects [None]
  1561. SeeAlso [Cudd_SetSiftMaxSwap Cudd_ReadSiftMaxVar]
  1562. ******************************************************************************/
  1563. void
  1564. Cudd_SetSiftMaxVar(
  1565. DdManager * dd,
  1566. int smv)
  1567. {
  1568. dd->siftMaxVar = smv;
  1569. } /* end of Cudd_SetSiftMaxVar */
  1570. /**Function********************************************************************
  1571. Synopsis [Reads the siftMaxSwap parameter of the manager.]
  1572. Description [Reads the siftMaxSwap parameter of the manager. This
  1573. parameter gives the maximum number of swaps that will be attempted
  1574. for each invocation of sifting. The real number of swaps may exceed
  1575. the set limit because the package will always complete the sifting
  1576. of the variable that causes the limit to be reached.]
  1577. SideEffects [None]
  1578. SeeAlso [Cudd_ReadSiftMaxVar Cudd_SetSiftMaxSwap]
  1579. ******************************************************************************/
  1580. int
  1581. Cudd_ReadSiftMaxSwap(
  1582. DdManager * dd)
  1583. {
  1584. return(dd->siftMaxSwap);
  1585. } /* end of Cudd_ReadSiftMaxSwap */
  1586. /**Function********************************************************************
  1587. Synopsis [Sets the siftMaxSwap parameter of the manager.]
  1588. Description [Sets the siftMaxSwap parameter of the manager. This
  1589. parameter gives the maximum number of swaps that will be attempted
  1590. for each invocation of sifting. The real number of swaps may exceed
  1591. the set limit because the package will always complete the sifting
  1592. of the variable that causes the limit to be reached.]
  1593. SideEffects [None]
  1594. SeeAlso [Cudd_SetSiftMaxVar Cudd_ReadSiftMaxSwap]
  1595. ******************************************************************************/
  1596. void
  1597. Cudd_SetSiftMaxSwap(
  1598. DdManager * dd,
  1599. int sms)
  1600. {
  1601. dd->siftMaxSwap = sms;
  1602. } /* end of Cudd_SetSiftMaxSwap */
  1603. /**Function********************************************************************
  1604. Synopsis [Reads the maxGrowth parameter of the manager.]
  1605. Description [Reads the maxGrowth parameter of the manager. This
  1606. parameter determines how much the number of nodes can grow during
  1607. sifting of a variable. Overall, sifting never increases the size of
  1608. the decision diagrams. This parameter only refers to intermediate
  1609. results. A lower value will speed up sifting, possibly at the
  1610. expense of quality.]
  1611. SideEffects [None]
  1612. SeeAlso [Cudd_SetMaxGrowth Cudd_ReadMaxGrowthAlternate]
  1613. ******************************************************************************/
  1614. double
  1615. Cudd_ReadMaxGrowth(
  1616. DdManager * dd)
  1617. {
  1618. return(dd->maxGrowth);
  1619. } /* end of Cudd_ReadMaxGrowth */
  1620. /**Function********************************************************************
  1621. Synopsis [Sets the maxGrowth parameter of the manager.]
  1622. Description [Sets the maxGrowth parameter of the manager. This
  1623. parameter determines how much the number of nodes can grow during
  1624. sifting of a variable. Overall, sifting never increases the size of
  1625. the decision diagrams. This parameter only refers to intermediate
  1626. results. A lower value will speed up sifting, possibly at the
  1627. expense of quality.]
  1628. SideEffects [None]
  1629. SeeAlso [Cudd_ReadMaxGrowth Cudd_SetMaxGrowthAlternate]
  1630. ******************************************************************************/
  1631. void
  1632. Cudd_SetMaxGrowth(
  1633. DdManager * dd,
  1634. double mg)
  1635. {
  1636. dd->maxGrowth = mg;
  1637. } /* end of Cudd_SetMaxGrowth */
  1638. /**Function********************************************************************
  1639. Synopsis [Reads the maxGrowthAlt parameter of the manager.]
  1640. Description [Reads the maxGrowthAlt parameter of the manager. This
  1641. parameter is analogous to the maxGrowth paramter, and is used every
  1642. given number of reorderings instead of maxGrowth. The number of
  1643. reorderings is set with Cudd_SetReorderingCycle. If the number of
  1644. reorderings is 0 (default) maxGrowthAlt is never used.]
  1645. SideEffects [None]
  1646. SeeAlso [Cudd_ReadMaxGrowth Cudd_SetMaxGrowthAlternate
  1647. Cudd_SetReorderingCycle Cudd_ReadReorderingCycle]
  1648. ******************************************************************************/
  1649. double
  1650. Cudd_ReadMaxGrowthAlternate(
  1651. DdManager * dd)
  1652. {
  1653. return(dd->maxGrowthAlt);
  1654. } /* end of Cudd_ReadMaxGrowthAlternate */
  1655. /**Function********************************************************************
  1656. Synopsis [Sets the maxGrowthAlt parameter of the manager.]
  1657. Description [Sets the maxGrowthAlt parameter of the manager. This
  1658. parameter is analogous to the maxGrowth paramter, and is used every
  1659. given number of reorderings instead of maxGrowth. The number of
  1660. reorderings is set with Cudd_SetReorderingCycle. If the number of
  1661. reorderings is 0 (default) maxGrowthAlt is never used.]
  1662. SideEffects [None]
  1663. SeeAlso [Cudd_ReadMaxGrowthAlternate Cudd_SetMaxGrowth
  1664. Cudd_SetReorderingCycle Cudd_ReadReorderingCycle]
  1665. ******************************************************************************/
  1666. void
  1667. Cudd_SetMaxGrowthAlternate(
  1668. DdManager * dd,
  1669. double mg)
  1670. {
  1671. dd->maxGrowthAlt = mg;
  1672. } /* end of Cudd_SetMaxGrowthAlternate */
  1673. /**Function********************************************************************
  1674. Synopsis [Reads the reordCycle parameter of the manager.]
  1675. Description [Reads the reordCycle parameter of the manager. This
  1676. parameter determines how often the alternate threshold on maximum
  1677. growth is used in reordering.]
  1678. SideEffects [None]
  1679. SeeAlso [Cudd_ReadMaxGrowthAlternate Cudd_SetMaxGrowthAlternate
  1680. Cudd_SetReorderingCycle]
  1681. ******************************************************************************/
  1682. int
  1683. Cudd_ReadReorderingCycle(
  1684. DdManager * dd)
  1685. {
  1686. return(dd->reordCycle);
  1687. } /* end of Cudd_ReadReorderingCycle */
  1688. /**Function********************************************************************
  1689. Synopsis [Sets the reordCycle parameter of the manager.]
  1690. Description [Sets the reordCycle parameter of the manager. This
  1691. parameter determines how often the alternate threshold on maximum
  1692. growth is used in reordering.]
  1693. SideEffects [None]
  1694. SeeAlso [Cudd_ReadMaxGrowthAlternate Cudd_SetMaxGrowthAlternate
  1695. Cudd_ReadReorderingCycle]
  1696. ******************************************************************************/
  1697. void
  1698. Cudd_SetReorderingCycle(
  1699. DdManager * dd,
  1700. int cycle)
  1701. {
  1702. dd->reordCycle = cycle;
  1703. } /* end of Cudd_SetReorderingCycle */
  1704. /**Function********************************************************************
  1705. Synopsis [Returns the variable group tree of the manager.]
  1706. Description []
  1707. SideEffects [None]
  1708. SeeAlso [Cudd_SetTree Cudd_FreeTree Cudd_ReadZddTree]
  1709. ******************************************************************************/
  1710. MtrNode *
  1711. Cudd_ReadTree(
  1712. DdManager * dd)
  1713. {
  1714. return(dd->tree);
  1715. } /* end of Cudd_ReadTree */
  1716. /**Function********************************************************************
  1717. Synopsis [Sets the variable group tree of the manager.]
  1718. Description []
  1719. SideEffects [None]
  1720. SeeAlso [Cudd_FreeTree Cudd_ReadTree Cudd_SetZddTree]
  1721. ******************************************************************************/
  1722. void
  1723. Cudd_SetTree(
  1724. DdManager * dd,
  1725. MtrNode * tree)
  1726. {
  1727. if (dd->tree != NULL) {
  1728. Mtr_FreeTree(dd->tree);
  1729. }
  1730. dd->tree = tree;
  1731. if (tree == NULL) return;
  1732. fixVarTree(tree, dd->perm, dd->size);
  1733. return;
  1734. } /* end of Cudd_SetTree */
  1735. /**Function********************************************************************
  1736. Synopsis [Frees the variable group tree of the manager.]
  1737. Description []
  1738. SideEffects [None]
  1739. SeeAlso [Cudd_SetTree Cudd_ReadTree Cudd_FreeZddTree]
  1740. ******************************************************************************/
  1741. void
  1742. Cudd_FreeTree(
  1743. DdManager * dd)
  1744. {
  1745. if (dd->tree != NULL) {
  1746. Mtr_FreeTree(dd->tree);
  1747. dd->tree = NULL;
  1748. }
  1749. return;
  1750. } /* end of Cudd_FreeTree */
  1751. /**Function********************************************************************
  1752. Synopsis [Returns the variable group tree of the manager.]
  1753. Description []
  1754. SideEffects [None]
  1755. SeeAlso [Cudd_SetZddTree Cudd_FreeZddTree Cudd_ReadTree]
  1756. ******************************************************************************/
  1757. MtrNode *
  1758. Cudd_ReadZddTree(
  1759. DdManager * dd)
  1760. {
  1761. return(dd->treeZ);
  1762. } /* end of Cudd_ReadZddTree */
  1763. /**Function********************************************************************
  1764. Synopsis [Sets the ZDD variable group tree of the manager.]
  1765. Description []
  1766. SideEffects [None]
  1767. SeeAlso [Cudd_FreeZddTree Cudd_ReadZddTree Cudd_SetTree]
  1768. ******************************************************************************/
  1769. void
  1770. Cudd_SetZddTree(
  1771. DdManager * dd,
  1772. MtrNode * tree)
  1773. {
  1774. if (dd->treeZ != NULL) {
  1775. Mtr_FreeTree(dd->treeZ);
  1776. }
  1777. dd->treeZ = tree;
  1778. if (tree == NULL) return;
  1779. fixVarTree(tree, dd->permZ, dd->sizeZ);
  1780. return;
  1781. } /* end of Cudd_SetZddTree */
  1782. /**Function********************************************************************
  1783. Synopsis [Frees the variable group tree of the manager.]
  1784. Description []
  1785. SideEffects [None]
  1786. SeeAlso [Cudd_SetZddTree Cudd_ReadZddTree Cudd_FreeTree]
  1787. ******************************************************************************/
  1788. void
  1789. Cudd_FreeZddTree(
  1790. DdManager * dd)
  1791. {
  1792. if (dd->treeZ != NULL) {
  1793. Mtr_FreeTree(dd->treeZ);
  1794. dd->treeZ = NULL;
  1795. }
  1796. return;
  1797. } /* end of Cudd_FreeZddTree */
  1798. /**Function********************************************************************
  1799. Synopsis [Returns the index of the node.]
  1800. Description [Returns the index of the node. The node pointer can be
  1801. either regular or complemented.]
  1802. SideEffects [None]
  1803. SeeAlso [Cudd_ReadIndex]
  1804. ******************************************************************************/
  1805. unsigned int
  1806. Cudd_NodeReadIndex(
  1807. DdNode * node)
  1808. {
  1809. return((unsigned int) Cudd_Regular(node)->index);
  1810. } /* end of Cudd_NodeReadIndex */
  1811. /**Function********************************************************************
  1812. Synopsis [Returns the current position of the i-th variable in the
  1813. order.]
  1814. Description [Returns the current position of the i-th variable in
  1815. the order. If the index is CUDD_CONST_INDEX, returns
  1816. CUDD_CONST_INDEX; otherwise, if the index is out of bounds returns
  1817. -1.]
  1818. SideEffects [None]
  1819. SeeAlso [Cudd_ReadInvPerm Cudd_ReadPermZdd]
  1820. ******************************************************************************/
  1821. int
  1822. Cudd_ReadPerm(
  1823. DdManager * dd,
  1824. int i)
  1825. {
  1826. if (i == CUDD_CONST_INDEX) return(CUDD_CONST_INDEX);
  1827. if (i < 0 || i >= dd->size) return(-1);
  1828. return(dd->perm[i]);
  1829. } /* end of Cudd_ReadPerm */
  1830. /**Function********************************************************************
  1831. Synopsis [Returns the current position of the i-th ZDD variable in the
  1832. order.]
  1833. Description [Returns the current position of the i-th ZDD variable
  1834. in the order. If the index is CUDD_CONST_INDEX, returns
  1835. CUDD_CONST_INDEX; otherwise, if the index is out of bounds returns
  1836. -1.]
  1837. SideEffects [None]
  1838. SeeAlso [Cudd_ReadInvPermZdd Cudd_ReadPerm]
  1839. ******************************************************************************/
  1840. int
  1841. Cudd_ReadPermZdd(
  1842. DdManager * dd,
  1843. int i)
  1844. {
  1845. if (i == CUDD_CONST_INDEX) return(CUDD_CONST_INDEX);
  1846. if (i < 0 || i >= dd->sizeZ) return(-1);
  1847. return(dd->permZ[i]);
  1848. } /* end of Cudd_ReadPermZdd */
  1849. /**Function********************************************************************
  1850. Synopsis [Returns the index of the variable currently in the i-th
  1851. position of the order.]
  1852. Description [Returns the index of the variable currently in the i-th
  1853. position of the order. If the index is CUDD_CONST_INDEX, returns
  1854. CUDD_CONST_INDEX; otherwise, if the index is out of bounds returns -1.]
  1855. SideEffects [None]
  1856. SeeAlso [Cudd_ReadPerm Cudd_ReadInvPermZdd]
  1857. ******************************************************************************/
  1858. int
  1859. Cudd_ReadInvPerm(
  1860. DdManager * dd,
  1861. int i)
  1862. {
  1863. if (i == CUDD_CONST_INDEX) return(CUDD_CONST_INDEX);
  1864. if (i < 0 || i >= dd->size) return(-1);
  1865. return(dd->invperm[i]);
  1866. } /* end of Cudd_ReadInvPerm */
  1867. /**Function********************************************************************
  1868. Synopsis [Returns the index of the ZDD variable currently in the i-th
  1869. position of the order.]
  1870. Description [Returns the index of the ZDD variable currently in the
  1871. i-th position of the order. If the index is CUDD_CONST_INDEX, returns
  1872. CUDD_CONST_INDEX; otherwise, if the index is out of bounds returns -1.]
  1873. SideEffects [None]
  1874. SeeAlso [Cudd_ReadPerm Cudd_ReadInvPermZdd]
  1875. ******************************************************************************/
  1876. int
  1877. Cudd_ReadInvPermZdd(
  1878. DdManager * dd,
  1879. int i)
  1880. {
  1881. if (i == CUDD_CONST_INDEX) return(CUDD_CONST_INDEX);
  1882. if (i < 0 || i >= dd->sizeZ) return(-1);
  1883. return(dd->invpermZ[i]);
  1884. } /* end of Cudd_ReadInvPermZdd */
  1885. /**Function********************************************************************
  1886. Synopsis [Returns the i-th element of the vars array.]
  1887. Description [Returns the i-th element of the vars array if it falls
  1888. within the array bounds; NULL otherwise. If i is the index of an
  1889. existing variable, this function produces the same result as
  1890. Cudd_bddIthVar. However, if the i-th var does not exist yet,
  1891. Cudd_bddIthVar will create it, whereas Cudd_ReadVars will not.]
  1892. SideEffects [None]
  1893. SeeAlso [Cudd_bddIthVar]
  1894. ******************************************************************************/
  1895. DdNode *
  1896. Cudd_ReadVars(
  1897. DdManager * dd,
  1898. int i)
  1899. {
  1900. if (i < 0 || i > dd->size) return(NULL);
  1901. return(dd->vars[i]);
  1902. } /* end of Cudd_ReadVars */
  1903. /**Function********************************************************************
  1904. Synopsis [Reads the epsilon parameter of the manager.]
  1905. Description [Reads the epsilon parameter of the manager. The epsilon
  1906. parameter control the comparison between floating point numbers.]
  1907. SideEffects [None]
  1908. SeeAlso [Cudd_SetEpsilon]
  1909. ******************************************************************************/
  1910. CUDD_VALUE_TYPE
  1911. Cudd_ReadEpsilon(
  1912. DdManager * dd)
  1913. {
  1914. return(dd->epsilon);
  1915. } /* end of Cudd_ReadEpsilon */
  1916. /**Function********************************************************************
  1917. Synopsis [Sets the epsilon parameter of the manager to ep.]
  1918. Description [Sets the epsilon parameter of the manager to ep. The epsilon
  1919. parameter control the comparison between floating point numbers.]
  1920. SideEffects [None]
  1921. SeeAlso [Cudd_ReadEpsilon]
  1922. ******************************************************************************/
  1923. void
  1924. Cudd_SetEpsilon(
  1925. DdManager * dd,
  1926. CUDD_VALUE_TYPE ep)
  1927. {
  1928. dd->epsilon = ep;
  1929. } /* end of Cudd_SetEpsilon */
  1930. /**Function********************************************************************
  1931. Synopsis [Reads the groupcheck parameter of the manager.]
  1932. Description [Reads the groupcheck parameter of the manager. The
  1933. groupcheck parameter determines the aggregation criterion in group
  1934. sifting.]
  1935. SideEffects [None]
  1936. SeeAlso [Cudd_SetGroupcheck]
  1937. ******************************************************************************/
  1938. Cudd_AggregationType
  1939. Cudd_ReadGroupcheck(
  1940. DdManager * dd)
  1941. {
  1942. return(dd->groupcheck);
  1943. } /* end of Cudd_ReadGroupCheck */
  1944. /**Function********************************************************************
  1945. Synopsis [Sets the parameter groupcheck of the manager to gc.]
  1946. Description [Sets the parameter groupcheck of the manager to gc. The
  1947. groupcheck parameter determines the aggregation criterion in group
  1948. sifting.]
  1949. SideEffects [None]
  1950. SeeAlso [Cudd_ReadGroupCheck]
  1951. ******************************************************************************/
  1952. void
  1953. Cudd_SetGroupcheck(
  1954. DdManager * dd,
  1955. Cudd_AggregationType gc)
  1956. {
  1957. dd->groupcheck = gc;
  1958. } /* end of Cudd_SetGroupcheck */
  1959. /**Function********************************************************************
  1960. Synopsis [Tells whether garbage collection is enabled.]
  1961. Description [Returns 1 if garbage collection is enabled; 0 otherwise.]
  1962. SideEffects [None]
  1963. SeeAlso [Cudd_EnableGarbageCollection Cudd_DisableGarbageCollection]
  1964. ******************************************************************************/
  1965. int
  1966. Cudd_GarbageCollectionEnabled(
  1967. DdManager * dd)
  1968. {
  1969. return(dd->gcEnabled);
  1970. } /* end of Cudd_GarbageCollectionEnabled */
  1971. /**Function********************************************************************
  1972. Synopsis [Enables garbage collection.]
  1973. Description [Enables garbage collection. Garbage collection is
  1974. initially enabled. Therefore it is necessary to call this function
  1975. only if garbage collection has been explicitly disabled.]
  1976. SideEffects [None]
  1977. SeeAlso [Cudd_DisableGarbageCollection Cudd_GarbageCollectionEnabled]
  1978. ******************************************************************************/
  1979. void
  1980. Cudd_EnableGarbageCollection(
  1981. DdManager * dd)
  1982. {
  1983. dd->gcEnabled = 1;
  1984. } /* end of Cudd_EnableGarbageCollection */
  1985. /**Function********************************************************************
  1986. Synopsis [Disables garbage collection.]
  1987. Description [Disables garbage collection. Garbage collection is
  1988. initially enabled. This function may be called to disable it.
  1989. However, garbage collection will still occur when a new node must be
  1990. created and no memory is left, or when garbage collection is required
  1991. for correctness. (E.g., before reordering.)]
  1992. SideEffects [None]
  1993. SeeAlso [Cudd_EnableGarbageCollection Cudd_GarbageCollectionEnabled]
  1994. ******************************************************************************/
  1995. void
  1996. Cudd_DisableGarbageCollection(
  1997. DdManager * dd)
  1998. {
  1999. dd->gcEnabled = 0;
  2000. } /* end of Cudd_DisableGarbageCollection */
  2001. /**Function********************************************************************
  2002. Synopsis [Tells whether dead nodes are counted towards triggering
  2003. reordering.]
  2004. Description [Tells whether dead nodes are counted towards triggering
  2005. reordering. Returns 1 if dead nodes are counted; 0 otherwise.]
  2006. SideEffects [None]
  2007. SeeAlso [Cudd_TurnOnCountDead Cudd_TurnOffCountDead]
  2008. ******************************************************************************/
  2009. int
  2010. Cudd_DeadAreCounted(
  2011. DdManager * dd)
  2012. {
  2013. return(dd->countDead == 0 ? 1 : 0);
  2014. } /* end of Cudd_DeadAreCounted */
  2015. /**Function********************************************************************
  2016. Synopsis [Causes the dead nodes to be counted towards triggering
  2017. reordering.]
  2018. Description [Causes the dead nodes to be counted towards triggering
  2019. reordering. This causes more frequent reorderings. By default dead
  2020. nodes are not counted.]
  2021. SideEffects [Changes the manager.]
  2022. SeeAlso [Cudd_TurnOffCountDead Cudd_DeadAreCounted]
  2023. ******************************************************************************/
  2024. void
  2025. Cudd_TurnOnCountDead(
  2026. DdManager * dd)
  2027. {
  2028. dd->countDead = 0;
  2029. } /* end of Cudd_TurnOnCountDead */
  2030. /**Function********************************************************************
  2031. Synopsis [Causes the dead nodes not to be counted towards triggering
  2032. reordering.]
  2033. Description [Causes the dead nodes not to be counted towards
  2034. triggering reordering. This causes less frequent reorderings. By
  2035. default dead nodes are not counted. Therefore there is no need to
  2036. call this function unless Cudd_TurnOnCountDead has been previously
  2037. called.]
  2038. SideEffects [Changes the manager.]
  2039. SeeAlso [Cudd_TurnOnCountDead Cudd_DeadAreCounted]
  2040. ******************************************************************************/
  2041. void
  2042. Cudd_TurnOffCountDead(
  2043. DdManager * dd)
  2044. {
  2045. dd->countDead = ~0;
  2046. } /* end of Cudd_TurnOffCountDead */
  2047. /**Function********************************************************************
  2048. Synopsis [Returns the current value of the recombination parameter used
  2049. in group sifting.]
  2050. Description [Returns the current value of the recombination
  2051. parameter used in group sifting. A larger (positive) value makes the
  2052. aggregation of variables due to the second difference criterion more
  2053. likely. A smaller (negative) value makes aggregation less likely.]
  2054. SideEffects [None]
  2055. SeeAlso [Cudd_SetRecomb]
  2056. ******************************************************************************/
  2057. int
  2058. Cudd_ReadRecomb(
  2059. DdManager * dd)
  2060. {
  2061. return(dd->recomb);
  2062. } /* end of Cudd_ReadRecomb */
  2063. /**Function********************************************************************
  2064. Synopsis [Sets the value of the recombination parameter used in group
  2065. sifting.]
  2066. Description [Sets the value of the recombination parameter used in
  2067. group sifting. A larger (positive) value makes the aggregation of
  2068. variables due to the second difference criterion more likely. A
  2069. smaller (negative) value makes aggregation less likely. The default
  2070. value is 0.]
  2071. SideEffects [Changes the manager.]
  2072. SeeAlso [Cudd_ReadRecomb]
  2073. ******************************************************************************/
  2074. void
  2075. Cudd_SetRecomb(
  2076. DdManager * dd,
  2077. int recomb)
  2078. {
  2079. dd->recomb = recomb;
  2080. } /* end of Cudd_SetRecomb */
  2081. /**Function********************************************************************
  2082. Synopsis [Returns the current value of the symmviolation parameter used
  2083. in group sifting.]
  2084. Description [Returns the current value of the symmviolation
  2085. parameter. This parameter is used in group sifting to decide how
  2086. many violations to the symmetry conditions <code>f10 = f01</code> or
  2087. <code>f11 = f00</code> are tolerable when checking for aggregation
  2088. due to extended symmetry. The value should be between 0 and 100. A
  2089. small value causes fewer variables to be aggregated. The default
  2090. value is 0.]
  2091. SideEffects [None]
  2092. SeeAlso [Cudd_SetSymmviolation]
  2093. ******************************************************************************/
  2094. int
  2095. Cudd_ReadSymmviolation(
  2096. DdManager * dd)
  2097. {
  2098. return(dd->symmviolation);
  2099. } /* end of Cudd_ReadSymmviolation */
  2100. /**Function********************************************************************
  2101. Synopsis [Sets the value of the symmviolation parameter used
  2102. in group sifting.]
  2103. Description [Sets the value of the symmviolation
  2104. parameter. This parameter is used in group sifting to decide how
  2105. many violations to the symmetry conditions <code>f10 = f01</code> or
  2106. <code>f11 = f00</code> are tolerable when checking for aggregation
  2107. due to extended symmetry. The value should be between 0 and 100. A
  2108. small value causes fewer variables to be aggregated. The default
  2109. value is 0.]
  2110. SideEffects [Changes the manager.]
  2111. SeeAlso [Cudd_ReadSymmviolation]
  2112. ******************************************************************************/
  2113. void
  2114. Cudd_SetSymmviolation(
  2115. DdManager * dd,
  2116. int symmviolation)
  2117. {
  2118. dd->symmviolation = symmviolation;
  2119. } /* end of Cudd_SetSymmviolation */
  2120. /**Function********************************************************************
  2121. Synopsis [Returns the current value of the arcviolation parameter used
  2122. in group sifting.]
  2123. Description [Returns the current value of the arcviolation
  2124. parameter. This parameter is used in group sifting to decide how
  2125. many arcs into <code>y</code> not coming from <code>x</code> are
  2126. tolerable when checking for aggregation due to extended
  2127. symmetry. The value should be between 0 and 100. A small value
  2128. causes fewer variables to be aggregated. The default value is 0.]
  2129. SideEffects [None]
  2130. SeeAlso [Cudd_SetArcviolation]
  2131. ******************************************************************************/
  2132. int
  2133. Cudd_ReadArcviolation(
  2134. DdManager * dd)
  2135. {
  2136. return(dd->arcviolation);
  2137. } /* end of Cudd_ReadArcviolation */
  2138. /**Function********************************************************************
  2139. Synopsis [Sets the value of the arcviolation parameter used
  2140. in group sifting.]
  2141. Description [Sets the value of the arcviolation
  2142. parameter. This parameter is used in group sifting to decide how
  2143. many arcs into <code>y</code> not coming from <code>x</code> are
  2144. tolerable when checking for aggregation due to extended
  2145. symmetry. The value should be between 0 and 100. A small value
  2146. causes fewer variables to be aggregated. The default value is 0.]
  2147. SideEffects [None]
  2148. SeeAlso [Cudd_ReadArcviolation]
  2149. ******************************************************************************/
  2150. void
  2151. Cudd_SetArcviolation(
  2152. DdManager * dd,
  2153. int arcviolation)
  2154. {
  2155. dd->arcviolation = arcviolation;
  2156. } /* end of Cudd_SetArcviolation */
  2157. /**Function********************************************************************
  2158. Synopsis [Reads the current size of the population used by the
  2159. genetic algorithm for reordering.]
  2160. Description [Reads the current size of the population used by the
  2161. genetic algorithm for variable reordering. A larger population size will
  2162. cause the genetic algorithm to take more time, but will generally
  2163. produce better results. The default value is 0, in which case the
  2164. package uses three times the number of variables as population size,
  2165. with a maximum of 120.]
  2166. SideEffects [None]
  2167. SeeAlso [Cudd_SetPopulationSize]
  2168. ******************************************************************************/
  2169. int
  2170. Cudd_ReadPopulationSize(
  2171. DdManager * dd)
  2172. {
  2173. return(dd->populationSize);
  2174. } /* end of Cudd_ReadPopulationSize */
  2175. /**Function********************************************************************
  2176. Synopsis [Sets the size of the population used by the
  2177. genetic algorithm for reordering.]
  2178. Description [Sets the size of the population used by the
  2179. genetic algorithm for variable reordering. A larger population size will
  2180. cause the genetic algorithm to take more time, but will generally
  2181. produce better results. The default value is 0, in which case the
  2182. package uses three times the number of variables as population size,
  2183. with a maximum of 120.]
  2184. SideEffects [Changes the manager.]
  2185. SeeAlso [Cudd_ReadPopulationSize]
  2186. ******************************************************************************/
  2187. void
  2188. Cudd_SetPopulationSize(
  2189. DdManager * dd,
  2190. int populationSize)
  2191. {
  2192. dd->populationSize = populationSize;
  2193. } /* end of Cudd_SetPopulationSize */
  2194. /**Function********************************************************************
  2195. Synopsis [Reads the current number of crossovers used by the
  2196. genetic algorithm for reordering.]
  2197. Description [Reads the current number of crossovers used by the
  2198. genetic algorithm for variable reordering. A larger number of crossovers will
  2199. cause the genetic algorithm to take more time, but will generally
  2200. produce better results. The default value is 0, in which case the
  2201. package uses three times the number of variables as number of crossovers,
  2202. with a maximum of 60.]
  2203. SideEffects [None]
  2204. SeeAlso [Cudd_SetNumberXovers]
  2205. ******************************************************************************/
  2206. int
  2207. Cudd_ReadNumberXovers(
  2208. DdManager * dd)
  2209. {
  2210. return(dd->numberXovers);
  2211. } /* end of Cudd_ReadNumberXovers */
  2212. /**Function********************************************************************
  2213. Synopsis [Sets the number of crossovers used by the
  2214. genetic algorithm for reordering.]
  2215. Description [Sets the number of crossovers used by the genetic
  2216. algorithm for variable reordering. A larger number of crossovers
  2217. will cause the genetic algorithm to take more time, but will
  2218. generally produce better results. The default value is 0, in which
  2219. case the package uses three times the number of variables as number
  2220. of crossovers, with a maximum of 60.]
  2221. SideEffects [None]
  2222. SeeAlso [Cudd_ReadNumberXovers]
  2223. ******************************************************************************/
  2224. void
  2225. Cudd_SetNumberXovers(
  2226. DdManager * dd,
  2227. int numberXovers)
  2228. {
  2229. dd->numberXovers = numberXovers;
  2230. } /* end of Cudd_SetNumberXovers */
  2231. /**Function********************************************************************
  2232. Synopsis [Returns the order randomization factor.]
  2233. Description [Returns the order randomization factor. If non-zero this
  2234. factor is used to determine a perturbation of the next reordering threshold.
  2235. Larger factors cause larger perturbations.]
  2236. SideEffects [None]
  2237. SeeAlso [Cudd_SetOrderRandomization]
  2238. ******************************************************************************/
  2239. unsigned int
  2240. Cudd_ReadOrderRandomization(
  2241. DdManager * dd)
  2242. {
  2243. return(dd->randomizeOrder);
  2244. } /* end of Cudd_ReadOrderRandomization */
  2245. /**Function********************************************************************
  2246. Synopsis [Sets the order randomization factor.]
  2247. Description []
  2248. SideEffects [None]
  2249. SeeAlso [Cudd_ReadOrderRandomization]
  2250. ******************************************************************************/
  2251. void
  2252. Cudd_SetOrderRandomization(
  2253. DdManager * dd,
  2254. unsigned int factor)
  2255. {
  2256. dd->randomizeOrder = factor;
  2257. } /* end of Cudd_SetOrderRandomization */
  2258. /**Function********************************************************************
  2259. Synopsis [Returns the memory in use by the manager measured in bytes.]
  2260. Description []
  2261. SideEffects [None]
  2262. SeeAlso []
  2263. ******************************************************************************/
  2264. unsigned long
  2265. Cudd_ReadMemoryInUse(
  2266. DdManager * dd)
  2267. {
  2268. return(dd->memused);
  2269. } /* end of Cudd_ReadMemoryInUse */
  2270. /**Function********************************************************************
  2271. Synopsis [Prints out statistics and settings for a CUDD manager.]
  2272. Description [Prints out statistics and settings for a CUDD manager.
  2273. Returns 1 if successful; 0 otherwise.]
  2274. SideEffects [None]
  2275. SeeAlso []
  2276. ******************************************************************************/
  2277. int
  2278. Cudd_PrintInfo(
  2279. DdManager * dd,
  2280. FILE * fp)
  2281. {
  2282. int retval;
  2283. Cudd_ReorderingType autoMethod, autoMethodZ;
  2284. /* Modifiable parameters. */
  2285. retval = fprintf(fp,"**** CUDD modifiable parameters ****\n");
  2286. if (retval == EOF) return(0);
  2287. retval = fprintf(fp,"Hard limit for cache size: %u\n",
  2288. Cudd_ReadMaxCacheHard(dd));
  2289. if (retval == EOF) return(0);
  2290. retval = fprintf(fp,"Cache hit threshold for resizing: %u%%\n",
  2291. Cudd_ReadMinHit(dd));
  2292. if (retval == EOF) return(0);
  2293. retval = fprintf(fp,"Garbage collection enabled: %s\n",
  2294. Cudd_GarbageCollectionEnabled(dd) ? "yes" : "no");
  2295. if (retval == EOF) return(0);
  2296. retval = fprintf(fp,"Limit for fast unique table growth: %u\n",
  2297. Cudd_ReadLooseUpTo(dd));
  2298. if (retval == EOF) return(0);
  2299. retval = fprintf(fp,
  2300. "Maximum number of variables sifted per reordering: %d\n",
  2301. Cudd_ReadSiftMaxVar(dd));
  2302. if (retval == EOF) return(0);
  2303. retval = fprintf(fp,
  2304. "Maximum number of variable swaps per reordering: %d\n",
  2305. Cudd_ReadSiftMaxSwap(dd));
  2306. if (retval == EOF) return(0);
  2307. retval = fprintf(fp,"Maximum growth while sifting a variable: %g\n",
  2308. Cudd_ReadMaxGrowth(dd));
  2309. if (retval == EOF) return(0);
  2310. retval = fprintf(fp,"Dynamic reordering of BDDs enabled: %s\n",
  2311. Cudd_ReorderingStatus(dd,&autoMethod) ? "yes" : "no");
  2312. if (retval == EOF) return(0);
  2313. retval = fprintf(fp,"Default BDD reordering method: %d\n",
  2314. (int) autoMethod);
  2315. if (retval == EOF) return(0);
  2316. retval = fprintf(fp,"Dynamic reordering of ZDDs enabled: %s\n",
  2317. Cudd_ReorderingStatusZdd(dd,&autoMethodZ) ? "yes" : "no");
  2318. if (retval == EOF) return(0);
  2319. retval = fprintf(fp,"Default ZDD reordering method: %d\n",
  2320. (int) autoMethodZ);
  2321. if (retval == EOF) return(0);
  2322. retval = fprintf(fp,"Realignment of ZDDs to BDDs enabled: %s\n",
  2323. Cudd_zddRealignmentEnabled(dd) ? "yes" : "no");
  2324. if (retval == EOF) return(0);
  2325. retval = fprintf(fp,"Realignment of BDDs to ZDDs enabled: %s\n",
  2326. Cudd_bddRealignmentEnabled(dd) ? "yes" : "no");
  2327. if (retval == EOF) return(0);
  2328. retval = fprintf(fp,"Dead nodes counted in triggering reordering: %s\n",
  2329. Cudd_DeadAreCounted(dd) ? "yes" : "no");
  2330. if (retval == EOF) return(0);
  2331. retval = fprintf(fp,"Group checking criterion: %d\n",
  2332. (int) Cudd_ReadGroupcheck(dd));
  2333. if (retval == EOF) return(0);
  2334. retval = fprintf(fp,"Recombination threshold: %d\n", Cudd_ReadRecomb(dd));
  2335. if (retval == EOF) return(0);
  2336. retval = fprintf(fp,"Symmetry violation threshold: %d\n",
  2337. Cudd_ReadSymmviolation(dd));
  2338. if (retval == EOF) return(0);
  2339. retval = fprintf(fp,"Arc violation threshold: %d\n",
  2340. Cudd_ReadArcviolation(dd));
  2341. if (retval == EOF) return(0);
  2342. retval = fprintf(fp,"GA population size: %d\n",
  2343. Cudd_ReadPopulationSize(dd));
  2344. if (retval == EOF) return(0);
  2345. retval = fprintf(fp,"Number of crossovers for GA: %d\n",
  2346. Cudd_ReadNumberXovers(dd));
  2347. if (retval == EOF) return(0);
  2348. retval = fprintf(fp,"Next reordering threshold: %u\n",
  2349. Cudd_ReadNextReordering(dd));
  2350. if (retval == EOF) return(0);
  2351. /* Non-modifiable parameters. */
  2352. retval = fprintf(fp,"**** CUDD non-modifiable parameters ****\n");
  2353. if (retval == EOF) return(0);
  2354. retval = fprintf(fp,"Memory in use: %lu\n", Cudd_ReadMemoryInUse(dd));
  2355. if (retval == EOF) return(0);
  2356. retval = fprintf(fp,"Peak number of nodes: %ld\n",
  2357. Cudd_ReadPeakNodeCount(dd));
  2358. if (retval == EOF) return(0);
  2359. retval = fprintf(fp,"Peak number of live nodes: %d\n",
  2360. Cudd_ReadPeakLiveNodeCount(dd));
  2361. if (retval == EOF) return(0);
  2362. retval = fprintf(fp,"Number of BDD variables: %d\n", dd->size);
  2363. if (retval == EOF) return(0);
  2364. retval = fprintf(fp,"Number of ZDD variables: %d\n", dd->sizeZ);
  2365. if (retval == EOF) return(0);
  2366. retval = fprintf(fp,"Number of cache entries: %u\n", dd->cacheSlots);
  2367. if (retval == EOF) return(0);
  2368. retval = fprintf(fp,"Number of cache look-ups: %.0f\n",
  2369. Cudd_ReadCacheLookUps(dd));
  2370. if (retval == EOF) return(0);
  2371. retval = fprintf(fp,"Number of cache hits: %.0f\n",
  2372. Cudd_ReadCacheHits(dd));
  2373. if (retval == EOF) return(0);
  2374. retval = fprintf(fp,"Number of cache insertions: %.0f\n",
  2375. dd->cacheinserts);
  2376. if (retval == EOF) return(0);
  2377. retval = fprintf(fp,"Number of cache collisions: %.0f\n",
  2378. dd->cachecollisions);
  2379. if (retval == EOF) return(0);
  2380. retval = fprintf(fp,"Number of cache deletions: %.0f\n",
  2381. dd->cachedeletions);
  2382. if (retval == EOF) return(0);
  2383. retval = cuddCacheProfile(dd,fp);
  2384. if (retval == 0) return(0);
  2385. retval = fprintf(fp,"Soft limit for cache size: %u\n",
  2386. Cudd_ReadMaxCache(dd));
  2387. if (retval == EOF) return(0);
  2388. retval = fprintf(fp,"Number of buckets in unique table: %u\n", dd->slots);
  2389. if (retval == EOF) return(0);
  2390. retval = fprintf(fp,"Used buckets in unique table: %.2f%% (expected %.2f%%)\n",
  2391. 100.0 * Cudd_ReadUsedSlots(dd),
  2392. 100.0 * Cudd_ExpectedUsedSlots(dd));
  2393. if (retval == EOF) return(0);
  2394. #ifdef DD_UNIQUE_PROFILE
  2395. retval = fprintf(fp,"Unique lookups: %.0f\n", dd->uniqueLookUps);
  2396. if (retval == EOF) return(0);
  2397. retval = fprintf(fp,"Unique links: %.0f (%g per lookup)\n",
  2398. dd->uniqueLinks, dd->uniqueLinks / dd->uniqueLookUps);
  2399. if (retval == EOF) return(0);
  2400. #endif
  2401. retval = fprintf(fp,"Number of BDD and ADD nodes: %u\n", dd->keys);
  2402. if (retval == EOF) return(0);
  2403. retval = fprintf(fp,"Number of ZDD nodes: %u\n", dd->keysZ);
  2404. if (retval == EOF) return(0);
  2405. retval = fprintf(fp,"Number of dead BDD and ADD nodes: %u\n", dd->dead);
  2406. if (retval == EOF) return(0);
  2407. retval = fprintf(fp,"Number of dead ZDD nodes: %u\n", dd->deadZ);
  2408. if (retval == EOF) return(0);
  2409. retval = fprintf(fp,"Total number of nodes allocated: %.0f\n",
  2410. dd->allocated);
  2411. if (retval == EOF) return(0);
  2412. retval = fprintf(fp,"Total number of nodes reclaimed: %.0f\n",
  2413. dd->reclaimed);
  2414. if (retval == EOF) return(0);
  2415. #ifdef DD_STATS
  2416. retval = fprintf(fp,"Nodes freed: %.0f\n", dd->nodesFreed);
  2417. if (retval == EOF) return(0);
  2418. retval = fprintf(fp,"Nodes dropped: %.0f\n", dd->nodesDropped);
  2419. if (retval == EOF) return(0);
  2420. #endif
  2421. #ifdef DD_COUNT
  2422. retval = fprintf(fp,"Number of recursive calls: %.0f\n",
  2423. Cudd_ReadRecursiveCalls(dd));
  2424. if (retval == EOF) return(0);
  2425. #endif
  2426. retval = fprintf(fp,"Garbage collections so far: %d\n",
  2427. Cudd_ReadGarbageCollections(dd));
  2428. if (retval == EOF) return(0);
  2429. retval = fprintf(fp,"Time for garbage collection: %.2f sec\n",
  2430. ((double)Cudd_ReadGarbageCollectionTime(dd)/1000.0));
  2431. if (retval == EOF) return(0);
  2432. retval = fprintf(fp,"Reorderings so far: %d\n", dd->reorderings);
  2433. if (retval == EOF) return(0);
  2434. retval = fprintf(fp,"Time for reordering: %.2f sec\n",
  2435. ((double)Cudd_ReadReorderingTime(dd)/1000.0));
  2436. if (retval == EOF) return(0);
  2437. #ifdef DD_COUNT
  2438. retval = fprintf(fp,"Node swaps in reordering: %.0f\n",
  2439. Cudd_ReadSwapSteps(dd));
  2440. if (retval == EOF) return(0);
  2441. #endif
  2442. return(1);
  2443. } /* end of Cudd_PrintInfo */
  2444. /**Function********************************************************************
  2445. Synopsis [Reports the peak number of nodes.]
  2446. Description [Reports the peak number of nodes. This number includes
  2447. node on the free list. At the peak, the number of nodes on the free
  2448. list is guaranteed to be less than DD_MEM_CHUNK.]
  2449. SideEffects [None]
  2450. SeeAlso [Cudd_ReadNodeCount Cudd_PrintInfo]
  2451. ******************************************************************************/
  2452. long
  2453. Cudd_ReadPeakNodeCount(
  2454. DdManager * dd)
  2455. {
  2456. long count = 0;
  2457. DdNodePtr *scan = dd->memoryList;
  2458. while (scan != NULL) {
  2459. count += DD_MEM_CHUNK;
  2460. scan = (DdNodePtr *) *scan;
  2461. }
  2462. return(count);
  2463. } /* end of Cudd_ReadPeakNodeCount */
  2464. /**Function********************************************************************
  2465. Synopsis [Reports the peak number of live nodes.]
  2466. Description [Reports the peak number of live nodes.]
  2467. SideEffects [None]
  2468. SeeAlso [Cudd_ReadNodeCount Cudd_PrintInfo Cudd_ReadPeakNodeCount]
  2469. ******************************************************************************/
  2470. int
  2471. Cudd_ReadPeakLiveNodeCount(
  2472. DdManager * dd)
  2473. {
  2474. unsigned int live = dd->keys - dd->dead;
  2475. if (live > dd->peakLiveNodes) {
  2476. dd->peakLiveNodes = live;
  2477. }
  2478. return((int)dd->peakLiveNodes);
  2479. } /* end of Cudd_ReadPeakLiveNodeCount */
  2480. /**Function********************************************************************
  2481. Synopsis [Reports the number of nodes in BDDs and ADDs.]
  2482. Description [Reports the number of live nodes in BDDs and ADDs. This
  2483. number does not include the isolated projection functions and the
  2484. unused constants. These nodes that are not counted are not part of
  2485. the DDs manipulated by the application.]
  2486. SideEffects [None]
  2487. SeeAlso [Cudd_ReadPeakNodeCount Cudd_zddReadNodeCount]
  2488. ******************************************************************************/
  2489. long
  2490. Cudd_ReadNodeCount(
  2491. DdManager * dd)
  2492. {
  2493. long count;
  2494. int i;
  2495. #ifndef DD_NO_DEATH_ROW
  2496. cuddClearDeathRow(dd);
  2497. #endif
  2498. count = (long) (dd->keys - dd->dead);
  2499. /* Count isolated projection functions. Their number is subtracted
  2500. ** from the node count because they are not part of the BDDs.
  2501. */
  2502. for (i=0; i < dd->size; i++) {
  2503. if (dd->vars[i]->ref == 1) count--;
  2504. }
  2505. /* Subtract from the count the unused constants. */
  2506. if (DD_ZERO(dd)->ref == 1) count--;
  2507. if (DD_PLUS_INFINITY(dd)->ref == 1) count--;
  2508. if (DD_MINUS_INFINITY(dd)->ref == 1) count--;
  2509. return(count);
  2510. } /* end of Cudd_ReadNodeCount */
  2511. /**Function********************************************************************
  2512. Synopsis [Reports the number of nodes in ZDDs.]
  2513. Description [Reports the number of nodes in ZDDs. This
  2514. number always includes the two constants 1 and 0.]
  2515. SideEffects [None]
  2516. SeeAlso [Cudd_ReadPeakNodeCount Cudd_ReadNodeCount]
  2517. ******************************************************************************/
  2518. long
  2519. Cudd_zddReadNodeCount(
  2520. DdManager * dd)
  2521. {
  2522. return((long)(dd->keysZ - dd->deadZ + 2));
  2523. } /* end of Cudd_zddReadNodeCount */
  2524. /**Function********************************************************************
  2525. Synopsis [Adds a function to a hook.]
  2526. Description [Adds a function to a hook. A hook is a list of
  2527. application-provided functions called on certain occasions by the
  2528. package. Returns 1 if the function is successfully added; 2 if the
  2529. function was already in the list; 0 otherwise.]
  2530. SideEffects [None]
  2531. SeeAlso [Cudd_RemoveHook]
  2532. ******************************************************************************/
  2533. int
  2534. Cudd_AddHook(
  2535. DdManager * dd,
  2536. DD_HFP f,
  2537. Cudd_HookType where)
  2538. {
  2539. DdHook **hook, *nextHook, *newHook;
  2540. switch (where) {
  2541. case CUDD_PRE_GC_HOOK:
  2542. hook = &(dd->preGCHook);
  2543. break;
  2544. case CUDD_POST_GC_HOOK:
  2545. hook = &(dd->postGCHook);
  2546. break;
  2547. case CUDD_PRE_REORDERING_HOOK:
  2548. hook = &(dd->preReorderingHook);
  2549. break;
  2550. case CUDD_POST_REORDERING_HOOK:
  2551. hook = &(dd->postReorderingHook);
  2552. break;
  2553. default:
  2554. return(0);
  2555. }
  2556. /* Scan the list and find whether the function is already there.
  2557. ** If so, just return. */
  2558. nextHook = *hook;
  2559. while (nextHook != NULL) {
  2560. if (nextHook->f == f) {
  2561. return(2);
  2562. }
  2563. hook = &(nextHook->next);
  2564. nextHook = nextHook->next;
  2565. }
  2566. /* The function was not in the list. Create a new item and append it
  2567. ** to the end of the list. */
  2568. newHook = ALLOC(DdHook,1);
  2569. if (newHook == NULL) {
  2570. dd->errorCode = CUDD_MEMORY_OUT;
  2571. return(0);
  2572. }
  2573. newHook->next = NULL;
  2574. newHook->f = f;
  2575. *hook = newHook;
  2576. return(1);
  2577. } /* end of Cudd_AddHook */
  2578. /**Function********************************************************************
  2579. Synopsis [Removes a function from a hook.]
  2580. Description [Removes a function from a hook. A hook is a list of
  2581. application-provided functions called on certain occasions by the
  2582. package. Returns 1 if successful; 0 the function was not in the list.]
  2583. SideEffects [None]
  2584. SeeAlso [Cudd_AddHook]
  2585. ******************************************************************************/
  2586. int
  2587. Cudd_RemoveHook(
  2588. DdManager * dd,
  2589. DD_HFP f,
  2590. Cudd_HookType where)
  2591. {
  2592. DdHook **hook, *nextHook;
  2593. switch (where) {
  2594. case CUDD_PRE_GC_HOOK:
  2595. hook = &(dd->preGCHook);
  2596. break;
  2597. case CUDD_POST_GC_HOOK:
  2598. hook = &(dd->postGCHook);
  2599. break;
  2600. case CUDD_PRE_REORDERING_HOOK:
  2601. hook = &(dd->preReorderingHook);
  2602. break;
  2603. case CUDD_POST_REORDERING_HOOK:
  2604. hook = &(dd->postReorderingHook);
  2605. break;
  2606. default:
  2607. return(0);
  2608. }
  2609. nextHook = *hook;
  2610. while (nextHook != NULL) {
  2611. if (nextHook->f == f) {
  2612. *hook = nextHook->next;
  2613. FREE(nextHook);
  2614. return(1);
  2615. }
  2616. hook = &(nextHook->next);
  2617. nextHook = nextHook->next;
  2618. }
  2619. return(0);
  2620. } /* end of Cudd_RemoveHook */
  2621. /**Function********************************************************************
  2622. Synopsis [Checks whether a function is in a hook.]
  2623. Description [Checks whether a function is in a hook. A hook is a list of
  2624. application-provided functions called on certain occasions by the
  2625. package. Returns 1 if the function is found; 0 otherwise.]
  2626. SideEffects [None]
  2627. SeeAlso [Cudd_AddHook Cudd_RemoveHook]
  2628. ******************************************************************************/
  2629. int
  2630. Cudd_IsInHook(
  2631. DdManager * dd,
  2632. DD_HFP f,
  2633. Cudd_HookType where)
  2634. {
  2635. DdHook *hook;
  2636. switch (where) {
  2637. case CUDD_PRE_GC_HOOK:
  2638. hook = dd->preGCHook;
  2639. break;
  2640. case CUDD_POST_GC_HOOK:
  2641. hook = dd->postGCHook;
  2642. break;
  2643. case CUDD_PRE_REORDERING_HOOK:
  2644. hook = dd->preReorderingHook;
  2645. break;
  2646. case CUDD_POST_REORDERING_HOOK:
  2647. hook = dd->postReorderingHook;
  2648. break;
  2649. default:
  2650. return(0);
  2651. }
  2652. /* Scan the list and find whether the function is already there. */
  2653. while (hook != NULL) {
  2654. if (hook->f == f) {
  2655. return(1);
  2656. }
  2657. hook = hook->next;
  2658. }
  2659. return(0);
  2660. } /* end of Cudd_IsInHook */
  2661. /**Function********************************************************************
  2662. Synopsis [Sample hook function to call before reordering.]
  2663. Description [Sample hook function to call before reordering.
  2664. Prints on the manager's stdout reordering method and initial size.
  2665. Returns 1 if successful; 0 otherwise.]
  2666. SideEffects [None]
  2667. SeeAlso [Cudd_StdPostReordHook]
  2668. ******************************************************************************/
  2669. int
  2670. Cudd_StdPreReordHook(
  2671. DdManager *dd,
  2672. const char *str,
  2673. void *data)
  2674. {
  2675. Cudd_ReorderingType method = (Cudd_ReorderingType) (ptruint) data;
  2676. int retval;
  2677. retval = fprintf(dd->out,"%s reordering with ", str);
  2678. if (retval == EOF) return(0);
  2679. switch (method) {
  2680. case CUDD_REORDER_SIFT_CONVERGE:
  2681. case CUDD_REORDER_SYMM_SIFT_CONV:
  2682. case CUDD_REORDER_GROUP_SIFT_CONV:
  2683. case CUDD_REORDER_WINDOW2_CONV:
  2684. case CUDD_REORDER_WINDOW3_CONV:
  2685. case CUDD_REORDER_WINDOW4_CONV:
  2686. case CUDD_REORDER_LINEAR_CONVERGE:
  2687. retval = fprintf(dd->out,"converging ");
  2688. if (retval == EOF) return(0);
  2689. break;
  2690. default:
  2691. break;
  2692. }
  2693. switch (method) {
  2694. case CUDD_REORDER_RANDOM:
  2695. case CUDD_REORDER_RANDOM_PIVOT:
  2696. retval = fprintf(dd->out,"random");
  2697. break;
  2698. case CUDD_REORDER_SIFT:
  2699. case CUDD_REORDER_SIFT_CONVERGE:
  2700. retval = fprintf(dd->out,"sifting");
  2701. break;
  2702. case CUDD_REORDER_SYMM_SIFT:
  2703. case CUDD_REORDER_SYMM_SIFT_CONV:
  2704. retval = fprintf(dd->out,"symmetric sifting");
  2705. break;
  2706. case CUDD_REORDER_LAZY_SIFT:
  2707. retval = fprintf(dd->out,"lazy sifting");
  2708. break;
  2709. case CUDD_REORDER_GROUP_SIFT:
  2710. case CUDD_REORDER_GROUP_SIFT_CONV:
  2711. retval = fprintf(dd->out,"group sifting");
  2712. break;
  2713. case CUDD_REORDER_WINDOW2:
  2714. case CUDD_REORDER_WINDOW3:
  2715. case CUDD_REORDER_WINDOW4:
  2716. case CUDD_REORDER_WINDOW2_CONV:
  2717. case CUDD_REORDER_WINDOW3_CONV:
  2718. case CUDD_REORDER_WINDOW4_CONV:
  2719. retval = fprintf(dd->out,"window");
  2720. break;
  2721. case CUDD_REORDER_ANNEALING:
  2722. retval = fprintf(dd->out,"annealing");
  2723. break;
  2724. case CUDD_REORDER_GENETIC:
  2725. retval = fprintf(dd->out,"genetic");
  2726. break;
  2727. case CUDD_REORDER_LINEAR:
  2728. case CUDD_REORDER_LINEAR_CONVERGE:
  2729. retval = fprintf(dd->out,"linear sifting");
  2730. break;
  2731. case CUDD_REORDER_EXACT:
  2732. retval = fprintf(dd->out,"exact");
  2733. break;
  2734. default:
  2735. return(0);
  2736. }
  2737. if (retval == EOF) return(0);
  2738. retval = fprintf(dd->out,": from %ld to ... ", strcmp(str, "BDD") == 0 ?
  2739. Cudd_ReadNodeCount(dd) : Cudd_zddReadNodeCount(dd));
  2740. if (retval == EOF) return(0);
  2741. fflush(dd->out);
  2742. return(1);
  2743. } /* end of Cudd_StdPreReordHook */
  2744. /**Function********************************************************************
  2745. Synopsis [Sample hook function to call after reordering.]
  2746. Description [Sample hook function to call after reordering.
  2747. Prints on the manager's stdout final size and reordering time.
  2748. Returns 1 if successful; 0 otherwise.]
  2749. SideEffects [None]
  2750. SeeAlso [Cudd_StdPreReordHook]
  2751. ******************************************************************************/
  2752. int
  2753. Cudd_StdPostReordHook(
  2754. DdManager *dd,
  2755. const char *str,
  2756. void *data)
  2757. {
  2758. unsigned long initialTime = (long) data;
  2759. int retval;
  2760. unsigned long finalTime = util_cpu_time();
  2761. double totalTimeSec = (double)(finalTime - initialTime) / 1000.0;
  2762. retval = fprintf(dd->out,"%ld nodes in %g sec\n", strcmp(str, "BDD") == 0 ?
  2763. Cudd_ReadNodeCount(dd) : Cudd_zddReadNodeCount(dd),
  2764. totalTimeSec);
  2765. if (retval == EOF) return(0);
  2766. retval = fflush(dd->out);
  2767. if (retval == EOF) return(0);
  2768. return(1);
  2769. } /* end of Cudd_StdPostReordHook */
  2770. /**Function********************************************************************
  2771. Synopsis [Enables reporting of reordering stats.]
  2772. Description [Enables reporting of reordering stats.
  2773. Returns 1 if successful; 0 otherwise.]
  2774. SideEffects [Installs functions in the pre-reordering and post-reordering
  2775. hooks.]
  2776. SeeAlso [Cudd_DisableReorderingReporting Cudd_ReorderingReporting]
  2777. ******************************************************************************/
  2778. int
  2779. Cudd_EnableReorderingReporting(
  2780. DdManager *dd)
  2781. {
  2782. if (!Cudd_AddHook(dd, Cudd_StdPreReordHook, CUDD_PRE_REORDERING_HOOK)) {
  2783. return(0);
  2784. }
  2785. if (!Cudd_AddHook(dd, Cudd_StdPostReordHook, CUDD_POST_REORDERING_HOOK)) {
  2786. return(0);
  2787. }
  2788. return(1);
  2789. } /* end of Cudd_EnableReorderingReporting */
  2790. /**Function********************************************************************
  2791. Synopsis [Disables reporting of reordering stats.]
  2792. Description [Disables reporting of reordering stats.
  2793. Returns 1 if successful; 0 otherwise.]
  2794. SideEffects [Removes functions from the pre-reordering and post-reordering
  2795. hooks.]
  2796. SeeAlso [Cudd_EnableReorderingReporting Cudd_ReorderingReporting]
  2797. ******************************************************************************/
  2798. int
  2799. Cudd_DisableReorderingReporting(
  2800. DdManager *dd)
  2801. {
  2802. if (!Cudd_RemoveHook(dd, Cudd_StdPreReordHook, CUDD_PRE_REORDERING_HOOK)) {
  2803. return(0);
  2804. }
  2805. if (!Cudd_RemoveHook(dd, Cudd_StdPostReordHook, CUDD_POST_REORDERING_HOOK)) {
  2806. return(0);
  2807. }
  2808. return(1);
  2809. } /* end of Cudd_DisableReorderingReporting */
  2810. /**Function********************************************************************
  2811. Synopsis [Returns 1 if reporting of reordering stats is enabled.]
  2812. Description [Returns 1 if reporting of reordering stats is enabled;
  2813. 0 otherwise.]
  2814. SideEffects [none]
  2815. SeeAlso [Cudd_EnableReorderingReporting Cudd_DisableReorderingReporting]
  2816. ******************************************************************************/
  2817. int
  2818. Cudd_ReorderingReporting(
  2819. DdManager *dd)
  2820. {
  2821. return(Cudd_IsInHook(dd, Cudd_StdPreReordHook, CUDD_PRE_REORDERING_HOOK));
  2822. } /* end of Cudd_ReorderingReporting */
  2823. /**Function********************************************************************
  2824. Synopsis [Hook function to print the current variable order.]
  2825. Description [Hook function to print the current variable order. It may be
  2826. called before or after reordering. Prints on the manager's stdout a
  2827. parenthesized list that describes the variable groups.
  2828. Returns 1 if successful; 0 otherwise.]
  2829. SideEffects [None]
  2830. SeeAlso [Cudd_StdPreReordHook]
  2831. ******************************************************************************/
  2832. int
  2833. Cudd_PrintGroupedOrder(
  2834. DdManager * dd,
  2835. const char *str,
  2836. void *data)
  2837. {
  2838. int isBdd = strcmp(str, "ZDD");
  2839. MtrNode *tree = isBdd ? dd->tree : dd->treeZ;
  2840. int *invperm = isBdd ? dd->invperm : dd->invpermZ;
  2841. int size = isBdd ? dd->size : dd->sizeZ;
  2842. if (tree == NULL) {
  2843. int i, retval;
  2844. for (i=0; i < size; i++) {
  2845. retval = fprintf(dd->out, "%c%d", i==0 ? '(' : ',', invperm[i]);
  2846. if (retval == EOF) return(0);
  2847. }
  2848. retval = fprintf(dd->out,")\n");
  2849. return (retval != EOF);
  2850. } else {
  2851. return Mtr_PrintGroupedOrder(tree,invperm,dd->out);
  2852. }
  2853. } /* end of Cudd_PrintGroupedOrder */
  2854. /**Function********************************************************************
  2855. Synopsis [Enables monitoring of ordering.]
  2856. Description [Enables monitoring of ordering.
  2857. Returns 1 if successful; 0 otherwise.]
  2858. SideEffects [Installs functions in the pre-reordering and post-reordering
  2859. hooks.]
  2860. SeeAlso [Cudd_EnableReorderingReporting]
  2861. ******************************************************************************/
  2862. int
  2863. Cudd_EnableOrderingMonitoring(
  2864. DdManager *dd)
  2865. {
  2866. if (!Cudd_AddHook(dd, Cudd_PrintGroupedOrder, CUDD_PRE_REORDERING_HOOK)) {
  2867. return(0);
  2868. }
  2869. if (!Cudd_AddHook(dd, Cudd_StdPreReordHook, CUDD_PRE_REORDERING_HOOK)) {
  2870. return(0);
  2871. }
  2872. if (!Cudd_AddHook(dd, Cudd_StdPostReordHook, CUDD_POST_REORDERING_HOOK)) {
  2873. return(0);
  2874. }
  2875. if (!Cudd_AddHook(dd, Cudd_PrintGroupedOrder, CUDD_POST_REORDERING_HOOK)) {
  2876. return(0);
  2877. }
  2878. return(1);
  2879. } /* end of Cudd_EnableOrderingMonitoring */
  2880. /**Function********************************************************************
  2881. Synopsis [Disables monitoring of ordering.]
  2882. Description [Disables monitoring of ordering.
  2883. Returns 1 if successful; 0 otherwise.]
  2884. SideEffects [Removes functions from the pre-reordering and post-reordering
  2885. hooks.]
  2886. SeeAlso [Cudd_EnableOrderingMonitoring]
  2887. ******************************************************************************/
  2888. int
  2889. Cudd_DisableOrderingMonitoring(
  2890. DdManager *dd)
  2891. {
  2892. if (!Cudd_RemoveHook(dd, Cudd_StdPreReordHook, CUDD_PRE_REORDERING_HOOK)) {
  2893. return(0);
  2894. }
  2895. if (!Cudd_RemoveHook(dd, Cudd_PrintGroupedOrder, CUDD_PRE_REORDERING_HOOK)) {
  2896. return(0);
  2897. }
  2898. if (!Cudd_RemoveHook(dd, Cudd_PrintGroupedOrder, CUDD_POST_REORDERING_HOOK)) {
  2899. return(0);
  2900. }
  2901. if (!Cudd_RemoveHook(dd, Cudd_StdPostReordHook, CUDD_POST_REORDERING_HOOK)) {
  2902. return(0);
  2903. }
  2904. return(1);
  2905. } /* end of Cudd_DisableOrderingMonitoring */
  2906. /**Function********************************************************************
  2907. Synopsis [Returns 1 if monitoring of ordering is enabled.]
  2908. Description [Returns 1 if monitoring of ordering is enabled;
  2909. 0 otherwise.]
  2910. SideEffects [none]
  2911. SeeAlso [Cudd_EnableOrderingMonitoring Cudd_DisableOrderingMonitoring]
  2912. ******************************************************************************/
  2913. int
  2914. Cudd_OrderingMonitoring(
  2915. DdManager *dd)
  2916. {
  2917. return(Cudd_IsInHook(dd, Cudd_PrintGroupedOrder, CUDD_PRE_REORDERING_HOOK));
  2918. } /* end of Cudd_OrderingMonitoring */
  2919. /**Function********************************************************************
  2920. Synopsis [Returns the code of the last error.]
  2921. Description [Returns the code of the last error. The error codes are
  2922. defined in cudd.h.]
  2923. SideEffects [None]
  2924. SeeAlso [Cudd_ClearErrorCode]
  2925. ******************************************************************************/
  2926. Cudd_ErrorType
  2927. Cudd_ReadErrorCode(
  2928. DdManager *dd)
  2929. {
  2930. return(dd->errorCode);
  2931. } /* end of Cudd_ReadErrorCode */
  2932. /**Function********************************************************************
  2933. Synopsis [Clear the error code of a manager.]
  2934. Description []
  2935. SideEffects [None]
  2936. SeeAlso [Cudd_ReadErrorCode]
  2937. ******************************************************************************/
  2938. void
  2939. Cudd_ClearErrorCode(
  2940. DdManager *dd)
  2941. {
  2942. dd->errorCode = CUDD_NO_ERROR;
  2943. } /* end of Cudd_ClearErrorCode */
  2944. /**Function********************************************************************
  2945. Synopsis [Reads the stdout of a manager.]
  2946. Description [Reads the stdout of a manager. This is the file pointer to
  2947. which messages normally going to stdout are written. It is initialized
  2948. to stdout. Cudd_SetStdout allows the application to redirect it.]
  2949. SideEffects [None]
  2950. SeeAlso [Cudd_SetStdout Cudd_ReadStderr]
  2951. ******************************************************************************/
  2952. FILE *
  2953. Cudd_ReadStdout(
  2954. DdManager *dd)
  2955. {
  2956. return(dd->out);
  2957. } /* end of Cudd_ReadStdout */
  2958. /**Function********************************************************************
  2959. Synopsis [Sets the stdout of a manager.]
  2960. Description []
  2961. SideEffects [None]
  2962. SeeAlso [Cudd_ReadStdout Cudd_SetStderr]
  2963. ******************************************************************************/
  2964. void
  2965. Cudd_SetStdout(
  2966. DdManager *dd,
  2967. FILE *fp)
  2968. {
  2969. dd->out = fp;
  2970. } /* end of Cudd_SetStdout */
  2971. /**Function********************************************************************
  2972. Synopsis [Reads the stderr of a manager.]
  2973. Description [Reads the stderr of a manager. This is the file pointer to
  2974. which messages normally going to stderr are written. It is initialized
  2975. to stderr. Cudd_SetStderr allows the application to redirect it.]
  2976. SideEffects [None]
  2977. SeeAlso [Cudd_SetStderr Cudd_ReadStdout]
  2978. ******************************************************************************/
  2979. FILE *
  2980. Cudd_ReadStderr(
  2981. DdManager *dd)
  2982. {
  2983. return(dd->err);
  2984. } /* end of Cudd_ReadStderr */
  2985. /**Function********************************************************************
  2986. Synopsis [Sets the stderr of a manager.]
  2987. Description []
  2988. SideEffects [None]
  2989. SeeAlso [Cudd_ReadStderr Cudd_SetStdout]
  2990. ******************************************************************************/
  2991. void
  2992. Cudd_SetStderr(
  2993. DdManager *dd,
  2994. FILE *fp)
  2995. {
  2996. dd->err = fp;
  2997. } /* end of Cudd_SetStderr */
  2998. /**Function********************************************************************
  2999. Synopsis [Returns the threshold for the next dynamic reordering.]
  3000. Description [Returns the threshold for the next dynamic reordering.
  3001. The threshold is in terms of number of nodes and is in effect only
  3002. if reordering is enabled. The count does not include the dead nodes,
  3003. unless the countDead parameter of the manager has been changed from
  3004. its default setting.]
  3005. SideEffects [None]
  3006. SeeAlso [Cudd_SetNextReordering]
  3007. ******************************************************************************/
  3008. unsigned int
  3009. Cudd_ReadNextReordering(
  3010. DdManager *dd)
  3011. {
  3012. return(dd->nextDyn);
  3013. } /* end of Cudd_ReadNextReordering */
  3014. /**Function********************************************************************
  3015. Synopsis [Sets the threshold for the next dynamic reordering.]
  3016. Description [Sets the threshold for the next dynamic reordering.
  3017. The threshold is in terms of number of nodes and is in effect only
  3018. if reordering is enabled. The count does not include the dead nodes,
  3019. unless the countDead parameter of the manager has been changed from
  3020. its default setting.]
  3021. SideEffects [None]
  3022. SeeAlso [Cudd_ReadNextReordering]
  3023. ******************************************************************************/
  3024. void
  3025. Cudd_SetNextReordering(
  3026. DdManager *dd,
  3027. unsigned int next)
  3028. {
  3029. dd->nextDyn = next;
  3030. } /* end of Cudd_SetNextReordering */
  3031. /**Function********************************************************************
  3032. Synopsis [Reads the number of elementary reordering steps.]
  3033. Description []
  3034. SideEffects [none]
  3035. SeeAlso []
  3036. ******************************************************************************/
  3037. double
  3038. Cudd_ReadSwapSteps(
  3039. DdManager *dd)
  3040. {
  3041. #ifdef DD_COUNT
  3042. return(dd->swapSteps);
  3043. #else
  3044. return(-1);
  3045. #endif
  3046. } /* end of Cudd_ReadSwapSteps */
  3047. /**Function********************************************************************
  3048. Synopsis [Reads the maximum allowed number of live nodes.]
  3049. Description [Reads the maximum allowed number of live nodes. When this
  3050. number is exceeded, the package returns NULL.]
  3051. SideEffects [none]
  3052. SeeAlso [Cudd_SetMaxLive]
  3053. ******************************************************************************/
  3054. unsigned int
  3055. Cudd_ReadMaxLive(
  3056. DdManager *dd)
  3057. {
  3058. return(dd->maxLive);
  3059. } /* end of Cudd_ReadMaxLive */
  3060. /**Function********************************************************************
  3061. Synopsis [Sets the maximum allowed number of live nodes.]
  3062. Description [Sets the maximum allowed number of live nodes. When this
  3063. number is exceeded, the package returns NULL.]
  3064. SideEffects [none]
  3065. SeeAlso [Cudd_ReadMaxLive]
  3066. ******************************************************************************/
  3067. void
  3068. Cudd_SetMaxLive(
  3069. DdManager *dd,
  3070. unsigned int maxLive)
  3071. {
  3072. dd->maxLive = maxLive;
  3073. } /* end of Cudd_SetMaxLive */
  3074. /**Function********************************************************************
  3075. Synopsis [Reads the maximum allowed memory.]
  3076. Description [Reads the maximum allowed memory. When this
  3077. number is exceeded, the package returns NULL.]
  3078. SideEffects [none]
  3079. SeeAlso [Cudd_SetMaxMemory]
  3080. ******************************************************************************/
  3081. unsigned long
  3082. Cudd_ReadMaxMemory(
  3083. DdManager *dd)
  3084. {
  3085. return(dd->maxmemhard);
  3086. } /* end of Cudd_ReadMaxMemory */
  3087. /**Function********************************************************************
  3088. Synopsis [Sets the maximum allowed memory.]
  3089. Description [Sets the maximum allowed memory. When this
  3090. number is exceeded, the package returns NULL.]
  3091. SideEffects [none]
  3092. SeeAlso [Cudd_ReadMaxMemory]
  3093. ******************************************************************************/
  3094. void
  3095. Cudd_SetMaxMemory(
  3096. DdManager *dd,
  3097. unsigned long maxMemory)
  3098. {
  3099. dd->maxmemhard = maxMemory;
  3100. } /* end of Cudd_SetMaxMemory */
  3101. /**Function********************************************************************
  3102. Synopsis [Prevents sifting of a variable.]
  3103. Description [This function sets a flag to prevent sifting of a
  3104. variable. Returns 1 if successful; 0 otherwise (i.e., invalid
  3105. variable index).]
  3106. SideEffects [Changes the "bindVar" flag in DdSubtable.]
  3107. SeeAlso [Cudd_bddUnbindVar]
  3108. ******************************************************************************/
  3109. int
  3110. Cudd_bddBindVar(
  3111. DdManager *dd /* manager */,
  3112. int index /* variable index */)
  3113. {
  3114. if (index >= dd->size || index < 0) return(0);
  3115. dd->subtables[dd->perm[index]].bindVar = 1;
  3116. return(1);
  3117. } /* end of Cudd_bddBindVar */
  3118. /**Function********************************************************************
  3119. Synopsis [Allows the sifting of a variable.]
  3120. Description [This function resets the flag that prevents the sifting
  3121. of a variable. In successive variable reorderings, the variable will
  3122. NOT be skipped, that is, sifted. Initially all variables can be
  3123. sifted. It is necessary to call this function only to re-enable
  3124. sifting after a call to Cudd_bddBindVar. Returns 1 if successful; 0
  3125. otherwise (i.e., invalid variable index).]
  3126. SideEffects [Changes the "bindVar" flag in DdSubtable.]
  3127. SeeAlso [Cudd_bddBindVar]
  3128. ******************************************************************************/
  3129. int
  3130. Cudd_bddUnbindVar(
  3131. DdManager *dd /* manager */,
  3132. int index /* variable index */)
  3133. {
  3134. if (index >= dd->size || index < 0) return(0);
  3135. dd->subtables[dd->perm[index]].bindVar = 0;
  3136. return(1);
  3137. } /* end of Cudd_bddUnbindVar */
  3138. /**Function********************************************************************
  3139. Synopsis [Tells whether a variable can be sifted.]
  3140. Description [This function returns 1 if a variable is enabled for
  3141. sifting. Initially all variables can be sifted. This function returns
  3142. 0 only if there has been a previous call to Cudd_bddBindVar for that
  3143. variable not followed by a call to Cudd_bddUnbindVar. The function returns
  3144. 0 also in the case in which the index of the variable is out of bounds.]
  3145. SideEffects [none]
  3146. SeeAlso [Cudd_bddBindVar Cudd_bddUnbindVar]
  3147. ******************************************************************************/
  3148. int
  3149. Cudd_bddVarIsBound(
  3150. DdManager *dd /* manager */,
  3151. int index /* variable index */)
  3152. {
  3153. if (index >= dd->size || index < 0) return(0);
  3154. return(dd->subtables[dd->perm[index]].bindVar);
  3155. } /* end of Cudd_bddVarIsBound */
  3156. /**Function********************************************************************
  3157. Synopsis [Sets a variable type to primary input.]
  3158. Description [Sets a variable type to primary input. The variable type is
  3159. used by lazy sifting. Returns 1 if successful; 0 otherwise.]
  3160. SideEffects [modifies the manager]
  3161. SeeAlso [Cudd_bddSetPsVar Cudd_bddSetNsVar Cudd_bddIsPiVar]
  3162. ******************************************************************************/
  3163. int
  3164. Cudd_bddSetPiVar(
  3165. DdManager *dd /* manager */,
  3166. int index /* variable index */)
  3167. {
  3168. if (index >= dd->size || index < 0) return (0);
  3169. dd->subtables[dd->perm[index]].varType = CUDD_VAR_PRIMARY_INPUT;
  3170. return(1);
  3171. } /* end of Cudd_bddSetPiVar */
  3172. /**Function********************************************************************
  3173. Synopsis [Sets a variable type to present state.]
  3174. Description [Sets a variable type to present state. The variable type is
  3175. used by lazy sifting. Returns 1 if successful; 0 otherwise.]
  3176. SideEffects [modifies the manager]
  3177. SeeAlso [Cudd_bddSetPiVar Cudd_bddSetNsVar Cudd_bddIsPsVar]
  3178. ******************************************************************************/
  3179. int
  3180. Cudd_bddSetPsVar(
  3181. DdManager *dd /* manager */,
  3182. int index /* variable index */)
  3183. {
  3184. if (index >= dd->size || index < 0) return (0);
  3185. dd->subtables[dd->perm[index]].varType = CUDD_VAR_PRESENT_STATE;
  3186. return(1);
  3187. } /* end of Cudd_bddSetPsVar */
  3188. /**Function********************************************************************
  3189. Synopsis [Sets a variable type to next state.]
  3190. Description [Sets a variable type to next state. The variable type is
  3191. used by lazy sifting. Returns 1 if successful; 0 otherwise.]
  3192. SideEffects [modifies the manager]
  3193. SeeAlso [Cudd_bddSetPiVar Cudd_bddSetPsVar Cudd_bddIsNsVar]
  3194. ******************************************************************************/
  3195. int
  3196. Cudd_bddSetNsVar(
  3197. DdManager *dd /* manager */,
  3198. int index /* variable index */)
  3199. {
  3200. if (index >= dd->size || index < 0) return (0);
  3201. dd->subtables[dd->perm[index]].varType = CUDD_VAR_NEXT_STATE;
  3202. return(1);
  3203. } /* end of Cudd_bddSetNsVar */
  3204. /**Function********************************************************************
  3205. Synopsis [Checks whether a variable is primary input.]
  3206. Description [Checks whether a variable is primary input. Returns 1 if
  3207. the variable's type is primary input; 0 if the variable exists but is
  3208. not a primary input; -1 if the variable does not exist.]
  3209. SideEffects [none]
  3210. SeeAlso [Cudd_bddSetPiVar Cudd_bddIsPsVar Cudd_bddIsNsVar]
  3211. ******************************************************************************/
  3212. int
  3213. Cudd_bddIsPiVar(
  3214. DdManager *dd /* manager */,
  3215. int index /* variable index */)
  3216. {
  3217. if (index >= dd->size || index < 0) return -1;
  3218. return (dd->subtables[dd->perm[index]].varType == CUDD_VAR_PRIMARY_INPUT);
  3219. } /* end of Cudd_bddIsPiVar */
  3220. /**Function********************************************************************
  3221. Synopsis [Checks whether a variable is present state.]
  3222. Description [Checks whether a variable is present state. Returns 1 if
  3223. the variable's type is present state; 0 if the variable exists but is
  3224. not a present state; -1 if the variable does not exist.]
  3225. SideEffects [none]
  3226. SeeAlso [Cudd_bddSetPsVar Cudd_bddIsPiVar Cudd_bddIsNsVar]
  3227. ******************************************************************************/
  3228. int
  3229. Cudd_bddIsPsVar(
  3230. DdManager *dd,
  3231. int index)
  3232. {
  3233. if (index >= dd->size || index < 0) return -1;
  3234. return (dd->subtables[dd->perm[index]].varType == CUDD_VAR_PRESENT_STATE);
  3235. } /* end of Cudd_bddIsPsVar */
  3236. /**Function********************************************************************
  3237. Synopsis [Checks whether a variable is next state.]
  3238. Description [Checks whether a variable is next state. Returns 1 if
  3239. the variable's type is present state; 0 if the variable exists but is
  3240. not a present state; -1 if the variable does not exist.]
  3241. SideEffects [none]
  3242. SeeAlso [Cudd_bddSetNsVar Cudd_bddIsPiVar Cudd_bddIsPsVar]
  3243. ******************************************************************************/
  3244. int
  3245. Cudd_bddIsNsVar(
  3246. DdManager *dd,
  3247. int index)
  3248. {
  3249. if (index >= dd->size || index < 0) return -1;
  3250. return (dd->subtables[dd->perm[index]].varType == CUDD_VAR_NEXT_STATE);
  3251. } /* end of Cudd_bddIsNsVar */
  3252. /**Function********************************************************************
  3253. Synopsis [Sets a corresponding pair index for a given index.]
  3254. Description [Sets a corresponding pair index for a given index.
  3255. These pair indices are present and next state variable. Returns 1 if
  3256. successful; 0 otherwise.]
  3257. SideEffects [modifies the manager]
  3258. SeeAlso [Cudd_bddReadPairIndex]
  3259. ******************************************************************************/
  3260. int
  3261. Cudd_bddSetPairIndex(
  3262. DdManager *dd /* manager */,
  3263. int index /* variable index */,
  3264. int pairIndex /* corresponding variable index */)
  3265. {
  3266. if (index >= dd->size || index < 0) return(0);
  3267. dd->subtables[dd->perm[index]].pairIndex = pairIndex;
  3268. return(1);
  3269. } /* end of Cudd_bddSetPairIndex */
  3270. /**Function********************************************************************
  3271. Synopsis [Reads a corresponding pair index for a given index.]
  3272. Description [Reads a corresponding pair index for a given index.
  3273. These pair indices are present and next state variable. Returns the
  3274. corresponding variable index if the variable exists; -1 otherwise.]
  3275. SideEffects [modifies the manager]
  3276. SeeAlso [Cudd_bddSetPairIndex]
  3277. ******************************************************************************/
  3278. int
  3279. Cudd_bddReadPairIndex(
  3280. DdManager *dd,
  3281. int index)
  3282. {
  3283. if (index >= dd->size || index < 0) return -1;
  3284. return dd->subtables[dd->perm[index]].pairIndex;
  3285. } /* end of Cudd_bddReadPairIndex */
  3286. /**Function********************************************************************
  3287. Synopsis [Sets a variable to be grouped.]
  3288. Description [Sets a variable to be grouped. This function is used for
  3289. lazy sifting. Returns 1 if successful; 0 otherwise.]
  3290. SideEffects [modifies the manager]
  3291. SeeAlso [Cudd_bddSetVarHardGroup Cudd_bddResetVarToBeGrouped]
  3292. ******************************************************************************/
  3293. int
  3294. Cudd_bddSetVarToBeGrouped(
  3295. DdManager *dd,
  3296. int index)
  3297. {
  3298. if (index >= dd->size || index < 0) return(0);
  3299. if (dd->subtables[dd->perm[index]].varToBeGrouped <= CUDD_LAZY_SOFT_GROUP) {
  3300. dd->subtables[dd->perm[index]].varToBeGrouped = CUDD_LAZY_SOFT_GROUP;
  3301. }
  3302. return(1);
  3303. } /* end of Cudd_bddSetVarToBeGrouped */
  3304. /**Function********************************************************************
  3305. Synopsis [Sets a variable to be a hard group.]
  3306. Description [Sets a variable to be a hard group. This function is used
  3307. for lazy sifting. Returns 1 if successful; 0 otherwise.]
  3308. SideEffects [modifies the manager]
  3309. SeeAlso [Cudd_bddSetVarToBeGrouped Cudd_bddResetVarToBeGrouped
  3310. Cudd_bddIsVarHardGroup]
  3311. ******************************************************************************/
  3312. int
  3313. Cudd_bddSetVarHardGroup(
  3314. DdManager *dd,
  3315. int index)
  3316. {
  3317. if (index >= dd->size || index < 0) return(0);
  3318. dd->subtables[dd->perm[index]].varToBeGrouped = CUDD_LAZY_HARD_GROUP;
  3319. return(1);
  3320. } /* end of Cudd_bddSetVarHardGrouped */
  3321. /**Function********************************************************************
  3322. Synopsis [Resets a variable not to be grouped.]
  3323. Description [Resets a variable not to be grouped. This function is
  3324. used for lazy sifting. Returns 1 if successful; 0 otherwise.]
  3325. SideEffects [modifies the manager]
  3326. SeeAlso [Cudd_bddSetVarToBeGrouped Cudd_bddSetVarHardGroup]
  3327. ******************************************************************************/
  3328. int
  3329. Cudd_bddResetVarToBeGrouped(
  3330. DdManager *dd,
  3331. int index)
  3332. {
  3333. if (index >= dd->size || index < 0) return(0);
  3334. if (dd->subtables[dd->perm[index]].varToBeGrouped <=
  3335. CUDD_LAZY_SOFT_GROUP) {
  3336. dd->subtables[dd->perm[index]].varToBeGrouped = CUDD_LAZY_NONE;
  3337. }
  3338. return(1);
  3339. } /* end of Cudd_bddResetVarToBeGrouped */
  3340. /**Function********************************************************************
  3341. Synopsis [Checks whether a variable is set to be grouped.]
  3342. Description [Checks whether a variable is set to be grouped. This
  3343. function is used for lazy sifting.]
  3344. SideEffects [none]
  3345. SeeAlso []
  3346. ******************************************************************************/
  3347. int
  3348. Cudd_bddIsVarToBeGrouped(
  3349. DdManager *dd,
  3350. int index)
  3351. {
  3352. if (index >= dd->size || index < 0) return(-1);
  3353. if (dd->subtables[dd->perm[index]].varToBeGrouped == CUDD_LAZY_UNGROUP)
  3354. return(0);
  3355. else
  3356. return(dd->subtables[dd->perm[index]].varToBeGrouped);
  3357. } /* end of Cudd_bddIsVarToBeGrouped */
  3358. /**Function********************************************************************
  3359. Synopsis [Sets a variable to be ungrouped.]
  3360. Description [Sets a variable to be ungrouped. This function is used
  3361. for lazy sifting. Returns 1 if successful; 0 otherwise.]
  3362. SideEffects [modifies the manager]
  3363. SeeAlso [Cudd_bddIsVarToBeUngrouped]
  3364. ******************************************************************************/
  3365. int
  3366. Cudd_bddSetVarToBeUngrouped(
  3367. DdManager *dd,
  3368. int index)
  3369. {
  3370. if (index >= dd->size || index < 0) return(0);
  3371. dd->subtables[dd->perm[index]].varToBeGrouped = CUDD_LAZY_UNGROUP;
  3372. return(1);
  3373. } /* end of Cudd_bddSetVarToBeGrouped */
  3374. /**Function********************************************************************
  3375. Synopsis [Checks whether a variable is set to be ungrouped.]
  3376. Description [Checks whether a variable is set to be ungrouped. This
  3377. function is used for lazy sifting. Returns 1 if the variable is marked
  3378. to be ungrouped; 0 if the variable exists, but it is not marked to be
  3379. ungrouped; -1 if the variable does not exist.]
  3380. SideEffects [none]
  3381. SeeAlso [Cudd_bddSetVarToBeUngrouped]
  3382. ******************************************************************************/
  3383. int
  3384. Cudd_bddIsVarToBeUngrouped(
  3385. DdManager *dd,
  3386. int index)
  3387. {
  3388. if (index >= dd->size || index < 0) return(-1);
  3389. return dd->subtables[dd->perm[index]].varToBeGrouped == CUDD_LAZY_UNGROUP;
  3390. } /* end of Cudd_bddIsVarToBeGrouped */
  3391. /**Function********************************************************************
  3392. Synopsis [Checks whether a variable is set to be in a hard group.]
  3393. Description [Checks whether a variable is set to be in a hard group. This
  3394. function is used for lazy sifting. Returns 1 if the variable is marked
  3395. to be in a hard group; 0 if the variable exists, but it is not marked to be
  3396. in a hard group; -1 if the variable does not exist.]
  3397. SideEffects [none]
  3398. SeeAlso [Cudd_bddSetVarHardGroup]
  3399. ******************************************************************************/
  3400. int
  3401. Cudd_bddIsVarHardGroup(
  3402. DdManager *dd,
  3403. int index)
  3404. {
  3405. if (index >= dd->size || index < 0) return(-1);
  3406. if (dd->subtables[dd->perm[index]].varToBeGrouped == CUDD_LAZY_HARD_GROUP)
  3407. return(1);
  3408. return(0);
  3409. } /* end of Cudd_bddIsVarToBeGrouped */
  3410. /*---------------------------------------------------------------------------*/
  3411. /* Definition of internal functions */
  3412. /*---------------------------------------------------------------------------*/
  3413. /*---------------------------------------------------------------------------*/
  3414. /* Definition of static functions */
  3415. /*---------------------------------------------------------------------------*/
  3416. /**Function********************************************************************
  3417. Synopsis [Fixes a variable group tree.]
  3418. Description []
  3419. SideEffects [Changes the variable group tree.]
  3420. SeeAlso []
  3421. ******************************************************************************/
  3422. static void
  3423. fixVarTree(
  3424. MtrNode * treenode,
  3425. int * perm,
  3426. int size)
  3427. {
  3428. treenode->index = treenode->low;
  3429. treenode->low = ((int) treenode->index < size) ?
  3430. perm[treenode->index] : treenode->index;
  3431. if (treenode->child != NULL)
  3432. fixVarTree(treenode->child, perm, size);
  3433. if (treenode->younger != NULL)
  3434. fixVarTree(treenode->younger, perm, size);
  3435. return;
  3436. } /* end of fixVarTree */
  3437. /**Function********************************************************************
  3438. Synopsis [Adds multiplicity groups to a ZDD variable group tree.]
  3439. Description [Adds multiplicity groups to a ZDD variable group tree.
  3440. Returns 1 if successful; 0 otherwise. This function creates the groups
  3441. for set of ZDD variables (whose cardinality is given by parameter
  3442. multiplicity) that are created for each BDD variable in
  3443. Cudd_zddVarsFromBddVars. The crux of the matter is to determine the index
  3444. each new group. (The index of the first variable in the group.)
  3445. We first build all the groups for the children of a node, and then deal
  3446. with the ZDD variables that are directly attached to the node. The problem
  3447. for these is that the tree itself does not provide information on their
  3448. position inside the group. While we deal with the children of the node,
  3449. therefore, we keep track of all the positions they occupy. The remaining
  3450. positions in the tree can be freely used. Also, we keep track of all the
  3451. variables placed in the children. All the remaining variables are directly
  3452. attached to the group. We can then place any pair of variables not yet
  3453. grouped in any pair of available positions in the node.]
  3454. SideEffects [Changes the variable group tree.]
  3455. SeeAlso [Cudd_zddVarsFromBddVars]
  3456. ******************************************************************************/
  3457. static int
  3458. addMultiplicityGroups(
  3459. DdManager *dd /* manager */,
  3460. MtrNode *treenode /* current tree node */,
  3461. int multiplicity /* how many ZDD vars per BDD var */,
  3462. char *vmask /* variable pairs for which a group has been already built */,
  3463. char *lmask /* levels for which a group has already been built*/)
  3464. {
  3465. int startV, stopV, startL;
  3466. int i, j;
  3467. MtrNode *auxnode = treenode;
  3468. while (auxnode != NULL) {
  3469. if (auxnode->child != NULL) {
  3470. addMultiplicityGroups(dd,auxnode->child,multiplicity,vmask,lmask);
  3471. }
  3472. /* Build remaining groups. */
  3473. startV = dd->permZ[auxnode->index] / multiplicity;
  3474. startL = auxnode->low / multiplicity;
  3475. stopV = startV + auxnode->size / multiplicity;
  3476. /* Walk down vmask starting at startV and build missing groups. */
  3477. for (i = startV, j = startL; i < stopV; i++) {
  3478. if (vmask[i] == 0) {
  3479. MtrNode *node;
  3480. while (lmask[j] == 1) j++;
  3481. node = Mtr_MakeGroup(auxnode, j * multiplicity, multiplicity,
  3482. MTR_FIXED);
  3483. if (node == NULL) {
  3484. return(0);
  3485. }
  3486. node->index = dd->invpermZ[i * multiplicity];
  3487. vmask[i] = 1;
  3488. lmask[j] = 1;
  3489. }
  3490. }
  3491. auxnode = auxnode->younger;
  3492. }
  3493. return(1);
  3494. } /* end of addMultiplicityGroups */