src/misc/espresso/reduce.c File Reference

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

Go to the source code of this file.

Functions

pcover reduce (INOUT pcover F, IN pcover D)
pcube reduce_cube (IN pcube *FD, IN pcube p)
pcube sccc (INOUT pcube *T)
pcube sccc_merge (INOUT register pcube left, INOUT register pcube right, INOUT register pcube cl, INOUT register pcube cr)
pcube sccc_cube (pcube result, pcube p)
bool sccc_special_cases (INOUT pcube *T, OUT pcube *result)

Variables

static bool toggle = TRUE

Function Documentation

pcover reduce ( INOUT pcover  F,
IN pcover  D 
)

Definition at line 56 of file reduce.c.

00059 {
00060     register pcube last, p, cunder, *FD;
00061 
00062     /* Order the cubes */
00063     if (use_random_order)
00064         F = random_order(F);
00065     else {
00066         F = toggle ? sort_reduce(F) : mini_sort(F, descend);
00067         toggle = ! toggle;
00068     }
00069 
00070     /* Try to reduce each cube */
00071     FD = cube2list(F, D);
00072     foreach_set(F, last, p) {
00073         cunder = reduce_cube(FD, p);            /* reduce the cube */
00074         if (setp_equal(cunder, p)) {            /* see if it actually did */
00075             SET(p, ACTIVE);     /* cube remains active */
00076             SET(p, PRIME);      /* cube remains prime ? */
00077         } else {
00078             if (debug & REDUCE) {
00079                 printf("REDUCE: %s to %s %s\n",
00080                     pc1(p), pc2(cunder), print_time(ptime()));
00081             }
00082             set_copy(p, cunder);                /* save reduced version */
00083             RESET(p, PRIME);                    /* cube is no longer prime */
00084             if (setp_empty(cunder))
00085                 RESET(p, ACTIVE);               /* if null, kill the cube */
00086             else
00087                 SET(p, ACTIVE);                 /* cube is active */
00088         }
00089         free_cube(cunder);
00090     }
00091     free_cubelist(FD);
00092 
00093     /* Delete any cubes of F which reduced to the empty cube */
00094     return sf_inactive(F);
00095 }

pcube reduce_cube ( IN pcube *  FD,
IN pcube  p 
)

Definition at line 98 of file reduce.c.

00100 {
00101     pcube cunder;
00102 
00103     cunder = sccc(cofactor(FD, p));
00104     return set_and(cunder, cunder, p);
00105 }

pcube sccc ( INOUT pcube *  T  ) 

Definition at line 109 of file reduce.c.

00111 {
00112     pcube r;
00113     register pcube cl, cr;
00114     register int best;
00115     static int sccc_level = 0;
00116 
00117     if (debug & REDUCE1) {
00118         debug_print(T, "SCCC", sccc_level++);
00119     }
00120 
00121     if (sccc_special_cases(T, &r) == MAYBE) {
00122         cl = new_cube();
00123         cr = new_cube();
00124         best = binate_split_select(T, cl, cr, REDUCE1);
00125         r = sccc_merge(sccc(scofactor(T, cl, best)),
00126                        sccc(scofactor(T, cr, best)), cl, cr);
00127         free_cubelist(T);
00128     }
00129 
00130     if (debug & REDUCE1)
00131         printf("SCCC[%d]: result is %s\n", --sccc_level, pc1(r));
00132     return r;
00133 }

pcube sccc_cube ( pcube  result,
pcube  p 
)

Definition at line 163 of file reduce.c.

00165 {
00166     register pcube temp=cube.temp[0], mask;
00167     int var;
00168 
00169     if ((var = cactive(p)) >= 0) {
00170         mask = cube.var_mask[var];
00171         INLINEset_xor(temp, p, mask);
00172         INLINEset_and(result, result, temp);
00173     }
00174     return result;
00175 }

pcube sccc_merge ( INOUT register pcube  left,
INOUT register pcube  right,
INOUT register pcube  cl,
INOUT register pcube  cr 
)

Definition at line 136 of file reduce.c.

00139 {
00140     INLINEset_and(left, left, cl);
00141     INLINEset_and(right, right, cr);
00142     INLINEset_or(left, left, right);
00143     free_cube(right);
00144     free_cube(cl);
00145     free_cube(cr);
00146     return left;
00147 }

bool sccc_special_cases ( INOUT pcube *  T,
OUT pcube *  result 
)

Definition at line 181 of file reduce.c.

00184 {
00185     register pcube *T1, p, temp = cube.temp[1], ceil, cof = T[0];
00186     pcube *A, *B;
00187 
00188     /* empty cover => complement is universe => SCCC is universe */
00189     if (T[2] == NULL) {
00190         *result = set_save(cube.fullset);
00191         free_cubelist(T);
00192         return TRUE;
00193     }
00194 
00195     /* row of 1's => complement is empty => SCCC is empty */
00196     for(T1 = T+2; (p = *T1++) != NULL; ) {
00197         if (full_row(p, cof)) {
00198             *result = new_cube();
00199             free_cubelist(T);
00200             return TRUE;
00201         }
00202     }
00203 
00204     /* Collect column counts, determine unate variables, etc. */
00205     massive_count(T);
00206 
00207     /* If cover is unate (or single cube), apply simple rules to find SCCCU */
00208     if (cdata.vars_unate == cdata.vars_active || T[3] == NULL) {
00209         *result = set_save(cube.fullset);
00210         for(T1 = T+2; (p = *T1++) != NULL; ) {
00211             (void) sccc_cube(*result, set_or(temp, p, cof));
00212         }
00213         free_cubelist(T);
00214         return TRUE;
00215     }
00216 
00217     /* Check for column of 0's (which can be easily factored( */
00218     ceil = set_save(cof);
00219     for(T1 = T+2; (p = *T1++) != NULL; ) {
00220         INLINEset_or(ceil, ceil, p);
00221     }
00222     if (! setp_equal(ceil, cube.fullset)) {
00223         *result = sccc_cube(set_save(cube.fullset), ceil);
00224         if (setp_equal(*result, cube.fullset)) {
00225             free_cube(ceil);
00226         } else {
00227             *result = sccc_merge(sccc(cofactor(T,ceil)),
00228                          set_save(cube.fullset), ceil, *result);
00229         }
00230         free_cubelist(T);
00231         return TRUE;
00232     }
00233     free_cube(ceil);
00234 
00235     /* Single active column at this point => tautology => SCCC is empty */
00236     if (cdata.vars_active == 1) {
00237         *result = new_cube();
00238         free_cubelist(T);
00239         return TRUE;
00240     }
00241 
00242     /* Check for components */
00243     if (cdata.var_zeros[cdata.best] < CUBELISTSIZE(T)/2) {
00244         if (cubelist_partition(T, &A, &B, debug & REDUCE1) == 0) {
00245             return MAYBE;
00246         } else {
00247             free_cubelist(T);
00248             *result = sccc(A);
00249             ceil = sccc(B);
00250             (void) set_and(*result, *result, ceil);
00251             set_free(ceil);
00252             return TRUE;
00253         }
00254     }
00255 
00256     /* Not much we can do about it */
00257     return MAYBE;
00258 }


Variable Documentation

bool toggle = TRUE [static]

Definition at line 21 of file reduce.c.


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