/************************************************************************* * This function perfoms a dfs starting from an unmatched col node * forming alternate paths **************************************************************************/ void MinCover_RowDFS(idxtype *xadj, idxtype *adjncy, int root, idxtype *mate, idxtype *where, int flag) { int i; if (flag == INROW) { if (where[root] == VR) return; where[root] = VR; for (i=xadj[root]; i<xadj[root+1]; i++) MinCover_RowDFS(xadj, adjncy, adjncy[i], mate, where, INCOL); } else { if (where[root] == VC) return; where[root] = VC; if (mate[root] != -1) MinCover_RowDFS(xadj, adjncy, mate[root], mate, where, INROW); } }
/************************************************************************* * This function perfoms a dfs starting from an unmatched col node * forming alternate paths **************************************************************************/ void MinCover_RowDFS(idx_t *xadj, idx_t *adjncy, idx_t root, idx_t *mate, idx_t *where, idx_t flag) { idx_t i; if (flag == INROW) { if (where[root] == VR) { return; } where[root] = VR; for (i = xadj[root]; i < xadj[root + 1]; i++) { MinCover_RowDFS(xadj, adjncy, adjncy[i], mate, where, INCOL); } } else { if (where[root] == VC) { return; } where[root] = VC; if (mate[root] != -1) { MinCover_RowDFS(xadj, adjncy, mate[root], mate, where, INROW); } } }
/************************************************************************* * This function performs a coarse decomposition and determines the * min-cover. * REF: Pothen ACMTrans. on Amth Software **************************************************************************/ void MinCover_Decompose(idxtype *xadj, idxtype *adjncy, int asize, int bsize, idxtype *mate, idxtype *cover, int *csize) { int i, k; idxtype *where; int card[10]; where = idxmalloc(bsize, "MinCover_Decompose: where"); for (i=0; i<10; i++) card[i] = 0; for (i=0; i<asize; i++) where[i] = SC; for (; i<bsize; i++) where[i] = SR; for (i=0; i<asize; i++) if (mate[i] == -1) MinCover_ColDFS(xadj, adjncy, i, mate, where, INCOL); for (; i<bsize; i++) if (mate[i] == -1) MinCover_RowDFS(xadj, adjncy, i, mate, where, INROW); for (i=0; i<bsize; i++) card[where[i]]++; k = 0; if (abs(card[VC]+card[SC]-card[HR]) < abs(card[VC]-card[SR]-card[HR])) { /* S = VC+SC+HR */ /* printf("%d %d ",vc+sc, hr); */ for (i=0; i<bsize; i++) if (where[i] == VC || where[i] == SC || where[i] == HR) cover[k++] = i; } else { /* S = VC+SR+HR */ /* printf("%d %d ",vc, hr+sr); */ for (i=0; i<bsize; i++) if (where[i] == VC || where[i] == SR || where[i] == HR) cover[k++] = i; } *csize = k; free(where); }
/************************************************************************* * This function performs a coarse decomposition and determines the * min-cover. * REF: Pothen ACMTrans. on Amth Software **************************************************************************/ void MinCover_Decompose(idx_t *xadj, idx_t *adjncy, idx_t asize, idx_t bsize, idx_t *mate, idx_t *cover, idx_t *csize) { idx_t i, k; idx_t *where; idx_t card[10]; where = imalloc(bsize, "MinCover_Decompose: where"); for (i = 0; i < 10; i++) { card[i] = 0; } for (i = 0; i < asize; i++) { where[i] = SC; } for (; i < bsize; i++) { where[i] = SR; } for (i = 0; i < asize; i++) { if (mate[i] == -1) { MinCover_ColDFS(xadj, adjncy, i, mate, where, INCOL); } } for (; i < bsize; i++) { if (mate[i] == -1) { MinCover_RowDFS(xadj, adjncy, i, mate, where, INROW); } } for (i = 0; i < bsize; i++) { card[where[i]]++; } k = 0; if (iabs(card[VC] + card[SC] - card[HR]) < iabs(card[VC] - card[SR] - card[HR])) { /* S = VC+SC+HR */ /* printf("%"PRIDX" %"PRIDX" ",vc+sc, hr); */ for (i = 0; i < bsize; i++) { if (where[i] == VC || where[i] == SC || where[i] == HR) { cover[k++] = i; } } } else { /* S = VC+SR+HR */ /* printf("%"PRIDX" %"PRIDX" ",vc, hr+sr); */ for (i = 0; i < bsize; i++) { if (where[i] == VC || where[i] == SR || where[i] == HR) { cover[k++] = i; } } } *csize = k; gk_free((void **) &where, LTERM); }