abc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
cuddClip.c File Reference
#include "misc/util/util_hack.h"
#include "cuddInt.h"

Go to the source code of this file.

Functions

static DdNodecuddBddClippingAndRecur (DdManager *manager, DdNode *f, DdNode *g, int distance, int direction)
 
static DdNodecuddBddClipAndAbsRecur (DdManager *manager, DdNode *f, DdNode *g, DdNode *cube, int distance, int direction)
 
DdNodeCudd_bddClippingAnd (DdManager *dd, DdNode *f, DdNode *g, int maxDepth, int direction)
 
DdNodeCudd_bddClippingAndAbstract (DdManager *dd, DdNode *f, DdNode *g, DdNode *cube, int maxDepth, int direction)
 
DdNodecuddBddClippingAnd (DdManager *dd, DdNode *f, DdNode *g, int maxDepth, int direction)
 
DdNodecuddBddClippingAndAbstract (DdManager *dd, DdNode *f, DdNode *g, DdNode *cube, int maxDepth, int direction)
 

Variables

static
ABC_NAMESPACE_IMPL_START char
rcsid[] 
DD_UNUSED = "$Id: cuddClip.c,v 1.8 2004/08/13 18:04:47 fabio Exp $"
 

Function Documentation

DdNode* Cudd_bddClippingAnd ( DdManager dd,
DdNode f,
DdNode g,
int  maxDepth,
int  direction 
)

AutomaticEnd Function********************************************************************

Synopsis [Approximates the conjunction of two BDDs f and g.]

Description [Approximates the conjunction of two BDDs f and g. Returns a pointer to the resulting BDD if successful; NULL if the intermediate result blows up.]

SideEffects [None]

SeeAlso [Cudd_bddAnd]

Definition at line 129 of file cuddClip.c.

135 {
136  DdNode *res;
137 
138  do {
139  dd->reordered = 0;
140  res = cuddBddClippingAnd(dd,f,g,maxDepth,direction);
141  } while (dd->reordered == 1);
142  return(res);
143 
144 } /* end of Cudd_bddClippingAnd */
Definition: cudd.h:278
DdNode * cuddBddClippingAnd(DdManager *dd, DdNode *f, DdNode *g, int maxDepth, int direction)
Definition: cuddClip.c:201
int reordered
Definition: cuddInt.h:409
DdNode* Cudd_bddClippingAndAbstract ( DdManager dd,
DdNode f,
DdNode g,
DdNode cube,
int  maxDepth,
int  direction 
)

Function********************************************************************

Synopsis [Approximates the conjunction of two BDDs f and g and simultaneously abstracts the variables in cube.]

Description [Approximates the conjunction of two BDDs f and g and simultaneously abstracts the variables in cube. The variables are existentially abstracted. Returns a pointer to the resulting BDD if successful; NULL if the intermediate result blows up.]

SideEffects [None]

SeeAlso [Cudd_bddAndAbstract Cudd_bddClippingAnd]

Definition at line 163 of file cuddClip.c.

170 {
171  DdNode *res;
172 
173  do {
174  dd->reordered = 0;
175  res = cuddBddClippingAndAbstract(dd,f,g,cube,maxDepth,direction);
176  } while (dd->reordered == 1);
177  return(res);
178 
179 } /* end of Cudd_bddClippingAndAbstract */
Definition: cudd.h:278
DdNode * cuddBddClippingAndAbstract(DdManager *dd, DdNode *f, DdNode *g, DdNode *cube, int maxDepth, int direction)
Definition: cuddClip.c:233
int reordered
Definition: cuddInt.h:409
static DdNode * cuddBddClipAndAbsRecur ( DdManager manager,
DdNode f,
DdNode g,
DdNode cube,
int  distance,
int  direction 
)
static

Function********************************************************************

Synopsis [Approximates the AND of two BDDs and simultaneously abstracts the variables in cube.]

Description [Approximates the AND of two BDDs and simultaneously abstracts the variables in cube. The variables are existentially abstracted. Returns a pointer to the result is successful; NULL otherwise.]

SideEffects [None]

SeeAlso [Cudd_bddClippingAndAbstract]

Definition at line 405 of file cuddClip.c.

412 {
413  DdNode *F, *ft, *fe, *G, *gt, *ge;
414  DdNode *one, *zero, *r, *t, *e, *Cube;
415  unsigned int topf, topg, topcube, top, index;
416  ptruint cacheTag;
417 
418  statLine(manager);
419  one = DD_ONE(manager);
420  zero = Cudd_Not(one);
421 
422  /* Terminal cases. */
423  if (f == zero || g == zero || f == Cudd_Not(g)) return(zero);
424  if (f == one && g == one) return(one);
425  if (cube == one) {
426  return(cuddBddClippingAndRecur(manager, f, g, distance, direction));
427  }
428  if (f == one || f == g) {
429  return (cuddBddExistAbstractRecur(manager, g, cube));
430  }
431  if (g == one) {
432  return (cuddBddExistAbstractRecur(manager, f, cube));
433  }
434  if (distance == 0) return(Cudd_NotCond(one,(direction == 0)));
435 
436  /* At this point f, g, and cube are not constant. */
437  distance--;
438 
439  /* Check cache. */
440  if (f > g) { /* Try to increase cache efficiency. */
441  DdNode *tmp = f;
442  f = g; g = tmp;
443  }
444  F = Cudd_Regular(f);
445  G = Cudd_Regular(g);
446  cacheTag = direction ? DD_BDD_CLIPPING_AND_ABSTRACT_UP_TAG :
448  if (F->ref != 1 || G->ref != 1) {
449  r = cuddCacheLookup(manager, cacheTag,
450  f, g, cube);
451  if (r != NULL) {
452  return(r);
453  }
454  }
455 
456  /* Here we can skip the use of cuddI, because the operands are known
457  ** to be non-constant.
458  */
459  topf = manager->perm[F->index];
460  topg = manager->perm[G->index];
461  top = ddMin(topf, topg);
462  topcube = manager->perm[cube->index];
463 
464  if (topcube < top) {
465  return(cuddBddClipAndAbsRecur(manager, f, g, cuddT(cube),
466  distance, direction));
467  }
468  /* Now, topcube >= top. */
469 
470  if (topf == top) {
471  index = F->index;
472  ft = cuddT(F);
473  fe = cuddE(F);
474  if (Cudd_IsComplement(f)) {
475  ft = Cudd_Not(ft);
476  fe = Cudd_Not(fe);
477  }
478  } else {
479  index = G->index;
480  ft = fe = f;
481  }
482 
483  if (topg == top) {
484  gt = cuddT(G);
485  ge = cuddE(G);
486  if (Cudd_IsComplement(g)) {
487  gt = Cudd_Not(gt);
488  ge = Cudd_Not(ge);
489  }
490  } else {
491  gt = ge = g;
492  }
493 
494  if (topcube == top) {
495  Cube = cuddT(cube);
496  } else {
497  Cube = cube;
498  }
499 
500  t = cuddBddClipAndAbsRecur(manager, ft, gt, Cube, distance, direction);
501  if (t == NULL) return(NULL);
502 
503  /* Special case: 1 OR anything = 1. Hence, no need to compute
504  ** the else branch if t is 1.
505  */
506  if (t == one && topcube == top) {
507  if (F->ref != 1 || G->ref != 1)
508  cuddCacheInsert(manager, cacheTag, f, g, cube, one);
509  return(one);
510  }
511  cuddRef(t);
512 
513  e = cuddBddClipAndAbsRecur(manager, fe, ge, Cube, distance, direction);
514  if (e == NULL) {
515  Cudd_RecursiveDeref(manager, t);
516  return(NULL);
517  }
518  cuddRef(e);
519 
520  if (topcube == top) { /* abstract */
521  r = cuddBddClippingAndRecur(manager, Cudd_Not(t), Cudd_Not(e),
522  distance, (direction == 0));
523  if (r == NULL) {
524  Cudd_RecursiveDeref(manager, t);
525  Cudd_RecursiveDeref(manager, e);
526  return(NULL);
527  }
528  r = Cudd_Not(r);
529  cuddRef(r);
530  Cudd_RecursiveDeref(manager, t);
531  Cudd_RecursiveDeref(manager, e);
532  cuddDeref(r);
533  } else if (t == e) {
534  r = t;
535  cuddDeref(t);
536  cuddDeref(e);
537  } else {
538  if (Cudd_IsComplement(t)) {
539  r = cuddUniqueInter(manager,(int)index,Cudd_Not(t),Cudd_Not(e));
540  if (r == NULL) {
541  Cudd_RecursiveDeref(manager, t);
542  Cudd_RecursiveDeref(manager, e);
543  return(NULL);
544  }
545  r = Cudd_Not(r);
546  } else {
547  r = cuddUniqueInter(manager,(int)index,t,e);
548  if (r == NULL) {
549  Cudd_RecursiveDeref(manager, t);
550  Cudd_RecursiveDeref(manager, e);
551  return(NULL);
552  }
553  }
554  cuddDeref(e);
555  cuddDeref(t);
556  }
557  if (F->ref != 1 || G->ref != 1)
558  cuddCacheInsert(manager, cacheTag, f, g, cube, r);
559  return (r);
560 
561 } /* end of cuddBddClipAndAbsRecur */
DdHalfWord ref
Definition: cudd.h:280
DdNode * cuddBddExistAbstractRecur(DdManager *manager, DdNode *f, DdNode *cube)
Definition: cuddBddAbs.c:352
#define cuddRef(n)
Definition: cuddInt.h:584
#define cuddDeref(n)
Definition: cuddInt.h:604
void Cudd_RecursiveDeref(DdManager *table, DdNode *n)
Definition: cuddRef.c:154
Definition: cudd.h:278
#define Cudd_Not(node)
Definition: cudd.h:367
#define Cudd_Regular(node)
Definition: cudd.h:397
#define DD_BDD_CLIPPING_AND_ABSTRACT_DOWN_TAG
Definition: cuddInt.h:178
void cuddCacheInsert(DdManager *table, ptruint op, DdNode *f, DdNode *g, DdNode *h, DdNode *data)
Definition: cuddCache.c:222
#define statLine(dd)
Definition: cuddInt.h:1037
ABC_PTRUINT_T ptruint
Definition: cuddInt.h:261
#define Cudd_IsComplement(node)
Definition: cudd.h:425
static DdNode * one
Definition: cuddDecomp.c:112
static DdNode * cuddBddClippingAndRecur(DdManager *manager, DdNode *f, DdNode *g, int distance, int direction)
Definition: cuddClip.c:269
#define ddMin(x, y)
Definition: cuddInt.h:818
#define cuddT(node)
Definition: cuddInt.h:636
DdHalfWord index
Definition: cudd.h:279
#define cuddE(node)
Definition: cuddInt.h:652
#define Cudd_NotCond(node, c)
Definition: cudd.h:383
static DdNode * cuddBddClipAndAbsRecur(DdManager *manager, DdNode *f, DdNode *g, DdNode *cube, int distance, int direction)
Definition: cuddClip.c:405
#define DD_ONE(dd)
Definition: cuddInt.h:911
int * perm
Definition: cuddInt.h:386
DdNode * cuddUniqueInter(DdManager *unique, int index, DdNode *T, DdNode *E)
Definition: cuddTable.c:1128
static DdNode * zero
Definition: cuddApa.c:100
DdNode * cuddCacheLookup(DdManager *table, ptruint op, DdNode *f, DdNode *g, DdNode *h)
Definition: cuddCache.c:369
#define DD_BDD_CLIPPING_AND_ABSTRACT_UP_TAG
Definition: cuddInt.h:177
DdNode* cuddBddClippingAnd ( DdManager dd,
DdNode f,
DdNode g,
int  maxDepth,
int  direction 
)

Function********************************************************************

Synopsis [Approximates the conjunction of two BDDs f and g.]

Description [Approximates the conjunction of two BDDs f and g. Returns a pointer to the resulting BDD if successful; NULL if the intermediate result blows up.]

SideEffects [None]

SeeAlso [Cudd_bddClippingAnd]

Definition at line 201 of file cuddClip.c.

207 {
208  DdNode *res;
209 
210  res = cuddBddClippingAndRecur(dd,f,g,maxDepth,direction);
211 
212  return(res);
213 
214 } /* end of cuddBddClippingAnd */
Definition: cudd.h:278
static DdNode * cuddBddClippingAndRecur(DdManager *manager, DdNode *f, DdNode *g, int distance, int direction)
Definition: cuddClip.c:269
DdNode* cuddBddClippingAndAbstract ( DdManager dd,
DdNode f,
DdNode g,
DdNode cube,
int  maxDepth,
int  direction 
)

Function********************************************************************

Synopsis [Approximates the conjunction of two BDDs f and g and simultaneously abstracts the variables in cube.]

Description [Approximates the conjunction of two BDDs f and g and simultaneously abstracts the variables in cube. Returns a pointer to the resulting BDD if successful; NULL if the intermediate result blows up.]

SideEffects [None]

SeeAlso [Cudd_bddClippingAndAbstract]

Definition at line 233 of file cuddClip.c.

240 {
241  DdNode *res;
242 
243  res = cuddBddClipAndAbsRecur(dd,f,g,cube,maxDepth,direction);
244 
245  return(res);
246 
247 } /* end of cuddBddClippingAndAbstract */
Definition: cudd.h:278
static DdNode * cuddBddClipAndAbsRecur(DdManager *manager, DdNode *f, DdNode *g, DdNode *cube, int distance, int direction)
Definition: cuddClip.c:405
static DdNode * cuddBddClippingAndRecur ( DdManager manager,
DdNode f,
DdNode g,
int  distance,
int  direction 
)
static

AutomaticStart

Function********************************************************************

Synopsis [Implements the recursive step of Cudd_bddClippingAnd.]

Description [Implements the recursive step of Cudd_bddClippingAnd by taking the conjunction of two BDDs. Returns a pointer to the result is successful; NULL otherwise.]

SideEffects [None]

SeeAlso [cuddBddClippingAnd]

Definition at line 269 of file cuddClip.c.

275 {
276  DdNode *F, *ft, *fe, *G, *gt, *ge;
277  DdNode *one, *zero, *r, *t, *e;
278  unsigned int topf, topg, index;
279  DD_CTFP cacheOp;
280 
281  statLine(manager);
282  one = DD_ONE(manager);
283  zero = Cudd_Not(one);
284 
285  /* Terminal cases. */
286  if (f == zero || g == zero || f == Cudd_Not(g)) return(zero);
287  if (f == g || g == one) return(f);
288  if (f == one) return(g);
289  if (distance == 0) {
290  /* One last attempt at returning the right result. We sort of
291  ** cheat by calling Cudd_bddLeq. */
292  if (Cudd_bddLeq(manager,f,g)) return(f);
293  if (Cudd_bddLeq(manager,g,f)) return(g);
294  if (direction == 1) {
295  if (Cudd_bddLeq(manager,f,Cudd_Not(g)) ||
296  Cudd_bddLeq(manager,g,Cudd_Not(f))) return(zero);
297  }
298  return(Cudd_NotCond(one,(direction == 0)));
299  }
300 
301  /* At this point f and g are not constant. */
302  distance--;
303 
304  /* Check cache. Try to increase cache efficiency by sorting the
305  ** pointers. */
306  if (f > g) {
307  DdNode *tmp = f;
308  f = g; g = tmp;
309  }
310  F = Cudd_Regular(f);
311  G = Cudd_Regular(g);
312  cacheOp = (DD_CTFP)
313  (direction ? Cudd_bddClippingAnd : cuddBddClippingAnd);
314  if (F->ref != 1 || G->ref != 1) {
315  r = cuddCacheLookup2(manager, cacheOp, f, g);
316  if (r != NULL) return(r);
317  }
318 
319  /* Here we can skip the use of cuddI, because the operands are known
320  ** to be non-constant.
321  */
322  topf = manager->perm[F->index];
323  topg = manager->perm[G->index];
324 
325  /* Compute cofactors. */
326  if (topf <= topg) {
327  index = F->index;
328  ft = cuddT(F);
329  fe = cuddE(F);
330  if (Cudd_IsComplement(f)) {
331  ft = Cudd_Not(ft);
332  fe = Cudd_Not(fe);
333  }
334  } else {
335  index = G->index;
336  ft = fe = f;
337  }
338 
339  if (topg <= topf) {
340  gt = cuddT(G);
341  ge = cuddE(G);
342  if (Cudd_IsComplement(g)) {
343  gt = Cudd_Not(gt);
344  ge = Cudd_Not(ge);
345  }
346  } else {
347  gt = ge = g;
348  }
349 
350  t = cuddBddClippingAndRecur(manager, ft, gt, distance, direction);
351  if (t == NULL) return(NULL);
352  cuddRef(t);
353  e = cuddBddClippingAndRecur(manager, fe, ge, distance, direction);
354  if (e == NULL) {
355  Cudd_RecursiveDeref(manager, t);
356  return(NULL);
357  }
358  cuddRef(e);
359 
360  if (t == e) {
361  r = t;
362  } else {
363  if (Cudd_IsComplement(t)) {
364  r = cuddUniqueInter(manager,(int)index,Cudd_Not(t),Cudd_Not(e));
365  if (r == NULL) {
366  Cudd_RecursiveDeref(manager, t);
367  Cudd_RecursiveDeref(manager, e);
368  return(NULL);
369  }
370  r = Cudd_Not(r);
371  } else {
372  r = cuddUniqueInter(manager,(int)index,t,e);
373  if (r == NULL) {
374  Cudd_RecursiveDeref(manager, t);
375  Cudd_RecursiveDeref(manager, e);
376  return(NULL);
377  }
378  }
379  }
380  cuddDeref(e);
381  cuddDeref(t);
382  if (F->ref != 1 || G->ref != 1)
383  cuddCacheInsert2(manager, cacheOp, f, g, r);
384  return(r);
385 
386 } /* end of cuddBddClippingAndRecur */
DdHalfWord ref
Definition: cudd.h:280
#define cuddRef(n)
Definition: cuddInt.h:584
#define cuddDeref(n)
Definition: cuddInt.h:604
void Cudd_RecursiveDeref(DdManager *table, DdNode *n)
Definition: cuddRef.c:154
Definition: cudd.h:278
#define Cudd_Not(node)
Definition: cudd.h:367
void cuddCacheInsert2(DdManager *table, DD_CTFP op, DdNode *f, DdNode *g, DdNode *data)
Definition: cuddCache.c:277
#define Cudd_Regular(node)
Definition: cudd.h:397
DdNode *(* DD_CTFP)(DdManager *, DdNode *, DdNode *)
Definition: cudd.h:321
#define statLine(dd)
Definition: cuddInt.h:1037
DdNode * cuddBddClippingAnd(DdManager *dd, DdNode *f, DdNode *g, int maxDepth, int direction)
Definition: cuddClip.c:201
DdNode * cuddCacheLookup2(DdManager *table, DD_CTFP op, DdNode *f, DdNode *g)
Definition: cuddCache.c:502
#define Cudd_IsComplement(node)
Definition: cudd.h:425
static DdNode * one
Definition: cuddDecomp.c:112
static DdNode * cuddBddClippingAndRecur(DdManager *manager, DdNode *f, DdNode *g, int distance, int direction)
Definition: cuddClip.c:269
#define cuddT(node)
Definition: cuddInt.h:636
int Cudd_bddLeq(DdManager *dd, DdNode *f, DdNode *g)
Definition: cuddBddIte.c:536
DdHalfWord index
Definition: cudd.h:279
#define cuddE(node)
Definition: cuddInt.h:652
#define Cudd_NotCond(node, c)
Definition: cudd.h:383
#define DD_ONE(dd)
Definition: cuddInt.h:911
int * perm
Definition: cuddInt.h:386
DdNode * cuddUniqueInter(DdManager *unique, int index, DdNode *T, DdNode *E)
Definition: cuddTable.c:1128
static DdNode * zero
Definition: cuddApa.c:100
DdNode * Cudd_bddClippingAnd(DdManager *dd, DdNode *f, DdNode *g, int maxDepth, int direction)
Definition: cuddClip.c:129

Variable Documentation

ABC_NAMESPACE_IMPL_START char rcsid [] DD_UNUSED = "$Id: cuddClip.c,v 1.8 2004/08/13 18:04:47 fabio Exp $"
static

CFile***********************************************************************

FileName [cuddClip.c]

PackageName [cudd]

Synopsis [Clipping functions.]

Description [External procedures included in this module:

Internal procedures included in this module:

Static procedures included in this module:

SeeAlso []

Author [Fabio Somenzi]

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.]

Definition at line 90 of file cuddClip.c.