PageRenderTime 52ms CodeModel.GetById 15ms RepoModel.GetById 1ms app.codeStats 0ms

/Cudd/nanotrav/main.c

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