⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cuddsat.c

📁 主要进行大规模的电路综合
💻 C
📖 第 1 页 / 共 3 页
字号:
    Cudd_Ref(res);    scan = cube;    while (!Cudd_IsConstant(scan)) {	DdNode *reg = Cudd_Regular(scan);	DdNode *var = dd->vars[reg->index];	DdNode *expanded = Cudd_bddExistAbstract(dd,res,var);	if (expanded == NULL) {	    return(NULL);	}	Cudd_Ref(expanded);	if (Cudd_bddLeq(dd,expanded,f)) {	    Cudd_RecursiveDeref(dd,res);	    res = expanded;	} else {	    Cudd_RecursiveDeref(dd,expanded);	}	cuddGetBranches(scan,&t,&e);	if (t == zero) {	    scan = e;	} else if (e == zero) {	    scan = t;	} else {	    Cudd_RecursiveDeref(dd,res);	    return(NULL);	/* cube is not a cube */	}    }    if (scan == DD_ONE(dd)) {	Cudd_Deref(res);	return(res);    } else {	Cudd_RecursiveDeref(dd,res);	return(NULL);    }} /* end of cuddBddMakePrime *//*---------------------------------------------------------------------------*//* Definition of static functions                                            *//*---------------------------------------------------------------------------*//**Function********************************************************************  Synopsis    [Frees the entries of the visited symbol table.]  Description [Frees the entries of the visited symbol table. Returns  ST_CONTINUE.]  SideEffects [None]******************************************************************************/static enum st_retvalfreePathPair(  char * key,  char * value,  char * arg){    cuddPathPair *pair;    pair = (cuddPathPair *) value;	FREE(pair);    return(ST_CONTINUE);} /* end of freePathPair *//**Function********************************************************************  Synopsis    [Finds the length of the shortest path(s) in a DD.]  Description [Finds the length of the shortest path(s) in a DD.  Uses a local symbol table to store the lengths for each  node. Only the lengths for the regular nodes are entered in the table,  because those for the complement nodes are simply obtained by swapping  the two lenghts.  Returns a pair of lengths: the length of the shortest path to 1;  and the length of the shortest path to 0. This is done so as to take  complement arcs into account.]  SideEffects [Accumulates the support of the DD in support.]  SeeAlso     []******************************************************************************/static cuddPathPairgetShortest(  DdNode * root,  int * cost,  int * support,  st_table * visited){    cuddPathPair *my_pair, res_pair, pair_T, pair_E;    DdNode	*my_root, *T, *E;    int		weight;    my_root = Cudd_Regular(root);    if (st_lookup(visited, (char *)my_root, (char **)&my_pair)) {	if (Cudd_IsComplement(root)) {	    res_pair.pos = my_pair->neg;	    res_pair.neg = my_pair->pos;	} else {	    res_pair.pos = my_pair->pos;	    res_pair.neg = my_pair->neg;	}	return(res_pair);    }    /* In the case of a BDD the following test is equivalent to    ** testing whether the BDD is the constant 1. This formulation,    ** however, works for ADDs as well, by assuming the usual    ** dichotomy of 0 and != 0.    */    if (cuddIsConstant(my_root)) {	if (my_root != zero) {	    res_pair.pos = 0;	    res_pair.neg = DD_BIGGY;	} else {	    res_pair.pos = DD_BIGGY;	    res_pair.neg = 0;	}    } else {	T = cuddT(my_root);	E = cuddE(my_root);	pair_T = getShortest(T, cost, support, visited);	pair_E = getShortest(E, cost, support, visited);	weight = WEIGHT(cost, my_root->index);	res_pair.pos = ddMin(pair_T.pos+weight, pair_E.pos);	res_pair.neg = ddMin(pair_T.neg+weight, pair_E.neg);	/* Update support. */	if (support != NULL) {	    support[my_root->index] = 1;	}    }    my_pair = ALLOC(cuddPathPair, 1);    if (my_pair == NULL) {	if (Cudd_IsComplement(root)) {	    int tmp = res_pair.pos;	    res_pair.pos = res_pair.neg;	    res_pair.neg = tmp;	}	return(res_pair);    }    my_pair->pos = res_pair.pos;    my_pair->neg = res_pair.neg;    st_insert(visited, (char *)my_root, (char *)my_pair);    if (Cudd_IsComplement(root)) {	res_pair.pos = my_pair->neg;	res_pair.neg = my_pair->pos;    } else {	res_pair.pos = my_pair->pos;	res_pair.neg = my_pair->neg;    }    return(res_pair);} /* end of getShortest *//**Function********************************************************************  Synopsis    [Build a BDD for a shortest path of f.]  Description [Build a BDD for a shortest path of f.  Given the minimum length from the root, and the minimum  lengths for each node (in visited), apply triangulation at each node.  Of the two children of each node on a shortest path, at least one is  on a shortest path. In case of ties the procedure chooses the THEN  children.  Returns a pointer to the cube BDD representing the path if  successful; NULL otherwise.]  SideEffects [None]  SeeAlso     []******************************************************************************/static DdNode *getPath(  DdManager * manager,  st_table * visited,  DdNode * f,  int * weight,  int  cost){    DdNode	*sol, *tmp;    DdNode	*my_dd, *T, *E;    cuddPathPair *T_pair, *E_pair;    int		Tcost, Ecost;    int		complement;    my_dd = Cudd_Regular(f);    complement = Cudd_IsComplement(f);    sol = one;    cuddRef(sol);    while (!cuddIsConstant(my_dd)) {	Tcost = cost - WEIGHT(weight, my_dd->index);	Ecost = cost;	T = cuddT(my_dd);	E = cuddE(my_dd);	if (complement) {T = Cudd_Not(T); E = Cudd_Not(E);}	st_lookup(visited, (char *)Cudd_Regular(T), (char **)&T_pair);	if ((Cudd_IsComplement(T) && T_pair->neg == Tcost) ||	(!Cudd_IsComplement(T) && T_pair->pos == Tcost)) {	    tmp = cuddBddAndRecur(manager,manager->vars[my_dd->index],sol);	    if (tmp == NULL) {		Cudd_RecursiveDeref(manager,sol);		return(NULL);	    }	    cuddRef(tmp);	    Cudd_RecursiveDeref(manager,sol);	    sol = tmp;	    complement =  Cudd_IsComplement(T);	    my_dd = Cudd_Regular(T);	    cost = Tcost;	    continue;	}	st_lookup(visited, (char *)Cudd_Regular(E), (char **)&E_pair);	if ((Cudd_IsComplement(E) && E_pair->neg == Ecost) ||	(!Cudd_IsComplement(E) && E_pair->pos == Ecost)) {	    tmp = cuddBddAndRecur(manager,Cudd_Not(manager->vars[my_dd->index]),sol);	    if (tmp == NULL) {		Cudd_RecursiveDeref(manager,sol);		return(NULL);	    }	    cuddRef(tmp);	    Cudd_RecursiveDeref(manager,sol);	    sol = tmp;	    complement = Cudd_IsComplement(E);	    my_dd = Cudd_Regular(E);	    cost = Ecost;	    continue;	}	(void) fprintf(manager->err,"We shouldn't be here!!\n");	manager->errorCode = CUDD_INTERNAL_ERROR;	return(NULL);    }    cuddDeref(sol);    return(sol);} /* end of getPath *//**Function********************************************************************  Synopsis    [Finds the size of the largest cube(s) in a DD.]  Description [Finds the size of the largest cube(s) in a DD.  This problem is translated into finding the shortest paths from a node  when both THEN and ELSE arcs have unit lengths.  Uses a local symbol table to store the lengths for each  node. Only the lengths for the regular nodes are entered in the table,  because those for the complement nodes are simply obtained by swapping  the two lenghts.  Returns a pair of lengths: the length of the shortest path to 1;  and the length of the shortest path to 0. This is done so as to take  complement arcs into account.]  SideEffects [none]  SeeAlso     []******************************************************************************/static cuddPathPairgetLargest(  DdNode * root,  st_table * visited){    cuddPathPair *my_pair, res_pair, pair_T, pair_E;    DdNode	*my_root, *T, *E;    my_root = Cudd_Regular(root);    if (st_lookup(visited, (char *)my_root, (char **)&my_pair)) {	if (Cudd_IsComplement(root)) {	    res_pair.pos = my_pair->neg;	    res_pair.neg = my_pair->pos;	} else {	    res_pair.pos = my_pair->pos;	    res_pair.neg = my_pair->neg;	}	return(res_pair);    }    /* In the case of a BDD the following test is equivalent to    ** testing whether the BDD is the constant 1. This formulation,    ** however, works for ADDs as well, by assuming the usual    ** dichotomy of 0 and != 0.    */    if (cuddIsConstant(my_root)) {	if (my_root != zero) {	    res_pair.pos = 0;	    res_pair.neg = DD_BIGGY;	} else {	    res_pair.pos = DD_BIGGY;	    res_pair.neg = 0;	}    } else {	T = cuddT(my_root);	E = cuddE(my_root);	pair_T = getLargest(T, visited);	pair_E = getLargest(E, visited);	res_pair.pos = ddMin(pair_T.pos, pair_E.pos) + 1;	res_pair.neg = ddMin(pair_T.neg, pair_E.neg) + 1;    }    my_pair = ALLOC(cuddPathPair, 1);    if (my_pair == NULL) {	/* simlpy do not cache this result */	if (Cudd_IsComplement(root)) {	    int tmp = res_pair.pos;	    res_pair.pos = res_pair.neg;	    res_pair.neg = tmp;	}	return(res_pair);    }    my_pair->pos = res_pair.pos;    my_pair->neg = res_pair.neg;    st_insert(visited, (char *)my_root, (char *)my_pair);    if (Cudd_IsComplement(root)) {	res_pair.pos = my_pair->neg;	res_pair.neg = my_pair->pos;    } else {	res_pair.pos = my_pair->pos;	res_pair.neg = my_pair->neg;    }    return(res_pair);} /* end of getLargest *//**Function********************************************************************  Synopsis    [Build a BDD for a largest cube of f.]  Description [Build a BDD for a largest cube of f.  Given the minimum length from the root, and the minimum  lengths for each node (in visited), apply triangulation at each node.  Of the two children of each node on a shortest path, at least one is  on a shortest path. In case of ties the procedure chooses the THEN  children.  Returns a pointer to the cube BDD representing the path if  successful; NULL otherwise.]  SideEffects [None]  SeeAlso     []******************************************************************************/static DdNode *getCube(  DdManager * manager,  st_table * visited,  DdNode * f,  int  cost){    DdNode	*sol, *tmp;    DdNode	*my_dd, *T, *E;    cuddPathPair *T_pair, *E_pair;    int		Tcost, Ecost;    int		complement;    my_dd = Cudd_Regular(f);    complement = Cudd_IsComplement(f);    sol = one;    cuddRef(sol);    while (!cuddIsConstant(my_dd)) {	Tcost = cost - 1;	Ecost = cost - 1;	T = cuddT(my_dd);	E = cuddE(my_dd);	if (complement) {T = Cudd_Not(T); E = Cudd_Not(E);}	st_lookup(visited, (char *)Cudd_Regular(T), (char **)&T_pair);	if ((Cudd_IsComplement(T) && T_pair->neg == Tcost) ||	(!Cudd_IsComplement(T) && T_pair->pos == Tcost)) {	    tmp = cuddBddAndRecur(manager,manager->vars[my_dd->index],sol);	    if (tmp == NULL) {		Cudd_RecursiveDeref(manager,sol);		return(NULL);	    }	    cuddRef(tmp);	    Cudd_RecursiveDeref(manager,sol);	    sol = tmp;	    complement =  Cudd_IsComplement(T);	    my_dd = Cudd_Regular(T);	    cost = Tcost;	    continue;	}	st_lookup(visited, (char *)Cudd_Regular(E), (char **)&E_pair);	if ((Cudd_IsComplement(E) && E_pair->neg == Ecost) ||	(!Cudd_IsComplement(E) && E_pair->pos == Ecost)) {	    tmp = cuddBddAndRecur(manager,Cudd_Not(manager->vars[my_dd->index]),sol);	    if (tmp == NULL) {		Cudd_RecursiveDeref(manager,sol);		return(NULL);	    }	    cuddRef(tmp);	    Cudd_RecursiveDeref(manager,sol);	    sol = tmp;	    complement = Cudd_IsComplement(E);	    my_dd = Cudd_Regular(E);	    cost = Ecost;	    continue;	}	(void) fprintf(manager->err,"We shouldn't be here!\n");	manager->errorCode = CUDD_INTERNAL_ERROR;	return(NULL);    }    cuddDeref(sol);    return(sol);} /* end of getCube */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -