SVF
cuddCof.c
Go to the documentation of this file.
1 
59 #include "CUDD/util.h"
60 #include "CUDD/cuddInt.h"
61 
62 /*---------------------------------------------------------------------------*/
63 /* Constant declarations */
64 /*---------------------------------------------------------------------------*/
65 
66 
67 /*---------------------------------------------------------------------------*/
68 /* Stucture declarations */
69 /*---------------------------------------------------------------------------*/
70 
71 
72 /*---------------------------------------------------------------------------*/
73 /* Type declarations */
74 /*---------------------------------------------------------------------------*/
75 
76 
77 /*---------------------------------------------------------------------------*/
78 /* Variable declarations */
79 /*---------------------------------------------------------------------------*/
80 
81 #ifndef lint
82 static char rcsid[] DD_UNUSED = "$Id: cuddCof.c,v 1.11 2012/02/05 01:07:18 fabio Exp $";
83 #endif
84 
85 /*---------------------------------------------------------------------------*/
86 /* Macro declarations */
87 /*---------------------------------------------------------------------------*/
88 
89 
92 /*---------------------------------------------------------------------------*/
93 /* Static function prototypes */
94 /*---------------------------------------------------------------------------*/
95 
96 
100 /*---------------------------------------------------------------------------*/
101 /* Definition of exported functions */
102 /*---------------------------------------------------------------------------*/
103 
104 
118 DdNode *
120  DdManager * dd,
121  DdNode * f,
122  DdNode * g)
123 {
124  DdNode *res,*zero;
125 
126  zero = Cudd_Not(DD_ONE(dd));
127  if (g == zero || g == DD_ZERO(dd)) {
128  (void) fprintf(dd->err,"Cudd_Cofactor: Invalid restriction 1\n");
130  return(NULL);
131  }
132  do {
133  dd->reordered = 0;
134  res = cuddCofactorRecur(dd,f,g);
135  } while (dd->reordered == 1);
136  return(res);
137 
138 } /* end of Cudd_Cofactor */
139 
140 
154 int
156  DdManager * dd,
157  DdNode * g)
158 {
159  DdNode *g1,*g0,*one,*zero;
160 
161  one = DD_ONE(dd);
162  if (g == one) return(1);
163  if (Cudd_IsConstant(g)) return(0);
164 
165  zero = Cudd_Not(one);
166  cuddGetBranches(g,&g1,&g0);
167 
168  if (g0 == zero) {
169  return(Cudd_CheckCube(dd, g1));
170  }
171  if (g1 == zero) {
172  return(Cudd_CheckCube(dd, g0));
173  }
174  return(0);
175 
176 } /* end of Cudd_CheckCube */
177 
178 
179 /*---------------------------------------------------------------------------*/
180 /* Definition of internal functions */
181 /*---------------------------------------------------------------------------*/
182 
183 
195 void
197  DdNode * g,
198  DdNode ** g1,
199  DdNode ** g0)
200 {
201  DdNode *G = Cudd_Regular(g);
202 
203  *g1 = cuddT(G);
204  *g0 = cuddE(G);
205  if (Cudd_IsComplement(g)) {
206  *g1 = Cudd_Not(*g1);
207  *g0 = Cudd_Not(*g0);
208  }
209 
210 } /* end of cuddGetBranches */
211 
212 
225 DdNode *
227  DdManager * dd,
228  DdNode * f,
229  DdNode * g)
230 {
231  DdNode *one,*zero,*F,*G,*g1,*g0,*f1,*f0,*t,*e,*r;
232  unsigned int topf,topg;
233  int comple;
234 
235  statLine(dd);
236  F = Cudd_Regular(f);
237  if (cuddIsConstant(F)) return(f);
238 
239  one = DD_ONE(dd);
240 
241  /* The invariant g != 0 is true on entry to this procedure and is
242  ** recursively maintained by it. Therefore it suffices to test g
243  ** against one to make sure it is not constant.
244  */
245  if (g == one) return(f);
246  /* From now on, f and g are known not to be constants. */
247 
248  comple = f != F;
249  r = cuddCacheLookup2(dd,Cudd_Cofactor,F,g);
250  if (r != NULL) {
251  return(Cudd_NotCond(r,comple));
252  }
253 
254  topf = dd->perm[F->index];
255  G = Cudd_Regular(g);
256  topg = dd->perm[G->index];
257 
258  /* We take the cofactors of F because we are going to rely on
259  ** the fact that the cofactors of the complement are the complements
260  ** of the cofactors to better utilize the cache. Variable comple
261  ** remembers whether we have to complement the result or not.
262  */
263  if (topf <= topg) {
264  f1 = cuddT(F); f0 = cuddE(F);
265  } else {
266  f1 = f0 = F;
267  }
268  if (topg <= topf) {
269  g1 = cuddT(G); g0 = cuddE(G);
270  if (g != G) { g1 = Cudd_Not(g1); g0 = Cudd_Not(g0); }
271  } else {
272  g1 = g0 = g;
273  }
274 
275  zero = Cudd_Not(one);
276  if (topf >= topg) {
277  if (g0 == zero || g0 == DD_ZERO(dd)) {
278  r = cuddCofactorRecur(dd, f1, g1);
279  } else if (g1 == zero || g1 == DD_ZERO(dd)) {
280  r = cuddCofactorRecur(dd, f0, g0);
281  } else {
282  (void) fprintf(dd->out,
283  "Cudd_Cofactor: Invalid restriction 2\n");
285  return(NULL);
286  }
287  if (r == NULL) return(NULL);
288  } else /* if (topf < topg) */ {
289  t = cuddCofactorRecur(dd, f1, g);
290  if (t == NULL) return(NULL);
291  cuddRef(t);
292  e = cuddCofactorRecur(dd, f0, g);
293  if (e == NULL) {
294  Cudd_RecursiveDeref(dd, t);
295  return(NULL);
296  }
297  cuddRef(e);
298 
299  if (t == e) {
300  r = t;
301  } else if (Cudd_IsComplement(t)) {
302  r = cuddUniqueInter(dd,(int)F->index,Cudd_Not(t),Cudd_Not(e));
303  if (r != NULL)
304  r = Cudd_Not(r);
305  } else {
306  r = cuddUniqueInter(dd,(int)F->index,t,e);
307  }
308  if (r == NULL) {
309  Cudd_RecursiveDeref(dd ,e);
310  Cudd_RecursiveDeref(dd ,t);
311  return(NULL);
312  }
313  cuddDeref(t);
314  cuddDeref(e);
315  }
316 
318 
319  return(Cudd_NotCond(r,comple));
320 
321 } /* end of cuddCofactorRecur */
322 
323 
324 /*---------------------------------------------------------------------------*/
325 /* Definition of static functions */
326 /*---------------------------------------------------------------------------*/
327 
#define cuddRef(n)
Definition: cuddInt.h:557
#define cuddDeref(n)
Definition: cuddInt.h:577
void Cudd_RecursiveDeref(DdManager *table, DdNode *n)
Definition: cuddRef.c:150
Definition: cudd.h:270
#define Cudd_Not(node)
Definition: cudd.h:354
DdNode * cuddCacheLookup2(DdManager *table, DdNode *(*)(DdManager *, DdNode *, DdNode *), DdNode *f, DdNode *g)
#define Cudd_IsConstant(node)
Definition: cudd.h:339
#define Cudd_Regular(node)
Definition: cudd.h:384
FILE * err
Definition: cuddInt.h:424
void cuddGetBranches(DdNode *g, DdNode **g1, DdNode **g0)
Definition: cuddCof.c:196
DdNode * Cudd_Cofactor(DdManager *dd, DdNode *f, DdNode *g)
Definition: cuddCof.c:119
#define statLine(dd)
Definition: cuddInt.h:990
int reordered
Definition: cuddInt.h:392
static DdNode * one
Definition: cuddSat.c:105
#define Cudd_IsComplement(node)
Definition: cudd.h:412
FILE * out
Definition: cuddInt.h:423
#define cuddIsConstant(node)
Definition: cuddInt.h:593
#define cuddT(node)
Definition: cuddInt.h:609
DdNode * cuddCofactorRecur(DdManager *dd, DdNode *f, DdNode *g)
Definition: cuddCof.c:226
void cuddCacheInsert2(DdManager *table, DdNode *(*)(DdManager *, DdNode *, DdNode *), DdNode *f, DdNode *g, DdNode *data)
DdHalfWord index
Definition: cudd.h:271
static DdNode * zero
Definition: cuddSat.c:105
static char rcsid [] DD_UNUSED
Definition: cuddCof.c:82
#define cuddE(node)
Definition: cuddInt.h:625
#define Cudd_NotCond(node, c)
Definition: cudd.h:370
int Cudd_CheckCube(DdManager *dd, DdNode *g)
Definition: cuddCof.c:155
#define DD_ONE(dd)
Definition: cuddInt.h:864
int * perm
Definition: cuddInt.h:369
Cudd_ErrorType errorCode
Definition: cuddInt.h:425
DdNode * cuddUniqueInter(DdManager *unique, int index, DdNode *T, DdNode *E)
Definition: cuddTable.c:1137
#define DD_ZERO(dd)
Definition: cuddInt.h:880