summaryrefslogtreecommitdiff
path: root/src/get_dual_clusters.c
blob: 3a51c386aeec111f80bf0a571c2006ed891184bd (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(net_t *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(net_t *instance, cholmod_common *c) {
	unsigned int *clusters = get_clusters(instance, c);
	unsigned int *cluster_dist = (unsigned int *)calloc(
			instance->graph->dnv, 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->graph->dnv; 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;
}