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.

201 lines
6.7 KiB

  1. /**CFile***********************************************************************
  2. FileName [cuddAddInv.c]
  3. PackageName [cudd]
  4. Synopsis [Function to compute the scalar inverse of an ADD.]
  5. Description [External procedures included in this module:
  6. <ul>
  7. <li> Cudd_addScalarInverse()
  8. </ul>
  9. Internal procedures included in this module:
  10. <ul>
  11. <li> cuddAddScalarInverseRecur()
  12. </ul>]
  13. Author [Fabio Somenzi]
  14. Copyright [Copyright (c) 1995-2012, Regents of the University of Colorado
  15. All rights reserved.
  16. Redistribution and use in source and binary forms, with or without
  17. modification, are permitted provided that the following conditions
  18. are met:
  19. Redistributions of source code must retain the above copyright
  20. notice, this list of conditions and the following disclaimer.
  21. Redistributions in binary form must reproduce the above copyright
  22. notice, this list of conditions and the following disclaimer in the
  23. documentation and/or other materials provided with the distribution.
  24. Neither the name of the University of Colorado nor the names of its
  25. contributors may be used to endorse or promote products derived from
  26. this software without specific prior written permission.
  27. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  28. "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  29. LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  30. FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  31. COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  32. INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  33. BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  34. LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  35. CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  36. LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
  37. ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  38. POSSIBILITY OF SUCH DAMAGE.]
  39. ******************************************************************************/
  40. #include "util.h"
  41. #include "cuddInt.h"
  42. /*---------------------------------------------------------------------------*/
  43. /* Constant declarations */
  44. /*---------------------------------------------------------------------------*/
  45. /*---------------------------------------------------------------------------*/
  46. /* Stucture declarations */
  47. /*---------------------------------------------------------------------------*/
  48. /*---------------------------------------------------------------------------*/
  49. /* Type declarations */
  50. /*---------------------------------------------------------------------------*/
  51. /*---------------------------------------------------------------------------*/
  52. /* Variable declarations */
  53. /*---------------------------------------------------------------------------*/
  54. #ifndef lint
  55. static char rcsid[] DD_UNUSED = "$Id: cuddAddInv.c,v 1.10 2012/02/05 01:07:18 fabio Exp $";
  56. #endif
  57. /*---------------------------------------------------------------------------*/
  58. /* Macro declarations */
  59. /*---------------------------------------------------------------------------*/
  60. /**AutomaticStart*************************************************************/
  61. /*---------------------------------------------------------------------------*/
  62. /* Static function prototypes */
  63. /*---------------------------------------------------------------------------*/
  64. /**AutomaticEnd***************************************************************/
  65. /*---------------------------------------------------------------------------*/
  66. /* Definition of exported functions */
  67. /*---------------------------------------------------------------------------*/
  68. /**Function********************************************************************
  69. Synopsis [Computes the scalar inverse of an ADD.]
  70. Description [Computes an n ADD where the discriminants are the
  71. multiplicative inverses of the corresponding discriminants of the
  72. argument ADD. Returns a pointer to the resulting ADD in case of
  73. success. Returns NULL if any discriminants smaller than epsilon is
  74. encountered.]
  75. SideEffects [None]
  76. ******************************************************************************/
  77. DdNode *
  78. Cudd_addScalarInverse(
  79. DdManager * dd,
  80. DdNode * f,
  81. DdNode * epsilon)
  82. {
  83. DdNode *res;
  84. if (!cuddIsConstant(epsilon)) {
  85. (void) fprintf(dd->err,"Invalid epsilon\n");
  86. return(NULL);
  87. }
  88. do {
  89. dd->reordered = 0;
  90. res = cuddAddScalarInverseRecur(dd,f,epsilon);
  91. } while (dd->reordered == 1);
  92. return(res);
  93. } /* end of Cudd_addScalarInverse */
  94. /*---------------------------------------------------------------------------*/
  95. /* Definition of internal functions */
  96. /*---------------------------------------------------------------------------*/
  97. /**Function********************************************************************
  98. Synopsis [Performs the recursive step of addScalarInverse.]
  99. Description [Returns a pointer to the resulting ADD in case of
  100. success. Returns NULL if any discriminants smaller than epsilon is
  101. encountered.]
  102. SideEffects [None]
  103. ******************************************************************************/
  104. DdNode *
  105. cuddAddScalarInverseRecur(
  106. DdManager * dd,
  107. DdNode * f,
  108. DdNode * epsilon)
  109. {
  110. DdNode *t, *e, *res;
  111. CUDD_VALUE_TYPE value;
  112. statLine(dd);
  113. if (cuddIsConstant(f)) {
  114. if (ddAbs(cuddV(f)) < cuddV(epsilon)) return(NULL);
  115. value = 1.0 / cuddV(f);
  116. res = cuddUniqueConst(dd,value);
  117. return(res);
  118. }
  119. res = cuddCacheLookup2(dd,Cudd_addScalarInverse,f,epsilon);
  120. if (res != NULL) return(res);
  121. t = cuddAddScalarInverseRecur(dd,cuddT(f),epsilon);
  122. if (t == NULL) return(NULL);
  123. cuddRef(t);
  124. e = cuddAddScalarInverseRecur(dd,cuddE(f),epsilon);
  125. if (e == NULL) {
  126. Cudd_RecursiveDeref(dd, t);
  127. return(NULL);
  128. }
  129. cuddRef(e);
  130. res = (t == e) ? t : cuddUniqueInter(dd,(int)f->index,t,e);
  131. if (res == NULL) {
  132. Cudd_RecursiveDeref(dd, t);
  133. Cudd_RecursiveDeref(dd, e);
  134. return(NULL);
  135. }
  136. cuddDeref(t);
  137. cuddDeref(e);
  138. cuddCacheInsert2(dd,Cudd_addScalarInverse,f,epsilon,res);
  139. return(res);
  140. } /* end of cuddAddScalarInverseRecur */
  141. /*---------------------------------------------------------------------------*/
  142. /* Definition of static functions */
  143. /*---------------------------------------------------------------------------*/