src/misc/espresso/gimpel.c File Reference

#include "mincov_int.h"
Include dependency graph for gimpel.c:

Go to the source code of this file.

Functions

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

Function Documentation

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

Definition at line 27 of file gimpel.c.

00036 {
00037     register sm_row *prow, *save_sec;
00038     register sm_col *c1, *c2;
00039     register sm_element *p, *p1;
00040     int c1_col_num, c2_col_num, primary_row_num, secondary_row_num;
00041     int reduce_it; 
00042 
00043     reduce_it = 0;
00044     for(prow = A->first_row; prow != 0; prow = prow->next_row) {
00045         if (prow->length == 2) {
00046             c1 = sm_get_col(A, prow->first_col->col_num);
00047             c2 = sm_get_col(A, prow->last_col->col_num);
00048             if (c1->length == 2) {
00049                 reduce_it = 1;
00050             } else if (c2->length == 2) {
00051                 c1 = sm_get_col(A, prow->last_col->col_num);
00052                 c2 = sm_get_col(A, prow->first_col->col_num);
00053                 reduce_it = 1;
00054             }
00055             if (reduce_it) {
00056                 primary_row_num = prow->row_num;
00057                 secondary_row_num = c1->first_row->row_num;
00058                 if (secondary_row_num == primary_row_num) {
00059                     secondary_row_num = c1->last_row->row_num;
00060                 }
00061                 break;
00062             }
00063         }
00064     }
00065 
00066     if (reduce_it) {
00067         c1_col_num = c1->col_num;
00068         c2_col_num = c2->col_num;
00069         save_sec = sm_row_dup(sm_get_row(A, secondary_row_num));
00070         sm_row_remove(save_sec, c1_col_num);
00071 
00072         for(p = c2->first_row; p != 0; p = p->next_row) {
00073             if (p->row_num != primary_row_num) {
00074                 /* merge rows S1 and T */
00075                 for(p1 = save_sec->first_col; p1 != 0; p1 = p1->next_col) {
00076                     (void) sm_insert(A, p->row_num, p1->col_num);
00077                 }
00078             }
00079         }
00080 
00081         sm_delcol(A, c1_col_num);
00082         sm_delcol(A, c2_col_num);
00083         sm_delrow(A, primary_row_num);
00084         sm_delrow(A, secondary_row_num);
00085 
00086         stats->gimpel_count++;
00087         stats->gimpel++;
00088         *best = sm_mincov(A, select, weight, lb-1, bound-1, depth, stats);
00089         stats->gimpel--;
00090 
00091         if (*best != NIL(solution_t)) {
00092             /* is secondary row covered ? */
00093             if (sm_row_intersects(save_sec, (*best)->row)) {
00094                 /* yes, actually select c2 */
00095                 solution_add(*best, weight, c2_col_num);
00096             } else {
00097                 solution_add(*best, weight, c1_col_num);
00098             }
00099         }
00100 
00101         sm_row_free(save_sec);
00102         return 1;
00103     } else {
00104         return 0;
00105     }
00106 }


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