ABC: A System for Sequential Synthesis and Verification
 
Loading...
Searching...
No Matches
mincov.c File Reference
#include "mincov_int.h"
Include dependency graph for mincov.c:

Go to the source code of this file.

Macros

#define USE_GIMPEL
 
#define USE_INDEP_SET
 
#define fail(why)
 

Functions

sm_rowsm_minimum_cover (sm_matrix *A, int *weight, int heuristic, int debug_level)
 
solution_tsm_mincov (sm_matrix *A, solution_t *select, int *weight, int lb, int bound, int depth, stats_t *stats)
 

Macro Definition Documentation

◆ fail

#define fail ( why)
Value:
{\
(void) fprintf(stderr, "Fatal error: file %s, line %d\n%s\n",\
__FILE__, __LINE__, why);\
(void) fflush(stdout);\
abort();\
}

Definition at line 26 of file mincov.c.

26#define fail(why) {\
27 (void) fprintf(stderr, "Fatal error: file %s, line %d\n%s\n",\
28 __FILE__, __LINE__, why);\
29 (void) fflush(stdout);\
30 abort();\
31}

◆ USE_GIMPEL

#define USE_GIMPEL

Definition at line 19 of file mincov.c.

◆ USE_INDEP_SET

#define USE_INDEP_SET

Definition at line 20 of file mincov.c.

Function Documentation

◆ sm_mincov()

solution_t * sm_mincov ( sm_matrix * A,
solution_t * select,
int * weight,
int lb,
int bound,
int depth,
stats_t * stats )

Definition at line 119 of file mincov.c.

127{
128 sm_matrix *A1, *A2, *L, *R;
129 sm_element *p;
130 solution_t *select1, *select2, *best, *best1, *best2, *indep;
131 int pick, lb_new, debug;
132
133 /* Start out with some debugging information */
134 stats->nodes++;
135 if (depth > stats->max_depth) stats->max_depth = depth;
136 debug = stats->debug && (depth <= stats->max_print_depth);
137
138 /* Apply row dominance, column dominance, and select essentials */
139 select_essential(A, select, weight, bound);
140 if (select->cost >= bound) {
141 return NIL(solution_t);
142 }
143
144 /* See if gimpel's reduction technique applies ... */
145#ifdef USE_GIMPEL
146 if ( weight == NIL(int)) { /* hack until we fix it */
147 if (gimpel_reduce(A, select, weight, lb, bound, depth, stats, &best)) {
148 return best;
149 }
150 }
151#endif
152
153#ifdef USE_INDEP_SET
154 /* Determine bound from here to final solution using independent-set */
155 indep = sm_maximal_independent_set(A, weight);
156
157 /* make sure the lower bound is monotonically increasing */
158 lb_new = MAX(select->cost + indep->cost, lb);
159 pick = select_column(A, weight, indep);
160 solution_free(indep);
161#else
162 lb_new = select->cost + (A->nrows > 0);
163 pick = select_column(A, weight, NIL(solution_t));
164#endif
165
166 if (depth == 0) {
167 stats->lower_bound = lb_new + stats->gimpel;
168 }
169
170 if (debug) {
171 (void) printf("ABSMIN[%2d]%s", depth, stats->component ? "*" : " ");
172 (void) printf(" %3dx%3d sel=%3d bnd=%3d lb=%3d %12s ",
173 A->nrows, A->ncols, select->cost + stats->gimpel,
174 bound + stats->gimpel, lb_new + stats->gimpel,
175 util_print_time(util_cpu_time()-stats->start_time));
176 }
177
178 /* Check for bounding based on no better solution possible */
179 if (lb_new >= bound) {
180 if (debug) (void) printf("bounded\n");
181 best = NIL(solution_t);
182
183
184 /* Check for new best solution */
185 } else if (A->nrows == 0) {
186 best = solution_dup(select);
187 if (debug) (void) printf("BEST\n");
188 if (stats->debug && stats->component == 0) {
189 (void) printf("new 'best' solution %d at level %d (time is %s)\n",
190 best->cost + stats->gimpel, depth,
191 util_print_time(util_cpu_time() - stats->start_time));
192 }
193
194
195 /* Check for a partition of the problem */
196 } else if (sm_block_partition(A, &L, &R)) {
197 /* Make L the smaller problem */
198 if (L->ncols > R->ncols) {
199 A1 = L;
200 L = R;
201 R = A1;
202 }
203 if (debug) (void) printf("comp %d %d\n", L->nrows, R->nrows);
204 stats->comp_count++;
205
206 /* Solve problem for L */
207 select1 = solution_alloc();
208 stats->component++;
209 best1 = sm_mincov(L, select1, weight, 0,
210 bound-select->cost, depth+1, stats);
211 stats->component--;
212 solution_free(select1);
213 sm_free(L);
214
215 /* Add best solution to the selected set */
216 if (best1 == NIL(solution_t)) {
217 best = NIL(solution_t);
218 } else {
219 for(p = best1->row->first_col; p != 0; p = p->next_col) {
220 solution_add(select, weight, p->col_num);
221 }
222 solution_free(best1);
223
224 /* recur for the remaining block */
225 best = sm_mincov(R, select, weight, lb_new, bound, depth+1, stats);
226 }
227 sm_free(R);
228
229 /* We've tried as hard as possible, but now we must split and recur */
230 } else {
231 if (debug) (void) printf("pick=%d\n", pick);
232
233 /* Assume we choose this column to be in the covering set */
234 A1 = sm_dup(A);
235 select1 = solution_dup(select);
236 solution_accept(select1, A1, weight, pick);
237 best1 = sm_mincov(A1, select1, weight, lb_new, bound, depth+1, stats);
238 solution_free(select1);
239 sm_free(A1);
240
241 /* Update the upper bound if we found a better solution */
242 if (best1 != NIL(solution_t) && bound > best1->cost) {
243 bound = best1->cost;
244 }
245
246 /* See if this is a heuristic covering (no branching) */
247 if (stats->no_branching) {
248 return best1;
249 }
250
251 /* Check for reaching lower bound -- if so, don't actually branch */
252 if (best1 != NIL(solution_t) && best1->cost == lb_new) {
253 return best1;
254 }
255
256 /* Now assume we cannot have that column */
257 A2 = sm_dup(A);
258 select2 = solution_dup(select);
259 solution_reject(select2, A2, weight, pick);
260 best2 = sm_mincov(A2, select2, weight, lb_new, bound, depth+1, stats);
261 solution_free(select2);
262 sm_free(A2);
263
264 best = solution_choose_best(best1, best2);
265 }
266
267 return best;
268}
#define NIL(type)
Definition avl.h:25
#define MAX(a, b)
Definition avl.h:23
unsigned int debug
Definition globals.c:19
Cube * p
Definition exorList.c:222
solution_t * solution_choose_best()
void solution_reject()
solution_t * solution_alloc()
Definition solution.c:17
void solution_accept()
void solution_add()
solution_t * sm_maximal_independent_set()
struct solution_struct solution_t
Definition mincov_int.h:35
solution_t * solution_dup()
int gimpel_reduce()
void solution_free()
solution_t * sm_mincov()
typedefABC_NAMESPACE_HEADER_START struct sm_element_struct sm_element
Definition sparse.h:21
sm_matrix * sm_dup()
int sm_block_partition()
void sm_free()
struct sm_matrix_struct sm_matrix
Definition sparse.h:24
sm_element * first_col
Definition sparse.h:48
#define util_cpu_time
Definition util_hack.h:36
Here is the call graph for this function:

◆ sm_minimum_cover()

sm_row * sm_minimum_cover ( sm_matrix * A,
int * weight,
int heuristic,
int debug_level )

Definition at line 34 of file mincov.c.

39{
40 stats_t stats;
41 solution_t *best, *select;
42 sm_row *prow, *sol;
43 sm_col *pcol;
44 sm_matrix *dup_A;
45 int nelem, bound;
46 double sparsity;
47
48 /* Avoid sillyness */
49 if (A->nrows <= 0) {
50 return sm_row_alloc(); /* easy to cover */
51 }
52
53 /* Initialize debugging structure */
54 stats.start_time = util_cpu_time();
55 stats.debug = debug_level > 0;
56 stats.max_print_depth = debug_level;
57 stats.max_depth = -1;
58 stats.nodes = 0;
59 stats.component = stats.comp_count = 0;
60 stats.gimpel = stats.gimpel_count = 0;
61 stats.no_branching = heuristic != 0;
62 stats.lower_bound = -1;
63
64 /* Check the matrix sparsity */
65 nelem = 0;
66 sm_foreach_row(A, prow) {
67 nelem += prow->length;
68 }
69 sparsity = (double) nelem / (double) (A->nrows * A->ncols);
70
71 /* Determine an upper bound on the solution */
72 bound = 1;
73 sm_foreach_col(A, pcol) {
74 bound += WEIGHT(weight, pcol->col_num);
75 }
76
77 /* Perform the covering */
78 select = solution_alloc();
79 dup_A = sm_dup(A);
80 best = sm_mincov(dup_A, select, weight, 0, bound, 0, &stats);
81 sm_free(dup_A);
82 solution_free(select);
83
84 if (stats.debug) {
85 if (stats.no_branching) {
86 (void) printf("**** heuristic covering ...\n");
87 (void) printf("lower bound = %d\n", stats.lower_bound);
88 }
89 (void) printf("matrix = %d by %d with %d elements (%4.3f%%)\n",
90 A->nrows, A->ncols, nelem, sparsity * 100.0);
91 (void) printf("cover size = %d elements\n", best->row->length);
92 (void) printf("cover cost = %d\n", best->cost);
93 (void) printf("time = %s\n",
94 util_print_time(util_cpu_time() - stats.start_time));
95 (void) printf("components = %d\n", stats.comp_count);
96 (void) printf("gimpel = %d\n", stats.gimpel_count);
97 (void) printf("nodes = %d\n", stats.nodes);
98 (void) printf("max_depth = %d\n", stats.max_depth);
99 }
100
101 sol = sm_row_dup(best->row);
102 if (! verify_cover(A, sol)) {
103 fail("mincov: internal error -- cover verification failed\n");
104 }
105 solution_free(best);
106 return sol;
107}
#define fail(why)
Definition mincov.c:26
ABC_NAMESPACE_IMPL_START sm_row * sm_row_alloc()
Definition rows.c:21
struct sm_col_struct sm_col
Definition sparse.h:23
struct sm_row_struct sm_row
Definition sparse.h:22
#define sm_foreach_row(A, prow)
Definition sparse.h:97
#define sm_foreach_col(A, pcol)
Definition sparse.h:100
sm_row * sm_row_dup()
int col_num
Definition sparse.h:60
Here is the call graph for this function: