00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 #include "espresso.h"
00011
00012
00013
00014 void cover_cost(F, cost)
00015 IN pcover F;
00016 INOUT pcost cost;
00017 {
00018 register pcube p, last;
00019 pcube *T;
00020 int var;
00021
00022
00023 massive_count(T = cube1list(F));
00024 free_cubelist(T);
00025
00026 cost->cubes = F->count;
00027 cost->total = cost->in = cost->out = cost->mv = cost->primes = 0;
00028
00029
00030 for(var = 0; var < cube.num_binary_vars; var++)
00031 cost->in += cdata.var_zeros[var];
00032
00033
00034 for(var = cube.num_binary_vars; var < cube.num_vars - 1; var++)
00035 if (cube.sparse[var])
00036 cost->mv += F->count * cube.part_size[var] - cdata.var_zeros[var];
00037 else
00038 cost->mv += cdata.var_zeros[var];
00039
00040
00041 if (cube.num_binary_vars != cube.num_vars) {
00042 var = cube.num_vars - 1;
00043 cost->out = F->count * cube.part_size[var] - cdata.var_zeros[var];
00044 }
00045
00046
00047 foreach_set(F, last, p)
00048 cost->primes += TESTP(p, PRIME) != 0;
00049
00050
00051 cost->total = cost->in + cost->out + cost->mv;
00052 }
00053
00054
00055
00056 char *fmt_cost(cost)
00057 IN pcost cost;
00058 {
00059 static char s[200];
00060
00061 if (cube.num_binary_vars == cube.num_vars - 1)
00062 (void) sprintf(s, "c=%d(%d) in=%d out=%d tot=%d",
00063 cost->cubes, cost->cubes - cost->primes, cost->in,
00064 cost->out, cost->total);
00065 else
00066 (void) sprintf(s, "c=%d(%d) in=%d mv=%d out=%d",
00067 cost->cubes, cost->cubes - cost->primes, cost->in,
00068 cost->mv, cost->out);
00069 return s;
00070 }
00071
00072
00073 char *print_cost(F)
00074 IN pcover F;
00075 {
00076 cost_t cost;
00077 cover_cost(F, &cost);
00078 return fmt_cost(&cost);
00079 }
00080
00081
00082
00083 void copy_cost(s, d)
00084 pcost s, d;
00085 {
00086 d->cubes = s->cubes;
00087 d->in = s->in;
00088 d->out = s->out;
00089 d->mv = s->mv;
00090 d->total = s->total;
00091 d->primes = s->primes;
00092 }
00093
00094
00095
00096 void size_stamp(T, name)
00097 IN pcover T;
00098 IN char *name;
00099 {
00100 (void) printf("# %s\tCost is %s\n", name, print_cost(T));
00101 (void) fflush(stdout);
00102 }
00103
00104
00105
00106 void print_trace(T, name, time)
00107 pcover T;
00108 char *name;
00109 long time;
00110 {
00111 (void) printf("# %s\tTime was %s, cost is %s\n",
00112 name, print_time(time), print_cost(T));
00113 (void) fflush(stdout);
00114 }
00115
00116
00117
00118 void totals(time, i, T, cost)
00119 long time;
00120 int i;
00121 pcover T;
00122 pcost cost;
00123 {
00124 time = ptime() - time;
00125 total_time[i] += time;
00126 total_calls[i]++;
00127 cover_cost(T, cost);
00128 if (trace) {
00129 (void) printf("# %s\tTime was %s, cost is %s\n",
00130 total_name[i], print_time(time), fmt_cost(cost));
00131 (void) fflush(stdout);
00132 }
00133 }
00134
00135
00136
00137 void fatal(s)
00138 char *s;
00139 {
00140 (void) fprintf(stderr, "espresso: %s\n", s);
00141 exit(1);
00142 }