abc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
expand.c
Go to the documentation of this file.
1 /*
2  * Revision Control Information
3  *
4  * $Source$
5  * $Author$
6  * $Revision$
7  * $Date$
8  *
9  */
10 /*
11  module: expand.c
12  purpose: Perform the Espresso-II Expansion Step
13 
14  The idea is to take each nonprime cube of the on-set and expand it
15  into a prime implicant such that we can cover as many other cubes
16  of the on-set. If no cube of the on-set can be covered, then we
17  expand each cube into a large prime implicant by transforming the
18  problem into a minimum covering problem which is solved by the
19  heuristics of minimum_cover.
20 
21  These routines revolve around having a representation of the
22  OFF-set. (In contrast to the Espresso-II manuscript, we do NOT
23  require an "unwrapped" version of the OFF-set).
24 
25  Some conventions on variable names:
26 
27  SUPER_CUBE is the supercube of all cubes which can be covered
28  by an expansion of the cube being expanded
29 
30  OVEREXPANDED_CUBE is the cube which would result from expanding
31  all parts which can expand individually of the cube being expanded
32 
33  RAISE is the current expansion of the current cube
34 
35  FREESET is the set of parts which haven't been raised or lowered yet.
36 
37  INIT_LOWER is a set of parts to be removed from the free parts before
38  starting the expansion
39 */
40 
41 #include "espresso.h"
42 
44 
45 
46 /*
47  expand -- expand each nonprime cube of F into a prime implicant
48 
49  If nonsparse is true, only the non-sparse variables will be expanded;
50  this is done by forcing all of the sparse variables out of the free set.
51 */
52 
53 pcover expand(F, R, nonsparse)
54 INOUT pcover F;
55 IN pcover R;
56 IN bool nonsparse; /* expand non-sparse variables only */
57 {
58  register pcube last, p;
59  pcube RAISE, FREESET, INIT_LOWER, SUPER_CUBE, OVEREXPANDED_CUBE;
60  int var, num_covered;
61  bool change;
62 
63  /* Order the cubes according to "chewing-away from the edges" of mini */
64  if (use_random_order)
65  F = random_order(F);
66  else
67  F = mini_sort(F, ascend);
68 
69  /* Allocate memory for variables needed by expand1() */
70  RAISE = new_cube();
71  FREESET = new_cube();
72  INIT_LOWER = new_cube();
73  SUPER_CUBE = new_cube();
74  OVEREXPANDED_CUBE = new_cube();
75 
76  /* Setup the initial lowering set (differs only for nonsparse) */
77  if (nonsparse)
78  for(var = 0; var < cube.num_vars; var++)
79  if (cube.sparse[var])
80  (void) set_or(INIT_LOWER, INIT_LOWER, cube.var_mask[var]);
81 
82  /* Mark all cubes as not covered, and maybe essential */
83  foreach_set(F, last, p) {
84  RESET(p, COVERED);
85  RESET(p, NONESSEN);
86  }
87 
88  /* Try to expand each nonprime and noncovered cube */
89  foreach_set(F, last, p) {
90  /* do not expand if PRIME or if covered by previous expansion */
91  if (! TESTP(p, PRIME) && ! TESTP(p, COVERED)) {
92 
93  /* expand the cube p, result is RAISE */
94  expand1(R, F, RAISE, FREESET, OVEREXPANDED_CUBE, SUPER_CUBE,
95  INIT_LOWER, &num_covered, p);
96  if (debug & EXPAND)
97  printf("EXPAND: %s (covered %d)\n", pc1(p), num_covered);
98  (void) set_copy(p, RAISE);
99  SET(p, PRIME);
100  RESET(p, COVERED); /* not really necessary */
101 
102  /* See if we generated an inessential prime */
103  if (num_covered == 0 && ! setp_equal(p, OVEREXPANDED_CUBE)) {
104  SET(p, NONESSEN);
105  }
106  }
107  }
108 
109  /* Delete any cubes of F which became covered during the expansion */
110  F->active_count = 0;
111  change = FALSE;
112  foreach_set(F, last, p) {
113  if (TESTP(p, COVERED)) {
114  RESET(p, ACTIVE);
115  change = TRUE;
116  } else {
117  SET(p, ACTIVE);
118  F->active_count++;
119  }
120  }
121  if (change)
122  F = sf_inactive(F);
123 
124  free_cube(RAISE);
125  free_cube(FREESET);
126  free_cube(INIT_LOWER);
127  free_cube(SUPER_CUBE);
128  free_cube(OVEREXPANDED_CUBE);
129  return F;
130 }
131 
132 /*
133  expand1 -- Expand a single cube against the OFF-set
134 */
135 void expand1(BB, CC, RAISE, FREESET, OVEREXPANDED_CUBE, SUPER_CUBE,
136  INIT_LOWER, num_covered, c)
137 pcover BB; /* Blocking matrix (OFF-set) */
138 pcover CC; /* Covering matrix (ON-set) */
139 pcube RAISE; /* The current parts which have been raised */
140 pcube FREESET; /* The current parts which are free */
141 pcube OVEREXPANDED_CUBE; /* Overexpanded cube of c */
142 pcube SUPER_CUBE; /* Supercube of all cubes of CC we cover */
143 pcube INIT_LOWER; /* Parts to initially remove from FREESET */
144 int *num_covered; /* Number of cubes of CC which are covered */
145 pcube c; /* The cube to be expanded */
146 {
147  int bestindex;
148 
149  if (debug & EXPAND1)
150  printf("\nEXPAND1: \t%s\n", pc1(c));
151 
152  /* initialize BB and CC */
153  SET(c, PRIME); /* don't try to cover ourself */
154  setup_BB_CC(BB, CC);
155 
156  /* initialize count of # cubes covered, and the supercube of them */
157  *num_covered = 0;
158  (void) set_copy(SUPER_CUBE, c);
159 
160  /* Initialize the lowering, raising and unassigned sets */
161  (void) set_copy(RAISE, c);
162  (void) set_diff(FREESET, cube.fullset, RAISE);
163 
164  /* If some parts are forced into lowering set, remove them */
165  if (! setp_empty(INIT_LOWER)) {
166  (void) set_diff(FREESET, FREESET, INIT_LOWER);
167  elim_lowering(BB, CC, RAISE, FREESET);
168  }
169 
170  /* Determine what can be raised, and return the over-expanded cube */
171  essen_parts(BB, CC, RAISE, FREESET);
172  (void) set_or(OVEREXPANDED_CUBE, RAISE, FREESET);
173 
174  /* While there are still cubes which can be covered, cover them ! */
175  if (CC->active_count > 0) {
176  select_feasible(BB, CC, RAISE, FREESET, SUPER_CUBE, num_covered);
177  }
178 
179  /* While there are still cubes covered by the overexpanded cube ... */
180  while (CC->active_count > 0) {
181  bestindex = most_frequent(CC, FREESET);
182  set_insert(RAISE, bestindex);
183  set_remove(FREESET, bestindex);
184  essen_parts(BB, CC, RAISE, FREESET);
185  }
186 
187  /* Finally, when all else fails, choose the largest possible prime */
188  /* We will loop only if we decide unravelling OFF-set is too expensive */
189  while (BB->active_count > 0) {
190  mincov(BB, RAISE, FREESET);
191  }
192 
193  /* Raise any remaining free coordinates */
194  (void) set_or(RAISE, RAISE, FREESET);
195 }
196 
197 /*
198  essen_parts -- determine which parts are forced into the lowering
199  set to insure that the cube be orthognal to the OFF-set.
200 
201  If any cube of the OFF-set is distance 1 from the raising cube,
202  then we must lower all parts of the conflicting variable. (If the
203  cube is distance 0, we detect this error here.)
204 
205  If there are essentially lowered parts, we can remove from consideration
206  any cubes of the OFF-set which are more than distance 1 from the
207  overexpanded cube of RAISE.
208 */
209 
210 void essen_parts(BB, CC, RAISE, FREESET)
211 pcover BB, CC;
212 pcube RAISE, FREESET;
213 {
214  register pcube p, r = RAISE;
215  pcube lastp, xlower = cube.temp[0];
216  int dist;
217 
218  (void) set_copy(xlower, cube.emptyset);
219 
220  foreach_active_set(BB, lastp, p) {
221 #ifdef NO_INLINE
222  if ((dist = cdist01(p, r)) > 1) goto exit_if;
223 #else
224  {register int w,last;register unsigned int x;dist=0;if((last=cube.inword)!=-1)
225 {x=p[last]&r[last];if((x=~(x|x>>1)&cube.inmask))if((dist=count_ones(x))>1)goto
226 exit_if;for(w=1;w<last;w++){x=p[w]&r[w];if((x=~(x|x>>1)&DISJOINT))if(dist==1||(
227 dist+=count_ones(x))>1)goto exit_if;}}}{register int w,var,last;register pcube
228 mask;for(var=cube.num_binary_vars;var<cube.num_vars;var++){mask=cube.var_mask[
229 var];last=cube.last_word[var];for(w=cube.first_word[var];w<=last;w++)if(p[w]&r[
230 w]&mask[w])goto nextvar;if(++dist>1)goto exit_if;nextvar:;}}
231 #endif
232  if (dist == 0) {
233  fatal("ON-set and OFF-set are not orthogonal");
234  } else {
235  (void) force_lower(xlower, p, r);
236  BB->active_count--;
237  RESET(p, ACTIVE);
238  }
239 exit_if: ;
240  }
241 
242  if (! setp_empty(xlower)) {
243  (void) set_diff(FREESET, FREESET, xlower);/* remove from free set */
244  elim_lowering(BB, CC, RAISE, FREESET);
245  }
246 
247  if (debug & EXPAND1)
248  printf("ESSEN_PARTS:\tRAISE=%s FREESET=%s\n", pc1(RAISE), pc2(FREESET));
249 }
250 
251 /*
252  essen_raising -- determine which parts may always be added to
253  the raising set without restricting further expansions
254 
255  General rule: if some part is not blocked by any cube of BB, then
256  this part can always be raised.
257 */
258 
259 void essen_raising(BB, RAISE, FREESET)
260 register pcover BB;
261 pcube RAISE, FREESET;
262 {
263  register pcube last, p, xraise = cube.temp[0];
264 
265  /* Form union of all cubes of BB, and then take complement wrt FREESET */
266  (void) set_copy(xraise, cube.emptyset);
267  foreach_active_set(BB, last, p)
268  INLINEset_or(xraise, xraise, p);
269  (void) set_diff(xraise, FREESET, xraise);
270 
271  (void) set_or(RAISE, RAISE, xraise); /* add to raising set */
272  (void) set_diff(FREESET, FREESET, xraise); /* remove from free set */
273 
274  if (debug & EXPAND1)
275  printf("ESSEN_RAISING:\tRAISE=%s FREESET=%s\n",
276  pc1(RAISE), pc2(FREESET));
277 }
278 
279 /*
280  elim_lowering -- after removing parts from FREESET, we can reduce the
281  size of both BB and CC.
282 
283  We mark as inactive any cube of BB which does not intersect the
284  overexpanded cube (i.e., RAISE + FREESET). Likewise, we remove
285  from CC any cube which is not covered by the overexpanded cube.
286 */
287 
288 void elim_lowering(BB, CC, RAISE, FREESET)
289 pcover BB, CC;
290 pcube RAISE, FREESET;
291 {
292  register pcube p, r = set_or(cube.temp[0], RAISE, FREESET);
293  pcube last;
294 
295  /*
296  * Remove sets of BB which are orthogonal to future expansions
297  */
298  foreach_active_set(BB, last, p) {
299 #ifdef NO_INLINE
300  if (! cdist0(p, r))
301 #else
302  {register int w,lastw;register unsigned int x;if((lastw=cube.inword)!=-1){x=p[
303 lastw]&r[lastw];if(~(x|x>>1)&cube.inmask)goto false;for(w=1;w<lastw;w++){x=p[w]
304 &r[w];if(~(x|x>>1)&DISJOINT)goto false;}}}{register int w,var,lastw;register
305 pcube mask;for(var=cube.num_binary_vars;var<cube.num_vars;var++){mask=cube.
306 var_mask[var];lastw=cube.last_word[var];for(w=cube.first_word[var];w<=lastw;w++)
307 if(p[w]&r[w]&mask[w])goto nextvar;goto false;nextvar:;}}continue;false:
308 #endif
309  BB->active_count--, RESET(p, ACTIVE);
310  }
311 
312 
313  /*
314  * Remove sets of CC which cannot be covered by future expansions
315  */
316  if (CC != (pcover) NULL) {
317  foreach_active_set(CC, last, p) {
318 #ifdef NO_INLINE
319  if (! setp_implies(p, r))
320 #else
321  INLINEsetp_implies(p, r, /* when false => */ goto false1);
322  /* when true => go to end of loop */ continue;
323  false1:
324 #endif
325  CC->active_count--, RESET(p, ACTIVE);
326  }
327  }
328 }
329 
330 /*
331  most_frequent -- When all else fails, select a reasonable part to raise
332  The active cubes of CC are the cubes which are covered by the
333  overexpanded cube of the original cube (however, we know that none
334  of them can actually be covered by a feasible expansion of the
335  original cube). We resort to the MINI strategy of selecting to
336  raise the part which will cover the same part in the most cubes of CC.
337 */
338 int most_frequent(CC, FREESET)
339 pcover CC;
340 pcube FREESET;
341 {
342  register int i, best_part, best_count, *count;
343  register pset p, last;
344 
345  /* Count occurences of each variable */
346  count = ALLOC(int, cube.size);
347  for(i = 0; i < cube.size; i++)
348  count[i] = 0;
349  if (CC != (pcover) NULL)
350  foreach_active_set(CC, last, p)
351  set_adjcnt(p, count, 1);
352 
353  /* Now find which free part occurs most often */
354  best_count = best_part = -1;
355  for(i = 0; i < cube.size; i++)
356  if (is_in_set(FREESET,i) && count[i] > best_count) {
357  best_part = i;
358  best_count = count[i];
359  }
360  FREE(count);
361 
362  if (debug & EXPAND1)
363  printf("MOST_FREQUENT:\tbest=%d FREESET=%s\n", best_part, pc2(FREESET));
364  return best_part;
365 }
366 
367 /*
368  setup_BB_CC -- set up the blocking and covering set families;
369 
370  Note that the blocking family is merely the set of cubes of R, and
371  that CC is the set of cubes of F which might possibly be covered
372  (i.e., nonprime cubes, and cubes not already covered)
373 */
374 
375 void setup_BB_CC(BB, CC)
376 register pcover BB, CC;
377 {
378  register pcube p, last;
379 
380  /* Create the block and cover set families */
381  BB->active_count = BB->count;
382  foreach_set(BB, last, p)
383  SET(p, ACTIVE);
384 
385  if (CC != (pcover) NULL) {
386  CC->active_count = CC->count;
387  foreach_set(CC, last, p)
388  if (TESTP(p, COVERED) || TESTP(p, PRIME))
389  CC->active_count--, RESET(p, ACTIVE);
390  else
391  SET(p, ACTIVE);
392  }
393 }
394 
395 /*
396  select_feasible -- Determine if there are cubes which can be covered,
397  and if so, raise those parts necessary to cover as many as possible.
398 
399  We really don't check to maximize the number that can be covered;
400  instead, we check, for each fcc, how many other fcc remain fcc
401  after expanding to cover the fcc. (Essentially one-level lookahead).
402 */
403 
404 void select_feasible(BB, CC, RAISE, FREESET, SUPER_CUBE, num_covered)
405 pcover BB, CC;
406 pcube RAISE, FREESET, SUPER_CUBE;
407 int *num_covered;
408 {
409  register pcube p, last;
410  register pcube bestfeas = NULL; // Suppress "might be used uninitialized"
411  register pcube *feas;
412  register int i, j;
413  pcube *feas_new_lower;
414  int bestcount, bestsize, count, size, numfeas, lastfeas;
415  pcover new_lower;
416 
417  /* Start out with all cubes covered by the over-expanded cube as
418  * the "possibly" feasibly-covered cubes (pfcc)
419  */
420  feas = ALLOC(pcube, CC->active_count);
421  numfeas = 0;
422  foreach_active_set(CC, last, p)
423  feas[numfeas++] = p;
424 
425  /* Setup extra cubes to record parts forced low after a covering */
426  feas_new_lower = ALLOC(pcube, CC->active_count);
427  new_lower = new_cover(numfeas);
428  for(i = 0; i < numfeas; i++)
429  feas_new_lower[i] = GETSET(new_lower, i);
430 
431 
432 loop:
433  /* Find the essentially raised parts -- this might cover some cubes
434  for us, without having to find out if they are fcc or not
435  */
436  essen_raising(BB, RAISE, FREESET);
437 
438  /* Now check all "possibly" feasibly covered cubes to check feasibility */
439  lastfeas = numfeas;
440  numfeas = 0;
441  for(i = 0; i < lastfeas; i++) {
442  p = feas[i];
443 
444  /* Check active because essen_parts might have removed it */
445  if (TESTP(p, ACTIVE)) {
446 
447  /* See if the cube is already covered by RAISE --
448  * this can happen because of essen_raising() or because of
449  * the previous "loop"
450  */
451  if (setp_implies(p, RAISE)) {
452  (*num_covered) += 1;
453  (void) set_or(SUPER_CUBE, SUPER_CUBE, p);
454  CC->active_count--;
455  RESET(p, ACTIVE);
456  SET(p, COVERED);
457  /* otherwise, test if it is feasibly covered */
458  } else if (feasibly_covered(BB,p,RAISE,feas_new_lower[numfeas])) {
459  feas[numfeas] = p; /* save the fcc */
460  numfeas++;
461  }
462  }
463  }
464  if (debug & EXPAND1)
465  printf("SELECT_FEASIBLE: started with %d pfcc, ended with %d fcc\n",
466  lastfeas, numfeas);
467 
468  /* Exit here if there are no feasibly covered cubes */
469  if (numfeas == 0) {
470  FREE(feas);
471  FREE(feas_new_lower);
472  free_cover(new_lower);
473  return;
474  }
475 
476  /* Now find which is the best feasibly covered cube */
477  bestcount = 0;
478  bestsize = 9999;
479  for(i = 0; i < numfeas; i++) {
480  size = set_dist(feas[i], FREESET); /* # of newly raised parts */
481  count = 0; /* # of other cubes which remain fcc after raising */
482 
483 #define NEW
484 #ifdef NEW
485  for(j = 0; j < numfeas; j++)
486  if (setp_disjoint(feas_new_lower[i], feas[j]))
487  count++;
488 #else
489  for(j = 0; j < numfeas; j++)
490  if (setp_implies(feas[j], feas[i]))
491  count++;
492 #endif
493  if (count > bestcount) {
494  bestcount = count;
495  bestfeas = feas[i];
496  bestsize = size;
497  } else if (count == bestcount && size < bestsize) {
498  bestfeas = feas[i];
499  bestsize = size;
500  }
501  }
502 
503  /* Add the necessary parts to the raising set */
504  (void) set_or(RAISE, RAISE, bestfeas);
505  (void) set_diff(FREESET, FREESET, RAISE);
506  if (debug & EXPAND1)
507  printf("FEASIBLE: \tRAISE=%s FREESET=%s\n", pc1(RAISE), pc2(FREESET));
508  essen_parts(BB, CC, RAISE, FREESET);
509  goto loop;
510 /* NOTREACHED */
511 }
512 
513 /*
514  feasibly_covered -- determine if the cube c is feasibly covered
515  (i.e., if it is possible to raise all of the necessary variables
516  while still insuring orthogonality with R). Also, if c is feasibly
517  covered, then compute the new set of parts which are forced into
518  the lowering set.
519 */
520 
521 bool feasibly_covered(BB, c, RAISE, new_lower)
522 pcover BB;
523 pcube c, RAISE, new_lower;
524 {
525  register pcube p, r = set_or(cube.temp[0], RAISE, c);
526  int dist;
527  pcube lastp;
528 
529  set_copy(new_lower, cube.emptyset);
530  foreach_active_set(BB, lastp, p) {
531 #ifdef NO_INLINE
532  if ((dist = cdist01(p, r)) > 1) goto exit_if;
533 #else
534  {register int w,last;register unsigned int x;dist=0;if((last=cube.inword)!=-1)
535 {x=p[last]&r[last];if((x=~(x|x>>1)&cube.inmask))if((dist=count_ones(x))>1)goto
536 exit_if;for(w=1;w<last;w++){x=p[w]&r[w];if((x=~(x|x>>1)&DISJOINT))if(dist==1||(
537 dist+=count_ones(x))>1)goto exit_if;}}}{register int w,var,last;register pcube
538 mask;for(var=cube.num_binary_vars;var<cube.num_vars;var++){mask=cube.var_mask[
539 var];last=cube.last_word[var];for(w=cube.first_word[var];w<=last;w++)if(p[w]&r[
540 w]&mask[w])goto nextvar;if(++dist>1)goto exit_if;nextvar:;}}
541 #endif
542  if (dist == 0)
543  return FALSE;
544  else
545  (void) force_lower(new_lower, p, r);
546  exit_if: ;
547  }
548  return TRUE;
549 }
550 
551 /*
552  mincov -- transform the problem of expanding a cube to a maximally-
553  large prime implicant into the problem of selecting a minimum
554  cardinality cover over a family of sets.
555 
556  When we get to this point, we must unravel the remaining off-set.
557  This may be painful.
558 */
559 
560 void mincov(BB, RAISE, FREESET)
561 pcover BB;
562 pcube RAISE, FREESET;
563 {
564  int expansion, nset, var, dist;
565  pset_family B;
566  register pcube xraise=cube.temp[0], xlower, p, last, plower;
567 
568 #ifdef RANDOM_MINCOV
569 #if defined(_POSIX_SOURCE) || defined(__SVR4)
570  dist = rand() % set_ord(FREESET);
571 #else
572  dist = random() % set_ord(FREESET);
573 #endif
574  for(var = 0; var < cube.size && dist >= 0; var++) {
575  if (is_in_set(FREESET, var)) {
576  dist--;
577  }
578  }
579 
580  set_insert(RAISE, var);
581  set_remove(FREESET, var);
582  (void) essen_parts(BB, /*CC*/ (pcover) NULL, RAISE, FREESET);
583 #else
584 
585  /* Create B which are those cubes which we must avoid intersecting */
586  B = new_cover(BB->active_count);
587  foreach_active_set(BB, last, p) {
588  plower = set_copy(GETSET(B, B->count++), cube.emptyset);
589  (void) force_lower(plower, p, RAISE);
590  }
591 
592  /* Determine how many sets it will blow up into after the unravel */
593  nset = 0;
594  foreach_set(B, last, p) {
595  expansion = 1;
596  for(var = cube.num_binary_vars; var < cube.num_vars; var++) {
597  if ((dist=set_dist(p, cube.var_mask[var])) > 1) {
598  expansion *= dist;
599  if (expansion > 500) goto heuristic_mincov;
600  }
601  }
602  nset += expansion;
603  if (nset > 500) goto heuristic_mincov;
604  }
605 
606  B = unravel(B, cube.num_binary_vars);
607  xlower = do_sm_minimum_cover(B);
608 
609  /* Add any remaining free parts to the raising set */
610  (void) set_or(RAISE, RAISE, set_diff(xraise, FREESET, xlower));
611  (void) set_copy(FREESET, cube.emptyset); /* free set is empty */
612  BB->active_count = 0; /* BB satisfied */
613  if (debug & EXPAND1) {
614  printf("MINCOV: \tRAISE=%s FREESET=%s\n", pc1(RAISE), pc2(FREESET));
615  }
616  sf_free(B);
617  set_free(xlower);
618  return;
619 
620 heuristic_mincov:
621  sf_free(B);
622  /* most_frequent will pick first free part */
623  set_insert(RAISE, most_frequent(/*CC*/ (pcover) NULL, FREESET));
624  (void) set_diff(FREESET, FREESET, RAISE);
625  essen_parts(BB, /*CC*/ (pcover) NULL, RAISE, FREESET);
626  return;
627 #endif
628 }
629 
630 /*
631  find_all_primes -- find all of the primes which cover the
632  currently reduced BB
633 */
634 pcover find_all_primes(BB, RAISE, FREESET)
635 pcover BB;
636 register pcube RAISE, FREESET;
637 {
638  register pset last, p, plower;
639  pset_family B, B1;
640 
641  if (BB->active_count == 0) {
642  B1 = new_cover(1);
643  p = GETSET(B1, B1->count++);
644  (void) set_copy(p, RAISE);
645  SET(p, PRIME);
646  } else {
647  B = new_cover(BB->active_count);
648  foreach_active_set(BB, last, p) {
649  plower = set_copy(GETSET(B, B->count++), cube.emptyset);
650  (void) force_lower(plower, p, RAISE);
651  }
652  B = sf_rev_contain(unravel(B, cube.num_binary_vars));
653  B1 = exact_minimum_cover(B);
654  foreach_set(B1, last, p) {
655  INLINEset_diff(p, FREESET, p);
656  INLINEset_or(p, p, RAISE);
657  SET(p, PRIME);
658  }
659  free_cover(B);
660  }
661  return B1;
662 }
663 
664 /*
665  all_primes -- foreach cube in F, generate all of the primes
666  which cover the cube.
667 */
668 
670 pcover F, R;
671 {
672  register pcube last, p, RAISE, FREESET;
673  pcover Fall_primes, B1;
674 
675  FREESET = new_cube();
676  RAISE = new_cube();
677  Fall_primes = new_cover(F->count);
678 
679  foreach_set(F, last, p) {
680  if (TESTP(p, PRIME)) {
681  Fall_primes = sf_addset(Fall_primes, p);
682  } else {
683  /* Setup for call to essential parts */
684  (void) set_copy(RAISE, p);
685  (void) set_diff(FREESET, cube.fullset, RAISE);
686  setup_BB_CC(R, /* CC */ (pcover) NULL);
687  essen_parts(R, /* CC */ (pcover) NULL, RAISE, FREESET);
688 
689  /* Find all of the primes, and add them to the prime set */
690  B1 = find_all_primes(R, RAISE, FREESET);
691  Fall_primes = sf_append(Fall_primes, B1);
692  }
693  }
694 
695  set_free(RAISE);
696  set_free(FREESET);
697  return Fall_primes;
698 }
700 
int most_frequent(pcover CC, pcube FREESET)
Definition: expand.c:338
pset force_lower()
pset set_or()
int cdist01()
#define INLINEset_diff(r, a, b)
Definition: espresso.h:208
void fatal(char *s)
Definition: cvrmisc.c:140
#define set_free(r)
Definition: espresso.h:167
#define FALSE
Definition: cudd.h:91
#define new_cube()
Definition: espresso.h:262
char * pc1(pcube c)
Definition: cvrout.c:379
pset_family sf_rev_contain(INOUT pset_family A)
Definition: contain.c:58
int set_dist()
static Llb_Mgr_t * p
Definition: llb3Image.c:950
#define free_cover(r)
Definition: espresso.h:266
#define pcover
Definition: espresso.h:264
pset set_copy()
pcover unravel(IN pcover B, IN int start)
Definition: cvrm.c:113
#define INLINEsetp_implies(a, b, when_false)
Definition: espresso.h:228
void essen_parts(pcover BB, pcover CC, pcube RAISE, pcube FREESET)
Definition: expand.c:210
pset_family exact_minimum_cover()
int var(Lit p)
Definition: SolverTypes.h:62
void essen_raising(pcover BB, pcube RAISE, pcube FREESET)
Definition: expand.c:259
pcover find_all_primes(pcover BB, pcube RAISE, pcube FREESET)
Definition: expand.c:634
int count
Definition: espresso.h:80
void sf_free()
char * pc2(pcube c)
Definition: cvrout.c:381
#define PRIME
Definition: espresso.h:127
#define free_cube(r)
Definition: espresso.h:263
pcover mini_sort(pcover F, int(*compare)())
Definition: cvrm.c:141
bool setp_disjoint()
#define SET(set, flag)
Definition: espresso.h:122
#define foreach_set(R, last, p)
Definition: espresso.h:135
#define RESET(set, flag)
Definition: espresso.h:123
#define INOUT
Definition: espresso.h:334
#define IN
Definition: espresso.h:332
pcover random_order(pcover F)
Definition: cvrm.c:199
#define INLINEset_or(r, a, b)
Definition: espresso.h:205
#define EXPAND
Definition: espresso.h:353
bool setp_equal()
pcover all_primes(pcover F, pcover R)
Definition: expand.c:669
void expand1(pcover BB, pcover CC, pcube RAISE, pcube FREESET, pcube OVEREXPANDED_CUBE, pcube SUPER_CUBE, pcube INIT_LOWER, int *num_covered, pcube c)
Definition: expand.c:135
pset_family sf_addset()
void setup_BB_CC(pcover BB, pcover CC)
Definition: expand.c:375
int ascend()
#define NONESSEN
Definition: espresso.h:128
pset set_diff()
#define EXPAND1
Definition: espresso.h:354
#define ALLOC(type, num)
Definition: avl.h:27
unsigned int debug
Definition: globals.c:19
#define COVERED
Definition: espresso.h:131
ABC_NAMESPACE_IMPL_START pcover expand(INOUT pcover F, IN pcover R, IN bool nonsparse)
Definition: expand.c:53
#define DISJOINT
Definition: espresso.h:514
#define ABC_NAMESPACE_IMPL_END
Definition: abc_global.h:108
void elim_lowering(pcover BB, pcover CC, pcube RAISE, pcube FREESET)
Definition: expand.c:288
#define FREE(obj)
Definition: avl.h:31
#define is_in_set(set, e)
Definition: espresso.h:170
long random()
void mincov(pcover BB, pcube RAISE, pcube FREESET)
Definition: expand.c:560
static int size
Definition: cuddSign.c:86
#define new_cover(i)
Definition: espresso.h:265
unsigned int * pset
Definition: espresso.h:73
#define foreach_active_set(R, last, p)
Definition: espresso.h:139
bool use_random_order
Definition: globals.c:38
#define ABC_NAMESPACE_IMPL_START
Definition: abc_global.h:107
#define set_remove(set, e)
Definition: espresso.h:171
#define TRUE
Definition: cudd.h:88
pset do_sm_minimum_cover()
#define set_insert(set, e)
Definition: espresso.h:172
#define GETSET(family, index)
Definition: espresso.h:161
bool setp_implies()
bool feasibly_covered(pcover BB, pcube c, pcube RAISE, pcube new_lower)
Definition: expand.c:521
#define count_ones(v)
Definition: espresso.h:245
bool setp_empty()
#define TESTP(set, flag)
Definition: espresso.h:124
pset_family sf_append()
#define ACTIVE
Definition: espresso.h:129
void select_feasible(pcover BB, pcover CC, pcube RAISE, pcube FREESET, pcube SUPER_CUBE, int *num_covered)
Definition: expand.c:404
void set_adjcnt()
bool cdist0()
pset_family sf_inactive()
#define pcube
Definition: espresso.h:261
int set_ord()