Beispiel #1
0
/**Function********************************************************************

  Synopsis    [Check that minterm counts have not changed.]

  Description [Counts the minterms in the global functions of the
  primary outputs of the network passed as argument.
  When it is calld with the second argument set to NULL, it allocates
  a symbol table and stores, for each output, the minterm count. If
  an output does not have a BDD, it stores a NULL pointer for it.
  If it is called with a non-null second argument, it assumes that
  the symbol table contains the minterm counts measured previously
  and it compares the new counts to the old ones. Finally, it frees
  the symbol table.
  check_minterms is designed so that it can be called twice: once before
  reordering, and once after reordering.
  Returns a pointer to the symbol table on the first invocation and NULL
  on the second invocation.]

  SideEffects [None]

  SeeAlso     []

******************************************************************************/
st_table *
checkMinterms(
  BnetNetwork * net,
  DdManager * dd,
  st_table * previous)
{
    BnetNode *po;
    int numPi;
    char *name;
    double *count, newcount, *oldcount;
    int flag,err,i;

    numPi = net->ninputs;

    if (previous == NULL) {
	previous = st_init_table(strcmp,st_strhash);
	if (previous == NULL) {
	    (void) printf("checkMinterms out-of-memory\n");
	    return(NULL);
	}
	for (i = 0; i < net->noutputs; i++) {
	    if (!st_lookup(net->hash,net->outputs[i],&po)) {
		exit(2);
	    }
	    name = net->outputs[i];
	    if (po->dd != NULL) {
		count = ALLOC(double,1);
		*count = Cudd_CountMinterm(dd,po->dd,numPi);
		err = st_insert(previous, name, (char *) count);
	    } else {
Beispiel #2
0
static keyvalue_table_ptr cudd_count(shadow_mgr mgr, set_ptr roots) {
    word_t wk, wv;
    keyvalue_table_ptr result = word_keyvalue_new();
    set_iterstart(roots);
    while (set_iternext(roots, &wk)) {
	ref_t r = (ref_t) wk;
	DdNode *n = get_ddnode(mgr, r);
	bool zdd = is_zdd(mgr, r);
#if USE_APA
	int digits;
	DdApaNumber num = Cudd_ApaCountMinterm(mgr->bdd_manager, n, mgr->nvars,
					       &digits);
	wv = apa2word(num, digits);
	FREE(num);
#else
	double fv = 0.0;
	if (zdd) {
	    fv = Cudd_zddCountMinterm(mgr->bdd_manager, n, mgr->nzvars);
	} else {
	    fv = Cudd_CountMinterm(mgr->bdd_manager, n, mgr->nvars);
	}
	wv = (word_t) fv;
#endif
	keyvalue_insert(result, wk, wv);
    }
    return result;
}
Beispiel #3
0
  void BDD::printTuples(int a, std::ostream& os) const {
    if (node ==CDD_ONE(Cudd::dd)) {
      os << "Universe";
      return;
    }
    if (node == CDD_ZERO(Cudd::dd)) {
      os << "Empty";
      return;
    }

    DdGen* gen;
    int *cube = (int*)malloc(sizeof(int)*(1<<(BBV+BA)));
    int tuple[1<<BA];
    CUDD_VALUE_TYPE val;
    int done;
    int i,k,j;
    os << "#(" << Cudd_CountMinterm(Cudd::dd,node,a<<BBV) << "){";
    //printf("Cardinality: %f\n", Cudd_CountMinterm(Cudd::dd,node,a<<BBV));
    for(k=0;k<1<<BA;k++)tuple[k]=0;
    Cudd_ForeachCube(Cudd::dd,node,gen,cube,val){
      done=0;
      while(!done){
        done=1;
        for(i=(1<<(BBV+BA))-1;i>=0;i--){
          if((i&((1<<BA)-1))<a){
            tuple[i&((1<<BA)-1)]&=~(1<<((1<<BBV)-1-(i>>BA)));
            tuple[i&((1<<BA)-1)]|=(cube[i]&1)<<((1<<BBV)-1-(i>>BA));
            if((cube[i]&2)&&done){
              done&=cube[i]&1;
              cube[i]^=1;
            }
          }
        }
        os << "<";
        for(j = 0; j < a; j++) {
          os << tuple[j] << ",";//printf("%d,",tuple[j]);
        }
        //printf(">\n");
        os << ">, ";
      }
Beispiel #4
0
/**Function*************************************************************

  Synopsis    []

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
void Abc_MvRead( Mv_Man_t * p )
{
    FILE * pFile;
    char Buffer[1000], * pLine;
    DdNode * bCube, * bTemp, * bProd, * bVar0, * bVar1, * bCubeSum;
    int i, v;

    // start the cube
    bCubeSum = Cudd_ReadLogicZero(p->dd);  Cudd_Ref( bCubeSum );

    // start the values
    for ( i = 0; i < 15; i++ )
    for ( v = 0; v < 4; v++ )
    {
        p->bValues[i][v]   = Cudd_ReadLogicZero(p->dd);  Cudd_Ref( p->bValues[i][v] );
        p->bValueDcs[i][v] = Cudd_ReadLogicZero(p->dd);  Cudd_Ref( p->bValueDcs[i][v] );
    }

    // read the file
    pFile = fopen( "input.pla", "r" );
    while ( fgets( Buffer, 1000, pFile ) )
    {
        if ( Buffer[0] == '#' )
            continue;
        if ( Buffer[0] == '.' )
        {
            if ( Buffer[1] == 'e' )
                break;
            continue;
        }

        // get the cube 
        bCube = Abc_MvReadCube( p->dd, Buffer, 18 );  Cudd_Ref( bCube );

        // add it to the values of the output functions
        pLine = Buffer + 19;
        for ( i = 0; i < 15; i++ )
        {
            if ( pLine[2*i] == '-' && pLine[2*i+1] == '-' )
            {
                for ( v = 0; v < 4; v++ )
                {
                    p->bValueDcs[i][v] = Cudd_bddOr( p->dd, bTemp = p->bValueDcs[i][v], bCube );  Cudd_Ref( p->bValueDcs[i][v] );
                    Cudd_RecursiveDeref( p->dd, bTemp );
                }
                continue;
            }
            else if ( pLine[2*i] == '0' && pLine[2*i+1] == '0' ) // 0
                v = 0;
            else if ( pLine[2*i] == '1' && pLine[2*i+1] == '0' ) // 1
                v = 1;
            else if ( pLine[2*i] == '0' && pLine[2*i+1] == '1' ) // 2
                v = 2;
            else if ( pLine[2*i] == '1' && pLine[2*i+1] == '1' ) // 3
                v = 3;
            else assert( 0 );
            // add the value
            p->bValues[i][v] = Cudd_bddOr( p->dd, bTemp = p->bValues[i][v], bCube );  Cudd_Ref( p->bValues[i][v] );
            Cudd_RecursiveDeref( p->dd, bTemp );
        }

        // add the cube
        bCubeSum = Cudd_bddOr( p->dd, bTemp = bCubeSum, bCube );  Cudd_Ref( bCubeSum );
        Cudd_RecursiveDeref( p->dd, bTemp );
        Cudd_RecursiveDeref( p->dd, bCube );
    }

    // add the complement of the domain to all values
    for ( i = 0; i < 15; i++ )
        for ( v = 0; v < 4; v++ )
        {
            if ( p->bValues[i][v] == Cudd_Not(Cudd_ReadOne(p->dd)) )
                continue;
            p->bValues[i][v] = Cudd_bddOr( p->dd, bTemp = p->bValues[i][v], p->bValueDcs[i][v] );  Cudd_Ref( p->bValues[i][v] );
            Cudd_RecursiveDeref( p->dd, bTemp );
            p->bValues[i][v] = Cudd_bddOr( p->dd, bTemp = p->bValues[i][v], Cudd_Not(bCubeSum) );  Cudd_Ref( p->bValues[i][v] );
            Cudd_RecursiveDeref( p->dd, bTemp );
        }
    printf( "Domain = %5.2f %%.\n", 100.0*Cudd_CountMinterm(p->dd, bCubeSum, 32)/Cudd_CountMinterm(p->dd, Cudd_ReadOne(p->dd), 32) ); 
    Cudd_RecursiveDeref( p->dd, bCubeSum );

    // create each output function
    for ( i = 0; i < 15; i++ )
    {
        p->bFuncs[i] = Cudd_ReadLogicZero(p->dd);  Cudd_Ref( p->bFuncs[i] );
        for ( v = 0; v < 4; v++ )
        {
            bVar0 = Cudd_NotCond( Cudd_bddIthVar(p->dd, 30), ((v & 1) == 0) );
            bVar1 = Cudd_NotCond( Cudd_bddIthVar(p->dd, 31), ((v & 2) == 0) );
            bCube = Cudd_bddAnd( p->dd, bVar0, bVar1 );             Cudd_Ref( bCube );
            bProd = Cudd_bddAnd( p->dd, p->bValues[i][v], bCube );  Cudd_Ref( bProd );
            Cudd_RecursiveDeref( p->dd, bCube );
            // add the value
            p->bFuncs[i] = Cudd_bddOr( p->dd, bTemp = p->bFuncs[i], bProd );  Cudd_Ref( p->bFuncs[i] );
            Cudd_RecursiveDeref( p->dd, bTemp );
            Cudd_RecursiveDeref( p->dd, bProd );
        }
    }
}
Beispiel #5
0
 double BDD::minterms(int nvars) const {
   return Cudd_CountMinterm(Cudd::dd, node, nvars<<BBV);
 }