src/misc/espresso/indep.c File Reference

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

Go to the source code of this file.

Functions

static sm_matrixbuild_intersection_matrix ()
solution_tsm_maximal_independent_set (sm_matrix *A, int *weight)
static sm_matrixbuild_intersection_matrix (sm_matrix *A)

Function Documentation

static sm_matrix* build_intersection_matrix ( sm_matrix A  )  [static]

Definition at line 99 of file indep.c.

00101 {
00102     register sm_row *prow, *prow1;
00103     register sm_element *p, *p1;
00104     register sm_col *pcol;
00105     sm_matrix *B;
00106 
00107     /* Build row-intersection matrix */
00108     B = sm_alloc();
00109     for(prow = A->first_row; prow != 0; prow = prow->next_row) {
00110 
00111         /* Clear flags on all rows we can reach from row 'prow' */
00112         for(p = prow->first_col; p != 0; p = p->next_col) {
00113             pcol = sm_get_col(A, p->col_num);
00114             for(p1 = pcol->first_row; p1 != 0; p1 = p1->next_row) {
00115                 prow1 = sm_get_row(A, p1->row_num);
00116                 prow1->flag = 0;
00117             }
00118         }
00119 
00120         /* Now record which rows can be reached */
00121         for(p = prow->first_col; p != 0; p = p->next_col) {
00122             pcol = sm_get_col(A, p->col_num);
00123             for(p1 = pcol->first_row; p1 != 0; p1 = p1->next_row) {
00124                 prow1 = sm_get_row(A, p1->row_num);
00125                 if (! prow1->flag) {
00126                     prow1->flag = 1;
00127                     (void) sm_insert(B, prow->row_num, prow1->row_num);
00128                 }
00129             }
00130         }
00131     }
00132 
00133     return B;
00134 }

static sm_matrix* build_intersection_matrix (  )  [static]
solution_t* sm_maximal_independent_set ( sm_matrix A,
int *  weight 
)

Definition at line 41 of file indep.c.

00044 {
00045     register sm_row *best_row, *prow;
00046     register sm_element *p;
00047     int least_weight;
00048     sm_row *save;
00049     sm_matrix *B;
00050     solution_t *indep;
00051 
00052     indep = solution_alloc();
00053     B = build_intersection_matrix(A);
00054 
00055     while (B->nrows > 0) {
00056         /*  Find the row which is disjoint from a maximum number of rows */
00057         best_row = B->first_row;
00058         for(prow = B->first_row->next_row; prow != 0; prow = prow->next_row) {
00059             if (prow->length < best_row->length) {
00060                 best_row = prow;
00061             }
00062         }
00063 
00064         /* Find which element in this row has least weight */
00065         if (weight == NIL(int)) {
00066             least_weight = 1;
00067         } else {
00068             prow = sm_get_row(A, best_row->row_num);
00069             least_weight = weight[prow->first_col->col_num];
00070             for(p = prow->first_col->next_col; p != 0; p = p->next_col) {
00071                 if (weight[p->col_num] < least_weight) {
00072                     least_weight = weight[p->col_num];
00073                 }
00074             }
00075         }
00076         indep->cost += least_weight;
00077         (void) sm_row_insert(indep->row, best_row->row_num);
00078 
00079         /*  Discard the rows which intersect this row */
00080         save = sm_row_dup(best_row);
00081         for(p = save->first_col; p != 0; p = p->next_col) {
00082             sm_delrow(B, p->col_num);
00083             sm_delcol(B, p->col_num);
00084         }
00085         sm_row_free(save);
00086     }
00087 
00088     sm_free(B);
00089 
00090 /*
00091     if (! verify_indep_set(A, indep->row)) {
00092         fail("sm_maximal_independent_set: row set is not independent");
00093     }
00094 */
00095     return indep;
00096 }


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