abc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
cuddZddMisc.c
Go to the documentation of this file.
1 /**CFile***********************************************************************
2 
3  FileName [cuddZddMisc.c]
4 
5  PackageName [cudd]
6 
7  Synopsis [Miscellaneous utility functions for ZDDs.]
8 
9  Description [External procedures included in this module:
10  <ul>
11  <li> Cudd_zddDagSize()
12  <li> Cudd_zddCountMinterm()
13  <li> Cudd_zddPrintSubtable()
14  </ul>
15  Internal procedures included in this module:
16  <ul>
17  </ul>
18  Static procedures included in this module:
19  <ul>
20  <li> cuddZddDagInt()
21  </ul>
22  ]
23 
24  SeeAlso []
25 
26  Author [Hyong-Kyoon Shin, In-Ho Moon]
27 
28  Copyright [Copyright (c) 1995-2004, Regents of the University of Colorado
29 
30  All rights reserved.
31 
32  Redistribution and use in source and binary forms, with or without
33  modification, are permitted provided that the following conditions
34  are met:
35 
36  Redistributions of source code must retain the above copyright
37  notice, this list of conditions and the following disclaimer.
38 
39  Redistributions in binary form must reproduce the above copyright
40  notice, this list of conditions and the following disclaimer in the
41  documentation and/or other materials provided with the distribution.
42 
43  Neither the name of the University of Colorado nor the names of its
44  contributors may be used to endorse or promote products derived from
45  this software without specific prior written permission.
46 
47  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
48  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
49  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
50  FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
51  COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
52  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
53  BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
54  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
55  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
56  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
57  ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
58  POSSIBILITY OF SUCH DAMAGE.]
59 
60 ******************************************************************************/
61 
62 #include <math.h>
63 #include "misc/util/util_hack.h"
64 #include "cuddInt.h"
65 
67 
68 
69 
70 /*---------------------------------------------------------------------------*/
71 /* Constant declarations */
72 /*---------------------------------------------------------------------------*/
73 
74 
75 /*---------------------------------------------------------------------------*/
76 /* Stucture declarations */
77 /*---------------------------------------------------------------------------*/
78 
79 
80 /*---------------------------------------------------------------------------*/
81 /* Type declarations */
82 /*---------------------------------------------------------------------------*/
83 
84 
85 /*---------------------------------------------------------------------------*/
86 /* Variable declarations */
87 /*---------------------------------------------------------------------------*/
88 
89 #ifndef lint
90 static char rcsid[] DD_UNUSED = "$Id: cuddZddMisc.c,v 1.16 2009/02/20 02:14:58 fabio Exp $";
91 #endif
92 
93 /*---------------------------------------------------------------------------*/
94 /* Macro declarations */
95 /*---------------------------------------------------------------------------*/
96 
97 
98 /**AutomaticStart*************************************************************/
99 
100 /*---------------------------------------------------------------------------*/
101 /* Static function prototypes */
102 /*---------------------------------------------------------------------------*/
103 
104 static int cuddZddDagInt (DdNode *n, st__table *tab);
105 
106 /**AutomaticEnd***************************************************************/
107 
108 
109 /*---------------------------------------------------------------------------*/
110 /* Definition of exported functions */
111 /*---------------------------------------------------------------------------*/
112 
113 
114 /**Function********************************************************************
115 
116  Synopsis [Counts the number of nodes in a ZDD.]
117 
118  Description [Counts the number of nodes in a ZDD. This function
119  duplicates Cudd_DagSize and is only retained for compatibility.]
120 
121  SideEffects [None]
122 
123  SeeAlso [Cudd_DagSize]
124 
125 ******************************************************************************/
126 int
128  DdNode * p_node)
129 {
130 
131  int i;
132  st__table *table;
133 
135  i = cuddZddDagInt(p_node, table);
136  st__free_table(table);
137  return(i);
138 
139 } /* end of Cudd_zddDagSize */
140 
141 
142 /**Function********************************************************************
143 
144  Synopsis [Counts the number of minterms of a ZDD.]
145 
146  Description [Counts the number of minterms of the ZDD rooted at
147  <code>node</code>. This procedure takes a parameter
148  <code>path</code> that specifies how many variables are in the
149  support of the function. If the procedure runs out of memory, it
150  returns (double) CUDD_OUT_OF_MEM.]
151 
152  SideEffects [None]
153 
154  SeeAlso [Cudd_zddCountDouble]
155 
156 ******************************************************************************/
157 double
159  DdManager * zdd,
160  DdNode * node,
161  int path)
162 {
163  double dc_var, minterms;
164 
165  dc_var = (double)((double)(zdd->sizeZ) - (double)path);
166  minterms = Cudd_zddCountDouble(zdd, node) / pow(2.0, dc_var);
167  return(minterms);
168 
169 } /* end of Cudd_zddCountMinterm */
170 
171 
172 /**Function********************************************************************
173 
174  Synopsis [Prints the ZDD table.]
175 
176  Description [Prints the ZDD table for debugging purposes.]
177 
178  SideEffects [None]
179 
180  SeeAlso []
181 
182 ******************************************************************************/
183 void
185  DdManager * table)
186 {
187  int i, j;
188  DdNode *z1, *z1_next, *base;
189  DdSubtable *ZSubTable;
190 
191  base = table->one;
192  for (i = table->sizeZ - 1; i >= 0; i--) {
193  ZSubTable = &(table->subtableZ[i]);
194  printf("subtable[%d]:\n", i);
195  for (j = ZSubTable->slots - 1; j >= 0; j--) {
196  z1 = ZSubTable->nodelist[j];
197  while (z1 != NIL(DdNode)) {
198  (void) fprintf(table->out,
199 #if SIZEOF_VOID_P == 8
200  "ID = 0x%lx\tindex = %u\tr = %u\t",
201  (ptruint) z1 / (ptruint) sizeof(DdNode),
202  z1->index, z1->ref);
203 #else
204  "ID = 0x%x\tindex = %hu\tr = %hu\t",
205  (ptruint) z1 / (ptruint) sizeof(DdNode),
206  z1->index, z1->ref);
207 #endif
208  z1_next = cuddT(z1);
209  if (Cudd_IsConstant(z1_next)) {
210  (void) fprintf(table->out, "T = %d\t\t",
211  (z1_next == base));
212  }
213  else {
214 #if SIZEOF_VOID_P == 8
215  (void) fprintf(table->out, "T = 0x%lx\t",
216  (ptruint) z1_next / (ptruint) sizeof(DdNode));
217 #else
218  (void) fprintf(table->out, "T = 0x%x\t",
219  (ptruint) z1_next / (ptruint) sizeof(DdNode));
220 #endif
221  }
222  z1_next = cuddE(z1);
223  if (Cudd_IsConstant(z1_next)) {
224  (void) fprintf(table->out, "E = %d\n",
225  (z1_next == base));
226  }
227  else {
228 #if SIZEOF_VOID_P == 8
229  (void) fprintf(table->out, "E = 0x%lx\n",
230  (ptruint) z1_next / (ptruint) sizeof(DdNode));
231 #else
232  (void) fprintf(table->out, "E = 0x%x\n",
233  (ptruint) z1_next / (ptruint) sizeof(DdNode));
234 #endif
235  }
236 
237  z1_next = z1->next;
238  z1 = z1_next;
239  }
240  }
241  }
242  putchar('\n');
243 
244 } /* Cudd_zddPrintSubtable */
245 
246 
247 /*---------------------------------------------------------------------------*/
248 /* Definition of static functions */
249 /*---------------------------------------------------------------------------*/
250 
251 
252 /**Function********************************************************************
253 
254  Synopsis [Performs the recursive step of Cudd_zddDagSize.]
255 
256  Description [Performs the recursive step of Cudd_zddDagSize. Does
257  not check for out-of-memory conditions.]
258 
259  SideEffects [None]
260 
261  SeeAlso []
262 
263 ******************************************************************************/
264 static int
266  DdNode * n,
267  st__table * tab)
268 {
269  if (n == NIL(DdNode))
270  return(0);
271 
272  if ( st__is_member(tab, (char *)n) == 1)
273  return(0);
274 
275  if (Cudd_IsConstant(n))
276  return(0);
277 
278  (void) st__insert(tab, (char *)n, NIL(char));
279  return(1 + cuddZddDagInt(cuddT(n), tab) +
280  cuddZddDagInt(cuddE(n), tab));
281 
282 } /* cuddZddDagInt */
283 
284 
286 
DdHalfWord ref
Definition: cudd.h:280
void st__free_table(st__table *table)
Definition: st.c:81
Definition: cudd.h:278
#define z1
Definition: extraBdd.h:78
double Cudd_zddCountMinterm(DdManager *zdd, DdNode *node, int path)
Definition: cuddZddMisc.c:158
int st__insert(st__table *table, const char *key, char *value)
Definition: st.c:171
#define Cudd_IsConstant(node)
Definition: cudd.h:352
int st__ptrcmp(const char *, const char *)
Definition: st.c:480
#define st__is_member(table, key)
Definition: st.h:70
#define NIL(type)
Definition: avl.h:25
struct DdNode DdNode
Definition: cudd.h:270
ABC_PTRUINT_T ptruint
Definition: cuddInt.h:261
st__table * st__init_table(st__compare_func_type compare, st__hash_func_type hash)
Definition: st.c:72
#define SIZEOF_VOID_P
Definition: cudd.h:78
FILE * out
Definition: cuddInt.h:441
Definition: st.h:52
int Cudd_zddDagSize(DdNode *p_node)
Definition: cuddZddMisc.c:127
static int cuddZddDagInt(DdNode *n, st__table *tab)
Definition: cuddZddMisc.c:265
DdNode * next
Definition: cudd.h:281
#define ABC_NAMESPACE_IMPL_END
Definition: abc_global.h:108
void Cudd_zddPrintSubtable(DdManager *table)
Definition: cuddZddMisc.c:184
DdNode ** nodelist
Definition: cuddInt.h:327
#define cuddT(node)
Definition: cuddInt.h:636
#define ABC_NAMESPACE_IMPL_START
Definition: abc_global.h:107
int sizeZ
Definition: cuddInt.h:362
DdHalfWord index
Definition: cudd.h:279
unsigned int slots
Definition: cuddInt.h:329
DdNode * one
Definition: cuddInt.h:345
#define cuddE(node)
Definition: cuddInt.h:652
double Cudd_zddCountDouble(DdManager *zdd, DdNode *P)
Definition: cuddZddCount.c:176
static ABC_NAMESPACE_IMPL_START char rcsid[] DD_UNUSED
Definition: cuddZddMisc.c:90
int st__ptrhash(const char *, int)
Definition: st.c:468
pset minterms()
DdSubtable * subtableZ
Definition: cuddInt.h:366