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

  Synopsis    [Creates one or more ZDD variables for each BDD variable.]

  Description [Creates one or more ZDD variables for each BDD
  variable.  If some ZDD variables already exist, only the missing
  variables are created.  Parameter multiplicity allows the caller to
  control how many variables are created for each BDD variable in
  existence. For instance, if ZDDs are used to represent covers, two
  ZDD variables are required for each BDD variable.  The order of the
  BDD variables is transferred to the ZDD variables. If a variable
  group tree exists for the BDD variables, a corresponding ZDD
  variable group tree is created by expanding the BDD variable
  tree. In any case, the ZDD variables derived from the same BDD
  variable are merged in a ZDD variable group. If a ZDD variable group
  tree exists, it is freed. Returns 1 if successful; 0 otherwise.]

  SideEffects [None]

  SeeAlso     [Cudd_bddNewVar Cudd_bddIthVar Cudd_bddNewVarAtLevel]

******************************************************************************/
Function
Synopsis    [Creates one or more ZDD variables for each BDD variable.]

Description [Creates one or more ZDD variables for each BDD
variable.  If some ZDD variables already exist, only the missing
variables are created.  Parameter multiplicity allows the caller to
control how many variables are created for each BDD variable in
existence. For instance, if ZDDs are used to represent covers, two
ZDD variables are required for each BDD variable.  The order of the
BDD variables is transferred to the ZDD variables. If a variable
group tree exists for the BDD variables, a corresponding ZDD
variable group tree is created by expanding the BDD variable
tree. In any case, the ZDD variables derived from the same BDD
variable are merged in a ZDD variable group. If a ZDD variable group
tree exists, it is freed. Returns 1 if successful; 0 otherwise.]




Function Synopsis [ Creates one or more ZDD variables for each BDD variable . ] Description [ Creates one or more ZDD variables for each BDD variable . If some ZDD variables already exist only the missing variables are created . Parameter multiplicity allows the caller to control how many variables are created for each BDD variable in existence . For instance if ZDDs are used to represent covers two ZDD variables are required for each BDD variable . The order of the BDD variables is transferred to the ZDD variables . If a variable group tree exists for the BDD variables a corresponding ZDD variable group tree is created by expanding the BDD variable tree . In any case the ZDD variables derived from the same BDD variable are merged in a ZDD variable group . If a ZDD variable group tree exists it is freed . Returns 1 if successful ; 0 otherwise . ]
int
Cudd_zddVarsFromBddVars(
  DdManager * dd ,
  int multiplicity )
{
    int res;
    int i, j;
    int allnew;
    int *permutation;
    if (multiplicity < 1) return(0);
    allnew = dd->sizeZ == 0;
    if (dd->size * multiplicity > dd->sizeZ) {
        res = cuddResizeTableZdd(dd,dd->size * multiplicity - 1);
        if (res == 0) return(0);
    }
    if (allnew) {
        for (i = 0; i < dd->size; i++) {
            for (j = 0; j < multiplicity; j++) {
                dd->permZ[i * multiplicity + j] =
                    dd->perm[i] * multiplicity + j;
                dd->invpermZ[dd->permZ[i * multiplicity + j]] =
                    i * multiplicity + j;
            }
        }
        for (i = 0; i < dd->sizeZ; i++) {
            dd->univ[i]->index = dd->invpermZ[i];
        }
    } else {
        permutation = ABC_ALLOC(int,dd->sizeZ);
        if (permutation == NULL) {
            dd->errorCode = CUDD_MEMORY_OUT;
            return(0);
        }
        for (i = 0; i < dd->size; i++) {
            for (j = 0; j < multiplicity; j++) {
                permutation[i * multiplicity + j] =
                    dd->invperm[i] * multiplicity + j;
            }
        }
        for (i = dd->size * multiplicity; i < dd->sizeZ; i++) {
            permutation[i] = i;
        }
        res = Cudd_zddShuffleHeap(dd, permutation);
        ABC_FREE(permutation);
        if (res == 0) return(0);
    }
    if (dd->treeZ != NULL) {
        Cudd_FreeZddTree(dd);
    }
    if (dd->tree != NULL) {
        dd->treeZ = Mtr_CopyTree(dd->tree, multiplicity);
        if (dd->treeZ == NULL) return(0);
    } else if (multiplicity > 1) {
        dd->treeZ = Mtr_InitGroupTree(0, dd->sizeZ);
        if (dd->treeZ == NULL) return(0);
        dd->treeZ->index = dd->invpermZ[0];
    }
    if (multiplicity > 1) {
        char *vmask, *lmask;
        vmask = ABC_ALLOC(char, dd->size);
        if (vmask == NULL) {
            dd->errorCode = CUDD_MEMORY_OUT;
            return(0);
        }
        lmask =  ABC_ALLOC(char, dd->size);
        if (lmask == NULL) {
            dd->errorCode = CUDD_MEMORY_OUT;
            return(0);
        }
        for (i = 0; i < dd->size; i++) {
            vmask[i] = lmask[i] = 0;
        }
        res = addMultiplicityGroups(dd,dd->treeZ,multiplicity,vmask,lmask);
        ABC_FREE(vmask);
        ABC_FREE(lmask);
        if (res == 0) return(0);
    }
    return(1);
}
int Cudd_zddVarsFromBddVars ( DdManager * dd , int multiplicity ) { int res ; int i , j ; int allnew ; int * permutation ; if ( multiplicity < 1 ) return ( 0 ) ; allnew = dd -> sizeZ == 0 ; if ( dd -> size * multiplicity > dd -> sizeZ ) { res = cuddResizeTableZdd ( dd , dd -> size * multiplicity - 1 ) ; if ( res == 0 ) return ( 0 ) ; } if ( allnew ) { for ( i = 0 ; i < dd -> size ; i ++ ) { for ( j = 0 ; j < multiplicity ; j ++ ) { dd -> permZ [ i * multiplicity + j ] = dd -> perm [ i ] * multiplicity + j ; dd -> invpermZ [ dd -> permZ [ i * multiplicity + j ] ] = i * multiplicity + j ; } } for ( i = 0 ; i < dd -> sizeZ ; i ++ ) { dd -> univ [ i ] -> index = dd -> invpermZ [ i ] ; } } else { permutation = ABC_ALLOC ( int , dd -> sizeZ ) ; if ( permutation == NULL ) { dd -> errorCode = CUDD_MEMORY_OUT ; return ( 0 ) ; } for ( i = 0 ; i < dd -> size ; i ++ ) { for ( j = 0 ; j < multiplicity ; j ++ ) { permutation [ i * multiplicity + j ] = dd -> invperm [ i ] * multiplicity + j ; } } for ( i = dd -> size * multiplicity ; i < dd -> sizeZ ; i ++ ) { permutation [ i ] = i ; } res = Cudd_zddShuffleHeap ( dd , permutation ) ; ABC_FREE ( permutation ) ; if ( res == 0 ) return ( 0 ) ; } if ( dd -> treeZ != NULL ) { Cudd_FreeZddTree ( dd ) ; } if ( dd -> tree != NULL ) { dd -> treeZ = Mtr_CopyTree ( dd -> tree , multiplicity ) ; if ( dd -> treeZ == NULL ) return ( 0 ) ; } else if ( multiplicity > 1 ) { dd -> treeZ = Mtr_InitGroupTree ( 0 , dd -> sizeZ ) ; if ( dd -> treeZ == NULL ) return ( 0 ) ; dd -> treeZ -> index = dd -> invpermZ [ 0 ] ; } if ( multiplicity > 1 ) { char * vmask , * lmask ; vmask = ABC_ALLOC ( char , dd -> size ) ; if ( vmask == NULL ) { dd -> errorCode = CUDD_MEMORY_OUT ; return ( 0 ) ; } lmask = ABC_ALLOC ( char , dd -> size ) ; if ( lmask == NULL ) { dd -> errorCode = CUDD_MEMORY_OUT ; return ( 0 ) ; } for ( i = 0 ; i < dd -> size ; i ++ ) { vmask [ i ] = lmask [ i ] = 0 ; } res = addMultiplicityGroups ( dd , dd -> treeZ , multiplicity , vmask , lmask ) ; ABC_FREE ( vmask ) ; ABC_FREE ( lmask ) ; if ( res == 0 ) return ( 0 ) ; } return ( 1 ) ; }
Function
Synopsis    [Creates one or more ZDD variables for each BDD variable.]
Function Synopsis [ Creates one or more ZDD variables for each BDD variable . ]
/* DD manager */ /* how many ZDD variables are created for each BDD variable */ /* Impose the order of the BDD variables to the ZDD variables. */ /* Copy and expand the variable group tree if it exists. */ /* Create groups for the ZDD variables derived from the same BDD variable.
    */