source: vis_dev/glu-2.3/src/calBdd/calPrintProfile.c @ 26

Last change on this file since 26 was 13, checked in by cecile, 13 years ago

library glu 2.3

File size: 10.6 KB
Line 
1/**CFile***********************************************************************
2
3  FileName    [calPrintProfile.c]
4
5  PackageName [cal]
6
7  Synopsis    [Routines for printing various profiles for a BDD.]
8
9  Description [ ]
10
11  SeeAlso     [optional]
12
13  Author      [Jagesh Sanghavi (sanghavi@eecs.berkeley.edu)
14               Rajeev Ranjan   (rajeev@eecs.berkeley.edu)
15               Originally written by David Long.
16              ]
17
18  Copyright   [Copyright (c) 1994-1996 The Regents of the Univ. of California.
19  All rights reserved.
20
21  Permission is hereby granted, without written agreement and without license
22  or royalty fees, to use, copy, modify, and distribute this software and its
23  documentation for any purpose, provided that the above copyright notice and
24  the following two paragraphs appear in all copies of this software.
25
26  IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR
27  DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
28  OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF
29  CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30
31  THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
32  INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
33  FITNESS FOR A PARTICULAR PURPOSE.  THE SOFTWARE PROVIDED HEREUNDER IS ON AN
34  "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO PROVIDE
35  MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.]
36
37  Revision    [$Id: calPrintProfile.c,v 1.1.1.3 1998/05/04 00:59:01 hsv Exp $]
38
39******************************************************************************/
40
41#include "calInt.h"
42
43/*---------------------------------------------------------------------------*/
44/* Constant declarations                                                     */
45/*---------------------------------------------------------------------------*/
46
47/*---------------------------------------------------------------------------*/
48/* Type declarations                                                         */
49/*---------------------------------------------------------------------------*/
50
51/*---------------------------------------------------------------------------*/
52/* Stucture declarations                                                     */
53/*---------------------------------------------------------------------------*/
54
55/*---------------------------------------------------------------------------*/
56/* Variable declarations                                                     */
57/*---------------------------------------------------------------------------*/
58
59static char profileWidth[] = "XXXXXXXXX";
60
61/*---------------------------------------------------------------------------*/
62/* Macro declarations                                                        */
63/*---------------------------------------------------------------------------*/
64
65
66/**AutomaticStart*************************************************************/
67
68/*---------------------------------------------------------------------------*/
69/* Static function prototypes                                                */
70/*---------------------------------------------------------------------------*/
71
72static void CalBddPrintProfileAux(Cal_BddManager_t * bddManager, long * levelCounts, Cal_VarNamingFn_t varNamingProc, char * env, int lineLength, FILE * fp);
73static void chars(char c, int n, FILE * fp);
74
75/**AutomaticEnd***************************************************************/
76
77/*---------------------------------------------------------------------------*/
78/* Definition of exported functions                                          */
79/*---------------------------------------------------------------------------*/
80
81/**Function********************************************************************
82
83  Synopsis    [Displays the node profile for f on fp. lineLength specifies
84               the maximum line length.  varNamingFn is as in
85               Cal_BddPrintBdd.]
86
87  Description [optional]
88
89  SideEffects [None]
90
91  SeeAlso     [optional]
92
93******************************************************************************/
94void
95Cal_BddPrintProfile(Cal_BddManager  bddManager,
96                    Cal_Bdd  fUserBdd,
97                    Cal_VarNamingFn_t varNamingProc,
98                    char * env,
99                    int  lineLength,
100                    FILE * fp)
101{
102  long *levelCounts;
103
104  if (CalBddPreProcessing(bddManager, 1, fUserBdd) == 0){
105        return;
106  }
107  levelCounts = Cal_MemAlloc(long, bddManager->numVars+1);
108  Cal_BddProfile(bddManager, fUserBdd, levelCounts, 1);
109  CalBddPrintProfileAux(bddManager, levelCounts, varNamingProc, env,
110                        lineLength, fp); 
111  Cal_MemFree(levelCounts);
112}
113
114/**Function********************************************************************
115
116  Synopsis    [Cal_BddPrintProfileMultiple is like Cal_BddPrintProfile except
117               it displays the profile for a set of BDDs]
118
119  Description [optional]
120
121  SideEffects [None]
122
123  SeeAlso     [optional]
124
125******************************************************************************/
126void
127Cal_BddPrintProfileMultiple(
128  Cal_BddManager bddManager,
129  Cal_Bdd *userBdds,
130  Cal_VarNamingFn_t varNamingProc,
131  char * env,
132  int  lineLength,
133  FILE * fp)
134{
135  long *levelCounts;
136
137  if (CalBddArrayPreProcessing(bddManager, userBdds) == 0){
138        return;
139  }
140  levelCounts = Cal_MemAlloc(long, bddManager->numVars+1);
141  Cal_BddProfileMultiple(bddManager, userBdds, levelCounts, 1);
142  CalBddPrintProfileAux(bddManager, levelCounts, varNamingProc, env, lineLength, fp);
143  Cal_MemFree(levelCounts);
144}
145
146
147
148/**Function********************************************************************
149
150  Synopsis    [Cal_BddPrintFunctionProfile is like Cal_BddPrintProfile except
151               it displays a function profile for f]
152
153  Description [optional]
154
155  SideEffects [None]
156
157  SeeAlso     [optional]
158
159******************************************************************************/
160void
161Cal_BddPrintFunctionProfile(Cal_BddManager bddManager,
162                            Cal_Bdd  f,
163                            Cal_VarNamingFn_t varNamingProc,
164                            char * env,
165                            int  lineLength,
166                            FILE * fp)
167{
168  long *levelCounts;
169  if (CalBddPreProcessing(bddManager, 1, f)){
170        return;
171  }
172  levelCounts = Cal_MemAlloc(long, bddManager->numVars+1);
173  Cal_BddFunctionProfile(bddManager, f, levelCounts);
174  CalBddPrintProfileAux(bddManager, levelCounts, varNamingProc, env,
175                        lineLength, fp); 
176  Cal_MemFree(levelCounts);
177}
178
179
180/**Function********************************************************************
181
182  Synopsis    [Cal_BddPrintFunctionProfileMultiple is like
183               Cal_BddPrintFunctionProfile except for multiple BDDs]
184
185  Description [optional]
186
187  SideEffects [None]
188
189  SeeAlso     [optional]
190
191******************************************************************************/
192void
193Cal_BddPrintFunctionProfileMultiple(Cal_BddManager bddManager,
194                                    Cal_Bdd *userBdds,
195                                    Cal_VarNamingFn_t varNamingProc,
196                                    char * env,
197                                    int  lineLength,
198                                    FILE * fp)
199{
200  long *levelCounts;
201  if (CalBddArrayPreProcessing(bddManager, userBdds) == 0){
202        return;
203  }
204  levelCounts = Cal_MemAlloc(long, bddManager->numVars+1);
205  Cal_BddFunctionProfileMultiple(bddManager, userBdds, levelCounts);
206  CalBddPrintProfileAux(bddManager, levelCounts, varNamingProc, env, lineLength, fp);
207  Cal_MemFree(levelCounts);
208}
209
210/*---------------------------------------------------------------------------*/
211/* Definition of static functions                                          */
212/*---------------------------------------------------------------------------*/
213/**Function********************************************************************
214
215  Synopsis    [Prints a profile to the file given by fp.  The varNamingProc
216               is as in Cal_BddPrintBdd. lineLength gives the line width to scale
217               the profile to.]
218
219  Description [optional]
220
221  SideEffects [required]
222
223  SeeAlso     [optional]
224
225******************************************************************************/
226static void
227CalBddPrintProfileAux(
228  Cal_BddManager_t * bddManager,
229  long * levelCounts,
230  Cal_VarNamingFn_t varNamingProc,
231  char * env,
232  int  lineLength,
233  FILE * fp)
234{
235  long i, n;
236  int l;
237  char *name;
238  int maxPrefixLen;
239  int maxProfileWidth;
240  int histogramColumn;
241  int histogramWidth;
242  int profileScale;
243  long total;
244
245  n = bddManager->numVars;
246  /* max_... initialized with values for leaf nodes */
247  maxPrefixLen = 5;
248  maxProfileWidth = levelCounts[n];
249  total = levelCounts[n];
250  for(i = 0; i < n; i++){
251    if(levelCounts[i]){
252      sprintf(profileWidth, "%ld", levelCounts[i]);
253      l = strlen(CalBddVarName(bddManager, 
254          bddManager->varBdds[bddManager->indexToId[i]],
255          varNamingProc, env)) + strlen((char *)profileWidth);
256      if(l > maxPrefixLen){
257        maxPrefixLen = l;
258      }
259      if(levelCounts[i] > maxProfileWidth){
260        maxProfileWidth = levelCounts[i];
261      }
262      total += levelCounts[i];
263    }
264  }
265  histogramColumn = maxPrefixLen+3;
266  histogramWidth = lineLength-histogramColumn-1;
267  if(histogramWidth < 20)
268    histogramWidth = 20;                /* Random minimum width */
269  if(histogramWidth >= maxProfileWidth){
270    profileScale = 1;
271  }
272  else{
273    profileScale = (maxProfileWidth+histogramWidth-1)/histogramWidth;
274  }
275  for(i = 0; i < n; ++i){
276    if(levelCounts[i]){
277      name = CalBddVarName(bddManager,
278          bddManager->varBdds[bddManager->indexToId[i]],
279          varNamingProc, env);
280      fputs(name, fp);
281      fputc(':', fp);
282      sprintf(profileWidth, "%ld", levelCounts[i]);
283      chars(' ', (int)(maxPrefixLen-strlen(name)-strlen(profileWidth)+1), fp);
284      fputs(profileWidth, fp);
285      fputc(' ', fp);
286      chars('#', levelCounts[i]/profileScale, fp);
287      fputc('\n', fp);
288    }
289  }
290  fputs("leaf:", fp);
291  sprintf(profileWidth, "%ld", levelCounts[n]);
292  chars(' ', (int)(maxPrefixLen-4-strlen(profileWidth)+1), fp);
293  fputs(profileWidth, fp);
294  fputc(' ', fp);
295  chars('#', levelCounts[n]/profileScale, fp);
296  fputc('\n', fp);
297  fprintf(fp, "Total: %ld\n", total);
298}
299
300/**Function********************************************************************
301
302  Synopsis    []
303
304  Description [optional]
305
306  SideEffects [required]
307
308  SeeAlso     [optional]
309
310******************************************************************************/
311static void
312chars(
313  char  c,
314  int  n,
315  FILE * fp)
316{
317  int i;
318
319  for(i = 0; i < n; ++i){
320    fputc(c, fp);
321  }
322}
323
324
325
326
327
328
329
330
331
332
333
334
Note: See TracBrowser for help on using the repository browser.