abc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
dominate.c
Go to the documentation of this file.
1 /*
2  * Revision Control Information
3  *
4  * $Source$
5  * $Author$
6  * $Revision$
7  * $Date$
8  *
9  */
10 #include "mincov_int.h"
11 
13 
14 
15 
16 int
18 sm_matrix *A;
19 {
20  register sm_row *prow, *prow1;
21  register sm_col *pcol, *least_col;
22  register sm_element *p, *pnext;
23  int rowcnt;
24 
25  rowcnt = A->nrows;
26 
27  /* Check each row against all other rows */
28  for(prow = A->first_row; prow != 0; prow = prow->next_row) {
29 
30  /* Among all columns with a 1 in this row, choose smallest */
31  least_col = sm_get_col(A, prow->first_col->col_num);
32  for(p = prow->first_col->next_col; p != 0; p = p->next_col) {
33  pcol = sm_get_col(A, p->col_num);
34  if (pcol->length < least_col->length) {
35  least_col = pcol;
36  }
37  }
38 
39  /* Only check for containment against rows in this column */
40  for(p = least_col->first_row; p != 0; p = pnext) {
41  pnext = p->next_row;
42 
43  prow1 = sm_get_row(A, p->row_num);
44  if ((prow1->length > prow->length) ||
45  (prow1->length == prow->length &&
46  prow1->row_num > prow->row_num)) {
47  if (sm_row_contains(prow, prow1)) {
48  sm_delrow(A, prow1->row_num);
49  }
50  }
51  }
52  }
53 
54  return rowcnt - A->nrows;
55 }
56 
57 int
58 sm_col_dominance(A, weight)
59 sm_matrix *A;
60 int *weight;
61 {
62  register sm_row *prow;
63  register sm_col *pcol, *pcol1;
64  register sm_element *p;
65  sm_row *least_row;
66  sm_col *next_col;
67  int colcnt;
68 
69  colcnt = A->ncols;
70 
71  /* Check each column against all other columns */
72  for(pcol = A->first_col; pcol != 0; pcol = next_col) {
73  next_col = pcol->next_col;
74 
75  /* Check all rows to find the one with fewest elements */
76  least_row = sm_get_row(A, pcol->first_row->row_num);
77  for(p = pcol->first_row->next_row; p != 0; p = p->next_row) {
78  prow = sm_get_row(A, p->row_num);
79  if (prow->length < least_row->length) {
80  least_row = prow;
81  }
82  }
83 
84  /* Only check for containment against columns in this row */
85  for(p = least_row->first_col; p != 0; p = p->next_col) {
86  pcol1 = sm_get_col(A, p->col_num);
87  if (weight != 0 && weight[pcol1->col_num] > weight[pcol->col_num])
88  continue;
89  if ((pcol1->length > pcol->length) ||
90  (pcol1->length == pcol->length &&
91  pcol1->col_num > pcol->col_num)) {
92  if (sm_col_contains(pcol, pcol1)) {
93  sm_delcol(A, pcol->col_num);
94  break;
95  }
96  }
97  }
98  }
99 
100  return colcnt - A->ncols;
101 }
103 
int length
Definition: sparse.h:46
int sm_col_dominance(sm_matrix *A, int *weight)
Definition: dominate.c:58
sm_row * next_row
Definition: sparse.h:50
static Llb_Mgr_t * p
Definition: llb3Image.c:950
sm_col * next_col
Definition: sparse.h:65
int length
Definition: sparse.h:61
int sm_row_contains(sm_row *p1, sm_row *p2)
Definition: rows.c:165
int row_num
Definition: sparse.h:45
void sm_delrow(sm_matrix *A, int i)
Definition: matrix.c:273
#define sm_get_row(A, rownum)
Definition: sparse.h:93
sm_element * first_row
Definition: sparse.h:63
#define ABC_NAMESPACE_IMPL_END
Definition: abc_global.h:108
#define sm_get_col(A, colnum)
Definition: sparse.h:89
ABC_NAMESPACE_IMPL_START int sm_row_dominance(sm_matrix *A)
Definition: dominate.c:17
int sm_col_contains(sm_col *p1, sm_col *p2)
Definition: cols.c:165
int col_num
Definition: sparse.h:60
#define ABC_NAMESPACE_IMPL_START
Definition: abc_global.h:107
typedefABC_NAMESPACE_HEADER_START struct sm_element_struct sm_element
Definition: sparse.h:21
void sm_delcol(sm_matrix *A, int i)
Definition: matrix.c:307
sm_element * first_col
Definition: sparse.h:48