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.

190 lines
5.9 KiB

  1. /**
  2. @file
  3. @ingroup cudd
  4. @brief Function to compute the scalar inverse of an %ADD.
  5. @author Fabio Somenzi
  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 "util.h"
  35. #include "cuddInt.h"
  36. /*---------------------------------------------------------------------------*/
  37. /* Constant declarations */
  38. /*---------------------------------------------------------------------------*/
  39. /*---------------------------------------------------------------------------*/
  40. /* Stucture declarations */
  41. /*---------------------------------------------------------------------------*/
  42. /*---------------------------------------------------------------------------*/
  43. /* Type declarations */
  44. /*---------------------------------------------------------------------------*/
  45. /*---------------------------------------------------------------------------*/
  46. /* Variable declarations */
  47. /*---------------------------------------------------------------------------*/
  48. /*---------------------------------------------------------------------------*/
  49. /* Macro declarations */
  50. /*---------------------------------------------------------------------------*/
  51. /** \cond */
  52. /*---------------------------------------------------------------------------*/
  53. /* Static function prototypes */
  54. /*---------------------------------------------------------------------------*/
  55. /** \endcond */
  56. /*---------------------------------------------------------------------------*/
  57. /* Definition of exported functions */
  58. /*---------------------------------------------------------------------------*/
  59. /**
  60. @brief Computes the scalar inverse of an %ADD.
  61. @details Computes an n %ADD where the discriminants are the
  62. multiplicative inverses of the corresponding discriminants of the
  63. argument %ADD.
  64. @return a pointer to the resulting %ADD in case of success. Returns
  65. NULL if any discriminants smaller than epsilon is encountered.
  66. @sideeffect None
  67. */
  68. DdNode *
  69. Cudd_addScalarInverse(
  70. DdManager * dd,
  71. DdNode * f,
  72. DdNode * epsilon)
  73. {
  74. DdNode *res;
  75. if (!cuddIsConstant(epsilon)) {
  76. (void) fprintf(dd->err,"Invalid epsilon\n");
  77. return(NULL);
  78. }
  79. do {
  80. dd->reordered = 0;
  81. res = cuddAddScalarInverseRecur(dd,f,epsilon);
  82. } while (dd->reordered == 1);
  83. if (dd->errorCode == CUDD_TIMEOUT_EXPIRED && dd->timeoutHandler) {
  84. dd->timeoutHandler(dd, dd->tohArg);
  85. }
  86. return(res);
  87. } /* end of Cudd_addScalarInverse */
  88. /*---------------------------------------------------------------------------*/
  89. /* Definition of internal functions */
  90. /*---------------------------------------------------------------------------*/
  91. /**
  92. @brief Performs the recursive step of addScalarInverse.
  93. @return a pointer to the resulting %ADD in case of success. Returns
  94. NULL if any discriminants smaller than epsilon is encountered.
  95. @sideeffect None
  96. */
  97. DdNode *
  98. cuddAddScalarInverseRecur(
  99. DdManager * dd,
  100. DdNode * f,
  101. DdNode * epsilon)
  102. {
  103. DdNode *t, *e, *res;
  104. CUDD_VALUE_TYPE value;
  105. statLine(dd);
  106. if (cuddIsConstant(f)) {
  107. if (ddAbs(cuddV(f)) < cuddV(epsilon)) return(NULL);
  108. value = 1.0 / cuddV(f);
  109. res = cuddUniqueConst(dd,value);
  110. return(res);
  111. }
  112. res = cuddCacheLookup2(dd,Cudd_addScalarInverse,f,epsilon);
  113. if (res != NULL) return(res);
  114. checkWhetherToGiveUp(dd);
  115. t = cuddAddScalarInverseRecur(dd,cuddT(f),epsilon);
  116. if (t == NULL) return(NULL);
  117. cuddRef(t);
  118. e = cuddAddScalarInverseRecur(dd,cuddE(f),epsilon);
  119. if (e == NULL) {
  120. Cudd_RecursiveDeref(dd, t);
  121. return(NULL);
  122. }
  123. cuddRef(e);
  124. res = (t == e) ? t : cuddUniqueInter(dd,(int)f->index,t,e);
  125. if (res == NULL) {
  126. Cudd_RecursiveDeref(dd, t);
  127. Cudd_RecursiveDeref(dd, e);
  128. return(NULL);
  129. }
  130. cuddDeref(t);
  131. cuddDeref(e);
  132. cuddCacheInsert2(dd,Cudd_addScalarInverse,f,epsilon,res);
  133. return(res);
  134. } /* end of cuddAddScalarInverseRecur */
  135. /*---------------------------------------------------------------------------*/
  136. /* Definition of static functions */
  137. /*---------------------------------------------------------------------------*/