abc/src/bdd/cudd/cuddSign.c
/**Function********************************************************************

  Synopsis    [Recursive Step for Cudd_CofMinterm function.]

  Description [Traverses the DD node and computes the fraction of
  minterms in the on-set of all positive cofactors simultaneously.
  It allocates an array with two more entries than there are
  variables below the one labeling the node.  One extra entry (the
  first in the array) is for the variable labeling the node. The other
  entry (the last one in the array) holds the fraction of minterms of
  the function rooted at node.  Each other entry holds the value for
  one cofactor. The array is put in a symbol table, to avoid repeated
  computation, and its address is returned by the procedure, for use
  by the caller.  Returns a pointer to the array of cofactor measures.]

  SideEffects [None]

  SeeAlso     []

******************************************************************************/
Function
Synopsis    [Recursive Step for Cudd_CofMinterm function.]

Description [Traverses the DD node and computes the fraction of
minterms in the on-set of all positive cofactors simultaneously.
It allocates an array with two more entries than there are
variables below the one labeling the node.  One extra entry (the
first in the array) is for the variable labeling the node. The other
entry (the last one in the array) holds the fraction of minterms of
the function rooted at node.  Each other entry holds the value for
one cofactor. The array is put in a symbol table, to avoid repeated
computation, and its address is returned by the procedure, for use
by the caller.  Returns a pointer to the array of cofactor measures.]




Function Synopsis [ Recursive Step for Cudd_CofMinterm function . ] Description [ Traverses the DD node and computes the fraction of minterms in the on - set of all positive cofactors simultaneously . It allocates an array with two more entries than there are variables below the one labeling the node . One extra entry ( the first in the array ) is for the variable labeling the node . The other entry ( the last one in the array ) holds the fraction of minterms of the function rooted at node . Each other entry holds the value for one cofactor . The array is put in a symbol table to avoid repeated computation and its address is returned by the procedure for use by the caller . Returns a pointer to the array of cofactor measures . ]
static double *
ddCofMintermAux(
  DdManager * dd,
  DdNode * node,
  st__table * table)
{
    DdNode      *N;             
    DdNode      *Nv, *Nnv;
    double      *values;
    double      *valuesT, *valuesE;
    int         i;
    int         localSize, localSizeT, localSizeE;
    double      vT, vE;
    statLine(dd);
#ifdef DD_STATS
    num_calls++;
#endif
    if ( st__lookup(table, (const char *)node, (char **)&values)) {
        return(values);
    }
    N = Cudd_Regular(node);
    if (cuddIsConstant(N)) {
        localSize = 1;
    } else {
        localSize = size - cuddI(dd,N->index) + 1;
    }
    values = ABC_ALLOC(double, localSize);
    if (values == NULL) {
        dd->errorCode = CUDD_MEMORY_OUT;
        return(NULL);
    }
    if (cuddIsConstant(N)) {
        if (node == DD_ZERO(dd) || node == Cudd_Not(DD_ONE(dd))) {
            values[0] = 0.0;
        } else {
            values[0] = 1.0;
        }
    } else {
        Nv = Cudd_NotCond(cuddT(N),N!=node);
        Nnv = Cudd_NotCond(cuddE(N),N!=node);
        valuesT = ddCofMintermAux(dd, Nv, table);
        if (valuesT == NULL) return(NULL);
        valuesE = ddCofMintermAux(dd, Nnv, table);
        if (valuesE == NULL) return(NULL);
        if (Cudd_IsConstant(Nv)) {
            localSizeT = 1;
        } else {
            localSizeT = size - cuddI(dd,Cudd_Regular(Nv)->index) + 1;
        }
        if (Cudd_IsConstant(Nnv)) {
            localSizeE = 1;
        } else {
            localSizeE = size - cuddI(dd,Cudd_Regular(Nnv)->index) + 1;
        }
        values[0] = valuesT[localSizeT - 1];
        for (i = 1; i < localSize; i++) {
            if (i >= cuddI(dd,Cudd_Regular(Nv)->index) - cuddI(dd,N->index)) {
                vT = valuesT[i - cuddI(dd,Cudd_Regular(Nv)->index) +
                            cuddI(dd,N->index)];
            } else {
                vT = valuesT[localSizeT - 1];
            }
            if (i >= cuddI(dd,Cudd_Regular(Nnv)->index) - cuddI(dd,N->index)) {
                vE = valuesE[i - cuddI(dd,Cudd_Regular(Nnv)->index) +
                            cuddI(dd,N->index)];
            } else {
                vE = valuesE[localSizeE - 1];
            }
            values[i] = (vT + vE) / 2.0;
        }
        if (Cudd_Regular(Nv)->ref == 1) ABC_FREE(valuesT);
        if (Cudd_Regular(Nnv)->ref == 1) ABC_FREE(valuesE);
    }
    if (N->ref > 1) {
        if ( st__add_direct(table, (char *) node, (char *) values) == st__OUT_OF_MEM) {
            ABC_FREE(values);
            return(NULL);
        }
#ifdef DD_STATS
        table_mem += localSize * sizeof(double) + sizeof( st__table_entry);
#endif
    }
    return(values);
}
static double * ddCofMintermAux ( DdManager * dd , DdNode * node , st__table * table ) { DdNode * N ; DdNode * Nv , * Nnv ; double * values ; double * valuesT , * valuesE ; int i ; int localSize , localSizeT , localSizeE ; double vT , vE ; statLine ( dd ) ; #ifdef DD_STATS num_calls ++ ; #endif if ( st__lookup ( table , ( const char * ) node , ( char * * ) & values ) ) { return ( values ) ; } N = Cudd_Regular ( node ) ; if ( cuddIsConstant ( N ) ) { localSize = 1 ; } else { localSize = size - cuddI ( dd , N -> index ) + 1 ; } values = ABC_ALLOC ( double , localSize ) ; if ( values == NULL ) { dd -> errorCode = CUDD_MEMORY_OUT ; return ( NULL ) ; } if ( cuddIsConstant ( N ) ) { if ( node == DD_ZERO ( dd ) || node == Cudd_Not ( DD_ONE ( dd ) ) ) { values [ 0 ] = 0.0 ; } else { values [ 0 ] = 1.0 ; } } else { Nv = Cudd_NotCond ( cuddT ( N ) , N != node ) ; Nnv = Cudd_NotCond ( cuddE ( N ) , N != node ) ; valuesT = ddCofMintermAux ( dd , Nv , table ) ; if ( valuesT == NULL ) return ( NULL ) ; valuesE = ddCofMintermAux ( dd , Nnv , table ) ; if ( valuesE == NULL ) return ( NULL ) ; if ( Cudd_IsConstant ( Nv ) ) { localSizeT = 1 ; } else { localSizeT = size - cuddI ( dd , Cudd_Regular ( Nv ) -> index ) + 1 ; } if ( Cudd_IsConstant ( Nnv ) ) { localSizeE = 1 ; } else { localSizeE = size - cuddI ( dd , Cudd_Regular ( Nnv ) -> index ) + 1 ; } values [ 0 ] = valuesT [ localSizeT - 1 ] ; for ( i = 1 ; i < localSize ; i ++ ) { if ( i >= cuddI ( dd , Cudd_Regular ( Nv ) -> index ) - cuddI ( dd , N -> index ) ) { vT = valuesT [ i - cuddI ( dd , Cudd_Regular ( Nv ) -> index ) + cuddI ( dd , N -> index ) ] ; } else { vT = valuesT [ localSizeT - 1 ] ; } if ( i >= cuddI ( dd , Cudd_Regular ( Nnv ) -> index ) - cuddI ( dd , N -> index ) ) { vE = valuesE [ i - cuddI ( dd , Cudd_Regular ( Nnv ) -> index ) + cuddI ( dd , N -> index ) ] ; } else { vE = valuesE [ localSizeE - 1 ] ; } values [ i ] = ( vT + vE ) / 2.0 ; } if ( Cudd_Regular ( Nv ) -> ref == 1 ) ABC_FREE ( valuesT ) ; if ( Cudd_Regular ( Nnv ) -> ref == 1 ) ABC_FREE ( valuesE ) ; } if ( N -> ref > 1 ) { if ( st__add_direct ( table , ( char * ) node , ( char * ) values ) == st__OUT_OF_MEM ) { ABC_FREE ( values ) ; return ( NULL ) ; } #ifdef DD_STATS table_mem += localSize * sizeof ( double ) + sizeof ( st__table_entry ) ; #endif } return ( values ) ; }
Function
Synopsis    [Recursive Step for Cudd_CofMinterm function.]
Function Synopsis [ Recursive Step for Cudd_CofMinterm function . ]
/* regular version of node */