src/misc/espresso/exact.c File Reference

#include "espresso.h"
Include dependency graph for exact.c:

Go to the source code of this file.

Functions

static void dump_irredundant ()
static pcover do_minimize ()
pcover minimize_exact (pcover F, pcover D, pcover R, int exact_cover)
pcover minimize_exact_literals (pcover F, pcover D, pcover R, int exact_cover)
static pcover do_minimize (pcover F, pcover D, pcover R, int exact_cover, int weighted)
static void dump_irredundant (pcover E, pcover Rt, pcover Rp, sm_matrix *table)

Function Documentation

static pcover do_minimize ( pcover  F,
pcover  D,
pcover  R,
int  exact_cover,
int  weighted 
) [static]

Definition at line 46 of file exact.c.

00050 {
00051     pcover newF, E, Rt, Rp;
00052     pset p, last;
00053     int heur, level, *weights, i;
00054     sm_matrix *table;
00055     sm_row *cover;
00056     sm_element *pe;
00057     int debug_save = debug;
00058 
00059     if (debug & EXACT) {
00060         debug |= (IRRED | MINCOV);
00061     }
00062 #if defined(sun) || defined(bsd4_2)                     /* hack ... */
00063     if (debug & MINCOV) {
00064         setlinebuf(stdout);
00065     }
00066 #endif
00067     level = (debug & MINCOV) ? 4 : 0;
00068     heur = ! exact_cover;
00069 
00070     /* Generate all prime implicants */
00071     EXEC(F = primes_consensus(cube2list(F, D)), "PRIMES     ", F);
00072 
00073     /* Setup the prime implicant table */
00074     EXEC(irred_split_cover(F, D, &E, &Rt, &Rp), "ESSENTIALS ", E);
00075     EXEC(table = irred_derive_table(D, E, Rp),  "PI-TABLE   ", Rp);
00076 
00077     /* Solve either a weighted or nonweighted covering problem */
00078     if (weighted) {
00079         /* correct only for all 2-valued variables */
00080         weights = ALLOC(int, F->count);
00081         foreach_set(Rp, last, p) {
00082             weights[SIZE(p)] = cube.size - set_ord(p);
00083             /* We have added the 0's in the output part instead of the 1's.
00084                This loop corrects the literal count. */
00085             for (i = cube.first_part[cube.output];
00086                  i <= cube.last_part[cube.output]; i++) {
00087                 is_in_set(p, i) ? weights[SIZE(p)]++ : weights[SIZE(p)]--;
00088             }
00089         }
00090     } else {
00091         weights = NIL(int);
00092     }
00093     EXEC(cover=sm_minimum_cover(table,weights,heur,level), "MINCOV     ", F);
00094     if (weights != 0) {
00095         FREE(weights);
00096     }
00097 
00098     if (debug & EXACT) {
00099         dump_irredundant(E, Rt, Rp, table);
00100     }
00101 
00102     /* Form the result cover */
00103     newF = new_cover(100);
00104     foreach_set(E, last, p) {
00105         newF = sf_addset(newF, p);
00106     }
00107     sm_foreach_row_element(cover, pe) {
00108         newF = sf_addset(newF, GETSET(F, pe->col_num));
00109     }
00110 
00111     free_cover(E);
00112     free_cover(Rt);
00113     free_cover(Rp);
00114     sm_free(table);
00115     sm_row_free(cover);
00116     free_cover(F);
00117 
00118     /* Attempt to make the results more sparse */
00119     debug &= ~ (IRRED | SHARP | MINCOV);
00120     if (! skip_make_sparse && R != 0) {
00121         newF = make_sparse(newF, D, R);
00122     }
00123 
00124     debug = debug_save;
00125     return newF;
00126 }

static pcover do_minimize (  )  [static]
static void dump_irredundant ( pcover  E,
pcover  Rt,
pcover  Rp,
sm_matrix table 
) [static]

Definition at line 129 of file exact.c.

00132 {
00133     FILE *fp_pi_table, *fp_primes;
00134     pPLA PLA;
00135     pset last, p;
00136     char *file;
00137 
00138     if (filename == 0 || strcmp(filename, "(stdin)") == 0) {
00139         fp_pi_table = fp_primes = stdout;
00140     } else {
00141         file = ALLOC(char, strlen(filename)+20);
00142         (void) sprintf(file, "%s.primes", filename);
00143         if ((fp_primes = fopen(file, "w")) == NULL) {
00144             (void) fprintf(stderr, "espresso: Unable to open %s\n", file);
00145             fp_primes = stdout;
00146         }
00147         (void) sprintf(file, "%s.pi", filename);
00148         if ((fp_pi_table = fopen(file, "w")) == NULL) {
00149             (void) fprintf(stderr, "espresso: Unable to open %s\n", file);
00150             fp_pi_table = stdout;
00151         }
00152         FREE(file);
00153     }
00154 
00155     PLA = new_PLA();
00156     PLA_labels(PLA);
00157 
00158     fpr_header(fp_primes, PLA, F_type);
00159     free_PLA(PLA);
00160 
00161     (void) fprintf(fp_primes, "# Essential primes are\n");
00162     foreach_set(E, last, p) {
00163         (void) fprintf(fp_primes, "%s\n", pc1(p));
00164     }
00165     (void) fprintf(fp_primes, "# Totally redundant primes are\n");
00166     foreach_set(Rt, last, p) {
00167         (void) fprintf(fp_primes, "%s\n", pc1(p));
00168     }
00169     (void) fprintf(fp_primes, "# Partially redundant primes are\n");
00170     foreach_set(Rp, last, p) {
00171         (void) fprintf(fp_primes, "%s\n", pc1(p));
00172     }
00173     if (fp_primes != stdout) {
00174         (void) fclose(fp_primes);
00175     }
00176         
00177     sm_write(fp_pi_table, table);
00178     if (fp_pi_table != stdout) {
00179         (void) fclose(fp_pi_table);
00180     }
00181 }

static void dump_irredundant (  )  [static]
pcover minimize_exact ( pcover  F,
pcover  D,
pcover  R,
int  exact_cover 
)

Definition at line 27 of file exact.c.

00030 {
00031     return do_minimize(F, D, R, exact_cover, /*weighted*/ 0);
00032 }

pcover minimize_exact_literals ( pcover  F,
pcover  D,
pcover  R,
int  exact_cover 
)

Definition at line 36 of file exact.c.

00039 {
00040     return do_minimize(F, D, R, exact_cover, /*weighted*/ 1);
00041 }


Generated on Tue Jan 5 12:19:10 2010 for abc70930 by  doxygen 1.6.1