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.

1365 lines
42 KiB

3 months ago
  1. /**
  2. @file
  3. @ingroup nanotrav
  4. @brief Main program for the nanotrav program.
  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 "cuddInt.h"
  35. #include "ntr.h"
  36. /*---------------------------------------------------------------------------*/
  37. /* Constant declarations */
  38. /*---------------------------------------------------------------------------*/
  39. #define NTR_VERSION "Nanotrav Version #0.13, Release date 2015/7/15"
  40. #define BUFLENGTH 8192
  41. /*---------------------------------------------------------------------------*/
  42. /* Stucture declarations */
  43. /*---------------------------------------------------------------------------*/
  44. /*---------------------------------------------------------------------------*/
  45. /* Type declarations */
  46. /*---------------------------------------------------------------------------*/
  47. /*---------------------------------------------------------------------------*/
  48. /* Variable declarations */
  49. /*---------------------------------------------------------------------------*/
  50. static char buffer[BUFLENGTH];
  51. #ifdef DD_DEBUG
  52. extern st_table *checkMinterms (BnetNetwork *net, DdManager *dd, st_table *previous);
  53. #endif
  54. /*---------------------------------------------------------------------------*/
  55. /* Macro declarations */
  56. /*---------------------------------------------------------------------------*/
  57. /** \cond */
  58. /*---------------------------------------------------------------------------*/
  59. /* Static function prototypes */
  60. /*---------------------------------------------------------------------------*/
  61. static NtrOptions * mainInit ();
  62. static void ntrReadOptions (int argc, char **argv, NtrOptions *option);
  63. static void ntrReadOptionsFile (char *name, char ***argv, int *argc);
  64. static char* readLine (FILE *fp);
  65. static FILE * open_file (char *filename, const char *mode);
  66. static int reorder (BnetNetwork *net, DdManager *dd, NtrOptions *option);
  67. static void freeOption (NtrOptions *option);
  68. static DdManager * startCudd (NtrOptions *option, int nvars);
  69. static int ntrReadTree (DdManager *dd, char *treefile, int nvars);
  70. /** \endcond */
  71. /*---------------------------------------------------------------------------*/
  72. /* Definition of exported functions */
  73. /*---------------------------------------------------------------------------*/
  74. /**
  75. @brief Main program for ntr.
  76. @details Performs initialization. Reads command line options and
  77. network(s). Builds BDDs with reordering, and optionally does
  78. reachability analysis. Prints stats.
  79. @sideeffect None
  80. */
  81. int
  82. main(
  83. int argc,
  84. char ** argv)
  85. {
  86. NtrOptions *option; /* options */
  87. FILE *fp1; /* first network file pointer */
  88. BnetNetwork *net1 = NULL; /* first network */
  89. FILE *fp2; /* second network file pointer */
  90. BnetNetwork *net2 = NULL; /* second network */
  91. DdManager *dd; /* pointer to DD manager */
  92. int exitval; /* return value of Cudd_CheckZeroRef */
  93. int ok; /* overall return value from main() */
  94. int result; /* stores the return value of functions */
  95. BnetNode *node; /* auxiliary pointer to network node */
  96. int i; /* loop index */
  97. int j; /* loop index */
  98. double *signatures; /* array of signatures */
  99. int pr; /* verbosity level */
  100. int reencoded; /* linear transformations attempted */
  101. /* Initialize. */
  102. #if defined(_WIN32) && defined(_TWO_DIGIT_EXPONENT)
  103. (void) _set_output_format(_TWO_DIGIT_EXPONENT);
  104. #endif
  105. option = mainInit();
  106. ntrReadOptions(argc,argv,option);
  107. pr = option->verb;
  108. reencoded = option->reordering == CUDD_REORDER_LINEAR ||
  109. option->reordering == CUDD_REORDER_LINEAR_CONVERGE ||
  110. option->autoMethod == CUDD_REORDER_LINEAR ||
  111. option->autoMethod == CUDD_REORDER_LINEAR_CONVERGE;
  112. /* Currently traversal requires global BDDs. Override whatever
  113. ** was specified for locGlob.
  114. */
  115. if (option->traverse == TRUE || option->envelope == TRUE ||
  116. option->scc == TRUE) {
  117. option->locGlob = BNET_GLOBAL_DD;
  118. }
  119. /* Read the first network... */
  120. fp1 = open_file(option->file1, "r");
  121. net1 = Bnet_ReadNetwork(fp1,pr);
  122. (void) fclose(fp1);
  123. if (net1 == NULL) {
  124. (void) fprintf(stderr,"Syntax error in %s.\n",option->file1);
  125. exit(2);
  126. }
  127. /* ... and optionally echo it to the standard output. */
  128. if (pr > 2) {
  129. Bnet_PrintNetwork(net1);
  130. }
  131. /* Read the second network... */
  132. if (option->verify == TRUE || option->second == TRUE ||
  133. option->clip > 0.0 || option->dontcares) {
  134. fp2 = open_file(option->file2, "r");
  135. net2 = Bnet_ReadNetwork(fp2,pr);
  136. (void) fclose(fp2);
  137. if (net2 == NULL) {
  138. (void) fprintf(stderr,"Syntax error in %s.\n",option->file2);
  139. exit(2);
  140. }
  141. /* ... and optionally echo it to the standard output. */
  142. if (pr > 2) {
  143. Bnet_PrintNetwork(net2);
  144. }
  145. }
  146. /* Initialize manager. We start with 0 variables, because
  147. ** Ntr_buildDDs will create new variables rather than using
  148. ** whatever already exists.
  149. */
  150. dd = startCudd(option,net1->ninputs);
  151. if (dd == NULL) { exit(2); }
  152. /* Build the BDDs for the nodes of the first network. */
  153. result = Ntr_buildDDs(net1,dd,option,NULL);
  154. if (result == 0) { exit(2); }
  155. /* Build the BDDs for the nodes of the second network if requested. */
  156. if (option->verify == TRUE || option->second == TRUE ||
  157. option->clip > 0.0 || option->dontcares == TRUE) {
  158. char *nodesave = option->node;
  159. option->node = NULL;
  160. result = Ntr_buildDDs(net2,dd,option,net1);
  161. option->node = nodesave;
  162. if (result == 0) { exit(2); }
  163. }
  164. if (option->noBuild == TRUE) {
  165. Bnet_FreeNetwork(net1);
  166. if (option->verify == TRUE || option->second == TRUE ||
  167. option->clip > 0.0) {
  168. Bnet_FreeNetwork(net2);
  169. }
  170. freeOption(option);
  171. exit(0);
  172. }
  173. if (option->locGlob != BNET_LOCAL_DD) {
  174. /* Print the order before the final reordering. */
  175. (void) printf("Order before final reordering\n");
  176. result = Bnet_PrintOrder(net1,dd);
  177. if (result == 0) exit(2);
  178. }
  179. /* Perform final reordering */
  180. if (option->zddtest == FALSE) {
  181. result = reorder(net1,dd,option);
  182. if (result == 0) exit(2);
  183. /* Print final order. */
  184. if ((option->reordering != CUDD_REORDER_NONE || option->gaOnOff) &&
  185. option->locGlob != BNET_LOCAL_DD) {
  186. (void) printf("New order\n");
  187. result = Bnet_PrintOrder(net1,dd);
  188. if (result == 0) exit(2);
  189. }
  190. /* Print the re-encoded inputs. */
  191. if (pr >= 1 && reencoded == 1) {
  192. for (i = 0; i < net1->npis; i++) {
  193. if (!st_lookup(net1->hash,net1->inputs[i],(void **)&node)) {
  194. exit(2);
  195. }
  196. (void) fprintf(stdout,"%s ",node->name);
  197. Cudd_PrintDebug(dd,node->dd,Cudd_ReadSize(dd),pr);
  198. }
  199. for (i = 0; i < net1->nlatches; i++) {
  200. if (!st_lookup(net1->hash,net1->latches[i][1],(void **)&node)) {
  201. exit(2);
  202. }
  203. (void) fprintf(stdout,"%s ",node->name);
  204. Cudd_PrintDebug(dd,node->dd,Cudd_ReadSize(dd),pr);
  205. }
  206. if (pr >= 3) {
  207. result = Cudd_PrintLinear(dd);
  208. if (result == 0) exit(2);
  209. }
  210. }
  211. }
  212. /* Verify (combinational) equivalence. */
  213. if (option->verify == TRUE) {
  214. result = Ntr_VerifyEquivalence(dd,net1,net2,option);
  215. if (result == 0) {
  216. (void) printf("Verification abnormally terminated\n");
  217. exit(2);
  218. } else if (result == -1) {
  219. (void) printf("Combinational verification failed\n");
  220. } else {
  221. (void) printf("Verification succeeded\n");
  222. }
  223. }
  224. /* Traverse if requested and if the circuit is sequential. */
  225. result = Ntr_Trav(dd,net1,option);
  226. if (result == 0) exit(2);
  227. /* Traverse with trasitive closure. */
  228. result = Ntr_ClosureTrav(dd,net1,option);
  229. if (result == 0) exit(2);
  230. /* Compute outer envelope if requested and if the circuit is sequential. */
  231. if (option->envelope == TRUE && net1->nlatches > 0) {
  232. NtrPartTR *T;
  233. T = Ntr_buildTR(dd,net1,option,option->image);
  234. result = Ntr_Envelope(dd,T,NULL,option);
  235. if (result == 0) exit(2);
  236. Ntr_freeTR(dd,T);
  237. }
  238. /* Compute SCCs if requested and if the circuit is sequential. */
  239. result = Ntr_SCC(dd,net1,option);
  240. if (result == 0) exit(2);
  241. /* Test Constrain Decomposition. */
  242. if (option->partition == TRUE && net1->nlatches > 0) {
  243. NtrPartTR *T;
  244. DdNode *product;
  245. DdNode **decomp;
  246. int sharingSize;
  247. T = Ntr_buildTR(dd,net1,option,NTR_IMAGE_MONO);
  248. decomp = Cudd_bddConstrainDecomp(dd,T->part[0]);
  249. if (decomp == NULL) exit(2);
  250. sharingSize = Cudd_SharingSize(decomp, Cudd_ReadSize(dd));
  251. (void) fprintf(stdout, "Decomposition Size: %d components %d nodes\n",
  252. Cudd_ReadSize(dd), sharingSize);
  253. product = Cudd_ReadOne(dd);
  254. Cudd_Ref(product);
  255. for (i = 0; i < Cudd_ReadSize(dd); i++) {
  256. DdNode *intermediate = Cudd_bddAnd(dd, product, decomp[i]);
  257. if (intermediate == NULL) {
  258. exit(2);
  259. }
  260. Cudd_Ref(intermediate);
  261. Cudd_IterDerefBdd(dd, product);
  262. product = intermediate;
  263. }
  264. if (product != T->part[0])
  265. exit(2);
  266. Cudd_IterDerefBdd(dd, product);
  267. for (i = 0; i < Cudd_ReadSize(dd); i++) {
  268. Cudd_IterDerefBdd(dd, decomp[i]);
  269. }
  270. FREE(decomp);
  271. Ntr_freeTR(dd,T);
  272. }
  273. /* Test char-to-vect conversion. */
  274. result = Ntr_TestCharToVect(dd,net1,option);
  275. if (result == 0) exit(2);
  276. /* Test extraction of two-literal clauses. */
  277. result = Ntr_TestTwoLiteralClauses(dd,net1,option);
  278. if (result == 0) exit(2);
  279. /* Test BDD minimization functions. */
  280. result = Ntr_TestMinimization(dd,net1,net2,option);
  281. if (result == 0) exit(2);
  282. /* Test density-related functions. */
  283. result = Ntr_TestDensity(dd,net1,option);
  284. if (result == 0) exit(2);
  285. /* Test decomposition functions. */
  286. result = Ntr_TestDecomp(dd,net1,option);
  287. if (result == 0) exit(2);
  288. /* Test cofactor estimation functions. */
  289. result = Ntr_TestCofactorEstimate(dd,net1,option);
  290. if (result == 0) exit(2);
  291. /* Test BDD clipping functions. */
  292. result = Ntr_TestClipping(dd,net1,net2,option);
  293. if (result == 0) exit(2);
  294. /* Test BDD equivalence and containment under DC functions. */
  295. result = Ntr_TestEquivAndContain(dd,net1,net2,option);
  296. if (result == 0) exit(2);
  297. /* Test BDD Cudd_bddClosestCube. */
  298. result = Ntr_TestClosestCube(dd,net1,option);
  299. if (result == 0) exit(2);
  300. /* Test ZDDs if requested. */
  301. if (option->stateOnly == FALSE && option->zddtest == TRUE) {
  302. result = Ntr_testZDD(dd,net1,option);
  303. if (result == 0)
  304. (void) fprintf(stdout,"ZDD test failed.\n");
  305. result = Ntr_testISOP(dd,net1,option);
  306. if (result == 0)
  307. (void) fprintf(stdout,"ISOP test failed.\n");
  308. }
  309. /* Compute maximum flow if requested and if the circuit is sequential. */
  310. if (option->maxflow == TRUE && net1->nlatches > 0) {
  311. result = Ntr_maxflow(dd,net1,option);
  312. if (result == 0)
  313. (void) fprintf(stdout,"Maxflow computation failed.\n");
  314. }
  315. /* Compute shortest paths if requested and if the circuit is sequential. */
  316. if (option->shortPath != NTR_SHORT_NONE && net1->nlatches > 0) {
  317. result = Ntr_ShortestPaths(dd,net1,option);
  318. if (result == 0)
  319. (void) fprintf(stdout,"Shortest paths computation failed.\n");
  320. }
  321. /* Compute output signatures if so requested. */
  322. if (option->signatures) {
  323. (void) printf("Positive cofactor measures\n");
  324. for (i = 0; i < net1->noutputs; i++) {
  325. if (!st_lookup(net1->hash,net1->outputs[i],(void **)&node)) {
  326. exit(2);
  327. }
  328. signatures = Cudd_CofMinterm(dd, node->dd);
  329. if (signatures) {
  330. (void) printf("%s:\n", node->name);
  331. for (j = 0; j < Cudd_ReadSize(dd); j++) {
  332. if((j%5 == 0)&&i) (void) printf("\n");
  333. (void) printf("%5d: %-#8.4g ", j, signatures[j]);
  334. }
  335. (void) printf("\n");
  336. FREE(signatures);
  337. } else {
  338. (void) printf("Signature computation failed.\n");
  339. }
  340. }
  341. }
  342. /* Dump BDDs if so requested. */
  343. if (option->bdddump && option->second == FALSE &&
  344. option->density == FALSE && option->decomp == FALSE &&
  345. option->cofest == FALSE && option->clip < 0.0 &&
  346. option->scc == FALSE) {
  347. (void) printf("Dumping BDDs to %s\n", option->dumpfile);
  348. if (option->node != NULL) {
  349. if (!st_lookup(net1->hash,option->node,(void **)&node)) {
  350. exit(2);
  351. }
  352. result = Bnet_bddArrayDump(dd,net1,option->dumpfile,&(node->dd),
  353. &(node->name),1,option->dumpFmt);
  354. } else {
  355. result = Bnet_bddDump(dd, net1, option->dumpfile,
  356. option->dumpFmt, reencoded);
  357. }
  358. if (result != 1) {
  359. (void) printf("BDD dump failed.\n");
  360. }
  361. }
  362. /* Print stats and clean up. */
  363. if (pr >= 0) {
  364. result = Cudd_PrintInfo(dd,stdout);
  365. if (result != 1) {
  366. (void) printf("Cudd_PrintInfo failed.\n");
  367. }
  368. }
  369. #if defined(DD_DEBUG) && !defined(DD_NO_DEATH_ROW)
  370. (void) fprintf(dd->err,"%d empty slots in death row\n",
  371. cuddTimesInDeathRow(dd,NULL));
  372. #endif
  373. (void) printf("Final size: %ld\n", Cudd_ReadNodeCount(dd));
  374. /* Dispose of node BDDs. */
  375. node = net1->nodes;
  376. while (node != NULL) {
  377. if (node->dd != NULL &&
  378. node->type != BNET_INPUT_NODE &&
  379. node->type != BNET_PRESENT_STATE_NODE) {
  380. Cudd_IterDerefBdd(dd,node->dd);
  381. node->dd = NULL;
  382. }
  383. node = node->next;
  384. }
  385. /* Dispose of network. */
  386. Bnet_FreeNetwork(net1);
  387. /* Do the same cleanup for the second network if it was created. */
  388. if (option->verify == TRUE || option->second == TRUE ||
  389. option->clip > 0.0 || option->dontcares == TRUE) {
  390. /* Since option->second is TRUE and reading the second network
  391. * didn't result in a failure, we know net2 is not NULL. */
  392. assert(net2 != NULL);
  393. node = net2->nodes;
  394. while (node != NULL) {
  395. if (node->dd != NULL &&
  396. node->type != BNET_INPUT_NODE &&
  397. node->type != BNET_PRESENT_STATE_NODE) {
  398. Cudd_IterDerefBdd(dd,node->dd);
  399. node->dd = NULL;
  400. }
  401. node = node->next;
  402. }
  403. Bnet_FreeNetwork(net2);
  404. }
  405. /* Check reference counts: At this point we should have dereferenced
  406. ** everything we had, except in the case of re-encoding.
  407. */
  408. if (reencoded == CUDD_FALSE) {
  409. exitval = Cudd_CheckZeroRef(dd);
  410. ok = exitval != 0; /* ok == 0 means O.K. */
  411. if (exitval != 0) {
  412. (void) fflush(stdout);
  413. (void) fprintf(stderr,
  414. "%d non-zero DD reference counts after dereferencing\n", exitval);
  415. }
  416. } else {
  417. ok = 0;
  418. }
  419. #ifdef DD_DEBUG
  420. Cudd_CheckKeys(dd);
  421. #endif
  422. Cudd_Quit(dd);
  423. if (pr >= 0) (void) printf("total time = %s\n",
  424. util_print_time(util_cpu_time() - option->initialTime));
  425. freeOption(option);
  426. if (pr >= 0) util_print_cpu_stats(stdout);
  427. exit(ok);
  428. } /* end of main */
  429. /*---------------------------------------------------------------------------*/
  430. /* Definition of internal functions */
  431. /*---------------------------------------------------------------------------*/
  432. /*---------------------------------------------------------------------------*/
  433. /* Definition of static functions */
  434. /*---------------------------------------------------------------------------*/
  435. /**
  436. @brief Allocates the option structure and initializes it.
  437. @sideeffect none
  438. @see ntrReadOptions
  439. */
  440. static NtrOptions *
  441. mainInit(
  442. )
  443. {
  444. NtrOptions *option;
  445. /* Initialize option structure. */
  446. option = ALLOC(NtrOptions,1);
  447. option->initialTime = util_cpu_time();
  448. option->verify = FALSE;
  449. option->second = FALSE;
  450. option->file1 = NULL;
  451. option->file2 = NULL;
  452. option->traverse = FALSE;
  453. option->depend = FALSE;
  454. option->image = NTR_IMAGE_MONO;
  455. option->imageClip = 1.0;
  456. option->approx = NTR_UNDER_APPROX;
  457. option->threshold = -1;
  458. option->from = NTR_FROM_NEW;
  459. option->groupnsps = NTR_GROUP_NONE;
  460. option->closure = FALSE;
  461. option->closureClip = 1.0;
  462. option->envelope = FALSE;
  463. option->scc = FALSE;
  464. option->maxflow = FALSE;
  465. option->shortPath = NTR_SHORT_NONE;
  466. option->selectiveTrace = FALSE;
  467. option->zddtest = FALSE;
  468. option->printcover = FALSE;
  469. option->sinkfile = NULL;
  470. option->partition = FALSE;
  471. option->char2vect = FALSE;
  472. option->density = FALSE;
  473. option->quality = 1.0;
  474. option->decomp = FALSE;
  475. option->cofest = FALSE;
  476. option->clip = -1.0;
  477. option->dontcares = FALSE;
  478. option->closestCube = FALSE;
  479. option->clauses = FALSE;
  480. option->noBuild = FALSE;
  481. option->stateOnly = FALSE;
  482. option->node = NULL;
  483. option->locGlob = BNET_GLOBAL_DD;
  484. option->progress = FALSE;
  485. option->cacheSize = 32768;
  486. option->maxMemory = 0; /* set automatically */
  487. option->maxMemHard = 0; /* don't set */
  488. option->maxLive = ~0U; /* very large number */
  489. option->slots = CUDD_UNIQUE_SLOTS;
  490. option->ordering = PI_PS_FROM_FILE;
  491. option->orderPiPs = NULL;
  492. option->reordering = CUDD_REORDER_NONE;
  493. option->autoMethod = CUDD_REORDER_SIFT;
  494. option->autoDyn = 0;
  495. option->treefile = NULL;
  496. option->firstReorder = DD_FIRST_REORDER;
  497. option->countDead = FALSE;
  498. option->maxGrowth = 20;
  499. option->groupcheck = CUDD_GROUP_CHECK7;
  500. option->arcviolation = 10;
  501. option->symmviolation = 10;
  502. option->recomb = DD_DEFAULT_RECOMB;
  503. option->nodrop = TRUE;
  504. option->signatures = FALSE;
  505. option->verb = 0;
  506. option->gaOnOff = 0;
  507. option->populationSize = 0; /* use default */
  508. option->numberXovers = 0; /* use default */
  509. option->bdddump = FALSE;
  510. option->dumpFmt = 0; /* dot */
  511. option->dumpfile = NULL;
  512. option->store = -1; /* do not store */
  513. option->storefile = NULL;
  514. option->load = FALSE;
  515. option->loadfile = NULL;
  516. option->seed = 1;
  517. return(option);
  518. } /* end of mainInit */
  519. /**
  520. @brief Reads the command line options.
  521. @details Scans the command line one argument at a time and performs
  522. a switch on each arguement it hits. Some arguemnts also read in the
  523. following arg from the list (i.e., -f also gets the filename which
  524. should folow.) Gives a usage message and exits if any unrecognized
  525. args are found.
  526. @sideeffect May initialize the random number generator.
  527. @see mainInit ntrReadOptionsFile
  528. */
  529. static void
  530. ntrReadOptions(
  531. int argc,
  532. char ** argv,
  533. NtrOptions * option)
  534. {
  535. int i = 0;
  536. if (argc < 2) goto usage;
  537. if (STRING_EQUAL(argv[1],"-f")) {
  538. ntrReadOptionsFile(argv[2],&argv,&argc);
  539. }
  540. for (i = 1; i < argc; i++) {
  541. if (argv[i][0] != '-' ) {
  542. if (option->file1 == NULL) {
  543. option->file1 = util_strsav(argv[i]);
  544. } else {
  545. goto usage;
  546. }
  547. } else if (STRING_EQUAL(argv[i],"-second")) {
  548. i++;
  549. option->file2 = util_strsav(argv[i]);
  550. option->second = TRUE;
  551. } else if (STRING_EQUAL(argv[i],"-verify")) {
  552. i++;
  553. option->file2 = util_strsav(argv[i]);
  554. option->verify = TRUE;
  555. } else if (STRING_EQUAL(argv[i],"-trav")) {
  556. option->traverse = TRUE;
  557. } else if (STRING_EQUAL(argv[i],"-depend")) {
  558. option->traverse = TRUE;
  559. option->depend = TRUE;
  560. } else if (STRING_EQUAL(argv[i],"-image")) {
  561. i++;
  562. if (STRING_EQUAL(argv[i],"part")) {
  563. option->image = NTR_IMAGE_PART;
  564. } else if (STRING_EQUAL(argv[i],"clip")) {
  565. option->image = NTR_IMAGE_CLIP;
  566. } else if (STRING_EQUAL(argv[i],"depend")) {
  567. option->image = NTR_IMAGE_DEPEND;
  568. } else if (STRING_EQUAL(argv[i],"mono")) {
  569. option->image = NTR_IMAGE_MONO;
  570. } else {
  571. goto usage;
  572. }
  573. } else if (STRING_EQUAL(argv[i],"-depth")) {
  574. i++;
  575. option->imageClip = (double) atof(argv[i]);
  576. } else if (STRING_EQUAL(argv[i],"-cdepth")) {
  577. i++;
  578. option->closureClip = (double) atof(argv[i]);
  579. } else if (STRING_EQUAL(argv[i],"-approx")) {
  580. i++;
  581. if (STRING_EQUAL(argv[i],"under")) {
  582. option->approx = NTR_UNDER_APPROX;
  583. } else if (STRING_EQUAL(argv[i],"over")) {
  584. option->approx = NTR_OVER_APPROX;
  585. } else {
  586. goto usage;
  587. }
  588. } else if (STRING_EQUAL(argv[i],"-threshold")) {
  589. i++;
  590. option->threshold = (int) atoi(argv[i]);
  591. } else if (STRING_EQUAL(argv[i],"-from")) {
  592. i++;
  593. if (STRING_EQUAL(argv[i],"new")) {
  594. option->from = NTR_FROM_NEW;
  595. } else if (STRING_EQUAL(argv[i],"reached")) {
  596. option->from = NTR_FROM_REACHED;
  597. } else if (STRING_EQUAL(argv[i],"restrict")) {
  598. option->from = NTR_FROM_RESTRICT;
  599. } else if (STRING_EQUAL(argv[i],"compact")) {
  600. option->from = NTR_FROM_COMPACT;
  601. } else if (STRING_EQUAL(argv[i],"squeeze")) {
  602. option->from = NTR_FROM_SQUEEZE;
  603. } else if (STRING_EQUAL(argv[i],"subset")) {
  604. option->from = NTR_FROM_UNDERAPPROX;
  605. } else if (STRING_EQUAL(argv[i],"superset")) {
  606. option->from = NTR_FROM_OVERAPPROX;
  607. } else {
  608. goto usage;
  609. }
  610. } else if (STRING_EQUAL(argv[i],"-groupnsps")) {
  611. i++;
  612. if (STRING_EQUAL(argv[i],"none")) {
  613. option->groupnsps = NTR_GROUP_NONE;
  614. } else if (STRING_EQUAL(argv[i],"default")) {
  615. option->groupnsps = NTR_GROUP_DEFAULT;
  616. } else if (STRING_EQUAL(argv[i],"fixed")) {
  617. option->groupnsps = NTR_GROUP_FIXED;
  618. } else {
  619. goto usage;
  620. }
  621. } else if (STRING_EQUAL(argv[i],"-closure")) {
  622. option->closure = TRUE;
  623. } else if (STRING_EQUAL(argv[i],"-envelope")) {
  624. option->envelope = TRUE;
  625. } else if (STRING_EQUAL(argv[i],"-scc")) {
  626. option->scc = TRUE;
  627. } else if (STRING_EQUAL(argv[i],"-maxflow")) {
  628. option->maxflow = TRUE;
  629. } else if (STRING_EQUAL(argv[i],"-shortpaths")) {
  630. i++;
  631. if (STRING_EQUAL(argv[i],"none")) {
  632. option->shortPath = NTR_SHORT_NONE;
  633. } else if (STRING_EQUAL(argv[i],"bellman")) {
  634. option->shortPath = NTR_SHORT_BELLMAN;
  635. } else if (STRING_EQUAL(argv[i],"floyd")) {
  636. option->shortPath = NTR_SHORT_FLOYD;
  637. } else if (STRING_EQUAL(argv[i],"square")) {
  638. option->shortPath = NTR_SHORT_SQUARE;
  639. } else {
  640. goto usage;
  641. }
  642. } else if (STRING_EQUAL(argv[i],"-selective")) {
  643. option->selectiveTrace = TRUE;
  644. } else if (STRING_EQUAL(argv[i],"-zdd")) {
  645. option->zddtest = TRUE;
  646. } else if (STRING_EQUAL(argv[i],"-cover")) {
  647. option->zddtest = TRUE;
  648. option->printcover = TRUE;
  649. } else if (STRING_EQUAL(argv[i],"-sink")) {
  650. i++;
  651. option->maxflow = TRUE;
  652. option->sinkfile = util_strsav(argv[i]);
  653. } else if (STRING_EQUAL(argv[i],"-part")) {
  654. option->partition = TRUE;
  655. } else if (STRING_EQUAL(argv[i],"-char2vect")) {
  656. option->char2vect = TRUE;
  657. } else if (STRING_EQUAL(argv[i],"-density")) {
  658. option->density = TRUE;
  659. } else if (STRING_EQUAL(argv[i],"-quality")) {
  660. i++;
  661. option->quality = (double) atof(argv[i]);
  662. } else if (STRING_EQUAL(argv[i],"-decomp")) {
  663. option->decomp = TRUE;
  664. } else if (STRING_EQUAL(argv[i],"-cofest")) {
  665. option->cofest = TRUE;
  666. } else if (STRING_EQUAL(argv[i],"-clip")) {
  667. i++;
  668. option->clip = (double) atof(argv[i]);
  669. i++;
  670. option->file2 = util_strsav(argv[i]);
  671. } else if (STRING_EQUAL(argv[i],"-dctest")) {
  672. option->dontcares = TRUE;
  673. i++;
  674. option->file2 = util_strsav(argv[i]);
  675. } else if (STRING_EQUAL(argv[i],"-closest")) {
  676. option->closestCube = TRUE;
  677. } else if (STRING_EQUAL(argv[i],"-clauses")) {
  678. option->clauses = TRUE;
  679. } else if (STRING_EQUAL(argv[i],"-nobuild")) {
  680. option->noBuild = TRUE;
  681. option->reordering = CUDD_REORDER_NONE;
  682. } else if (STRING_EQUAL(argv[i],"-delta")) {
  683. option->stateOnly = TRUE;
  684. } else if (STRING_EQUAL(argv[i],"-node")) {
  685. i++;
  686. option->node = util_strsav(argv[i]);
  687. } else if (STRING_EQUAL(argv[i],"-local")) {
  688. option->locGlob = BNET_LOCAL_DD;
  689. } else if (STRING_EQUAL(argv[i],"-progress")) {
  690. option->progress = TRUE;
  691. } else if (STRING_EQUAL(argv[i],"-cache")) {
  692. i++;
  693. option->cacheSize = (int) atoi(argv[i]);
  694. } else if (STRING_EQUAL(argv[i],"-maxmem")) {
  695. i++;
  696. option->maxMemory = 1048576 * (int) atoi(argv[i]);
  697. } else if (STRING_EQUAL(argv[i],"-memhard")) {
  698. i++;
  699. option->maxMemHard = 1048576 * (int) atoi(argv[i]);
  700. } else if (STRING_EQUAL(argv[i],"-maxlive")) {
  701. i++;
  702. option->maxLive = (unsigned int) atoi(argv[i]);
  703. } else if (STRING_EQUAL(argv[i],"-slots")) {
  704. i++;
  705. option->slots = (int) atoi(argv[i]);
  706. } else if (STRING_EQUAL(argv[i],"-ordering")) {
  707. i++;
  708. if (STRING_EQUAL(argv[i],"dfs")) {
  709. option->ordering = PI_PS_DFS;
  710. } else if (STRING_EQUAL(argv[i],"hw")) {
  711. option->ordering = PI_PS_FROM_FILE;
  712. } else {
  713. goto usage;
  714. }
  715. } else if (STRING_EQUAL(argv[i],"-order")) {
  716. i++;
  717. option->ordering = PI_PS_GIVEN;
  718. option->orderPiPs = util_strsav(argv[i]);
  719. } else if (STRING_EQUAL(argv[i],"-reordering")) {
  720. i++;
  721. if (STRING_EQUAL(argv[i],"none")) {
  722. option->reordering = CUDD_REORDER_NONE;
  723. } else if (STRING_EQUAL(argv[i],"random")) {
  724. option->reordering = CUDD_REORDER_RANDOM;
  725. } else if (STRING_EQUAL(argv[i],"bernard") ||
  726. STRING_EQUAL(argv[i],"pivot")) {
  727. option->reordering = CUDD_REORDER_RANDOM_PIVOT;
  728. } else if (STRING_EQUAL(argv[i],"sifting")) {
  729. option->reordering = CUDD_REORDER_SIFT;
  730. } else if (STRING_EQUAL(argv[i],"converge")) {
  731. option->reordering = CUDD_REORDER_SIFT_CONVERGE;
  732. } else if (STRING_EQUAL(argv[i],"symm")) {
  733. option->reordering = CUDD_REORDER_SYMM_SIFT;
  734. } else if (STRING_EQUAL(argv[i],"cosymm")) {
  735. option->reordering = CUDD_REORDER_SYMM_SIFT_CONV;
  736. } else if (STRING_EQUAL(argv[i],"tree") ||
  737. STRING_EQUAL(argv[i],"group")) {
  738. option->reordering = CUDD_REORDER_GROUP_SIFT;
  739. } else if (STRING_EQUAL(argv[i],"cotree") ||
  740. STRING_EQUAL(argv[i],"cogroup")) {
  741. option->reordering = CUDD_REORDER_GROUP_SIFT_CONV;
  742. } else if (STRING_EQUAL(argv[i],"win2")) {
  743. option->reordering = CUDD_REORDER_WINDOW2;
  744. } else if (STRING_EQUAL(argv[i],"win3")) {
  745. option->reordering = CUDD_REORDER_WINDOW3;
  746. } else if (STRING_EQUAL(argv[i],"win4")) {
  747. option->reordering = CUDD_REORDER_WINDOW4;
  748. } else if (STRING_EQUAL(argv[i],"win2conv")) {
  749. option->reordering = CUDD_REORDER_WINDOW2_CONV;
  750. } else if (STRING_EQUAL(argv[i],"win3conv")) {
  751. option->reordering = CUDD_REORDER_WINDOW3_CONV;
  752. } else if (STRING_EQUAL(argv[i],"win4conv")) {
  753. option->reordering = CUDD_REORDER_WINDOW4_CONV;
  754. } else if (STRING_EQUAL(argv[i],"annealing")) {
  755. option->reordering = CUDD_REORDER_ANNEALING;
  756. } else if (STRING_EQUAL(argv[i],"genetic")) {
  757. option->reordering = CUDD_REORDER_GENETIC;
  758. } else if (STRING_EQUAL(argv[i],"linear")) {
  759. option->reordering = CUDD_REORDER_LINEAR;
  760. } else if (STRING_EQUAL(argv[i],"linconv")) {
  761. option->reordering = CUDD_REORDER_LINEAR_CONVERGE;
  762. } else if (STRING_EQUAL(argv[i],"exact")) {
  763. option->reordering = CUDD_REORDER_EXACT;
  764. } else {
  765. goto usage;
  766. }
  767. } else if (STRING_EQUAL(argv[i],"-autodyn")) {
  768. option->autoDyn = 3;
  769. } else if (STRING_EQUAL(argv[i],"-autodynB")) {
  770. option->autoDyn |= 1;
  771. } else if (STRING_EQUAL(argv[i],"-autodynZ")) {
  772. option->autoDyn |= 2;
  773. } else if (STRING_EQUAL(argv[i],"-automethod")) {
  774. i++;
  775. if (STRING_EQUAL(argv[i],"none")) {
  776. option->autoMethod = CUDD_REORDER_NONE;
  777. } else if (STRING_EQUAL(argv[i],"random")) {
  778. option->autoMethod = CUDD_REORDER_RANDOM;
  779. } else if (STRING_EQUAL(argv[i],"bernard") ||
  780. STRING_EQUAL(argv[i],"pivot")) {
  781. option->autoMethod = CUDD_REORDER_RANDOM_PIVOT;
  782. } else if (STRING_EQUAL(argv[i],"sifting")) {
  783. option->autoMethod = CUDD_REORDER_SIFT;
  784. } else if (STRING_EQUAL(argv[i],"converge")) {
  785. option->autoMethod = CUDD_REORDER_SIFT_CONVERGE;
  786. } else if (STRING_EQUAL(argv[i],"symm")) {
  787. option->autoMethod = CUDD_REORDER_SYMM_SIFT;
  788. } else if (STRING_EQUAL(argv[i],"cosymm")) {
  789. option->autoMethod = CUDD_REORDER_SYMM_SIFT_CONV;
  790. } else if (STRING_EQUAL(argv[i],"tree") ||
  791. STRING_EQUAL(argv[i],"group")) {
  792. option->autoMethod = CUDD_REORDER_GROUP_SIFT;
  793. } else if (STRING_EQUAL(argv[i],"cotree") ||
  794. STRING_EQUAL(argv[i],"cogroup")) {
  795. option->autoMethod = CUDD_REORDER_GROUP_SIFT_CONV;
  796. } else if (STRING_EQUAL(argv[i],"win2")) {
  797. option->autoMethod = CUDD_REORDER_WINDOW2;
  798. } else if (STRING_EQUAL(argv[i],"win3")) {
  799. option->autoMethod = CUDD_REORDER_WINDOW3;
  800. } else if (STRING_EQUAL(argv[i],"win4")) {
  801. option->autoMethod = CUDD_REORDER_WINDOW4;
  802. } else if (STRING_EQUAL(argv[i],"win2conv")) {
  803. option->autoMethod = CUDD_REORDER_WINDOW2_CONV;
  804. } else if (STRING_EQUAL(argv[i],"win3conv")) {
  805. option->autoMethod = CUDD_REORDER_WINDOW3_CONV;
  806. } else if (STRING_EQUAL(argv[i],"win4conv")) {
  807. option->autoMethod = CUDD_REORDER_WINDOW4_CONV;
  808. } else if (STRING_EQUAL(argv[i],"annealing")) {
  809. option->autoMethod = CUDD_REORDER_ANNEALING;
  810. } else if (STRING_EQUAL(argv[i],"genetic")) {
  811. option->autoMethod = CUDD_REORDER_GENETIC;
  812. } else if (STRING_EQUAL(argv[i],"linear")) {
  813. option->autoMethod = CUDD_REORDER_LINEAR;
  814. } else if (STRING_EQUAL(argv[i],"linconv")) {
  815. option->autoMethod = CUDD_REORDER_LINEAR_CONVERGE;
  816. } else if (STRING_EQUAL(argv[i],"exact")) {
  817. option->autoMethod = CUDD_REORDER_EXACT;
  818. } else {
  819. goto usage;
  820. }
  821. } else if (STRING_EQUAL(argv[i],"-tree")) {
  822. i++;
  823. option->treefile = util_strsav(argv[i]);
  824. } else if (STRING_EQUAL(argv[i],"-first")) {
  825. i++;
  826. option->firstReorder = (int)atoi(argv[i]);
  827. } else if (STRING_EQUAL(argv[i],"-countdead")) {
  828. option->countDead = TRUE;
  829. } else if (STRING_EQUAL(argv[i],"-growth")) {
  830. i++;
  831. option->maxGrowth = (int)atoi(argv[i]);
  832. } else if (STRING_EQUAL(argv[i],"-groupcheck")) {
  833. i++;
  834. if (STRING_EQUAL(argv[i],"check")) {
  835. option->groupcheck = CUDD_GROUP_CHECK;
  836. } else if (STRING_EQUAL(argv[i],"nocheck")) {
  837. option->groupcheck = CUDD_NO_CHECK;
  838. } else if (STRING_EQUAL(argv[i],"check2")) {
  839. option->groupcheck = CUDD_GROUP_CHECK2;
  840. } else if (STRING_EQUAL(argv[i],"check3")) {
  841. option->groupcheck = CUDD_GROUP_CHECK3;
  842. } else if (STRING_EQUAL(argv[i],"check4")) {
  843. option->groupcheck = CUDD_GROUP_CHECK4;
  844. } else if (STRING_EQUAL(argv[i],"check5")) {
  845. option->groupcheck = CUDD_GROUP_CHECK5;
  846. } else if (STRING_EQUAL(argv[i],"check6")) {
  847. option->groupcheck = CUDD_GROUP_CHECK6;
  848. } else if (STRING_EQUAL(argv[i],"check7")) {
  849. option->groupcheck = CUDD_GROUP_CHECK7;
  850. } else if (STRING_EQUAL(argv[i],"check8")) {
  851. option->groupcheck = CUDD_GROUP_CHECK8;
  852. } else if (STRING_EQUAL(argv[i],"check9")) {
  853. option->groupcheck = CUDD_GROUP_CHECK9;
  854. } else {
  855. goto usage;
  856. }
  857. } else if (STRING_EQUAL(argv[i],"-arcviolation")) {
  858. i++;
  859. option->arcviolation = (int)atoi(argv[i]);
  860. } else if (STRING_EQUAL(argv[i],"-symmviolation")) {
  861. i++;
  862. option->symmviolation = (int)atoi(argv[i]);
  863. } else if (STRING_EQUAL(argv[i],"-recomb")) {
  864. i++;
  865. option->recomb = (int)atoi(argv[i]);
  866. } else if (STRING_EQUAL(argv[i],"-drop")) {
  867. option->nodrop = FALSE;
  868. } else if (STRING_EQUAL(argv[i],"-sign")) {
  869. option->signatures = TRUE;
  870. } else if (STRING_EQUAL(argv[i],"-genetic")) {
  871. option->gaOnOff = 1;
  872. } else if (STRING_EQUAL(argv[i],"-genepop")) {
  873. option->gaOnOff = 1;
  874. i++;
  875. option->populationSize = (int)atoi(argv[i]);
  876. } else if (STRING_EQUAL(argv[i],"-genexover")) {
  877. option->gaOnOff = 1;
  878. i++;
  879. option->numberXovers = (int) atoi(argv[i]);
  880. } else if (STRING_EQUAL(argv[i],"-seed")) {
  881. i++;
  882. option->seed = (int32_t) atoi(argv[i]);
  883. } else if (STRING_EQUAL(argv[i],"-dumpfile")) {
  884. i++;
  885. option->bdddump = TRUE;
  886. option->dumpfile = util_strsav(argv[i]);
  887. } else if (STRING_EQUAL(argv[i],"-dumpblif")) {
  888. option->dumpFmt = 1; /* blif */
  889. } else if (STRING_EQUAL(argv[i],"-dumpdaVinci")) {
  890. option->dumpFmt = 2; /* daVinci */
  891. } else if (STRING_EQUAL(argv[i],"-dumpddcal")) {
  892. option->dumpFmt = 3; /* DDcal */
  893. } else if (STRING_EQUAL(argv[i],"-dumpfact")) {
  894. option->dumpFmt = 4; /* factored form */
  895. } else if (STRING_EQUAL(argv[i],"-dumpmv")) {
  896. option->dumpFmt = 5; /* blif-MV */
  897. } else if (STRING_EQUAL(argv[i],"-store")) {
  898. i++;
  899. option->store = (int) atoi(argv[i]);
  900. } else if (STRING_EQUAL(argv[i],"-storefile")) {
  901. i++;
  902. option->storefile = util_strsav(argv[i]);
  903. } else if (STRING_EQUAL(argv[i],"-loadfile")) {
  904. i++;
  905. option->load = 1;
  906. option->loadfile = util_strsav(argv[i]);
  907. } else if (STRING_EQUAL(argv[i],"-p")) {
  908. i++;
  909. option->verb = (int) atoi(argv[i]);
  910. } else {
  911. goto usage;
  912. }
  913. }
  914. if (option->store >= 0 && option->storefile == NULL) {
  915. (void) fprintf(stdout,"-storefile mandatory with -store\n");
  916. exit(-1);
  917. }
  918. if (option->verb >= 0) {
  919. (void) printf("# %s\n", NTR_VERSION);
  920. /* echo command line and arguments */
  921. (void) printf("#");
  922. for (i = 0; i < argc; i++) {
  923. (void) printf(" %s", argv[i]);
  924. }
  925. (void) printf("\n");
  926. (void) printf("# CUDD Version ");
  927. Cudd_PrintVersion(stdout);
  928. (void) fflush(stdout);
  929. }
  930. return;
  931. usage: /* convenient goto */
  932. printf("Usage: please read man page\n");
  933. if (i == 0) {
  934. (void) fprintf(stdout,"too few arguments\n");
  935. } else {
  936. (void) fprintf(stdout,"option: %s is not defined\n",argv[i]);
  937. }
  938. exit(-1);
  939. } /* end of ntrReadOptions */
  940. /**
  941. @brief Reads the program options from a file.
  942. @details Opens file. Reads the command line from the otpions file
  943. using the read_line func. Scans the line looking for spaces, each
  944. space is a searator and demarks a new option. When a space is
  945. found, it is changed to a \0 to terminate that string; then the next
  946. value of slot points to the next non-space character. There is a
  947. limit of 1024 options. Should produce an error (presently doesn't)
  948. on overrun of options, but this is very unlikely to happen.
  949. @sideeffect none
  950. */
  951. static void
  952. ntrReadOptionsFile(
  953. char * name,
  954. char *** argv,
  955. int * argc)
  956. {
  957. char **slot;
  958. char *line;
  959. char c;
  960. int index,flag;
  961. FILE *fp;
  962. if ((fp = fopen(name,"r")) == NULL) {
  963. fprintf(stderr,"Error: can not find cmd file %s\n",name);
  964. exit(-1);
  965. }
  966. slot = ALLOC(char *,1024);
  967. index = 1;
  968. line = readLine(fp);
  969. flag = TRUE;
  970. do {
  971. c = *line;
  972. if ( c == ' ') {
  973. flag = TRUE;
  974. *line = '\0';
  975. } else if ( c != ' ' && flag == TRUE) {
  976. flag = FALSE;
  977. slot[index] = line;
  978. index++;
  979. }
  980. line++;
  981. } while ( *line != '\0');
  982. *argv = slot;
  983. *argc = index;
  984. fclose(fp);
  985. } /* end of ntrReadOptionsFile */
  986. /**
  987. @brief Reads a line from the option file.
  988. @sideeffect none
  989. */
  990. static char*
  991. readLine(
  992. FILE * fp)
  993. {
  994. int c;
  995. char *pbuffer;
  996. pbuffer = buffer;
  997. /* Strip white space from beginning of line. */
  998. for(;;) {
  999. c = getc(fp);
  1000. if ( c == EOF) return(NULL);
  1001. if ( c == '\n') {
  1002. *pbuffer = '\0';
  1003. return(buffer); /* got a blank line */
  1004. }
  1005. if ( c != ' ') break;
  1006. }
  1007. do {
  1008. if ( c == '\\' ) { /* if we have a continuation character.. */
  1009. do { /* scan to end of line */
  1010. c = getc(fp);
  1011. if ( c == '\n' ) break;
  1012. } while ( c != EOF);
  1013. if ( c != EOF) {
  1014. *pbuffer = ' ';
  1015. pbuffer++;
  1016. } else return( buffer);
  1017. c = getc(fp);
  1018. continue;
  1019. }
  1020. *pbuffer = (char) c;
  1021. pbuffer++;
  1022. c = getc(fp);
  1023. } while( c != '\n' && c != EOF);
  1024. *pbuffer = '\0';
  1025. return(buffer);
  1026. } /* end of readLine */
  1027. /**
  1028. @brief Opens a file.
  1029. @details Opens a file, or fails with an error message and exits.
  1030. Allows '-' as a synonym for standard input.
  1031. @sideeffect None
  1032. */
  1033. static FILE *
  1034. open_file(
  1035. char * filename,
  1036. const char * mode)
  1037. {
  1038. FILE *fp;
  1039. if (strcmp(filename, "-") == 0) {
  1040. return mode[0] == 'r' ? stdin : stdout;
  1041. } else if ((fp = fopen(filename, mode)) == NULL) {
  1042. perror(filename);
  1043. exit(1);
  1044. }
  1045. return(fp);
  1046. } /* end of open_file */
  1047. /**
  1048. @brief Explicitly applies reordering to the DDs.
  1049. @return 1 if successful; 0 otherwise.
  1050. @sideeffect None
  1051. */
  1052. static int
  1053. reorder(
  1054. BnetNetwork * net,
  1055. DdManager * dd,
  1056. NtrOptions * option)
  1057. {
  1058. #ifdef DD_DEBUG
  1059. st_table *mintermTable; /* minterm counts for each output */
  1060. #endif
  1061. int result; /* return value from functions */
  1062. (void) printf("Number of inputs = %d\n",net->ninputs);
  1063. /* Perform the final reordering */
  1064. if (option->reordering != CUDD_REORDER_NONE) {
  1065. #ifdef DD_DEBUG
  1066. result = Cudd_DebugCheck(dd);
  1067. if (result != 0) {
  1068. (void) fprintf(stderr,"Error reported by Cudd_DebugCheck\n");
  1069. return(0);
  1070. }
  1071. result = Cudd_CheckKeys(dd);
  1072. if (result != 0) {
  1073. (void) fprintf(stderr,"Error reported by Cudd_CheckKeys\n");
  1074. return(0);
  1075. }
  1076. mintermTable = checkMinterms(net,dd,NULL);
  1077. if (mintermTable == NULL) exit(2);
  1078. #endif
  1079. dd->siftMaxVar = 1000000;
  1080. dd->siftMaxSwap = 1000000000;
  1081. result = Cudd_ReduceHeap(dd,option->reordering,1);
  1082. if (result == 0) return(0);
  1083. #ifdef DD_DEBUG
  1084. result = Cudd_DebugCheck(dd);
  1085. if (result != 0) {
  1086. (void) fprintf(stderr,"Error reported by Cudd_DebugCheck\n");
  1087. return(0);
  1088. }
  1089. result = Cudd_CheckKeys(dd);
  1090. if (result != 0) {
  1091. (void) fprintf(stderr,"Error reported by Cudd_CheckKeys\n");
  1092. return(0);
  1093. }
  1094. mintermTable = checkMinterms(net,dd,mintermTable);
  1095. if (mintermTable != NULL) {
  1096. (void) fprintf(stderr,"Error in checkMinterms\n");
  1097. return(0);
  1098. }
  1099. #endif
  1100. /* Print symmetry stats if pertinent */
  1101. if (dd->tree == NULL &&
  1102. (option->reordering == CUDD_REORDER_SYMM_SIFT ||
  1103. option->reordering == CUDD_REORDER_SYMM_SIFT_CONV))
  1104. Cudd_SymmProfile(dd,0,dd->size - 1);
  1105. }
  1106. if (option->gaOnOff) {
  1107. result = Cudd_ReduceHeap(dd,CUDD_REORDER_GENETIC,1);
  1108. if (result == 0) {
  1109. (void) printf("Something went wrong in cuddGa\n");
  1110. return(0);
  1111. }
  1112. }
  1113. return(1);
  1114. } /* end of reorder */
  1115. /**
  1116. @brief Frees the option structure and its appendages.
  1117. @sideeffect None
  1118. */
  1119. static void
  1120. freeOption(
  1121. NtrOptions * option)
  1122. {
  1123. if (option->file1 != NULL) FREE(option->file1);
  1124. if (option->file2 != NULL) FREE(option->file2);
  1125. if (option->orderPiPs != NULL) FREE(option->orderPiPs);
  1126. if (option->treefile != NULL) FREE(option->treefile);
  1127. if (option->sinkfile != NULL) FREE(option->sinkfile);
  1128. if (option->dumpfile != NULL) FREE(option->dumpfile);
  1129. if (option->loadfile != NULL) FREE(option->loadfile);
  1130. if (option->storefile != NULL) FREE(option->storefile);
  1131. if (option->node != NULL) FREE(option->node);
  1132. FREE(option);
  1133. } /* end of freeOption */
  1134. /**
  1135. @brief Starts the CUDD manager with the desired options.
  1136. @details Starts with 0 variables, because Ntr_buildDDs will create
  1137. new variables rather than using whatever already exists.
  1138. @sideeffect None
  1139. */
  1140. static DdManager *
  1141. startCudd(
  1142. NtrOptions * option,
  1143. int nvars)
  1144. {
  1145. DdManager *dd;
  1146. int result;
  1147. dd = Cudd_Init(0, 0, option->slots, option->cacheSize, option->maxMemory);
  1148. if (dd == NULL) return(NULL);
  1149. Cudd_Srandom(dd, option->seed);
  1150. if (option->maxMemHard != 0) {
  1151. Cudd_SetMaxMemory(dd,option->maxMemHard);
  1152. }
  1153. Cudd_SetMaxLive(dd,option->maxLive);
  1154. Cudd_SetGroupcheck(dd,option->groupcheck);
  1155. if (option->autoDyn & 1) {
  1156. Cudd_AutodynEnable(dd,option->autoMethod);
  1157. }
  1158. dd->nextDyn = option->firstReorder;
  1159. dd->countDead = (option->countDead == FALSE) ? ~0 : 0;
  1160. dd->maxGrowth = 1.0 + ((float) option->maxGrowth / 100.0);
  1161. dd->recomb = option->recomb;
  1162. dd->arcviolation = option->arcviolation;
  1163. dd->symmviolation = option->symmviolation;
  1164. dd->populationSize = option->populationSize;
  1165. dd->numberXovers = option->numberXovers;
  1166. result = ntrReadTree(dd,option->treefile,nvars);
  1167. if (result == 0) {
  1168. Cudd_Quit(dd);
  1169. return(NULL);
  1170. }
  1171. #ifndef DD_STATS
  1172. result = Cudd_EnableReorderingReporting(dd);
  1173. if (result == 0) {
  1174. (void) fprintf(stderr,
  1175. "Error reported by Cudd_EnableReorderingReporting\n");
  1176. Cudd_Quit(dd);
  1177. return(NULL);
  1178. }
  1179. #endif
  1180. return(dd);
  1181. } /* end of startCudd */
  1182. /**
  1183. @brief Reads the variable group tree from a file.
  1184. @return 1 if successful; 0 otherwise.
  1185. @sideeffect None
  1186. */
  1187. static int
  1188. ntrReadTree(
  1189. DdManager * dd,
  1190. char * treefile,
  1191. int nvars)
  1192. {
  1193. FILE *fp;
  1194. MtrNode *root;
  1195. if (treefile == NULL) {
  1196. return(1);
  1197. }
  1198. if ((fp = fopen(treefile,"r")) == NULL) {
  1199. (void) fprintf(stderr,"Unable to open %s\n",treefile);
  1200. return(0);
  1201. }
  1202. root = Mtr_ReadGroups(fp,ddMax(Cudd_ReadSize(dd),nvars));
  1203. if (root == NULL) {
  1204. return(0);
  1205. }
  1206. Cudd_SetTree(dd,root);
  1207. return(1);
  1208. } /* end of ntrReadTree */