free(matched);
}
-static int scomp(const void *s1, const void *s2){
- const double *ss1 = s1;
- const double *ss2 = s2;
-
- if (ss1[1] > ss2[1]){
- return -1;
- } else if (ss1[1] < ss2[1]){
- return 1;
- }
- return 0;
-}
-
-static void maximal_independent_edge_set_heavest_cluster_pernode_leaves_first(SparseMatrix A, int csize,
- int **cluster, int **clusterp, int *ncluster){
- int i, ii, j, *ia, *ja, m, n, *p = NULL, q, iv;
- (void)n;
- double *a;
- int *matched, nz, nz0, nzz,k, nv;
- enum {MATCHED = -1};
- double *vlist;
-
- assert(A);
- assert(SparseMatrix_known_strucural_symmetric(A));
- ia = A->ia;
- ja = A->ja;
- m = A->m;
- n = A->n;
- assert(n == m);
- *cluster = gv_calloc(m, sizeof(int));
- *clusterp = gv_calloc(m + 1, sizeof(int));
- matched = gv_calloc(m, sizeof(int));
- vlist = gv_calloc(2 * m, sizeof(double));
-
- for (i = 0; i < m; i++) matched[i] = i;
-
- assert(SparseMatrix_is_symmetric(A, false));
- assert(A->type == MATRIX_TYPE_REAL);
-
- *ncluster = 0;
- (*clusterp)[0] = 0;
- nz = 0;
- a = A->a;
-
- p = random_permutation(m);
- for (ii = 0; ii < m; ii++){
- i = p[ii];
- if (matched[i] == MATCHED || node_degree(i) != 1) continue;
- q = ja[ia[i]];
- assert(matched[q] != MATCHED);
- matched[q] = MATCHED;
- (*cluster)[nz++] = q;
- for (j = ia[q]; j < ia[q+1]; j++){
- if (q == ja[j]) continue;
- if (node_degree(ja[j]) == 1){
- matched[ja[j]] = MATCHED;
- (*cluster)[nz++] = ja[j];
- }
- }
- nz0 = (*clusterp)[*ncluster];
- if (nz - nz0 <= MAX_CLUSTER_SIZE){
- (*clusterp)[++(*ncluster)] = nz;
- } else {
- (*clusterp)[++(*ncluster)] = ++nz0;
- nzz = nz0;
- for (k = nz0; k < nz && nzz < nz; k++){
- nzz += MAX_CLUSTER_SIZE - 1;
- nzz = MIN(nz, nzz);
- (*clusterp)[++(*ncluster)] = nzz;
- }
- }
- }
-
- for (ii = 0; ii < m; ii++){
- i = p[ii];
- if (matched[i] == MATCHED) continue;
- nv = 0;
- for (j = ia[i]; j < ia[i+1]; j++){
- if (i == ja[j]) continue;
- if (matched[ja[j]] != MATCHED && matched[i] != MATCHED){
- vlist[2*nv] = ja[j];
- vlist[2*nv+1] = a[j];
- nv++;
- }
- }
- if (nv > 0){
- qsort(vlist, nv, sizeof(double)*2, scomp);
- for (j = 0; j < MIN(csize - 1, nv); j++){
- iv = (int) vlist[2*j];
- matched[iv] = MATCHED;
- (*cluster)[nz++] = iv;
- }
- matched[i] = MATCHED;
- (*cluster)[nz++] = i;
- (*clusterp)[++(*ncluster)] = nz;
- }
- }
-
- for (i = 0; i < m; i++){
- if (matched[i] == i){
- (*cluster)[nz++] = i;
- (*clusterp)[++(*ncluster)] = nz;
- }
- }
- free(p);
-
-
- free(matched);
-}
-
static void Multilevel_coarsen_internal(SparseMatrix A, SparseMatrix *cA, SparseMatrix *cD,
double *node_wgt, double **cnode_wgt,
SparseMatrix *P, SparseMatrix *R, Multilevel_control ctrl){