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.

275 lines
7.2 KiB

2 months ago
  1. /**
  2. @file
  3. @ingroup cudd
  4. @brief Function to compute the negation of an %ADD.
  5. @author Fabio Somenzi, Balakrishna Kumthekar
  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 additive inverse of an %ADD.
  61. @return a pointer to the result if successful; NULL otherwise.
  62. @sideeffect None
  63. @see Cudd_addCmpl
  64. */
  65. DdNode *
  66. Cudd_addNegate(
  67. DdManager * dd,
  68. DdNode * f)
  69. {
  70. DdNode *res;
  71. do {
  72. dd->reordered = 0;
  73. res = cuddAddNegateRecur(dd,f);
  74. } while (dd->reordered == 1);
  75. if (dd->errorCode == CUDD_TIMEOUT_EXPIRED && dd->timeoutHandler) {
  76. dd->timeoutHandler(dd, dd->tohArg);
  77. }
  78. return(res);
  79. } /* end of Cudd_addNegate */
  80. /**
  81. @brief Rounds off the discriminants of an %ADD.
  82. @details The discriminants are rounded off to N digits after the
  83. decimal.
  84. @return a pointer to the result %ADD if successful; NULL otherwise.
  85. @sideeffect None
  86. */
  87. DdNode *
  88. Cudd_addRoundOff(
  89. DdManager * dd,
  90. DdNode * f,
  91. int N)
  92. {
  93. DdNode *res;
  94. double trunc = pow(10.0,(double)N);
  95. do {
  96. dd->reordered = 0;
  97. res = cuddAddRoundOffRecur(dd,f,trunc);
  98. } while (dd->reordered == 1);
  99. if (dd->errorCode == CUDD_TIMEOUT_EXPIRED && dd->timeoutHandler) {
  100. dd->timeoutHandler(dd, dd->tohArg);
  101. }
  102. return(res);
  103. } /* end of Cudd_addRoundOff */
  104. /*---------------------------------------------------------------------------*/
  105. /* Definition of internal functions */
  106. /*---------------------------------------------------------------------------*/
  107. /**
  108. @brief Implements the recursive step of Cudd_addNegate.
  109. @return a pointer to the result.
  110. @sideeffect None
  111. */
  112. DdNode *
  113. cuddAddNegateRecur(
  114. DdManager * dd,
  115. DdNode * f)
  116. {
  117. DdNode *res,
  118. *fv, *fvn,
  119. *T, *E;
  120. statLine(dd);
  121. /* Check terminal cases. */
  122. if (cuddIsConstant(f)) {
  123. res = cuddUniqueConst(dd,-cuddV(f));
  124. return(res);
  125. }
  126. /* Check cache */
  127. res = cuddCacheLookup1(dd,Cudd_addNegate,f);
  128. if (res != NULL) return(res);
  129. checkWhetherToGiveUp(dd);
  130. /* Recursive Step */
  131. fv = cuddT(f);
  132. fvn = cuddE(f);
  133. T = cuddAddNegateRecur(dd,fv);
  134. if (T == NULL) return(NULL);
  135. cuddRef(T);
  136. E = cuddAddNegateRecur(dd,fvn);
  137. if (E == NULL) {
  138. Cudd_RecursiveDeref(dd,T);
  139. return(NULL);
  140. }
  141. cuddRef(E);
  142. res = (T == E) ? T : cuddUniqueInter(dd,(int)f->index,T,E);
  143. if (res == NULL) {
  144. Cudd_RecursiveDeref(dd, T);
  145. Cudd_RecursiveDeref(dd, E);
  146. return(NULL);
  147. }
  148. cuddDeref(T);
  149. cuddDeref(E);
  150. /* Store result. */
  151. cuddCacheInsert1(dd,Cudd_addNegate,f,res);
  152. return(res);
  153. } /* end of cuddAddNegateRecur */
  154. /**
  155. @brief Implements the recursive step of Cudd_addRoundOff.
  156. @return a pointer to the result.
  157. @sideeffect None
  158. */
  159. DdNode *
  160. cuddAddRoundOffRecur(
  161. DdManager * dd,
  162. DdNode * f,
  163. double trunc)
  164. {
  165. DdNode *res, *fv, *fvn, *T, *E;
  166. double n;
  167. DD_CTFP1 cacheOp;
  168. statLine(dd);
  169. if (cuddIsConstant(f)) {
  170. n = ceil(cuddV(f)*trunc)/trunc;
  171. res = cuddUniqueConst(dd,n);
  172. return(res);
  173. }
  174. cacheOp = (DD_CTFP1) Cudd_addRoundOff;
  175. res = cuddCacheLookup1(dd,cacheOp,f);
  176. if (res != NULL) {
  177. return(res);
  178. }
  179. checkWhetherToGiveUp(dd);
  180. /* Recursive Step */
  181. fv = cuddT(f);
  182. fvn = cuddE(f);
  183. T = cuddAddRoundOffRecur(dd,fv,trunc);
  184. if (T == NULL) {
  185. return(NULL);
  186. }
  187. cuddRef(T);
  188. E = cuddAddRoundOffRecur(dd,fvn,trunc);
  189. if (E == NULL) {
  190. Cudd_RecursiveDeref(dd,T);
  191. return(NULL);
  192. }
  193. cuddRef(E);
  194. res = (T == E) ? T : cuddUniqueInter(dd,(int)f->index,T,E);
  195. if (res == NULL) {
  196. Cudd_RecursiveDeref(dd,T);
  197. Cudd_RecursiveDeref(dd,E);
  198. return(NULL);
  199. }
  200. cuddDeref(T);
  201. cuddDeref(E);
  202. /* Store result. */
  203. cuddCacheInsert1(dd,cacheOp,f,res);
  204. return(res);
  205. } /* end of cuddAddRoundOffRecur */
  206. /*---------------------------------------------------------------------------*/
  207. /* Definition of static functions */
  208. /*---------------------------------------------------------------------------*/