source: vis_dev/glu-2.3/src/cmuBdd/bddprprofile.c @ 104

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

library glu 2.3

File size: 5.0 KB
Line 
1/* BDD library profile printing routines */
2
3
4#include "bddint.h"
5#if STDC_HEADERS
6#include <string.h>
7#endif
8
9static char profile_width[]="XXXXXXXXX";
10
11
12static
13void
14chars(char c, int n, FILE *fp)
15{
16  int i;
17
18  for (i=0; i < n; ++i)
19    fputc(c, fp);
20}
21
22
23/* cmu_bdd_print_profile_aux(bddm, level_counts, var_naming_fn, line_length, */
24/* env, fp) prints a profile to the file given by fp.  The var_naming_fn */
25/* is as in cmu_bdd_print_bdd.  line_length gives the line width to scale the */
26/* profile to. */
27
28void
29cmu_bdd_print_profile_aux(cmu_bdd_manager bddm,
30                      long *level_counts,
31                      char *(*var_naming_fn)(cmu_bdd_manager, bdd, pointer),
32                      pointer env,
33                      int line_length,
34                      FILE *fp)
35{
36  long i, n;
37  int l;
38  char *name;
39  int max_prefix_len;
40  int max_profile_width;
41  int histogram_column;
42  int histogram_width;
43  int profile_scale;
44  long total;
45
46  n=bddm->vars;
47  /* max_... initialized with values for leaf nodes */
48  max_prefix_len=5;
49  max_profile_width=level_counts[n];
50  total=level_counts[n];
51  for (i=0; i < n; ++i)
52    if (level_counts[i])
53      {
54        sprintf(profile_width, "%ld", level_counts[i]);
55        l=strlen(bdd_var_name(bddm, bddm->variables[bddm->indexindexes[i]], var_naming_fn, env))+strlen(profile_width);
56        if (l > max_prefix_len)
57          max_prefix_len=l;
58        if (level_counts[i] > max_profile_width)
59          max_profile_width=level_counts[i];
60        total+=level_counts[i];
61      }
62  histogram_column=max_prefix_len+3;
63  histogram_width=line_length-histogram_column-1;
64  if (histogram_width < 20)
65    histogram_width=20;         /* Random minimum width */
66  if (histogram_width >= max_profile_width)
67    profile_scale=1;
68  else
69    profile_scale=(max_profile_width+histogram_width-1)/histogram_width;
70  for (i=0; i < n; ++i)
71    if (level_counts[i])
72      {
73        name=bdd_var_name(bddm, bddm->variables[bddm->indexindexes[i]], var_naming_fn, env);
74        fputs(name, fp);
75        fputc(':', fp);
76        sprintf(profile_width, "%ld", level_counts[i]);
77        chars(' ', (int)(max_prefix_len-strlen(name)-strlen(profile_width)+1), fp);
78        fputs(profile_width, fp);
79        fputc(' ', fp);
80        chars('#', level_counts[i]/profile_scale, fp);
81        fputc('\n', fp);
82      }
83  fputs("leaf:", fp);
84  sprintf(profile_width, "%ld", level_counts[n]);
85  chars(' ', (int)(max_prefix_len-4-strlen(profile_width)+1), fp);
86  fputs(profile_width, fp);
87  fputc(' ', fp);
88  chars('#', level_counts[n]/profile_scale, fp);
89  fputc('\n', fp);
90  fprintf(fp, "Total: %ld\n", total);
91}
92
93
94/* cmu_bdd_print_profile(bddm, f, var_naming_fn, env, line_length, fp) displays */
95/* the node profile for f on fp.  line_length specifies the maximum line */
96/* length.  var_naming_fn is as in cmu_bdd_print_bdd. */
97
98void
99cmu_bdd_print_profile(cmu_bdd_manager bddm,
100                  bdd f,
101                  char *(*var_naming_fn)(cmu_bdd_manager, bdd, pointer),
102                  pointer env,
103                  int line_length,
104                  FILE *fp)
105{
106  long *level_counts;
107
108  if (bdd_check_arguments(1, f))
109    {
110      level_counts=(long *)mem_get_block((SIZE_T)((bddm->vars+1)*sizeof(long)));
111      cmu_bdd_profile(bddm, f, level_counts, 1);
112      cmu_bdd_print_profile_aux(bddm, level_counts, var_naming_fn, env, line_length, fp);
113      mem_free_block((pointer)level_counts);
114    }
115  else
116    fputs("overflow\n", fp);
117}
118
119
120/* cmu_bdd_print_profile_multiple is like cmu_bdd_print_profile except it displays */
121/* the profile for a set of BDDs. */
122
123void
124cmu_bdd_print_profile_multiple(cmu_bdd_manager bddm,
125                           bdd* fs,
126                           char *(*var_naming_fn)(cmu_bdd_manager, bdd, pointer),
127                           pointer env,
128                           int line_length,
129                           FILE *fp)
130{
131  long *level_counts;
132
133  bdd_check_array(fs);
134  level_counts=(long *)mem_get_block((SIZE_T)((bddm->vars+1)*sizeof(long)));
135  cmu_bdd_profile_multiple(bddm, fs, level_counts, 1);
136  cmu_bdd_print_profile_aux(bddm, level_counts, var_naming_fn, env, line_length, fp);
137  mem_free_block((pointer)level_counts);
138}
139
140
141/* cmu_bdd_print_function_profile is like cmu_bdd_print_profile except it displays */
142/* a function profile for f. */
143
144void
145cmu_bdd_print_function_profile(cmu_bdd_manager bddm,
146                           bdd f,
147                           char *(*var_naming_fn)(cmu_bdd_manager, bdd, pointer),
148                           pointer env,
149                           int line_length,
150                           FILE *fp)
151{
152  long *level_counts;
153
154  if (bdd_check_arguments(1, f))
155    {
156      level_counts=(long *)mem_get_block((SIZE_T)((bddm->vars+1)*sizeof(long)));
157      cmu_bdd_function_profile(bddm, f, level_counts);
158      cmu_bdd_print_profile_aux(bddm, level_counts, var_naming_fn, env, line_length, fp);
159      mem_free_block((pointer)level_counts);
160    }
161  else
162    fputs("overflow\n", fp);
163}
164
165
166/* cmu_bdd_print_function_profile_multiple is like cmu_bdd_print_function_profile */
167/* except for multiple BDDs. */
168
169void
170cmu_bdd_print_function_profile_multiple(cmu_bdd_manager bddm,
171                                    bdd* fs,
172                                    char *(*var_naming_fn)(cmu_bdd_manager, bdd, pointer),
173                                    pointer env,
174                                    int line_length,
175                                    FILE *fp)
176{
177  long *level_counts;
178
179  bdd_check_array(fs);
180  level_counts=(long *)mem_get_block((SIZE_T)((bddm->vars+1)*sizeof(long)));
181  cmu_bdd_function_profile_multiple(bddm, fs, level_counts);
182  cmu_bdd_print_profile_aux(bddm, level_counts, var_naming_fn, env, line_length, fp);
183  mem_free_block((pointer)level_counts);
184}
Note: See TracBrowser for help on using the repository browser.