コード例 #1
0
ファイル: mtrBasic.c プロジェクト: AndrewSmart/CS5600
/**Function********************************************************************

  Synopsis    [Disposes of tree rooted at node.]

  Description []

  SideEffects [None]

  SeeAlso     [Mtr_InitTree]

******************************************************************************/
void
Mtr_FreeTree(
  MtrNode * node)
{
    if (node == NULL) return;
    if (! MTR_TEST(node,MTR_TERMINAL)) Mtr_FreeTree(node->child);
    Mtr_FreeTree(node->younger);
    Mtr_DeallocNode(node);
    return;

} /* end of Mtr_FreeTree */
コード例 #2
0
ファイル: mtrBasic.c プロジェクト: AndrewSmart/CS5600
/**Function********************************************************************

  Synopsis    [Makes a copy of tree.]

  Description [Makes a copy of tree. If parameter expansion is greater
  than 1, it will expand the tree by that factor. It is an error for
  expansion to be less than 1. Returns a pointer to the copy if
  successful; NULL otherwise.]

  SideEffects [None]

  SeeAlso     [Mtr_InitTree]

******************************************************************************/
MtrNode *
Mtr_CopyTree(
  MtrNode * node,
  int  expansion)
{
    MtrNode *copy;

    if (node == NULL) return(NULL);
    if (expansion < 1) return(NULL);
    copy = Mtr_AllocNode();
    if (copy == NULL) return(NULL);
    copy->parent = copy->elder = copy->child = copy->younger = NULL;
    if (node->child != NULL) {
	copy->child = Mtr_CopyTree(node->child, expansion);
	if (copy->child == NULL) {
	    Mtr_DeallocNode(copy);
	    return(NULL);
	}
    }
    if (node->younger != NULL) {
	copy->younger = Mtr_CopyTree(node->younger, expansion);
	if (copy->younger == NULL) {
	    Mtr_FreeTree(copy);
	    return(NULL);
	}
    }
    copy->flags = node->flags;
    copy->low = node->low * expansion;
    copy->size = node->size * expansion;
    copy->index = node->index * expansion;
    if (copy->younger) copy->younger->elder = copy;
    if (copy->child) {
	MtrNode *auxnode = copy->child;
	while (auxnode != NULL) {
	    auxnode->parent = copy;
	    auxnode = auxnode->younger;
	}
    }
    return(copy);

} /* end of Mtr_CopyTree */
コード例 #3
0
ファイル: testmtr.c プロジェクト: graydon/iimc
/**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 */
コード例 #4
0
ファイル: testmtr.c プロジェクト: ancailliau/pynusmv
/**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 */