abc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
expand.c File Reference
#include "espresso.h"

Go to the source code of this file.

Macros

#define NEW
 

Functions

ABC_NAMESPACE_IMPL_START pcover expand (INOUT pcover F, IN pcover R, IN bool nonsparse)
 
void expand1 (pcover BB, pcover CC, pcube RAISE, pcube FREESET, pcube OVEREXPANDED_CUBE, pcube SUPER_CUBE, pcube INIT_LOWER, int *num_covered, pcube c)
 
void essen_parts (pcover BB, pcover CC, pcube RAISE, pcube FREESET)
 
void essen_raising (pcover BB, pcube RAISE, pcube FREESET)
 
void elim_lowering (pcover BB, pcover CC, pcube RAISE, pcube FREESET)
 
int most_frequent (pcover CC, pcube FREESET)
 
void setup_BB_CC (pcover BB, pcover CC)
 
void select_feasible (pcover BB, pcover CC, pcube RAISE, pcube FREESET, pcube SUPER_CUBE, int *num_covered)
 
bool feasibly_covered (pcover BB, pcube c, pcube RAISE, pcube new_lower)
 
void mincov (pcover BB, pcube RAISE, pcube FREESET)
 
pcover find_all_primes (pcover BB, pcube RAISE, pcube FREESET)
 
pcover all_primes (pcover F, pcover R)
 

Macro Definition Documentation

#define NEW

Function Documentation

pcover all_primes ( pcover  F,
pcover  R 
)

Definition at line 669 of file expand.c.

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 }
#define set_free(r)
Definition: espresso.h:167
#define new_cube()
Definition: espresso.h:262
static Llb_Mgr_t * p
Definition: llb3Image.c:950
#define pcover
Definition: espresso.h:264
pset set_copy()
void essen_parts(pcover BB, pcover CC, pcube RAISE, pcube FREESET)
Definition: expand.c:210
pcover find_all_primes(pcover BB, pcube RAISE, pcube FREESET)
Definition: expand.c:634
#define PRIME
Definition: espresso.h:127
#define foreach_set(R, last, p)
Definition: espresso.h:135
pset_family sf_addset()
void setup_BB_CC(pcover BB, pcover CC)
Definition: expand.c:375
pset set_diff()
#define new_cover(i)
Definition: espresso.h:265
#define TESTP(set, flag)
Definition: espresso.h:124
pset_family sf_append()
#define pcube
Definition: espresso.h:261
void elim_lowering ( pcover  BB,
pcover  CC,
pcube  RAISE,
pcube  FREESET 
)

Definition at line 288 of file expand.c.

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 }
pset set_or()
static Llb_Mgr_t * p
Definition: llb3Image.c:950
#define pcover
Definition: espresso.h:264
#define INLINEsetp_implies(a, b, when_false)
Definition: espresso.h:228
int var(Lit p)
Definition: SolverTypes.h:62
#define RESET(set, flag)
Definition: espresso.h:123
#define DISJOINT
Definition: espresso.h:514
#define foreach_active_set(R, last, p)
Definition: espresso.h:139
bool setp_implies()
#define ACTIVE
Definition: espresso.h:129
bool cdist0()
#define pcube
Definition: espresso.h:261
void essen_parts ( pcover  BB,
pcover  CC,
pcube  RAISE,
pcube  FREESET 
)

Definition at line 210 of file expand.c.

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 }
pset force_lower()
int cdist01()
void fatal(char *s)
Definition: cvrmisc.c:140
char * pc1(pcube c)
Definition: cvrout.c:379
static Llb_Mgr_t * p
Definition: llb3Image.c:950
pset set_copy()
int var(Lit p)
Definition: SolverTypes.h:62
char * pc2(pcube c)
Definition: cvrout.c:381
#define RESET(set, flag)
Definition: espresso.h:123
pset set_diff()
#define EXPAND1
Definition: espresso.h:354
unsigned int debug
Definition: globals.c:19
#define DISJOINT
Definition: espresso.h:514
void elim_lowering(pcover BB, pcover CC, pcube RAISE, pcube FREESET)
Definition: expand.c:288
#define foreach_active_set(R, last, p)
Definition: espresso.h:139
#define count_ones(v)
Definition: espresso.h:245
bool setp_empty()
#define ACTIVE
Definition: espresso.h:129
#define pcube
Definition: espresso.h:261
void essen_raising ( pcover  BB,
pcube  RAISE,
pcube  FREESET 
)

Definition at line 259 of file expand.c.

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 }
pset set_or()
char * pc1(pcube c)
Definition: cvrout.c:379
static Llb_Mgr_t * p
Definition: llb3Image.c:950
pset set_copy()
char * pc2(pcube c)
Definition: cvrout.c:381
#define INLINEset_or(r, a, b)
Definition: espresso.h:205
pset set_diff()
#define EXPAND1
Definition: espresso.h:354
unsigned int debug
Definition: globals.c:19
if(last==0)
Definition: sparse_int.h:34
#define foreach_active_set(R, last, p)
Definition: espresso.h:139
#define pcube
Definition: espresso.h:261
ABC_NAMESPACE_IMPL_START pcover expand ( INOUT pcover  F,
IN pcover  R,
IN bool  nonsparse 
)

Definition at line 53 of file expand.c.

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 }
pset set_or()
#define FALSE
Definition: cudd.h:91
#define new_cube()
Definition: espresso.h:262
char * pc1(pcube c)
Definition: cvrout.c:379
static Llb_Mgr_t * p
Definition: llb3Image.c:950
pset set_copy()
int var(Lit p)
Definition: SolverTypes.h:62
#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
#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
pcover random_order(pcover F)
Definition: cvrm.c:199
#define EXPAND
Definition: espresso.h:353
bool setp_equal()
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
int ascend()
#define NONESSEN
Definition: espresso.h:128
unsigned int debug
Definition: globals.c:19
#define COVERED
Definition: espresso.h:131
bool use_random_order
Definition: globals.c:38
#define TRUE
Definition: cudd.h:88
#define TESTP(set, flag)
Definition: espresso.h:124
#define ACTIVE
Definition: espresso.h:129
pset_family sf_inactive()
#define pcube
Definition: espresso.h:261
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 at line 135 of file expand.c.

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 }
int most_frequent(pcover CC, pcube FREESET)
Definition: expand.c:338
pset set_or()
char * pc1(pcube c)
Definition: cvrout.c:379
pset set_copy()
void essen_parts(pcover BB, pcover CC, pcube RAISE, pcube FREESET)
Definition: expand.c:210
#define PRIME
Definition: espresso.h:127
#define SET(set, flag)
Definition: espresso.h:122
void setup_BB_CC(pcover BB, pcover CC)
Definition: expand.c:375
pset set_diff()
#define EXPAND1
Definition: espresso.h:354
unsigned int debug
Definition: globals.c:19
void elim_lowering(pcover BB, pcover CC, pcube RAISE, pcube FREESET)
Definition: expand.c:288
void mincov(pcover BB, pcube RAISE, pcube FREESET)
Definition: expand.c:560
#define set_remove(set, e)
Definition: espresso.h:171
#define set_insert(set, e)
Definition: espresso.h:172
bool setp_empty()
void select_feasible(pcover BB, pcover CC, pcube RAISE, pcube FREESET, pcube SUPER_CUBE, int *num_covered)
Definition: expand.c:404
bool feasibly_covered ( pcover  BB,
pcube  c,
pcube  RAISE,
pcube  new_lower 
)

Definition at line 521 of file expand.c.

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 }
pset force_lower()
pset set_or()
int cdist01()
#define FALSE
Definition: cudd.h:91
static Llb_Mgr_t * p
Definition: llb3Image.c:950
pset set_copy()
int var(Lit p)
Definition: SolverTypes.h:62
#define DISJOINT
Definition: espresso.h:514
#define foreach_active_set(R, last, p)
Definition: espresso.h:139
#define TRUE
Definition: cudd.h:88
#define count_ones(v)
Definition: espresso.h:245
#define pcube
Definition: espresso.h:261
pcover find_all_primes ( pcover  BB,
pcube  RAISE,
pcube  FREESET 
)

Definition at line 634 of file expand.c.

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 }
pset force_lower()
#define INLINEset_diff(r, a, b)
Definition: espresso.h:208
pset_family sf_rev_contain(INOUT pset_family A)
Definition: contain.c:58
static Llb_Mgr_t * p
Definition: llb3Image.c:950
#define free_cover(r)
Definition: espresso.h:266
pset set_copy()
pcover unravel(IN pcover B, IN int start)
Definition: cvrm.c:113
pset_family exact_minimum_cover()
int count
Definition: espresso.h:80
#define PRIME
Definition: espresso.h:127
#define SET(set, flag)
Definition: espresso.h:122
#define foreach_set(R, last, p)
Definition: espresso.h:135
#define INLINEset_or(r, a, b)
Definition: espresso.h:205
#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
#define GETSET(family, index)
Definition: espresso.h:161
void mincov ( pcover  BB,
pcube  RAISE,
pcube  FREESET 
)

Definition at line 560 of file expand.c.

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 }
int most_frequent(pcover CC, pcube FREESET)
Definition: expand.c:338
pset force_lower()
pset set_or()
#define set_free(r)
Definition: espresso.h:167
char * pc1(pcube c)
Definition: cvrout.c:379
int set_dist()
static Llb_Mgr_t * p
Definition: llb3Image.c:950
#define pcover
Definition: espresso.h:264
pset set_copy()
pcover unravel(IN pcover B, IN int start)
Definition: cvrm.c:113
void essen_parts(pcover BB, pcover CC, pcube RAISE, pcube FREESET)
Definition: expand.c:210
int var(Lit p)
Definition: SolverTypes.h:62
int count
Definition: espresso.h:80
void sf_free()
char * pc2(pcube c)
Definition: cvrout.c:381
#define foreach_set(R, last, p)
Definition: espresso.h:135
pset set_diff()
#define EXPAND1
Definition: espresso.h:354
unsigned int debug
Definition: globals.c:19
#define is_in_set(set, e)
Definition: espresso.h:170
long random()
#define new_cover(i)
Definition: espresso.h:265
#define foreach_active_set(R, last, p)
Definition: espresso.h:139
#define set_remove(set, e)
Definition: espresso.h:171
pset do_sm_minimum_cover()
#define set_insert(set, e)
Definition: espresso.h:172
#define GETSET(family, index)
Definition: espresso.h:161
#define pcube
Definition: espresso.h:261
int set_ord()
int most_frequent ( pcover  CC,
pcube  FREESET 
)

Definition at line 338 of file expand.c.

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 }
static Llb_Mgr_t * p
Definition: llb3Image.c:950
#define pcover
Definition: espresso.h:264
char * pc2(pcube c)
Definition: cvrout.c:381
for(p=first;p->value< newval;p=p->next)
#define EXPAND1
Definition: espresso.h:354
#define ALLOC(type, num)
Definition: avl.h:27
unsigned int debug
Definition: globals.c:19
if(last==0)
Definition: sparse_int.h:34
#define FREE(obj)
Definition: avl.h:31
#define is_in_set(set, e)
Definition: espresso.h:170
static int size
Definition: cuddSign.c:86
unsigned int * pset
Definition: espresso.h:73
#define foreach_active_set(R, last, p)
Definition: espresso.h:139
void set_adjcnt()
void select_feasible ( pcover  BB,
pcover  CC,
pcube  RAISE,
pcube  FREESET,
pcube  SUPER_CUBE,
int *  num_covered 
)

Definition at line 404 of file expand.c.

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 }
pset set_or()
char * pc1(pcube c)
Definition: cvrout.c:379
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
void essen_parts(pcover BB, pcover CC, pcube RAISE, pcube FREESET)
Definition: expand.c:210
void essen_raising(pcover BB, pcube RAISE, pcube FREESET)
Definition: expand.c:259
char * pc2(pcube c)
Definition: cvrout.c:381
bool setp_disjoint()
#define SET(set, flag)
Definition: espresso.h:122
#define RESET(set, flag)
Definition: espresso.h:123
for(p=first;p->value< newval;p=p->next)
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
#define FREE(obj)
Definition: avl.h:31
static int size
Definition: cuddSign.c:86
#define new_cover(i)
Definition: espresso.h:265
#define foreach_active_set(R, last, p)
Definition: espresso.h:139
#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 TESTP(set, flag)
Definition: espresso.h:124
#define ACTIVE
Definition: espresso.h:129
#define pcube
Definition: espresso.h:261
void setup_BB_CC ( pcover  BB,
pcover  CC 
)

Definition at line 375 of file expand.c.

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 }
static Llb_Mgr_t * p
Definition: llb3Image.c:950
#define pcover
Definition: espresso.h:264
#define PRIME
Definition: espresso.h:127
#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 COVERED
Definition: espresso.h:131
if(last==0)
Definition: sparse_int.h:34
else
Definition: sparse_int.h:55
#define TESTP(set, flag)
Definition: espresso.h:124
#define ACTIVE
Definition: espresso.h:129
#define pcube
Definition: espresso.h:261