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

Go to the source code of this file.

Data Structures

struct  hashEntry
 

Typedefs

typedef
ABC_NAMESPACE_IMPL_START
struct hashEntry 
HashEntry
 

Functions

static double bddCorrelationAux (DdManager *dd, DdNode *f, DdNode *g, st__table *table)
 
static double bddCorrelationWeightsAux (DdManager *dd, DdNode *f, DdNode *g, double *prob, st__table *table)
 
static int CorrelCompare (const char *key1, const char *key2)
 
static int CorrelHash (const char *key, int modulus)
 
static enum st__retval CorrelCleanUp (char *key, char *value, char *arg)
 
double Cudd_bddCorrelation (DdManager *manager, DdNode *f, DdNode *g)
 
double Cudd_bddCorrelationWeights (DdManager *manager, DdNode *f, DdNode *g, double *prob)
 

Variables

static char rcsid[] DD_UNUSED = "$Id: cuddBddCorr.c,v 1.14 2004/08/13 18:04:46 fabio Exp $"
 

Typedef Documentation

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

FileName [cuddBddCorr.c]

PackageName [cudd]

Synopsis [Correlation between BDDs.]

Description [External procedures included in this module:

Static procedures included in this module:

]

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

Function Documentation

static double bddCorrelationAux ( DdManager dd,
DdNode f,
DdNode g,
st__table table 
)
static

AutomaticStart

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

Synopsis [Performs the recursive step of Cudd_bddCorrelation.]

Description [Performs the recursive step of Cudd_bddCorrelation. Returns the fraction of minterms in the ON-set of the EXNOR of f and g.]

SideEffects [None]

SeeAlso [bddCorrelationWeightsAux]

Definition at line 237 of file cuddBddCorr.c.

242 {
243  DdNode *Fv, *Fnv, *G, *Gv, *Gnv;
244  double min, *pmin, min1, min2, *dummy;
245  HashEntry *entry;
246  unsigned int topF, topG;
247 
248  statLine(dd);
249 #ifdef CORREL_STATS
250  num_calls++;
251 #endif
252 
253  /* Terminal cases: only work for BDDs. */
254  if (f == g) return(1.0);
255  if (f == Cudd_Not(g)) return(0.0);
256 
257  /* Standardize call using the following properties:
258  ** (f EXNOR g) = (g EXNOR f)
259  ** (f' EXNOR g') = (f EXNOR g).
260  */
261  if (cuddF2L(f) > cuddF2L(g)) {
262  DdNode *tmp = f;
263  f = g; g = tmp;
264  }
265  if (Cudd_IsComplement(f)) {
266  f = Cudd_Not(f);
267  g = Cudd_Not(g);
268  }
269  /* From now on, f is regular. */
270 
271  entry = ABC_ALLOC(HashEntry,1);
272  if (entry == NULL) {
274  return(CUDD_OUT_OF_MEM);
275  }
276  entry->f = f; entry->g = g;
277 
278  /* We do not use the fact that
279  ** correlation(f,g') = 1 - correlation(f,g)
280  ** to minimize the risk of cancellation.
281  */
282  if ( st__lookup(table, (const char *)entry, (char **)&dummy)) {
283  min = *dummy;
284  ABC_FREE(entry);
285  return(min);
286  }
287 
288  G = Cudd_Regular(g);
289  topF = cuddI(dd,f->index); topG = cuddI(dd,G->index);
290  if (topF <= topG) { Fv = cuddT(f); Fnv = cuddE(f); } else { Fv = Fnv = f; }
291  if (topG <= topF) { Gv = cuddT(G); Gnv = cuddE(G); } else { Gv = Gnv = G; }
292 
293  if (g != G) {
294  Gv = Cudd_Not(Gv);
295  Gnv = Cudd_Not(Gnv);
296  }
297 
298  min1 = bddCorrelationAux(dd, Fv, Gv, table) / 2.0;
299  if (min1 == (double)CUDD_OUT_OF_MEM) {
300  ABC_FREE(entry);
301  return(CUDD_OUT_OF_MEM);
302  }
303  min2 = bddCorrelationAux(dd, Fnv, Gnv, table) / 2.0;
304  if (min2 == (double)CUDD_OUT_OF_MEM) {
305  ABC_FREE(entry);
306  return(CUDD_OUT_OF_MEM);
307  }
308  min = (min1+min2);
309 
310  pmin = ABC_ALLOC(double,1);
311  if (pmin == NULL) {
313  return((double)CUDD_OUT_OF_MEM);
314  }
315  *pmin = min;
316 
317  if ( st__insert(table,(char *)entry, (char *)pmin) == st__OUT_OF_MEM) {
318  ABC_FREE(entry);
319  ABC_FREE(pmin);
320  return((double)CUDD_OUT_OF_MEM);
321  }
322  return(min);
323 
324 } /* end of bddCorrelationAux */
static double bddCorrelationAux(DdManager *dd, DdNode *f, DdNode *g, st__table *table)
Definition: cuddBddCorr.c:237
#define CUDD_OUT_OF_MEM
Definition: cudd.h:95
Definition: cudd.h:278
#define Cudd_Not(node)
Definition: cudd.h:367
int st__insert(st__table *table, const char *key, char *value)
Definition: st.c:171
#define Cudd_Regular(node)
Definition: cudd.h:397
#define ABC_ALLOC(type, num)
Definition: abc_global.h:229
#define statLine(dd)
Definition: cuddInt.h:1037
static int * entry
Definition: cuddGroup.c:122
#define Cudd_IsComplement(node)
Definition: cudd.h:425
#define cuddF2L(f)
Definition: cuddInt.h:718
#define cuddT(node)
Definition: cuddInt.h:636
#define st__OUT_OF_MEM
Definition: st.h:113
#define cuddI(dd, index)
Definition: cuddInt.h:686
int st__lookup(st__table *table, const char *key, char **value)
Definition: st.c:114
DdHalfWord index
Definition: cudd.h:279
#define ABC_FREE(obj)
Definition: abc_global.h:232
#define cuddE(node)
Definition: cuddInt.h:652
ABC_NAMESPACE_IMPL_START struct hashEntry HashEntry
Cudd_ErrorType errorCode
Definition: cuddInt.h:447
static double bddCorrelationWeightsAux ( DdManager dd,
DdNode f,
DdNode g,
double *  prob,
st__table table 
)
static

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

Synopsis [Performs the recursive step of Cudd_bddCorrelationWeigths.]

Description []

SideEffects [None]

SeeAlso [bddCorrelationAux]

Definition at line 339 of file cuddBddCorr.c.

345 {
346  DdNode *Fv, *Fnv, *G, *Gv, *Gnv;
347  double min, *pmin, min1, min2, *dummy;
348  HashEntry *entry;
349  int topF, topG, index;
350 
351  statLine(dd);
352 #ifdef CORREL_STATS
353  num_calls++;
354 #endif
355 
356  /* Terminal cases: only work for BDDs. */
357  if (f == g) return(1.0);
358  if (f == Cudd_Not(g)) return(0.0);
359 
360  /* Standardize call using the following properties:
361  ** (f EXNOR g) = (g EXNOR f)
362  ** (f' EXNOR g') = (f EXNOR g).
363  */
364  if (cuddF2L(f) > cuddF2L(g)) {
365  DdNode *tmp = f;
366  f = g; g = tmp;
367  }
368  if (Cudd_IsComplement(f)) {
369  f = Cudd_Not(f);
370  g = Cudd_Not(g);
371  }
372  /* From now on, f is regular. */
373 
374  entry = ABC_ALLOC(HashEntry,1);
375  if (entry == NULL) {
377  return((double)CUDD_OUT_OF_MEM);
378  }
379  entry->f = f; entry->g = g;
380 
381  /* We do not use the fact that
382  ** correlation(f,g') = 1 - correlation(f,g)
383  ** to minimize the risk of cancellation.
384  */
385  if ( st__lookup(table, (const char *)entry, (char **)&dummy)) {
386  min = *dummy;
387  ABC_FREE(entry);
388  return(min);
389  }
390 
391  G = Cudd_Regular(g);
392  topF = cuddI(dd,f->index); topG = cuddI(dd,G->index);
393  if (topF <= topG) {
394  Fv = cuddT(f); Fnv = cuddE(f);
395  index = f->index;
396  } else {
397  Fv = Fnv = f;
398  index = G->index;
399  }
400  if (topG <= topF) { Gv = cuddT(G); Gnv = cuddE(G); } else { Gv = Gnv = G; }
401 
402  if (g != G) {
403  Gv = Cudd_Not(Gv);
404  Gnv = Cudd_Not(Gnv);
405  }
406 
407  min1 = bddCorrelationWeightsAux(dd, Fv, Gv, prob, table) * prob[index];
408  if (min1 == (double)CUDD_OUT_OF_MEM) {
409  ABC_FREE(entry);
410  return((double)CUDD_OUT_OF_MEM);
411  }
412  min2 = bddCorrelationWeightsAux(dd, Fnv, Gnv, prob, table) * (1.0 - prob[index]);
413  if (min2 == (double)CUDD_OUT_OF_MEM) {
414  ABC_FREE(entry);
415  return((double)CUDD_OUT_OF_MEM);
416  }
417  min = (min1+min2);
418 
419  pmin = ABC_ALLOC(double,1);
420  if (pmin == NULL) {
422  return((double)CUDD_OUT_OF_MEM);
423  }
424  *pmin = min;
425 
426  if ( st__insert(table,(char *)entry, (char *)pmin) == st__OUT_OF_MEM) {
427  ABC_FREE(entry);
428  ABC_FREE(pmin);
429  return((double)CUDD_OUT_OF_MEM);
430  }
431  return(min);
432 
433 } /* end of bddCorrelationWeightsAux */
#define CUDD_OUT_OF_MEM
Definition: cudd.h:95
Definition: cudd.h:278
#define Cudd_Not(node)
Definition: cudd.h:367
int st__insert(st__table *table, const char *key, char *value)
Definition: st.c:171
static double bddCorrelationWeightsAux(DdManager *dd, DdNode *f, DdNode *g, double *prob, st__table *table)
Definition: cuddBddCorr.c:339
#define Cudd_Regular(node)
Definition: cudd.h:397
#define ABC_ALLOC(type, num)
Definition: abc_global.h:229
#define statLine(dd)
Definition: cuddInt.h:1037
static int * entry
Definition: cuddGroup.c:122
#define Cudd_IsComplement(node)
Definition: cudd.h:425
#define cuddF2L(f)
Definition: cuddInt.h:718
#define cuddT(node)
Definition: cuddInt.h:636
#define st__OUT_OF_MEM
Definition: st.h:113
#define cuddI(dd, index)
Definition: cuddInt.h:686
int st__lookup(st__table *table, const char *key, char **value)
Definition: st.c:114
DdHalfWord index
Definition: cudd.h:279
#define ABC_FREE(obj)
Definition: abc_global.h:232
#define cuddE(node)
Definition: cuddInt.h:652
ABC_NAMESPACE_IMPL_START struct hashEntry HashEntry
Cudd_ErrorType errorCode
Definition: cuddInt.h:447
static enum st__retval CorrelCleanUp ( char *  key,
char *  value,
char *  arg 
)
static

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

Synopsis [Frees memory associated with hash table.]

Description [Frees memory associated with hash table. Returns st__CONTINUE.]

SideEffects [None]

Definition at line 504 of file cuddBddCorr.c.

508 {
509  double *d;
510  HashEntry *entry;
511 
512  entry = (HashEntry *) key;
513  ABC_FREE(entry);
514  d = (double *)value;
515  ABC_FREE(d);
516  return st__CONTINUE;
517 
518 } /* end of CorrelCleanUp */
static int * entry
Definition: cuddGroup.c:122
#define ABC_FREE(obj)
Definition: abc_global.h:232
enum keys key
int value
ABC_NAMESPACE_IMPL_START struct hashEntry HashEntry
static int CorrelCompare ( const char *  key1,
const char *  key2 
)
static

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

Synopsis [Compares two hash table entries.]

Description [Compares two hash table entries. Returns 0 if they are identical; 1 otherwise.]

SideEffects [None]

Definition at line 447 of file cuddBddCorr.c.

450 {
451  HashEntry *entry1;
452  HashEntry *entry2;
453 
454  entry1 = (HashEntry *) key1;
455  entry2 = (HashEntry *) key2;
456  if (entry1->f != entry2->f || entry1->g != entry2->g) return(1);
457 
458  return(0);
459 
460 } /* end of CorrelCompare */
ABC_NAMESPACE_IMPL_START struct hashEntry HashEntry
static int CorrelHash ( const char *  key,
int  modulus 
)
static

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

Synopsis [Hashes a hash table entry.]

Description [Hashes a hash table entry. It is patterned after st__strhash. Returns a value between 0 and modulus.]

SideEffects [None]

Definition at line 474 of file cuddBddCorr.c.

477 {
478  HashEntry *entry;
479  int val = 0;
480 
481  entry = (HashEntry *) key;
482 #if SIZEOF_VOID_P == 8 && SIZEOF_INT == 4
483  val = ((int) ((long)entry->f))*997 + ((int) ((long)entry->g));
484 #else
485  val = ((int) entry->f)*997 + ((int) entry->g);
486 #endif
487 
488  return ((val < 0) ? -val : val) % modulus;
489 
490 } /* end of CorrelHash */
static int * entry
Definition: cuddGroup.c:122
enum keys key
ABC_NAMESPACE_IMPL_START struct hashEntry HashEntry
double Cudd_bddCorrelation ( DdManager manager,
DdNode f,
DdNode g 
)

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

Synopsis [Computes the correlation of f and g.]

Description [Computes the correlation of f and g. If f == g, their correlation is 1. If f == g', their correlation is 0. Returns the fraction of minterms in the ON-set of the EXNOR of f and g. If it runs out of memory, returns (double)CUDD_OUT_OF_MEM.]

SideEffects [None]

SeeAlso [Cudd_bddCorrelationWeights]

Definition at line 147 of file cuddBddCorr.c.

151 {
152 
153  st__table *table;
154  double correlation;
155 
156 #ifdef CORREL_STATS
157  num_calls = 0;
158 #endif
159 
161  if (table == NULL) return((double)CUDD_OUT_OF_MEM);
162  correlation = bddCorrelationAux(manager,f,g,table);
163  st__foreach(table, CorrelCleanUp, NIL(char));
164  st__free_table(table);
165  return(correlation);
166 
167 } /* end of Cudd_bddCorrelation */
static double bddCorrelationAux(DdManager *dd, DdNode *f, DdNode *g, st__table *table)
Definition: cuddBddCorr.c:237
void st__free_table(st__table *table)
Definition: st.c:81
#define CUDD_OUT_OF_MEM
Definition: cudd.h:95
static int CorrelCompare(const char *key1, const char *key2)
Definition: cuddBddCorr.c:447
#define NIL(type)
Definition: avl.h:25
st__table * st__init_table(st__compare_func_type compare, st__hash_func_type hash)
Definition: st.c:72
Definition: st.h:52
static enum st__retval CorrelCleanUp(char *key, char *value, char *arg)
Definition: cuddBddCorr.c:504
int st__foreach(st__table *table, enum st__retval(*func)(char *, char *, char *), char *arg)
Definition: st.c:421
static int CorrelHash(const char *key, int modulus)
Definition: cuddBddCorr.c:474
double Cudd_bddCorrelationWeights ( DdManager manager,
DdNode f,
DdNode g,
double *  prob 
)

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

Synopsis [Computes the correlation of f and g for given input probabilities.]

Description [Computes the correlation of f and g for given input probabilities. On input, prob[i] is supposed to contain the probability of the i-th input variable to be 1. If f == g, their correlation is 1. If f == g', their correlation is 0. Returns the probability that f and g have the same value. If it runs out of memory, returns (double)CUDD_OUT_OF_MEM. The correlation of f and the constant one gives the probability of f.]

SideEffects [None]

SeeAlso [Cudd_bddCorrelation]

Definition at line 189 of file cuddBddCorr.c.

194 {
195 
196  st__table *table;
197  double correlation;
198 
199 #ifdef CORREL_STATS
200  num_calls = 0;
201 #endif
202 
204  if (table == NULL) return((double)CUDD_OUT_OF_MEM);
205  correlation = bddCorrelationWeightsAux(manager,f,g,prob,table);
206  st__foreach(table, CorrelCleanUp, NIL(char));
207  st__free_table(table);
208  return(correlation);
209 
210 } /* end of Cudd_bddCorrelationWeights */
void st__free_table(st__table *table)
Definition: st.c:81
#define CUDD_OUT_OF_MEM
Definition: cudd.h:95
static int CorrelCompare(const char *key1, const char *key2)
Definition: cuddBddCorr.c:447
static double bddCorrelationWeightsAux(DdManager *dd, DdNode *f, DdNode *g, double *prob, st__table *table)
Definition: cuddBddCorr.c:339
#define NIL(type)
Definition: avl.h:25
st__table * st__init_table(st__compare_func_type compare, st__hash_func_type hash)
Definition: st.c:72
Definition: st.h:52
static enum st__retval CorrelCleanUp(char *key, char *value, char *arg)
Definition: cuddBddCorr.c:504
int st__foreach(st__table *table, enum st__retval(*func)(char *, char *, char *), char *arg)
Definition: st.c:421
static int CorrelHash(const char *key, int modulus)
Definition: cuddBddCorr.c:474

Variable Documentation

char rcsid [] DD_UNUSED = "$Id: cuddBddCorr.c,v 1.14 2004/08/13 18:04:46 fabio Exp $"
static

Definition at line 93 of file cuddBddCorr.c.