39 std::vector<int> mark(inn, -1);
40 std::queue<ord_type> active;
50 while(active.empty() ==
false) {
56 for(
ord_type j = inRowPtr[i]; j < inRowPtr[i+1]; ++j) {
66 for(
ord_type i_r = lastSearch; i_r < inn; ++i_r) {
79 std::vector<ord_type> compSize(ncc, 0);
80 for(
ord_type i_c = 0; i_c < inn; ++i_c) {
82 std::cout <<
"Vertex " << i_c <<
" is untouched,, Exiting!\n";
86 compSize[mark[i_c]]++;
92 for(
ord_type i_l = 0; i_l < ncc; ++i_l) {
93 if(compSize[i_l] > maxSize) {
94 maxSize = compSize[i_l];
101 for(
ord_type i_v = 0; i_v < inn; ++i_v) {
102 if(mark[i_v] == maxId)
108 if(outn != maxSize) {
109 std::cout <<
"The number of vertices in this component: " << outn <<
" does not match the maximum component size: " << maxSize <<
"\n";
117 for(
ord_type ii = 0; ii < inn; ii++) {
119 for(
ord_type j = inRowPtr[ii]; j < inRowPtr[ii+1]; ++j) {
122 std::cout <<
"Neighbor " << v <<
" of " << ii <<
" is found to be absent in the component\n";
125 outColInd[ptr++] = mark[v];
128 outRowPtr[outn] = ptr;
132 if(outn != maxSize) {
133 std::cout <<
"The number of vertices written: " << outn <<
" does not match the maximum component size: " << maxSize <<
"\n";
139 int main(
int argc,
char* argv[])
145 std::ifstream in(argv[1]);
150 while(line[0] ==
'%');
152 std::stringstream ss1(line);
153 ss1 >> nrows >> nrows >> nnzs;
154 std::cout <<
"Number of Rows " << nrows <<
" Number of Columns " << nrows << std::endl;
155 std::vector<bool> diag(nrows,
false);
158 for(
ord_type i = 0; i < nrows+2; i++)
161 while(getline(in, line)) {
163 std::stringstream ss2(line);
175 for(
ord_type j0 = 0; j0 < nrows; j0++)
179 for(
ord_type k = 2; k < nrows+2; k++)
180 rowPtr[k] += rowPtr[k-1];
189 while(line[0] ==
'%');
192 while(getline(in, line)) {
194 std::stringstream ss2(line);
200 colInd[rowPtr[r+1]++] = c;
201 colInd[rowPtr[c+1]++] = r;
208 for(
ord_type i0 = 0; i0 < nrows; i0++)
209 colInd[rowPtr[i0+1]++] = i0;
218 for(
ord_type i1 = 0; i1 < nrows; i1++) {
220 ord_type deg = rowPtr[i1+1] - rowPtr[i1];
223 std::sort(&colInd[rowPtr[i1]], &colInd[rowPtr[i1+1]]);
224 colIndNew[ptr++] = colInd[rowPtr[i1]];
225 prev = colInd[rowPtr[i1]];
226 for(
ord_type j1 = rowPtr[i1]+1; j1 < rowPtr[i1+1]; j1++) {
227 if(colInd[j1] != prev) {
228 colIndNew[ptr++] = colInd[j1];
234 rowPtrNew[i1+1] = ptr;
237 for(
ord_type i2 = 0; i2 < nrows; i2++) {
238 for(
ord_type j2 = rowPtrNew[i2]; j2 < rowPtrNew[i2+1]; ++j2)
239 if(colIndNew[j2] == i2)
242 if(diag[i2] ==
false)
243 std::cout <<
"ROW " << i2 <<
" misses diagonal\n";
246 std::cout << argv[1] <<
" " << nrows <<
" " << ptr <<
" ";
250 nrows, rowPtrNew, colIndNew,
251 newnrows, rowPtr, colInd );
252 ptr = rowPtr[newnrows];
255 for(
ord_type i3 = 0; i3 < nrows; i3++) {
256 deg = rowPtrNew[i3+1] - rowPtrNew[i3];
262 std::ofstream out(argv[2], std::ios::out | std::ios::binary);
263 out.write((
char*)&newnrows,
sizeof(
ord_type));
264 out.write((
char*)&ptr,
sizeof(
ord_type));
266 out.write((
char*)rowPtr,
sizeof(
ord_type)*(newnrows+1));
267 out.write((
char*)colInd,
sizeof(
ord_type)*(ptr));
271 std::cout << newnrows <<
" " << ptr <<
" " << max <<
"\n";
int main(int narg, char **arg)
void findLargestComponent(ord_type seed, ord_type inn, ord_type *inRowPtr, ord_type *inColInd, ord_type &outn, ord_type *outRowPtr, ord_type *outColInd)