#include "espresso.h"
Go to the source code of this file.
Functions | |
pcover | espresso (pcover F, pcover D1, pcover R) |
pcover espresso | ( | pcover | F, | |
pcover | D1, | |||
pcover | R | |||
) |
Definition at line 50 of file espresso.c.
00052 { 00053 pcover E, D, Fsave; 00054 pset last, p; 00055 cost_t cost, best_cost; 00056 00057 begin: 00058 Fsave = sf_save(F); /* save original function */ 00059 D = sf_save(D1); /* make a scratch copy of D */ 00060 00061 /* Setup has always been a problem */ 00062 if (recompute_onset) { 00063 EXEC(E = simplify(cube1list(F)), "SIMPLIFY ", E); 00064 free_cover(F); 00065 F = E; 00066 } 00067 cover_cost(F, &cost); 00068 if (unwrap_onset && (cube.part_size[cube.num_vars - 1] > 1) 00069 && (cost.out != cost.cubes*cube.part_size[cube.num_vars-1]) 00070 && (cost.out < 5000)) 00071 EXEC(F = sf_contain(unravel(F, cube.num_vars - 1)), "SETUP ", F); 00072 00073 /* Initial expand and irredundant */ 00074 foreach_set(F, last, p) { 00075 RESET(p, PRIME); 00076 } 00077 EXECUTE(F = expand(F, R, FALSE), EXPAND_TIME, F, cost); 00078 EXECUTE(F = irredundant(F, D), IRRED_TIME, F, cost); 00079 00080 if (! single_expand) { 00081 if (remove_essential) { 00082 EXECUTE(E = essential(&F, &D), ESSEN_TIME, E, cost); 00083 } else { 00084 E = new_cover(0); 00085 } 00086 00087 cover_cost(F, &cost); 00088 do { 00089 00090 /* Repeat inner loop until solution becomes "stable" */ 00091 do { 00092 copy_cost(&cost, &best_cost); 00093 EXECUTE(F = reduce(F, D), REDUCE_TIME, F, cost); 00094 EXECUTE(F = expand(F, R, FALSE), EXPAND_TIME, F, cost); 00095 EXECUTE(F = irredundant(F, D), IRRED_TIME, F, cost); 00096 } while (cost.cubes < best_cost.cubes); 00097 00098 /* Perturb solution to see if we can continue to iterate */ 00099 copy_cost(&cost, &best_cost); 00100 if (use_super_gasp) { 00101 F = super_gasp(F, D, R, &cost); 00102 if (cost.cubes >= best_cost.cubes) 00103 break; 00104 } else { 00105 F = last_gasp(F, D, R, &cost); 00106 } 00107 00108 } while (cost.cubes < best_cost.cubes || 00109 (cost.cubes == best_cost.cubes && cost.total < best_cost.total)); 00110 00111 /* Append the essential cubes to F */ 00112 F = sf_append(F, E); /* disposes of E */ 00113 if (trace) size_stamp(F, "ADJUST "); 00114 } 00115 00116 /* Free the D which we used */ 00117 free_cover(D); 00118 00119 /* Attempt to make the PLA matrix sparse */ 00120 if (! skip_make_sparse) { 00121 F = make_sparse(F, D1, R); 00122 } 00123 00124 /* 00125 * Check to make sure function is actually smaller !! 00126 * This can only happen because of the initial unravel. If we fail, 00127 * then run the whole thing again without the unravel. 00128 */ 00129 if (Fsave->count < F->count) { 00130 free_cover(F); 00131 F = Fsave; 00132 unwrap_onset = FALSE; 00133 goto begin; 00134 } else { 00135 free_cover(Fsave); 00136 } 00137 00138 return F; 00139 }