00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 #include "mincov_int.h"
00011
00012 static int visit_col();
00013
00014 static void
00015 copy_row(A, prow)
00016 register sm_matrix *A;
00017 register sm_row *prow;
00018 {
00019 register sm_element *p;
00020
00021 for(p = prow->first_col; p != 0; p = p->next_col) {
00022 (void) sm_insert(A, p->row_num, p->col_num);
00023 }
00024 }
00025
00026
00027 static int
00028 visit_row(A, prow, rows_visited, cols_visited)
00029 sm_matrix *A;
00030 sm_row *prow;
00031 int *rows_visited;
00032 int *cols_visited;
00033 {
00034 sm_element *p;
00035 sm_col *pcol;
00036
00037 if (! prow->flag) {
00038 prow->flag = 1;
00039 (*rows_visited)++;
00040 if (*rows_visited == A->nrows) {
00041 return 1;
00042 }
00043 for(p = prow->first_col; p != 0; p = p->next_col) {
00044 pcol = sm_get_col(A, p->col_num);
00045 if (! pcol->flag) {
00046 if (visit_col(A, pcol, rows_visited, cols_visited)) {
00047 return 1;
00048 }
00049 }
00050 }
00051 }
00052 return 0;
00053 }
00054
00055
00056 static int
00057 visit_col(A, pcol, rows_visited, cols_visited)
00058 sm_matrix *A;
00059 sm_col *pcol;
00060 int *rows_visited;
00061 int *cols_visited;
00062 {
00063 sm_element *p;
00064 sm_row *prow;
00065
00066 if (! pcol->flag) {
00067 pcol->flag = 1;
00068 (*cols_visited)++;
00069 if (*cols_visited == A->ncols) {
00070 return 1;
00071 }
00072 for(p = pcol->first_row; p != 0; p = p->next_row) {
00073 prow = sm_get_row(A, p->row_num);
00074 if (! prow->flag) {
00075 if (visit_row(A, prow, rows_visited, cols_visited)) {
00076 return 1;
00077 }
00078 }
00079 }
00080 }
00081 return 0;
00082 }
00083
00084 int
00085 sm_block_partition(A, L, R)
00086 sm_matrix *A;
00087 sm_matrix **L, **R;
00088 {
00089 int cols_visited, rows_visited;
00090 register sm_row *prow;
00091 register sm_col *pcol;
00092
00093
00094 if (A->nrows == 0) {
00095 return 0;
00096 }
00097
00098
00099 for(prow = A->first_row; prow != 0; prow = prow->next_row) {
00100 prow->flag = 0;
00101 }
00102 for(pcol = A->first_col; pcol != 0; pcol = pcol->next_col) {
00103 pcol->flag = 0;
00104 }
00105
00106 cols_visited = rows_visited = 0;
00107 if (visit_row(A, A->first_row, &rows_visited, &cols_visited)) {
00108
00109 return 0;
00110 } else {
00111 *L = sm_alloc();
00112 *R = sm_alloc();
00113 for(prow = A->first_row; prow != 0; prow = prow->next_row) {
00114 if (prow->flag) {
00115 copy_row(*L, prow);
00116 } else {
00117 copy_row(*R, prow);
00118 }
00119 }
00120 return 1;
00121 }
00122 }