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

  Synopsis    [Recursively counts minterms of each node in the DAG.]

  Description [Recursively counts minterms of each node in the DAG.
  Similar to the cuddCountMintermAux which recursively counts the
  number of minterms for the dag rooted at each node in terms of the
  total number of variables (max). This procedure creates the node
  data structure and stores the minterm count as part of the node
  data structure. ]

  SideEffects [Creates structures of type node quality and fills the st__table]

  SeeAlso     [SubsetCountMinterm]

******************************************************************************/
Function
Synopsis    [Recursively counts minterms of each node in the DAG.]

Description [Recursively counts minterms of each node in the DAG.
Similar to the cuddCountMintermAux which recursively counts the
number of minterms for the dag rooted at each node in terms of the
total number of variables (max). This procedure creates the node
data structure and stores the minterm count as part of the node
data structure.

SideEffects [Creates structures of type node quality and fills the st__table]


Function Synopsis [ Recursively counts minterms of each node in the DAG . ] Description [ Recursively counts minterms of each node in the DAG . Similar to the cuddCountMintermAux which recursively counts the number of minterms for the dag rooted at each node in terms of the total number of variables ( max ) . This procedure creates the node data structure and stores the minterm count as part of the node data structure . SideEffects [ Creates structures of type node quality and fills the st__table ]
static double
SubsetCountMintermAux(
  DdNode * node ,
  double  max ,
  st__table * table )
{
    DdNode      *N,*Nv,*Nnv; 
    double      min,*pmin; 
    double      min1, min2; 
    NodeData_t *dummy;
    NodeData_t *newEntry;
    int i;
#ifdef DEBUG
    num_calls++;
#endif
    if (Cudd_IsConstant(node)) {
        if (node == zero) {
            return(0.0);
        } else {
            return(max);
        }
    } else {
        if ( st__lookup(table, (const char *)node, (char **)&dummy)) {
            min = *(dummy->mintermPointer);
            return(min);
        }
        N = Cudd_Regular(node);
        Nv = Cudd_T(N);
        Nnv = Cudd_E(N);
        Nv = Cudd_NotCond(Nv, Cudd_IsComplement(node));
        Nnv = Cudd_NotCond(Nnv, Cudd_IsComplement(node));
        min1 =  SubsetCountMintermAux(Nv, max,table)/2.0;
        if (memOut) return(0.0);
        min2 =  SubsetCountMintermAux(Nnv,max,table)/2.0;
        if (memOut) return(0.0);
        min = (min1+min2);
        if (pageIndex == pageSize) ResizeCountMintermPages();
        if (memOut) {
            for (i = 0; i <= nodeDataPage; i++) ABC_FREE(nodeDataPages[i]);
            ABC_FREE(nodeDataPages);
            st__free_table(table);
            return(0.0);
        }
        pmin = currentMintermPage+pageIndex;
        pageIndex++;
        *pmin = min;
        if (nodeDataPageIndex == nodeDataPageSize) ResizeNodeDataPages();
        if (memOut) {
            for (i = 0; i <= page; i++) ABC_FREE(mintermPages[i]);
            ABC_FREE(mintermPages);
            st__free_table(table);
            return(0.0);
        }
        newEntry = currentNodeDataPage + nodeDataPageIndex;
        nodeDataPageIndex++;
        newEntry->mintermPointer = pmin;
        newEntry->nodesPointer = NULL;
        if ( st__insert(table,(char *)node, (char *)newEntry) == st__OUT_OF_MEM) {
            memOut = 1;
            for (i = 0; i <= page; i++) ABC_FREE(mintermPages[i]);
            ABC_FREE(mintermPages);
            for (i = 0; i <= nodeDataPage; i++) ABC_FREE(nodeDataPages[i]);
            ABC_FREE(nodeDataPages);
            st__free_table(table);
            return(0.0);
        }
        return(min);
    }
}
static double SubsetCountMintermAux ( DdNode * node , double max , st__table * table ) { DdNode * N , * Nv , * Nnv ; double min , * pmin ; double min1 , min2 ; NodeData_t * dummy ; NodeData_t * newEntry ; int i ; #ifdef DEBUG num_calls ++ ; #endif if ( Cudd_IsConstant ( node ) ) { if ( node == zero ) { return ( 0.0 ) ; } else { return ( max ) ; } } else { if ( st__lookup ( table , ( const char * ) node , ( char * * ) & dummy ) ) { min = * ( dummy -> mintermPointer ) ; return ( min ) ; } N = Cudd_Regular ( node ) ; Nv = Cudd_T ( N ) ; Nnv = Cudd_E ( N ) ; Nv = Cudd_NotCond ( Nv , Cudd_IsComplement ( node ) ) ; Nnv = Cudd_NotCond ( Nnv , Cudd_IsComplement ( node ) ) ; min1 = SubsetCountMintermAux ( Nv , max , table ) / 2.0 ; if ( memOut ) return ( 0.0 ) ; min2 = SubsetCountMintermAux ( Nnv , max , table ) / 2.0 ; if ( memOut ) return ( 0.0 ) ; min = ( min1 + min2 ) ; if ( pageIndex == pageSize ) ResizeCountMintermPages ( ) ; if ( memOut ) { for ( i = 0 ; i <= nodeDataPage ; i ++ ) ABC_FREE ( nodeDataPages [ i ] ) ; ABC_FREE ( nodeDataPages ) ; st__free_table ( table ) ; return ( 0.0 ) ; } pmin = currentMintermPage + pageIndex ; pageIndex ++ ; * pmin = min ; if ( nodeDataPageIndex == nodeDataPageSize ) ResizeNodeDataPages ( ) ; if ( memOut ) { for ( i = 0 ; i <= page ; i ++ ) ABC_FREE ( mintermPages [ i ] ) ; ABC_FREE ( mintermPages ) ; st__free_table ( table ) ; return ( 0.0 ) ; } newEntry = currentNodeDataPage + nodeDataPageIndex ; nodeDataPageIndex ++ ; newEntry -> mintermPointer = pmin ; newEntry -> nodesPointer = NULL ; if ( st__insert ( table , ( char * ) node , ( char * ) newEntry ) == st__OUT_OF_MEM ) { memOut = 1 ; for ( i = 0 ; i <= page ; i ++ ) ABC_FREE ( mintermPages [ i ] ) ; ABC_FREE ( mintermPages ) ; for ( i = 0 ; i <= nodeDataPage ; i ++ ) ABC_FREE ( nodeDataPages [ i ] ) ; ABC_FREE ( nodeDataPages ) ; st__free_table ( table ) ; return ( 0.0 ) ; } return ( min ) ; } }
Function
Synopsis    [Recursively counts minterms of each node in the DAG.]
Function Synopsis [ Recursively counts minterms of each node in the DAG . ]
/* function to analyze */ /* number of minterms of constant 1 */ /* visitedTable table */ /* nodes to store cofactors  */ /* minterm count */ /* minterm count */ /* Constant case */ /* check if entry for this node exists */ /* Make the node regular to extract cofactors */ /* store the cofactors */ /* if page index is at the bottom, then create a new page */ /* point to the correct location in the page */ /* store the minterm count of this node in the page */ /* Note I allocate the struct here. Freeing taken care of later */ /* points to the correct location in the page */ /* initialize this field of the Node Quality structure */ /* insert entry for the node in the table */