Пример #1
0
/**Function********************************************************************

  Synopsis    [Reads the variable group tree from a file.]

  Description [Reads the variable group tree from a file.
  Returns 1 if successful; 0 otherwise.]

  SideEffects [None]

  SeeAlso     []

*****************************************************************************/
static int
ntrReadTree(
  DdManager * dd,
  char * treefile,
  int  nvars)
{
    FILE *fp;
    MtrNode *root;

    if (treefile == NULL) {
	return(1);
    }

    if ((fp = fopen(treefile,"r")) == NULL) {
	(void) fprintf(stderr,"Unable to open %s\n",treefile);
	return(0);
    }

    root = Mtr_ReadGroups(fp,ddMax(Cudd_ReadSize(dd),nvars));
    if (root == NULL) {
	return(0);
    }

    Cudd_SetTree(dd,root);

    return(1);

} /* end of ntrReadTree */
Пример #2
0
/**Function********************************************************************

  Synopsis    [Main program for testmtr.]

  Description [Main program for testmtr.  Performs initialization.
  Reads command line options and network(s).  Builds some simple trees
  and prints them out.]

  SideEffects [None]

  SeeAlso     []

******************************************************************************/
int
main(
  int  argc,
  char ** argv)
{
    MtrNode *root,
	    *node;
    int	    i,
	    c,
	    pr = 0;
    FILE    *fp;
    const char *file = NULL;
    
    while ((c = getopt(argc, argv, "Mhp:")) != EOF) {
	switch(c) {
	case 'M':
	    break;
	case 'p':
	    pr = atoi(optarg);
	    break;
	case 'h':
	default:
            printHeader(argc, argv);
	    usage(argv[0]);
	    break;
	}
    }

    if (argc - optind == 0) {
	file = "-";
    } else if (argc - optind == 1) {
	file = argv[optind];
    } else {
        printHeader(argc, argv);
	usage(argv[0]);
    }
    if (pr > 0)
        printHeader(argc, argv);

    /* Create and print a simple tree. */
    root = Mtr_InitTree();
    root->flags = 0;
    node = Mtr_CreateFirstChild(root);
    node->flags = 1;
    node = Mtr_CreateLastChild(root);
    node->flags = 2;
    node = Mtr_CreateFirstChild(root);
    node->flags = 3;
    node = Mtr_AllocNode();
    node->child = NULL;
    node->flags = 4;
    Mtr_MakeNextSibling(root->child,node);
    if (pr > 0) {
        Mtr_PrintTree(root);
        (void) printf("#------------------------\n");
    }
    Mtr_FreeTree(root);

    /* Create an initial tree in which all variables belong to one group. */
    root = Mtr_InitGroupTree(0,12);
    if (pr > 0) {
        Mtr_PrintTree(root); (void) printf("#  ");
        Mtr_PrintGroups(root,pr == 0); (void) printf("\n");
    }
    node = Mtr_MakeGroup(root,0,6,MTR_DEFAULT);
    node = Mtr_MakeGroup(root,6,6,MTR_DEFAULT);
    if (pr > 0) {
        Mtr_PrintTree(root); (void) printf("#  ");
        Mtr_PrintGroups(root,pr == 0); (void) printf("\n");
    }
    for (i = 0; i < 6; i+=2) {
	node = Mtr_MakeGroup(root,(unsigned) i,(unsigned) 2,MTR_DEFAULT);
    }
    node = Mtr_MakeGroup(root,0,12,MTR_FIXED);
    if (pr > 0) {
        Mtr_PrintTree(root); (void) printf("#  ");
        Mtr_PrintGroups(root,pr == 0); (void) printf("\n");
        /* Print a partial tree. */
        (void) printf("#  ");
        Mtr_PrintGroups(root->child,pr == 0); (void) printf("\n");
    }
    node = Mtr_FindGroup(root,0,6);
    node = Mtr_DissolveGroup(node);
    if (pr > 0) {
        Mtr_PrintTree(root); (void) printf("#  ");
        Mtr_PrintGroups(root,pr == 0); (void) printf("\n");
    }
    node = Mtr_FindGroup(root,4,2);
    if (!Mtr_SwapGroups(node,node->younger)) {
	(void) printf("error in Mtr_SwapGroups\n");
	return 3;
    }
    if (pr > 0) {
        Mtr_PrintTree(root); (void) printf("#  ");
        Mtr_PrintGroups(root,pr == 0);
        (void) printf("#------------------------\n");
    }
    Mtr_FreeTree(root);

    /* Create a group tree with fixed subgroups. */
    root = Mtr_InitGroupTree(0,4);
    if (pr > 0) {
        Mtr_PrintTree(root); (void) printf("#  ");
        Mtr_PrintGroups(root,pr == 0); (void) printf("\n");
    }
    node = Mtr_MakeGroup(root,0,2,MTR_FIXED);
    node = Mtr_MakeGroup(root,2,2,MTR_FIXED);
    if (pr > 0) {
        Mtr_PrintTree(root); (void) printf("#  ");
        Mtr_PrintGroups(root,pr == 0); (void) printf("\n");
    }
    Mtr_FreeTree(root);
    if (pr > 0) {
        (void) printf("#------------------------\n");
    }

    /* Open input file. */
    fp = open_file(file, "r");
    root = Mtr_ReadGroups(fp,12);
    fclose(fp);
    if (pr > 0) {
        if (root) {
            Mtr_PrintTree(root); (void) printf("#  ");
            Mtr_PrintGroups(root,pr == 0); (void) printf("\n");
        } else {
            (void) printf("error in group file\n");
        }
    }
    Mtr_FreeTree(root);

    return 0;

} /* end of main */
Пример #3
0
/**Function********************************************************************

  Synopsis    [Main program for testmtr.]

  Description [Main program for testmtr.  Performs initialization.
  Reads command line options and network(s).  Builds some simple trees
  and prints them out.]

  SideEffects [None]

  SeeAlso     []

******************************************************************************/
int
main(
  int  argc,
  char ** argv)
{
    MtrNode *root,
	    *node;
    int	    i,
	    c,
	    pr = 0;
    FILE    *fp;
    char    *file = NULL;
    
    (void) printf("# %s\n", TESTMTR_VERSION);
    /* Echo command line and arguments. */
    (void) printf("#");
    for(i = 0; i < argc; i++) {
	(void) printf(" %s", argv[i]);
    }
    (void) printf("\n");
    (void) fflush(stdout);

    while ((c = getopt(argc, argv, "Mhp:")) != EOF) {
	switch(c) {
	case 'M':
#ifdef MNEMOSYNE
	    (void) mnem_setrecording(0);
#endif
	    break;
	case 'p':
	    pr = atoi(optarg);
	    break;
	case 'h':
	default:
	    usage(argv[0]);
	    break;
	}
    }

    if (argc - optind == 0) {
	file = "-";
    } else if (argc - optind == 1) {
	file = argv[optind];
    } else {
	usage(argv[0]);
    }

    /* Create and print a simple tree. */
    root = Mtr_InitTree();
    root->flags = 0;
    node = Mtr_CreateFirstChild(root);
    node->flags = 1;
    node = Mtr_CreateLastChild(root);
    node->flags = 2;
    node = Mtr_CreateFirstChild(root);
    node->flags = 3;
    node = Mtr_AllocNode();
    node->flags = 4;
    Mtr_MakeNextSibling(root->child,node);
    Mtr_PrintTree(root);
    Mtr_FreeTree(root);
    (void) printf("#------------------------\n");

    /* Create an initial tree in which all variables belong to one group. */
    root = Mtr_InitGroupTree(0,12);
    Mtr_PrintTree(root); (void) printf("#  ");
    Mtr_PrintGroups(root,pr == 0); (void) printf("\n");
    node = Mtr_MakeGroup(root,0,6,MTR_DEFAULT);
    node = Mtr_MakeGroup(root,6,6,MTR_DEFAULT);
    Mtr_PrintTree(root); (void) printf("#  ");
    Mtr_PrintGroups(root,pr == 0); (void) printf("\n");
    for (i = 0; i < 6; i+=2) {
	node = Mtr_MakeGroup(root,(unsigned) i,(unsigned) 2,MTR_DEFAULT);
    }
    node = Mtr_MakeGroup(root,0,12,MTR_FIXED);
    Mtr_PrintTree(root); (void) printf("#  ");
    Mtr_PrintGroups(root,pr == 0); (void) printf("\n");
    /* Print a partial tree. */
    (void) printf("#  ");
    Mtr_PrintGroups(root->child,pr == 0); (void) printf("\n");
    node = Mtr_FindGroup(root,0,6);
    node = Mtr_DissolveGroup(node);
    Mtr_PrintTree(root); (void) printf("#  ");
    Mtr_PrintGroups(root,pr == 0); (void) printf("\n");
    node = Mtr_FindGroup(root,4,2);
    if (!Mtr_SwapGroups(node,node->younger)) {
	(void) printf("error in Mtr_SwapGroups\n");
	exit(3);
    }
    Mtr_PrintTree(root); (void) printf("#  ");
    Mtr_PrintGroups(root,pr == 0);
    Mtr_FreeTree(root);
    (void) printf("#------------------------\n");

    /* Create a group tree with fixed subgroups. */
    root = Mtr_InitGroupTree(0,4);
    Mtr_PrintTree(root); (void) printf("#  ");
    Mtr_PrintGroups(root,pr == 0); (void) printf("\n");
    node = Mtr_MakeGroup(root,0,2,MTR_FIXED);
    node = Mtr_MakeGroup(root,2,2,MTR_FIXED);
    Mtr_PrintTree(root); (void) printf("#  ");
    Mtr_PrintGroups(root,pr == 0); (void) printf("\n");
    Mtr_FreeTree(root);
    (void) printf("#------------------------\n");

    /* Open input file. */
    fp = open_file(file, "r");
    root = Mtr_ReadGroups(fp,12);
    Mtr_PrintTree(root); (void) printf("#  ");
    Mtr_PrintGroups(root,pr == 0); (void) printf("\n");

    Mtr_FreeTree(root);

#ifdef MNEMOSYNE
    mnem_writestats();
#endif

    exit(0);
    /* NOTREACHED */

} /* end of main */