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.

233 lines
6.5 KiB

2 months ago
  1. /**
  2. @file
  3. @ingroup cudd
  4. @brief Miscellaneous utility functions for ZDDs.
  5. @author Hyong-Kyoon Shin, In-Ho Moon
  6. @copyright@parblock
  7. Copyright (c) 1995-2015, Regents of the University of Colorado
  8. All rights reserved.
  9. Redistribution and use in source and binary forms, with or without
  10. modification, are permitted provided that the following conditions
  11. are met:
  12. Redistributions of source code must retain the above copyright
  13. notice, this list of conditions and the following disclaimer.
  14. Redistributions in binary form must reproduce the above copyright
  15. notice, this list of conditions and the following disclaimer in the
  16. documentation and/or other materials provided with the distribution.
  17. Neither the name of the University of Colorado nor the names of its
  18. contributors may be used to endorse or promote products derived from
  19. this software without specific prior written permission.
  20. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  21. "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  22. LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  23. FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  24. COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  25. INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  26. BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  27. LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  28. CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  29. LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
  30. ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  31. POSSIBILITY OF SUCH DAMAGE.
  32. @endparblock
  33. */
  34. #include <math.h>
  35. #include "util.h"
  36. #include "cuddInt.h"
  37. /*---------------------------------------------------------------------------*/
  38. /* Constant declarations */
  39. /*---------------------------------------------------------------------------*/
  40. /*---------------------------------------------------------------------------*/
  41. /* Stucture declarations */
  42. /*---------------------------------------------------------------------------*/
  43. /*---------------------------------------------------------------------------*/
  44. /* Type declarations */
  45. /*---------------------------------------------------------------------------*/
  46. /*---------------------------------------------------------------------------*/
  47. /* Variable declarations */
  48. /*---------------------------------------------------------------------------*/
  49. /*---------------------------------------------------------------------------*/
  50. /* Macro declarations */
  51. /*---------------------------------------------------------------------------*/
  52. /** \cond */
  53. /*---------------------------------------------------------------------------*/
  54. /* Static function prototypes */
  55. /*---------------------------------------------------------------------------*/
  56. static int cuddZddDagInt (DdNode *n, st_table *tab);
  57. /** \endcond */
  58. /*---------------------------------------------------------------------------*/
  59. /* Definition of exported functions */
  60. /*---------------------------------------------------------------------------*/
  61. /**
  62. @brief Counts the number of nodes in a %ZDD.
  63. @deprecated This function duplicates Cudd_DagSize and is only
  64. retained for compatibility.
  65. @sideeffect None
  66. @see Cudd_DagSize
  67. */
  68. int
  69. Cudd_zddDagSize(
  70. DdNode * p_node)
  71. {
  72. int i;
  73. st_table *table;
  74. table = st_init_table(st_ptrcmp, st_ptrhash);
  75. i = cuddZddDagInt(p_node, table);
  76. st_free_table(table);
  77. return(i);
  78. } /* end of Cudd_zddDagSize */
  79. /**
  80. @brief Counts the number of minterms of a %ZDD.
  81. @details Counts the number of minterms of the %ZDD rooted at
  82. <code>node</code>. This procedure takes a parameter
  83. <code>path</code> that specifies how many variables are in the
  84. support of the function.
  85. @return the count. If the procedure runs out of memory, it returns
  86. (double) CUDD_OUT_OF_MEM.
  87. @sideeffect None
  88. @see Cudd_zddCountDouble
  89. */
  90. double
  91. Cudd_zddCountMinterm(
  92. DdManager * zdd,
  93. DdNode * node,
  94. int path)
  95. {
  96. double dc_var, minterms;
  97. dc_var = (double)((double)(zdd->sizeZ) - (double)path);
  98. minterms = Cudd_zddCountDouble(zdd, node) / pow(2.0, dc_var);
  99. return(minterms);
  100. } /* end of Cudd_zddCountMinterm */
  101. /**
  102. @brief Prints the %ZDD table for debugging purposes.
  103. @sideeffect None
  104. */
  105. void
  106. Cudd_zddPrintSubtable(
  107. DdManager * table)
  108. {
  109. int i, j;
  110. DdNode *z1, *z1_next, *base;
  111. DdSubtable *ZSubTable;
  112. base = table->one;
  113. for (i = table->sizeZ - 1; i >= 0; i--) {
  114. ZSubTable = &(table->subtableZ[i]);
  115. printf("subtable[%d]:\n", i);
  116. for (j = ZSubTable->slots - 1; j >= 0; j--) {
  117. z1 = ZSubTable->nodelist[j];
  118. while (z1 != NIL(DdNode)) {
  119. (void) fprintf(table->out,
  120. "ID = 0x%" PRIxPTR "\tindex = %u\tr = %u\t",
  121. (ptruint) z1 / (ptruint) sizeof(DdNode),
  122. z1->index, z1->ref);
  123. z1_next = cuddT(z1);
  124. if (Cudd_IsConstantInt(z1_next)) {
  125. (void) fprintf(table->out, "T = %d\t\t",
  126. (z1_next == base));
  127. }
  128. else {
  129. (void) fprintf(table->out, "T = 0x%" PRIxPTR "\t",
  130. (ptruint) z1_next / (ptruint) sizeof(DdNode));
  131. }
  132. z1_next = cuddE(z1);
  133. if (Cudd_IsConstantInt(z1_next)) {
  134. (void) fprintf(table->out, "E = %d\n",
  135. (z1_next == base));
  136. }
  137. else {
  138. (void) fprintf(table->out, "E = 0x%" PRIxPTR "\n",
  139. (ptruint) z1_next / (ptruint) sizeof(DdNode));
  140. }
  141. z1_next = z1->next;
  142. z1 = z1_next;
  143. }
  144. }
  145. }
  146. putchar('\n');
  147. } /* Cudd_zddPrintSubtable */
  148. /*---------------------------------------------------------------------------*/
  149. /* Definition of static functions */
  150. /*---------------------------------------------------------------------------*/
  151. /**
  152. @brief Performs the recursive step of Cudd_zddDagSize.
  153. @details Does not check for out-of-memory conditions.
  154. @sideeffect None
  155. */
  156. static int
  157. cuddZddDagInt(
  158. DdNode * n,
  159. st_table * tab)
  160. {
  161. if (n == NIL(DdNode))
  162. return(0);
  163. if (st_is_member(tab, n) == 1)
  164. return(0);
  165. if (Cudd_IsConstantInt(n))
  166. return(0);
  167. (void)st_insert(tab, n, NIL(void));
  168. return(1 + cuddZddDagInt(cuddT(n), tab) +
  169. cuddZddDagInt(cuddE(n), tab));
  170. } /* cuddZddDagInt */