cuddSplit.c 21.2 KB
Newer Older
Alan Mishchenko committed
1 2 3 4 5 6 7 8 9
/**CFile***********************************************************************

  FileName    [cuddSplit.c]

  PackageName [cudd]

  Synopsis    [Returns a subset of minterms from a boolean function.]

  Description [External functions included in this modoule:
10 11 12 13 14 15 16
                <ul>
                <li> Cudd_SplitSet()
                </ul>
        Internal functions included in this module:
                <ul>
                <li> cuddSplitSetRecur()
                </u>
Alan Mishchenko committed
17
        Static functions included in this module:
18 19 20 21 22
                <ul>
                <li> selectMintermsFromUniverse()
                <li> mintermsFromUniverse()
                <li> bddAnnotateMintermCount()
                </ul> ]
Alan Mishchenko committed
23 24 25 26 27

  SeeAlso     []

  Author      [Balakrishna Kumthekar]

28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
  Copyright   [Copyright (c) 1995-2004, Regents of the University of Colorado

  All rights reserved.

  Redistribution and use in source and binary forms, with or without
  modification, are permitted provided that the following conditions
  are met:

  Redistributions of source code must retain the above copyright
  notice, this list of conditions and the following disclaimer.

  Redistributions in binary form must reproduce the above copyright
  notice, this list of conditions and the following disclaimer in the
  documentation and/or other materials provided with the distribution.

  Neither the name of the University of Colorado nor the names of its
  contributors may be used to endorse or promote products derived from
  this software without specific prior written permission.

  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
  ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  POSSIBILITY OF SUCH DAMAGE.]
Alan Mishchenko committed
59 60 61

******************************************************************************/

62
#include "misc/util/util_hack.h"
Alan Mishchenko committed
63 64
#include "cuddInt.h"

65 66 67
ABC_NAMESPACE_IMPL_START


68

Alan Mishchenko committed
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98
/*---------------------------------------------------------------------------*/
/* Constant declarations                                                     */
/*---------------------------------------------------------------------------*/

/*---------------------------------------------------------------------------*/
/* Type declarations                                                         */
/*---------------------------------------------------------------------------*/


/*---------------------------------------------------------------------------*/
/* Structure declarations                                                    */
/*---------------------------------------------------------------------------*/


/*---------------------------------------------------------------------------*/
/* Variable declarations                                                     */
/*---------------------------------------------------------------------------*/


/*---------------------------------------------------------------------------*/
/* Macro declarations                                                        */
/*---------------------------------------------------------------------------*/


/**AutomaticStart*************************************************************/

/*---------------------------------------------------------------------------*/
/* Static function prototypes                                                */
/*---------------------------------------------------------------------------*/

99 100
static DdNode * selectMintermsFromUniverse (DdManager *manager, int *varSeen, double n);
static DdNode * mintermsFromUniverse (DdManager *manager, DdNode **vars, int numVars, double n, int index);
101
static double bddAnnotateMintermCount (DdManager *manager, DdNode *node, double max, st__table *table);
Alan Mishchenko committed
102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137

/**AutomaticEnd***************************************************************/


/*---------------------------------------------------------------------------*/
/* Definition of exported functions                                          */
/*---------------------------------------------------------------------------*/


/**Function********************************************************************

  Synopsis    [Returns m minterms from a BDD.]

  Description [Returns <code>m</code> minterms from a BDD whose
  support has <code>n</code> variables at most.  The procedure tries
  to create as few extra nodes as possible. The function represented
  by <code>S</code> depends on at most <code>n</code> of the variables
  in <code>xVars</code>. Returns a BDD with <code>m</code> minterms
  of the on-set of S if successful; NULL otherwise.]

  SideEffects [None]

  SeeAlso     []

******************************************************************************/
DdNode *
Cudd_SplitSet(
  DdManager * manager,
  DdNode * S,
  DdNode ** xVars,
  int  n,
  double  m)
{
    DdNode *result;
    DdNode *zero, *one;
    double  max, num;
138
    st__table *mtable;
Alan Mishchenko committed
139 140 141 142 143 144 145 146 147
    int *varSeen;
    int i,index, size;

    size = manager->size;
    one = DD_ONE(manager);
    zero = Cudd_Not(one);

    /* Trivial cases. */
    if (m == 0.0) {
148
        return(zero);
Alan Mishchenko committed
149 150
    }
    if (S == zero) {
151
        return(NULL);
Alan Mishchenko committed
152 153 154 155 156 157
    }

    max = pow(2.0,(double)n);
    if (m > max)
        return(NULL);

158 159 160 161
    do {
        manager->reordered = 0;
        /* varSeen is used to mark the variables that are encountered
        ** while traversing the BDD S.
Alan Mishchenko committed
162
        */
163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185
        varSeen = ABC_ALLOC(int, size);
        if (varSeen == NULL) {
            manager->errorCode = CUDD_MEMORY_OUT;
            return(NULL);
        }
        for (i = 0; i < size; i++) {
            varSeen[i] = -1;
        }
        for (i = 0; i < n; i++) {
            index = (xVars[i])->index;
            varSeen[manager->invperm[index]] = 0;
        }

        if (S == one) {
            if (m == max) {
                ABC_FREE(varSeen);
                return(S);
            }
            result = selectMintermsFromUniverse(manager,varSeen,m);
            if (result)
                cuddRef(result);
            ABC_FREE(varSeen);
        } else {
186
            mtable = st__init_table( st__ptrcmp, st__ptrhash);
187 188 189 190 191 192 193 194 195 196 197 198 199
            if (mtable == NULL) {
                (void) fprintf(manager->out,
                               "Cudd_SplitSet: out-of-memory.\n");
                ABC_FREE(varSeen);
                manager->errorCode = CUDD_MEMORY_OUT;
                return(NULL);
            }
            /* The nodes of BDD S are annotated by the number of minterms
            ** in their onset. The node and the number of minterms in its
            ** onset are stored in mtable.
            */
            num = bddAnnotateMintermCount(manager,S,max,mtable);
            if (m == num) {
200 201
                st__foreach(mtable,cuddStCountfree,NIL(char));
                st__free_table(mtable);
202 203 204 205 206 207 208
                ABC_FREE(varSeen);
                return(S);
            }
            
            result = cuddSplitSetRecur(manager,mtable,varSeen,S,m,max,0);
            if (result)
                cuddRef(result);
209 210
            st__foreach(mtable,cuddStCountfree,NULL);
            st__free_table(mtable);
211
            ABC_FREE(varSeen);
Alan Mishchenko committed
212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248
        }
    } while (manager->reordered == 1);

    cuddDeref(result);
    return(result);

} /* end of Cudd_SplitSet */


/*---------------------------------------------------------------------------*/
/* Definition of internal functions                                          */
/*---------------------------------------------------------------------------*/

/**Function********************************************************************

  Synopsis    [Implements the recursive step of Cudd_SplitSet.]

  Description [Implements the recursive step of Cudd_SplitSet. The
  procedure recursively traverses the BDD and checks to see if any
  node satisfies the minterm requirements as specified by 'n'. At any
  node X, n is compared to the number of minterms in the onset of X's
  children. If either of the child nodes have exactly n minterms, then
  that node is returned; else, if n is greater than the onset of one
  of the child nodes, that node is retained and the difference in the
  number of minterms is extracted from the other child. In case n
  minterms can be extracted from constant 1, the algorithm returns the
  result with at most log(n) nodes.]

  SideEffects [The array 'varSeen' is updated at every recursive call
  to set the variables traversed by the procedure.]

  SeeAlso     []

******************************************************************************/
DdNode*
cuddSplitSetRecur(
  DdManager * manager,
249
  st__table * mtable,
Alan Mishchenko committed
250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270
  int * varSeen,
  DdNode * p,
  double  n,
  double  max,
  int  index)
{
    DdNode *one, *zero, *N, *Nv;
    DdNode *Nnv, *q, *r, *v;
    DdNode *result;
    double *dummy, numT, numE;
    int variable, positive;
  
    statLine(manager);
    one = DD_ONE(manager);
    zero = Cudd_Not(one);

    /* If p is constant, extract n minterms from constant 1.  The procedure by
    ** construction guarantees that minterms will not be extracted from
    ** constant 0.
    */
    if (Cudd_IsConstant(p)) {
271 272
        q = selectMintermsFromUniverse(manager,varSeen,n);
        return(q);
Alan Mishchenko committed
273 274 275 276 277 278 279 280 281 282 283
    }

    N = Cudd_Regular(p);

    /* Set variable as seen. */
    variable = N->index;
    varSeen[manager->invperm[variable]] = -1;

    Nv = cuddT(N);
    Nnv = cuddE(N);
    if (Cudd_IsComplement(p)) {
284 285
        Nv = Cudd_Not(Nv);
        Nnv = Cudd_Not(Nnv);
Alan Mishchenko committed
286 287 288 289 290 291
    }

    /* If both the children of 'p' are constants, extract n minterms from a
    ** constant node.
    */
    if (Cudd_IsConstant(Nv) && Cudd_IsConstant(Nnv)) {
292 293 294 295 296 297 298 299 300 301 302
        q = selectMintermsFromUniverse(manager,varSeen,n);
        if (q == NULL) {
            return(NULL);
        }
        cuddRef(q);
        r = cuddBddAndRecur(manager,p,q);
        if (r == NULL) {
            Cudd_RecursiveDeref(manager,q);
            return(NULL);
        }
        cuddRef(r);
Alan Mishchenko committed
303
        Cudd_RecursiveDeref(manager,q);
304 305
        cuddDeref(r);
        return(r);
Alan Mishchenko committed
306 307 308 309
    }
  
    /* Lookup the # of minterms in the onset of the node from the table. */
    if (!Cudd_IsConstant(Nv)) {
310
        if (! st__lookup(mtable, (const char *)Nv, (char **)&dummy)) return(NULL);
311
        numT = *dummy/(2*(1<<index));
Alan Mishchenko committed
312
    } else if (Nv == one) {
313
        numT = max/(2*(1<<index));
Alan Mishchenko committed
314
    } else {
315
        numT = 0;
Alan Mishchenko committed
316 317 318
    }
  
    if (!Cudd_IsConstant(Nnv)) {
319
        if (! st__lookup(mtable, (const char *)Nnv, (char **)&dummy)) return(NULL);
320
        numE = *dummy/(2*(1<<index));
Alan Mishchenko committed
321
    } else if (Nnv == one) {
322
        numE = max/(2*(1<<index));
Alan Mishchenko committed
323
    } else {
324
        numE = 0;
Alan Mishchenko committed
325 326 327 328 329 330 331
    }

    v = cuddUniqueInter(manager,variable,one,zero);
    cuddRef(v);

    /* If perfect match. */
    if (numT == n) {
332 333 334 335 336 337
        q = cuddBddAndRecur(manager,v,Nv);
        if (q == NULL) {
            Cudd_RecursiveDeref(manager,v);
            return(NULL);
        }
        cuddRef(q);
Alan Mishchenko committed
338
        Cudd_RecursiveDeref(manager,v);
339 340
        cuddDeref(q);
        return(q);
Alan Mishchenko committed
341 342
    }
    if (numE == n) {
343 344 345 346 347 348
        q = cuddBddAndRecur(manager,Cudd_Not(v),Nnv);
        if (q == NULL) {
            Cudd_RecursiveDeref(manager,v);
            return(NULL);
        }
        cuddRef(q);
Alan Mishchenko committed
349
        Cudd_RecursiveDeref(manager,v);
350 351
        cuddDeref(q);
        return(q);
Alan Mishchenko committed
352 353 354 355 356
    }
    /* If n is greater than numT, extract the difference from the ELSE child
    ** and retain the function represented by the THEN branch.
    */
    if (numT < n) {
357 358 359 360 361 362 363 364 365 366 367 368 369 370
        q = cuddSplitSetRecur(manager,mtable,varSeen,
                              Nnv,(n-numT),max,index+1);
        if (q == NULL) {
            Cudd_RecursiveDeref(manager,v);
            return(NULL);
        }
        cuddRef(q);
        r = cuddBddIteRecur(manager,v,Nv,q);
        if (r == NULL) {
            Cudd_RecursiveDeref(manager,q);
            Cudd_RecursiveDeref(manager,v);
            return(NULL);
        }
        cuddRef(r);
Alan Mishchenko committed
371 372
        Cudd_RecursiveDeref(manager,q);
        Cudd_RecursiveDeref(manager,v);
373 374
        cuddDeref(r);
        return(r);
Alan Mishchenko committed
375 376 377 378 379
    }
    /* If n is greater than numE, extract the difference from the THEN child
    ** and retain the function represented by the ELSE branch.
    */
    if (numE < n) {
380 381 382 383 384 385 386 387 388 389 390 391 392 393
        q = cuddSplitSetRecur(manager,mtable,varSeen,
                              Nv, (n-numE),max,index+1);
        if (q == NULL) {
            Cudd_RecursiveDeref(manager,v);
            return(NULL);
        }
        cuddRef(q);
        r = cuddBddIteRecur(manager,v,q,Nnv);
        if (r == NULL) {
            Cudd_RecursiveDeref(manager,q);
            Cudd_RecursiveDeref(manager,v);
            return(NULL);
        }
        cuddRef(r);
Alan Mishchenko committed
394 395
        Cudd_RecursiveDeref(manager,q);
        Cudd_RecursiveDeref(manager,v);
396 397
        cuddDeref(r);    
        return(r);
Alan Mishchenko committed
398 399 400 401 402 403 404
    }

    /* None of the above cases; (n < numT and n < numE) and either of
    ** the Nv, Nnv or both are not constants. If possible extract the
    ** required minterms the constant branch.
    */
    if (Cudd_IsConstant(Nv) && !Cudd_IsConstant(Nnv)) {
405 406 407 408 409 410 411 412 413 414 415 416 417
        q = selectMintermsFromUniverse(manager,varSeen,n);
        if (q == NULL) {
            Cudd_RecursiveDeref(manager,v);
            return(NULL);
        }
        cuddRef(q);
        result = cuddBddAndRecur(manager,v,q);
        if (result == NULL) {
            Cudd_RecursiveDeref(manager,q);
            Cudd_RecursiveDeref(manager,v);
            return(NULL);
        }
        cuddRef(result);
Alan Mishchenko committed
418 419
        Cudd_RecursiveDeref(manager,q);
        Cudd_RecursiveDeref(manager,v);
420 421
        cuddDeref(result);
        return(result);
Alan Mishchenko committed
422
    } else if (!Cudd_IsConstant(Nv) && Cudd_IsConstant(Nnv)) {
423 424 425 426 427 428 429 430 431 432 433 434 435
        q = selectMintermsFromUniverse(manager,varSeen,n);
        if (q == NULL) {
            Cudd_RecursiveDeref(manager,v);
            return(NULL);
        }
        cuddRef(q);
        result = cuddBddAndRecur(manager,Cudd_Not(v),q);
        if (result == NULL) {
            Cudd_RecursiveDeref(manager,q);
            Cudd_RecursiveDeref(manager,v);
            return(NULL);
        }
        cuddRef(result);
Alan Mishchenko committed
436 437
        Cudd_RecursiveDeref(manager,q);
        Cudd_RecursiveDeref(manager,v);
438 439
        cuddDeref(result);
        return(result);
Alan Mishchenko committed
440 441 442 443 444 445 446
    }

    /* Both Nv and Nnv are not constants. So choose the one which
    ** has fewer minterms in its onset.
    */
    positive = 0;
    if (numT < numE) {
447 448 449
        q = cuddSplitSetRecur(manager,mtable,varSeen,
                              Nv,n,max,index+1);
        positive = 1;
Alan Mishchenko committed
450
    } else {
451 452
        q = cuddSplitSetRecur(manager,mtable,varSeen,
                              Nnv,n,max,index+1);
Alan Mishchenko committed
453 454 455
    }

    if (q == NULL) {
456 457
        Cudd_RecursiveDeref(manager,v);
        return(NULL);
Alan Mishchenko committed
458 459 460 461
    }
    cuddRef(q);

    if (positive) {
462
        result = cuddBddAndRecur(manager,v,q);
Alan Mishchenko committed
463
    } else {
464
        result = cuddBddAndRecur(manager,Cudd_Not(v),q);
Alan Mishchenko committed
465 466
    }
    if (result == NULL) {
467 468 469
        Cudd_RecursiveDeref(manager,q);
        Cudd_RecursiveDeref(manager,v);
        return(NULL);
Alan Mishchenko committed
470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517
    }
    cuddRef(result);
    Cudd_RecursiveDeref(manager,q);
    Cudd_RecursiveDeref(manager,v);
    cuddDeref(result);

    return(result);

} /* end of cuddSplitSetRecur */


/*---------------------------------------------------------------------------*/
/* Definition of static functions                                            */
/*---------------------------------------------------------------------------*/

/**Function********************************************************************

  Synopsis [This function prepares an array of variables which have not been
  encountered so far when traversing the procedure cuddSplitSetRecur.]

  Description [This function prepares an array of variables which have not been
  encountered so far when traversing the procedure cuddSplitSetRecur. This
  array is then used to extract the required number of minterms from a constant
  1. The algorithm guarantees that the size of BDD will be utmost \log(n).]

  SideEffects [None]

******************************************************************************/
static DdNode *
selectMintermsFromUniverse(
  DdManager * manager,
  int * varSeen,
  double  n)
{
    int numVars;
    int i, size, j;
     DdNode *one, *zero, *result;
    DdNode **vars;

    numVars = 0;
    size = manager->size;
    one = DD_ONE(manager);
    zero = Cudd_Not(one);

    /* Count the number of variables not encountered so far in procedure
    ** cuddSplitSetRecur.
    */
    for (i = size-1; i >= 0; i--) {
518 519
        if(varSeen[i] == 0)
            numVars++;
Alan Mishchenko committed
520
    }
Alan Mishchenko committed
521
    vars = ABC_ALLOC(DdNode *, numVars);
Alan Mishchenko committed
522
    if (!vars) {
523 524
        manager->errorCode = CUDD_MEMORY_OUT;
        return(NULL);
Alan Mishchenko committed
525 526 527 528
    }

    j = 0;
    for (i = size-1; i >= 0; i--) {
529 530 531 532 533
        if(varSeen[i] == 0) {
            vars[j] = cuddUniqueInter(manager,manager->perm[i],one,zero);
            cuddRef(vars[j]);
            j++;
        }
Alan Mishchenko committed
534 535 536 537 538 539 540
    }

    /* Compute a function which has n minterms and depends on at most
    ** numVars variables.
    */
    result = mintermsFromUniverse(manager,vars,numVars,n, 0);
    if (result) 
541
        cuddRef(result);
Alan Mishchenko committed
542 543

    for (i = 0; i < numVars; i++)
544
        Cudd_RecursiveDeref(manager,vars[i]);
Alan Mishchenko committed
545
    ABC_FREE(vars);
Alan Mishchenko committed
546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580

    return(result);

} /* end of selectMintermsFromUniverse */


/**Function********************************************************************

  Synopsis    [Recursive procedure to extract n mintems from constant 1.]

  Description [Recursive procedure to extract n mintems from constant 1.]

  SideEffects [None]

******************************************************************************/
static DdNode *
mintermsFromUniverse(
  DdManager * manager,
  DdNode ** vars,
  int  numVars,
  double  n,
  int  index)
{
    DdNode *one, *zero;
    DdNode *q, *result;
    double max, max2;
    
    statLine(manager);
    one = DD_ONE(manager);
    zero = Cudd_Not(one);

    max = pow(2.0, (double)numVars);
    max2 = max / 2.0;

    if (n == max)
581
        return(one);
Alan Mishchenko committed
582
    if (n == 0.0)
583
        return(zero);
Alan Mishchenko committed
584 585
    /* if n == 2^(numVars-1), return a single variable */
    if (n == max2)
586
        return vars[index];
Alan Mishchenko committed
587
    else if (n > max2) {
588 589 590 591 592 593 594 595 596
        /* When n > 2^(numVars-1), a single variable vars[index]
        ** contains 2^(numVars-1) minterms. The rest are extracted
        ** from a constant with 1 less variable.
        */
        q = mintermsFromUniverse(manager,vars,numVars-1,(n-max2),index+1);
        if (q == NULL)
            return(NULL);
        cuddRef(q);
        result = cuddBddIteRecur(manager,vars[index],one,q);
Alan Mishchenko committed
597
    } else {
598 599 600 601 602 603 604 605 606
        /* When n < 2^(numVars-1), a literal of variable vars[index]
        ** is selected. The required n minterms are extracted from a
        ** constant with 1 less variable.
        */
        q = mintermsFromUniverse(manager,vars,numVars-1,n,index+1);
        if (q == NULL)
            return(NULL);
        cuddRef(q);
        result = cuddBddAndRecur(manager,vars[index],q);
Alan Mishchenko committed
607 608 609
    }
    
    if (result == NULL) {
610 611
        Cudd_RecursiveDeref(manager,q);
        return(NULL);
Alan Mishchenko committed
612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636
    }
    cuddRef(result);
    Cudd_RecursiveDeref(manager,q);
    cuddDeref(result);
    return(result);

} /* end of mintermsFromUniverse */


/**Function********************************************************************

  Synopsis    [Annotates every node in the BDD node with its minterm count.]

  Description [Annotates every node in the BDD node with its minterm count.
  In this function, every node and the minterm count represented by it are
  stored in a hash table.]

  SideEffects [Fills up 'table' with the pair <node,minterm_count>.]

******************************************************************************/
static double
bddAnnotateMintermCount(
  DdManager * manager,
  DdNode * node,
  double  max,
637
  st__table * table)
Alan Mishchenko committed
638 639 640 641 642 643 644 645 646 647 648
{

    DdNode *N,*Nv,*Nnv;
    register double min_v,min_nv;
    register double min_N;
    double *pmin;
    double *dummy;

    statLine(manager);
    N = Cudd_Regular(node);
    if (cuddIsConstant(N)) {
649 650 651 652 653
        if (node == DD_ONE(manager)) {
            return(max);
        } else {
            return(0.0);
        }
Alan Mishchenko committed
654 655
    }

656
    if ( st__lookup(table, (const char *)node, (char **)&dummy)) {
657 658
        return(*dummy);
    }   
Alan Mishchenko committed
659 660 661 662
  
    Nv = cuddT(N);
    Nnv = cuddE(N);
    if (N != node) {
663 664
        Nv = Cudd_Not(Nv);
        Nnv = Cudd_Not(Nnv);
Alan Mishchenko committed
665 666 667 668 669
    }

    /* Recur on the two branches. */
    min_v  = bddAnnotateMintermCount(manager,Nv,max,table) / 2.0;
    if (min_v == (double)CUDD_OUT_OF_MEM)
670
        return ((double)CUDD_OUT_OF_MEM);
Alan Mishchenko committed
671 672
    min_nv = bddAnnotateMintermCount(manager,Nnv,max,table) / 2.0;
    if (min_nv == (double)CUDD_OUT_OF_MEM)
673
        return ((double)CUDD_OUT_OF_MEM);
Alan Mishchenko committed
674 675
    min_N  = min_v + min_nv;

Alan Mishchenko committed
676
    pmin = ABC_ALLOC(double,1);
Alan Mishchenko committed
677
    if (pmin == NULL) {
678 679
        manager->errorCode = CUDD_MEMORY_OUT;
        return((double)CUDD_OUT_OF_MEM);
Alan Mishchenko committed
680 681 682
    }
    *pmin = min_N;

683
    if ( st__insert(table,(char *)node, (char *)pmin) == st__OUT_OF_MEM) {
684 685
        ABC_FREE(pmin);
        return((double)CUDD_OUT_OF_MEM);
Alan Mishchenko committed
686 687 688 689 690
    }
    
    return(min_N);

} /* end of bddAnnotateMintermCount */
691 692


693 694
ABC_NAMESPACE_IMPL_END