Ejemplo n.º 1
0
static pset_family
do_minimize(pset_family F, pset_family D, pset_family R, int exact_cover, int weighted)
{
pset_family newF, E, Rt, Rp;
pset p, last;
int heur, level, *weights;
sm_matrix *table;
sm_row *cover;
sm_element *pe;
int debug_save = debug;
if (debug & 0x0400) {
debug |= (0x0020 | 0x0800);
}
if (debug & 0x0800) {
setlinebuf((&_iob[1]));
}
level = (debug & 0x0800) ? 4 : 0;
heur = ! exact_cover;
{long t=util_cpu_time();F = primes_consensus(cube2list(F, D));if(trace)print_trace( F, "PRIMES     ",util_cpu_time()-t);};
{long t=util_cpu_time();irred_split_cover(F, D, &E, &Rt, &Rp);if(trace)print_trace( E, "ESSENTIALS ",util_cpu_time()-t);};
{long t=util_cpu_time();table = irred_derive_table(D, E, Rp);if(trace)print_trace( Rp, "PI-TABLE   ",util_cpu_time()-t);};
if (weighted) {
weights = ((int *) malloc(sizeof(int) * ( F->count)));
for( p=Rp->data, last= p+Rp->count*Rp->wsize; p< last; p+=Rp->wsize) {
weights[(p[0] >> 16)] = cube.size - set_ord(p);
}
} else {
Ejemplo n.º 2
0
Archivo: exact.c Proyecto: GtTmy/pyeda
static set_family_t *
do_minimize(set_family_t *F, set_family_t *D, set_family_t *R, int exact_cover, int weighted)
{
    set_family_t *newF, *E, *Rt, *Rp;
    set *p, *last;
    int heur, level, *weights;
    sm_matrix *table;
    sm_row *cover;
    sm_element *pe;
    int debug_save = debug;

    if (debug & EXACT) {
        debug |= (IRRED | MINCOV);
    }
    level = (debug & MINCOV) ? 4 : 0;
    heur = ! exact_cover;

    // Generate all prime implicants
    F = primes_consensus(cube2list(F, D));

    // Setup the prime implicant table
    irred_split_cover(F, D, &E, &Rt, &Rp);
    table = irred_derive_table(D, E, Rp);

    // Solve either a weighted or nonweighted covering problem
    if (weighted) {
        // correct only for all 2-valued variables
        weights = ALLOC(int, F->count);
        foreach_set(Rp, last, p) {
            weights[SIZE(p)] = CUBE.size - set_ord(p);
        }
    }
Ejemplo n.º 3
0
/* primes_consensus -- generate primes using consensus */
pcover primes_consensus(pset *T)
  /* T will be disposed of */
{
  register pcube cl, cr;
  register int best;
  pcover Tnew, Tl, Tr;

  if (primes_consensus_special_cases(T, &Tnew) == MAYBE) {
    cl = new_cube();
    cr = new_cube();
    best = binate_split_select(T, cl, cr, COMPL);

    Tl = primes_consensus(scofactor(T, cl, best));
    Tr = primes_consensus(scofactor(T, cr, best));
    Tnew = primes_consensus_merge(Tl, Tr, cl, cr);

    free_cube(cl);
    free_cube(cr);
    free_cubelist(T);
  }

  return Tnew;
}
Ejemplo n.º 4
0
static bool
primes_consensus_special_cases(pset *T, pset_family *Tnew)
  /* will be disposed if answer is determined */
  /* returned only if answer determined */
{
  register pcube *T1, p, ceil, cof=T[0];
  pcube last;
  pcover A;

  /* Check for no cubes in the cover */
  if (T[2] == NULL) {
    *Tnew = new_cover(0);
    free_cubelist(T);
    return TRUE;
  }

  /* Check for only a single cube in the cover */
  if (T[3] == NULL) {
    *Tnew = sf_addset(new_cover(1), set_or(cof, cof, T[2]));
    free_cubelist(T);
    return TRUE;
  }

  /* Check for a row of all 1's (implies function is a tautology) */
  for(T1 = T+2; (p = *T1++) != NULL; ) {
    if (full_row(p, cof)) {
      *Tnew = sf_addset(new_cover(1), cube.fullset);
      free_cubelist(T);
      return TRUE;
    }
  }

  /* Check for a column of all 0's which can be factored out */
  ceil = set_save(cof);
  for(T1 = T+2; (p = *T1++) != NULL; ) {
    INLINEset_or(ceil, ceil, p);
  }
  if (! setp_equal(ceil, cube.fullset)) {
    p = new_cube();
    (void) set_diff(p, cube.fullset, ceil);
    (void) set_or(cof, cof, p);
    free_cube(p);

    A = primes_consensus(T);
    foreach_set(A, last, p) {
      INLINEset_and(p, p, ceil);
    }
Ejemplo n.º 5
0
static pcover
do_minimize(pset_family F, pset_family D, pset_family R, int exact_cover, int weighted)
{
  pcover newF, E, Rt, Rp;
  pset p, last;
  int heur, level, *weights;
  sm_matrix *table;
  sm_row *cover;
  sm_element *pe;
  int debug_save = debug;

  if (debug & EXACT) {
    debug |= (IRRED | MINCOV);
  }
#if defined(sun) || defined(bsd4_2)     /* hack ... */
  if (debug & MINCOV) {
    setlinebuf(stdout);
  }
#endif
  level = (debug & MINCOV) ? 4 : 0;
  heur = ! exact_cover;

  /* Generate all prime implicants */
  EXEC(F = primes_consensus(cube2list(F, D)), "PRIMES     ", F);

  /* Setup the prime implicant table */
  EXEC(irred_split_cover(F, D, &E, &Rt, &Rp), "ESSENTIALS ", E);
  EXEC(table = irred_derive_table(D, E, Rp),  "PI-TABLE   ", Rp);

  /* Solve either a weighted or nonweighted covering problem */
  if (weighted) {
    /* correct only for all 2-valued variables */
    weights = ALLOC(int, F->count);
    foreach_set(Rp, last, p) {
      weights[SIZE(p)] = cube.size - set_ord(p);
    }
  } else {