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

Go to the source code of this file.

Functions

static double * ddCofMintermAux (DdManager *dd, DdNode *node, st__table *table)
 
double * Cudd_CofMinterm (DdManager *dd, DdNode *node)
 

Variables

static
ABC_NAMESPACE_IMPL_START char
rcsid[] 
DD_UNUSED = "$Id: cuddSign.c,v 1.22 2009/02/20 02:14:58 fabio Exp $"
 
static int size
 

Function Documentation

double* Cudd_CofMinterm ( DdManager dd,
DdNode node 
)

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

Synopsis [Computes the fraction of minterms in the on-set of all the positive cofactors of a BDD or ADD.]

Description [Computes the fraction of minterms in the on-set of all the positive cofactors of DD. Returns the pointer to an array of doubles if successful; NULL otherwise. The array has as many positions as there are BDD variables in the manager plus one. The last position of the array contains the fraction of the minterms in the ON-set of the function represented by the BDD or ADD. The other positions of the array hold the variable signatures.]

SideEffects [None]

Definition at line 131 of file cuddSign.c.

134 {
135  st__table *table;
136  double *values;
137  double *result = NULL;
138  int i, firstLevel;
139 
140 #ifdef DD_STATS
141  long startTime;
142  startTime = util_cpu_time();
143  num_calls = 0;
144  table_mem = sizeof( st__table);
145 #endif
146 
148  if (table == NULL) {
149  (void) fprintf(dd->err,
150  "out-of-memory, couldn't measure DD cofactors.\n");
152  return(NULL);
153  }
154  size = dd->size;
155  values = ddCofMintermAux(dd, node, table);
156  if (values != NULL) {
157  result = ABC_ALLOC(double,size + 1);
158  if (result != NULL) {
159 #ifdef DD_STATS
160  table_mem += (size + 1) * sizeof(double);
161 #endif
162  if (Cudd_IsConstant(node))
163  firstLevel = 1;
164  else
165  firstLevel = cuddI(dd,Cudd_Regular(node)->index);
166  for (i = 0; i < size; i++) {
167  if (i >= cuddI(dd,Cudd_Regular(node)->index)) {
168  result[dd->invperm[i]] = values[i - firstLevel];
169  } else {
170  result[dd->invperm[i]] = values[size - firstLevel];
171  }
172  }
173  result[size] = values[size - firstLevel];
174  } else {
176  }
177  }
178 
179 #ifdef DD_STATS
180  table_mem += table->num_bins * sizeof( st__table_entry *);
181 #endif
182  if (Cudd_Regular(node)->ref == 1) ABC_FREE(values);
183  st__foreach(table, cuddStCountfree, NULL);
184  st__free_table(table);
185 #ifdef DD_STATS
186  (void) fprintf(dd->out,"Number of calls: %d\tTable memory: %d bytes\n",
187  num_calls, table_mem);
188  (void) fprintf(dd->out,"Time to compute measures: %s\n",
189  util_print_time(util_cpu_time() - startTime));
190 #endif
191  if (result == NULL) {
192  (void) fprintf(dd->out,
193  "out-of-memory, couldn't measure DD cofactors.\n");
195  }
196  return(result);
197 
198 } /* end of Cudd_CofMinterm */
void st__free_table(st__table *table)
Definition: st.c:81
struct st__table st__table
Definition: st.h:51
int num_bins
Definition: st.h:55
static double * ddCofMintermAux(DdManager *dd, DdNode *node, st__table *table)
Definition: cuddSign.c:232
int size
Definition: cuddInt.h:361
#define Cudd_IsConstant(node)
Definition: cudd.h:352
#define Cudd_Regular(node)
Definition: cudd.h:397
enum st__retval cuddStCountfree(char *key, char *value, char *arg)
Definition: cuddUtil.c:2895
int st__ptrcmp(const char *, const char *)
Definition: st.c:480
FILE * err
Definition: cuddInt.h:442
#define ABC_ALLOC(type, num)
Definition: abc_global.h:229
#define util_cpu_time
Definition: util_hack.h:36
st__table * st__init_table(st__compare_func_type compare, st__hash_func_type hash)
Definition: st.c:72
FILE * out
Definition: cuddInt.h:441
Definition: st.h:52
Definition: st.h:45
static int size
Definition: cuddSign.c:86
int st__foreach(st__table *table, enum st__retval(*func)(char *, char *, char *), char *arg)
Definition: st.c:421
#define cuddI(dd, index)
Definition: cuddInt.h:686
#define ABC_FREE(obj)
Definition: abc_global.h:232
int * invperm
Definition: cuddInt.h:388
static int result
Definition: cuddGenetic.c:125
Cudd_ErrorType errorCode
Definition: cuddInt.h:447
int st__ptrhash(const char *, int)
Definition: st.c:468
static double * ddCofMintermAux ( DdManager dd,
DdNode node,
st__table table 
)
static

AutomaticStart

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

Synopsis [Recursive Step for Cudd_CofMinterm function.]

Description [Traverses the DD node and computes the fraction of minterms in the on-set of all positive cofactors simultaneously. It allocates an array with two more entries than there are variables below the one labeling the node. One extra entry (the first in the array) is for the variable labeling the node. The other entry (the last one in the array) holds the fraction of minterms of the function rooted at node. Each other entry holds the value for one cofactor. The array is put in a symbol table, to avoid repeated computation, and its address is returned by the procedure, for use by the caller. Returns a pointer to the array of cofactor measures.]

SideEffects [None]

SeeAlso []

Definition at line 232 of file cuddSign.c.

236 {
237  DdNode *N; /* regular version of node */
238  DdNode *Nv, *Nnv;
239  double *values;
240  double *valuesT, *valuesE;
241  int i;
242  int localSize, localSizeT, localSizeE;
243  double vT, vE;
244 
245  statLine(dd);
246 #ifdef DD_STATS
247  num_calls++;
248 #endif
249 
250  if ( st__lookup(table, (const char *)node, (char **)&values)) {
251  return(values);
252  }
253 
254  N = Cudd_Regular(node);
255  if (cuddIsConstant(N)) {
256  localSize = 1;
257  } else {
258  localSize = size - cuddI(dd,N->index) + 1;
259  }
260  values = ABC_ALLOC(double, localSize);
261  if (values == NULL) {
263  return(NULL);
264  }
265 
266  if (cuddIsConstant(N)) {
267  if (node == DD_ZERO(dd) || node == Cudd_Not(DD_ONE(dd))) {
268  values[0] = 0.0;
269  } else {
270  values[0] = 1.0;
271  }
272  } else {
273  Nv = Cudd_NotCond(cuddT(N),N!=node);
274  Nnv = Cudd_NotCond(cuddE(N),N!=node);
275 
276  valuesT = ddCofMintermAux(dd, Nv, table);
277  if (valuesT == NULL) return(NULL);
278  valuesE = ddCofMintermAux(dd, Nnv, table);
279  if (valuesE == NULL) return(NULL);
280 
281  if (Cudd_IsConstant(Nv)) {
282  localSizeT = 1;
283  } else {
284  localSizeT = size - cuddI(dd,Cudd_Regular(Nv)->index) + 1;
285  }
286  if (Cudd_IsConstant(Nnv)) {
287  localSizeE = 1;
288  } else {
289  localSizeE = size - cuddI(dd,Cudd_Regular(Nnv)->index) + 1;
290  }
291  values[0] = valuesT[localSizeT - 1];
292  for (i = 1; i < localSize; i++) {
293  if (i >= cuddI(dd,Cudd_Regular(Nv)->index) - cuddI(dd,N->index)) {
294  vT = valuesT[i - cuddI(dd,Cudd_Regular(Nv)->index) +
295  cuddI(dd,N->index)];
296  } else {
297  vT = valuesT[localSizeT - 1];
298  }
299  if (i >= cuddI(dd,Cudd_Regular(Nnv)->index) - cuddI(dd,N->index)) {
300  vE = valuesE[i - cuddI(dd,Cudd_Regular(Nnv)->index) +
301  cuddI(dd,N->index)];
302  } else {
303  vE = valuesE[localSizeE - 1];
304  }
305  values[i] = (vT + vE) / 2.0;
306  }
307  if (Cudd_Regular(Nv)->ref == 1) ABC_FREE(valuesT);
308  if (Cudd_Regular(Nnv)->ref == 1) ABC_FREE(valuesE);
309  }
310 
311  if (N->ref > 1) {
312  if ( st__add_direct(table, (char *) node, (char *) values) == st__OUT_OF_MEM) {
313  ABC_FREE(values);
314  return(NULL);
315  }
316 #ifdef DD_STATS
317  table_mem += localSize * sizeof(double) + sizeof( st__table_entry);
318 #endif
319  }
320  return(values);
321 
322 } /* end of ddCofMintermAux */
DdHalfWord ref
Definition: cudd.h:280
Definition: cudd.h:278
#define Cudd_Not(node)
Definition: cudd.h:367
static double * ddCofMintermAux(DdManager *dd, DdNode *node, st__table *table)
Definition: cuddSign.c:232
#define Cudd_IsConstant(node)
Definition: cudd.h:352
#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
Definition: st.h:45
#define cuddIsConstant(node)
Definition: cuddInt.h:620
static int size
Definition: cuddSign.c:86
#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
int st__add_direct(st__table *table, char *key, char *value)
Definition: st.c:205
#define Cudd_NotCond(node, c)
Definition: cudd.h:383
#define DD_ONE(dd)
Definition: cuddInt.h:911
Cudd_ErrorType errorCode
Definition: cuddInt.h:447
#define DD_ZERO(dd)
Definition: cuddInt.h:927

Variable Documentation

ABC_NAMESPACE_IMPL_START char rcsid [] DD_UNUSED = "$Id: cuddSign.c,v 1.22 2009/02/20 02:14:58 fabio Exp $"
static

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

FileName [cuddSign.c]

PackageName [cudd]

Synopsis [Computation of signatures.]

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

Definition at line 83 of file cuddSign.c.

int size
static

Definition at line 86 of file cuddSign.c.