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.

278 lines
8.5 KiB

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