return Dijkstra_internal(A, root, dist, nlist, list, dist_max, mask);
}
-real SparseMatrix_pseudo_diameter_weighted(SparseMatrix A0, int root, int aggressive, int *end1, int *end2, int *connectedQ){
- /* weighted graph. But still assume to be undirected. unsymmetric matrix ill be symmetrized */
- SparseMatrix A = A0;
- int m = A->m, i, *list = NULL, nlist;
- int flag;
- real *dist = NULL, dist_max = -1, dist0 = -1;
- int roots[5], iroots, end11, end22;
-
- if (!SparseMatrix_is_symmetric(A, TRUE)){
- A = SparseMatrix_symmetrize(A, TRUE);
- }
- assert(m == A->n);
-
- dist = MALLOC(sizeof(real)*((size_t)m));
- list = MALLOC(sizeof(int)*((size_t)m));
- nlist = 1;
- list[nlist-1] = root;
-
- assert(SparseMatrix_is_symmetric(A, TRUE));
-
- do {
- dist0 = dist_max;
- root = list[nlist - 1];
- flag = Dijkstra(A, root, dist, &nlist, list, &dist_max);
- //fprintf(stderr,"after Dijkstra, {%d,%d}-%f\n",root, list[nlist-1], dist_max);
- assert(dist[list[nlist-1]] == dist_max);
- assert(root == list[0]);
- assert(nlist > 0);
- } while (dist_max > dist0);
-
- *connectedQ = (!flag);
- assert((dist_max - dist0)/MAX(1, MAX(fabs(dist0), fabs(dist_max))) < 1.e-10);
-
- *end1 = root;
- *end2 = list[nlist-1];
- //fprintf(stderr,"after search for diameter, diam = %f, ends = {%d,%d}\n", dist_max, *end1, *end2);
-
- if (aggressive){
- iroots = 0;
- for (i = MAX(0, nlist - 6); i < nlist - 1; i++){
- roots[iroots++] = list[i];
- }
- for (i = 0; i < iroots; i++){
- root = roots[i];
- dist0 = dist_max;
- fprintf(stderr,"search for diameter again from root=%d\n", root);
- dist_max = SparseMatrix_pseudo_diameter_weighted(A, root, FALSE, &end11, &end22, connectedQ);
- if (dist_max > dist0){
- *end1 = end11; *end2 = end22;
- } else {
- dist_max = dist0;
- }
- }
- fprintf(stderr,"after aggressive search for diameter, diam = %f, ends = {%d,%d}\n", dist_max, *end1, *end2);
- }
-
- FREE(dist);
- FREE(list);
-
- if (A != A0) SparseMatrix_delete(A);
- return dist_max;
-
-}
-
void SparseMatrix_decompose_to_supervariables(SparseMatrix A, int *ncluster, int **cluster, int **clusterp){
/* nodes for a super variable if they share exactly the same neighbors. This is know as modules in graph theory.
We work on columns only and columns with the same pattern are grouped as a super variable
SparseMatrix SparseMatrix_copy(SparseMatrix A);
int SparseMatrix_has_diagonal(SparseMatrix A);
SparseMatrix SparseMatrix_make_undirected(SparseMatrix A);/* make it strictly low diag only, and set flag to undirected */
-real SparseMatrix_pseudo_diameter_weighted(SparseMatrix A0, int root, int aggressive, int *end1, int *end2, int *connectedQ); /* assume real distances, unsymmetric matrix ill be symmetrized */
void SparseMatrix_level_sets(SparseMatrix A, int root, int *nlevel, int **levelset_ptr, int **levelset, int **mask, int reintialize_mask);
void SparseMatrix_level_sets_khops(int khops, SparseMatrix A, int root, int *nlevel, int **levelset_ptr, int **levelset, int **mask, int reintialize_mask);
void SparseMatrix_weakly_connected_components(SparseMatrix A0, int *ncomp, int **comps, int **comps_ptr);