summaryrefslogtreecommitdiff
path: root/src/get_dual_clusters.c
blob: 488793fea29fa2bc8ab1ef655a29e8a25f9ac891 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36

#include "fracture.h"

unsigned int *get_clusters(finst *instance, cholmod_common *c) {
	cholmod_sparse *s_dual = gen_adjacency(instance, true, false, 0, c);

	unsigned int *dual_marks = find_components(s_dual, 0);
	CHOL_F(free_sparse)(&s_dual, c);

	return dual_marks;
}

unsigned int *get_cluster_dist(finst *instance, cholmod_common *c) {
	unsigned int *clusters = get_clusters(instance, c);
	unsigned int *cluster_dist = (unsigned int *)calloc(
			instance->network->num_dual_verts, sizeof(unsigned int));

	unsigned int cur_mark = 0;
	while (true) {
		cur_mark++;
		unsigned int num_in_cluster = 0;
		for (unsigned int i = 0; i < instance->network->num_dual_verts; i++) {
			if (clusters[i] == cur_mark)
				num_in_cluster++;
		}

		if (num_in_cluster == 0)
			break;

		cluster_dist[num_in_cluster - 1]++;
	}

	free(clusters);

	return cluster_dist;
}