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.

281 lines
12 KiB

3 months ago
  1. /**
  2. @file
  3. @ingroup nanotrav
  4. @brief Simple-minded package to do traversal.
  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. #ifndef _NTR
  35. #define _NTR
  36. /*---------------------------------------------------------------------------*/
  37. /* Nested includes */
  38. /*---------------------------------------------------------------------------*/
  39. #include "dddmp.h"
  40. #include "bnet.h"
  41. #ifdef __cplusplus
  42. extern "C" {
  43. #endif
  44. /*---------------------------------------------------------------------------*/
  45. /* Constant declarations */
  46. /*---------------------------------------------------------------------------*/
  47. #define PI_PS_FROM_FILE 0
  48. #define PI_PS_DFS 1
  49. #define PI_PS_GIVEN 2
  50. #define NTR_IMAGE_MONO 0
  51. #define NTR_IMAGE_PART 1
  52. #define NTR_IMAGE_CLIP 2
  53. #define NTR_IMAGE_DEPEND 3
  54. #define NTR_UNDER_APPROX 0
  55. #define NTR_OVER_APPROX 1
  56. #define NTR_FROM_NEW 0
  57. #define NTR_FROM_REACHED 1
  58. #define NTR_FROM_RESTRICT 2
  59. #define NTR_FROM_COMPACT 3
  60. #define NTR_FROM_SQUEEZE 4
  61. #define NTR_FROM_UNDERAPPROX 5
  62. #define NTR_FROM_OVERAPPROX 6
  63. #define NTR_GROUP_NONE 0
  64. #define NTR_GROUP_DEFAULT 1
  65. #define NTR_GROUP_FIXED 2
  66. #define NTR_SHORT_NONE 0
  67. #define NTR_SHORT_BELLMAN 1
  68. #define NTR_SHORT_FLOYD 2
  69. #define NTR_SHORT_SQUARE 3
  70. /*---------------------------------------------------------------------------*/
  71. /* Stucture declarations */
  72. /*---------------------------------------------------------------------------*/
  73. /*---------------------------------------------------------------------------*/
  74. /* Type declarations */
  75. /*---------------------------------------------------------------------------*/
  76. /**
  77. @brief Options for nanotrav.
  78. */
  79. typedef struct NtrOptions {
  80. long initialTime; /**< this is here for convenience */
  81. int verify; /**< read two networks and compare them */
  82. char *file1; /**< first network file name */
  83. char *file2; /**< second network file name */
  84. int second; /**< a second network is given */
  85. int traverse; /**< do reachability analysis */
  86. int depend; /**< do latch dependence analysis */
  87. int image; /**< monolithic, partitioned, or clip */
  88. double imageClip; /**< clipping depth in image computation */
  89. int approx; /**< under or over approximation */
  90. int threshold; /**< approximation threshold */
  91. int from; /**< method to compute from states */
  92. int groupnsps; /**< group present state and next state vars */
  93. int closure; /**< use transitive closure */
  94. double closureClip; /**< clipping depth in closure computation */
  95. int envelope; /**< compute outer envelope */
  96. int scc; /**< compute strongly connected components */
  97. int zddtest; /**< do zdd test */
  98. int printcover; /**< print ISOP covers when testing ZDDs */
  99. int maxflow; /**< compute maximum flow in network */
  100. int shortPath; /**< compute shortest paths in network */
  101. int selectiveTrace; /**< use selective trace in shortest paths */
  102. char *sinkfile; /**< file for externally provided sink node */
  103. int partition; /**< test McMillan conjunctive partitioning */
  104. int char2vect; /**< test char-to-vect decomposition */
  105. int density; /**< test density-related functions */
  106. double quality; /**< quality parameter for density functions */
  107. int decomp; /**< test decomposition functions */
  108. int cofest; /**< test cofactor estimation */
  109. double clip; /**< test clipping functions */
  110. int dontcares; /**< test equivalence and containment with DCs */
  111. int closestCube; /**< test Cudd_bddClosestCube */
  112. int clauses; /**< test extraction of two-literal clauses */
  113. int noBuild; /**< do not build BDDs; just echo order */
  114. int stateOnly; /**< ignore primary outputs */
  115. char *node; /**< only node for which to build %BDD */
  116. int locGlob; /**< build global or local BDDs */
  117. int progress; /**< report output names while building BDDs */
  118. int cacheSize; /**< computed table initial size */
  119. size_t maxMemory; /**< target maximum memory */
  120. size_t maxMemHard; /**< maximum allowed memory */
  121. unsigned int maxLive; /**< maximum number of nodes */
  122. int slots; /**< unique subtable initial slots */
  123. int ordering; /**< FANIN DFS ... */
  124. char *orderPiPs; /**< file for externally provided order */
  125. Cudd_ReorderingType reordering; /**< NONE RANDOM PIVOT SIFTING ... */
  126. int autoDyn; /**< ON OFF */
  127. Cudd_ReorderingType autoMethod; /**< RANDOM PIVOT SIFTING CONVERGE ... */
  128. char *treefile; /**< file name for variable tree */
  129. int firstReorder; /**< when to do first reordering */
  130. int countDead; /**< count dead nodes toward triggering
  131. reordering */
  132. int maxGrowth; /**< maximum growth during reordering (%) */
  133. Cudd_AggregationType groupcheck; /**< grouping function */
  134. int arcviolation; /**< percent violation of arcs in
  135. extended symmetry check */
  136. int symmviolation; /**< percent symm violation in
  137. extended symmetry check */
  138. int recomb; /**< recombination parameter for grouping */
  139. int nodrop; /**< don't drop intermediate BDDs ASAP */
  140. int signatures; /**< computation of signatures */
  141. int gaOnOff; /**< whether to run GA at the end */
  142. int populationSize; /**< population size for GA */
  143. int numberXovers; /**< number of crossovers for GA */
  144. int bdddump; /**< ON OFF */
  145. int dumpFmt; /**< 0 -> dot 1 -> blif 2 ->daVinci 3 -> DDcal
  146. ** 4 -> factored form */
  147. char *dumpfile; /**< filename for dump */
  148. int store; /**< iteration at which to store Reached */
  149. char *storefile; /**< filename for storing Reached */
  150. int load; /**< load initial states from file */
  151. char *loadfile; /**< filename for loading states */
  152. int verb; /**< level of verbosity */
  153. int32_t seed; /**< seed for random number generator */
  154. } NtrOptions;
  155. /**
  156. @brief Type of entry of NtrHeap.
  157. */
  158. typedef struct NtrHeapSlot NtrHeapSlot;
  159. /**
  160. @brief Type of heap-based priority queue.
  161. */
  162. typedef struct NtrHeap NtrHeap;
  163. /**
  164. @brief Data structure for partitioned transition relation.
  165. */
  166. typedef struct NtrPartTR {
  167. int nparts; /**< number of parts */
  168. DdNode **part; /**< array of parts */
  169. DdNode **icube; /**< quantification cubes for image */
  170. DdNode **pcube; /**< quantification cubes for preimage */
  171. DdNode **nscube; /**< next state variables in each part */
  172. DdNode *preiabs; /**< present state vars and inputs in no part */
  173. DdNode *prepabs; /**< inputs in no part */
  174. DdNode *xw; /**< cube of all present states and PIs */
  175. NtrHeap *factors; /**< factors extracted from the image */
  176. int nlatches; /**< number of latches */
  177. DdNode **x; /**< array of present state variables */
  178. DdNode **y; /**< array of next state variables */
  179. } NtrPartTR;
  180. /*---------------------------------------------------------------------------*/
  181. /* Variable declarations */
  182. /*---------------------------------------------------------------------------*/
  183. /*---------------------------------------------------------------------------*/
  184. /* Macro declarations */
  185. /*---------------------------------------------------------------------------*/
  186. #ifndef TRUE
  187. # define TRUE 1
  188. #endif
  189. #ifndef FALSE
  190. # define FALSE 0
  191. #endif
  192. /**
  193. @brief Returns 1 if the two arguments are identical strings.
  194. @sideeffect none
  195. */
  196. #define STRING_EQUAL(s1,s2) (strcmp((s1),(s2)) == 0)
  197. /** \cond */
  198. /*---------------------------------------------------------------------------*/
  199. /* Function prototypes */
  200. /*---------------------------------------------------------------------------*/
  201. extern int Ntr_buildDDs (BnetNetwork *net, DdManager *dd, NtrOptions *option, BnetNetwork *net2);
  202. extern NtrPartTR * Ntr_buildTR (DdManager *dd, BnetNetwork *net, NtrOptions *option, int image);
  203. extern DdNode * Ntr_TransitiveClosure (DdManager *dd, NtrPartTR *TR, NtrOptions *option);
  204. extern int Ntr_Trav (DdManager *dd, BnetNetwork *net, NtrOptions *option);
  205. extern int Ntr_SCC (DdManager *dd, BnetNetwork *net, NtrOptions *option);
  206. extern int Ntr_ClosureTrav (DdManager *dd, BnetNetwork *net, NtrOptions *option);
  207. extern void Ntr_freeTR (DdManager *dd, NtrPartTR *TR);
  208. extern NtrPartTR * Ntr_cloneTR (NtrPartTR *TR);
  209. extern DdNode * Ntr_initState (DdManager *dd, BnetNetwork *net, NtrOptions *option);
  210. extern DdNode * Ntr_getStateCube (DdManager *dd, BnetNetwork *net, char *filename, int pr);
  211. extern int Ntr_Envelope (DdManager *dd, NtrPartTR *TR, FILE *dfp, NtrOptions *option);
  212. extern int Ntr_TestMinimization (DdManager *dd, BnetNetwork *net1, BnetNetwork *net2, NtrOptions *option);
  213. extern int Ntr_TestDensity (DdManager *dd, BnetNetwork *net1, NtrOptions *option);
  214. extern int Ntr_TestDecomp (DdManager *dd, BnetNetwork *net1, NtrOptions *option);
  215. extern int Ntr_VerifyEquivalence (DdManager *dd, BnetNetwork *net1, BnetNetwork *net2, NtrOptions *option);
  216. extern int Ntr_TestCofactorEstimate (DdManager * dd, BnetNetwork * net, NtrOptions * option);
  217. extern int Ntr_TestClipping (DdManager *dd, BnetNetwork *net1, BnetNetwork *net2, NtrOptions *option);
  218. extern int Ntr_TestEquivAndContain (DdManager *dd, BnetNetwork *net1, BnetNetwork *net2, NtrOptions *option);
  219. extern int Ntr_TestClosestCube (DdManager * dd, BnetNetwork * net, NtrOptions * option);
  220. extern int Ntr_TestTwoLiteralClauses (DdManager * dd, BnetNetwork * net1, NtrOptions * option);
  221. extern int Ntr_TestCharToVect(DdManager * dd, BnetNetwork * net1, NtrOptions * option);
  222. extern int Ntr_maxflow (DdManager *dd, BnetNetwork *net, NtrOptions *option);
  223. extern double Ntr_maximum01Flow (DdManager *bdd, DdNode *sx, DdNode *ty, DdNode *E, DdNode **F, DdNode **cut, DdNode **x, DdNode **y, DdNode **z, int n, int pr);
  224. extern int Ntr_testZDD (DdManager *dd, BnetNetwork *net, NtrOptions *option);
  225. extern int Ntr_testISOP (DdManager *dd, BnetNetwork *net, NtrOptions *option);
  226. extern NtrHeap * Ntr_InitHeap (int size);
  227. extern void Ntr_FreeHeap (NtrHeap *heap);
  228. extern int Ntr_HeapInsert (NtrHeap *heap, void *item, int key);
  229. extern int Ntr_HeapExtractMin (NtrHeap *heap, void *item, int *key);
  230. extern int Ntr_HeapCount (NtrHeap *heap);
  231. extern NtrHeap * Ntr_HeapClone (NtrHeap *source);
  232. extern void Ntr_HeapForeach (NtrHeap *heap, void (*f)(void *e, void *arg), void *arg);
  233. extern int Ntr_TestHeap (NtrHeap *heap, int i);
  234. extern int Ntr_ShortestPaths (DdManager *dd, BnetNetwork *net, NtrOptions *option);
  235. /** \endcond */
  236. #ifdef __cplusplus
  237. }
  238. #endif
  239. #endif /* _NTR */