| 1 |
/*! |
| 2 |
\file |
| 3 |
\brief Functions that deal with eliminating disconnected partitions |
| 4 |
|
| 5 |
\date Started 7/15/98 |
| 6 |
\author George |
| 7 |
\author Copyright 1997-2009, Regents of the University of Minnesota |
| 8 |
\version $Id: contig.c 10513 2011-07-07 22:06:03Z karypis $ |
| 9 |
*/ |
| 10 |
|
| 11 |
#include "metislib.h" |
| 12 |
|
| 13 |
/*************************************************************************/ |
| 14 |
/*! This function identifies the number of connected components in a graph |
| 15 |
that result after removing the vertices that belong to the vertex |
| 16 |
separator (i.e., graph->where[i] == 2). |
| 17 |
The connected component memberships are returned in the CSR-style |
| 18 |
pair of arrays cptr, cind. |
| 19 |
*/ |
| 20 |
/**************************************************************************/ |
| 21 |
idx_t FindSepInducedComponents(ctrl_t *ctrl, graph_t *graph, idx_t *cptr, |
| 22 |
idx_t *cind) |
| 23 |
{ |
| 24 |
idx_t i, j, k, nvtxs, first, last, nleft, ncmps, wgt; |
| 25 |
const idx_t *xadj, *adjncy; |
| 26 |
idx_t *where, *touched, *queue; |
| 27 |
|
| 28 |
nvtxs = graph->nvtxs; |
| 29 |
xadj = graph->xadj_orig ? graph->xadj_orig : graph->xadj; |
| 30 |
adjncy = graph->adjncy_orig ? graph->adjncy_orig : graph->adjncy; |
| 31 |
where = graph->where; |
| 32 |
|
| 33 |
touched = ismalloc(nvtxs, 0); |
| 34 |
|
| 35 |
for (i=0; i<graph->nbnd; i++) |
| 36 |
touched[graph->bndind[i]] = 1; |
| 37 |
|
| 38 |
queue = cind; |
| 39 |
|
| 40 |
nleft = 0; |
| 41 |
for (i=0; i<nvtxs; i++) { |
| 42 |
if (where[i] != 2) |
| 43 |
nleft++; |
| 44 |
} |
| 45 |
|
| 46 |
for (i=0; i<nvtxs; i++) { |
| 47 |
if (where[i] != 2) |
| 48 |
break; |
| 49 |
} |
| 50 |
|
| 51 |
touched[i] = 1; |
| 52 |
queue[0] = i; |
| 53 |
first = 0; |
| 54 |
last = 1; |
| 55 |
cptr[0] = 0; /* This actually points to queue */ |
| 56 |
ncmps = 0; |
| 57 |
|
| 58 |
while (first != nleft) { |
| 59 |
if (first == last) { /* Find another starting vertex */ |
| 60 |
cptr[++ncmps] = first; |
| 61 |
for (i=0; i<nvtxs; i++) { |
| 62 |
if (!touched[i]) |
| 63 |
break; |
| 64 |
} |
| 65 |
queue[last++] = i; |
| 66 |
touched[i] = 1; |
| 67 |
} |
| 68 |
|
| 69 |
i = queue[first++]; |
| 70 |
for (j=xadj[i]; j<xadj[i+1]; j++) { |
| 71 |
k = adjncy[j]; |
| 72 |
if (!touched[k]) { |
| 73 |
queue[last++] = k; |
| 74 |
touched[k] = 1; |
| 75 |
} |
| 76 |
} |
| 77 |
} |
| 78 |
cptr[++ncmps] = first; |
| 79 |
|
| 80 |
gk_free((void **)&touched); |
| 81 |
|
| 82 |
return ncmps; |
| 83 |
} |