forked from ongjinzen/social-network-analysis
-
Notifications
You must be signed in to change notification settings - Fork 0
/
testLanceWilliamsHAC.c
69 lines (51 loc) · 1.32 KB
/
testLanceWilliamsHAC.c
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#include "LanceWilliamsHAC.h"
#include "BSTree.h"
#include "GraphRead.h"
#include <stdlib.h>
#include <stdio.h>
#include <assert.h>
void printClusters(Tree t, int depth){
// To avoid infinite looping, due to a possible
// incorrect logic in the program being tested!
assert( depth < 200 );
printf("%d: {", depth);
printTree(t);
printf("}");
if((getLeftTree(t) == NULL) && (getRightTree(t) == NULL)) {
printf(" (leaf)");
}
printf("\n");
}
Tree printDendrogram(Dendrogram dn, int depth){
// To avoid infinite looping, due to a possible
// incorrect logic in the program being tested!
assert( depth < 200 );
Tree tr, tl;
if(dn == NULL) return NULL;
if((dn->left == NULL) && (dn->right == NULL)){
Tree t = newTree();
t = TreeInsert(t, dn->vertex);
return t;
}
if(dn->left !=NULL) {
tl = printDendrogram(dn->left, depth+1);
printClusters(tl, depth);
}
if(dn->right !=NULL) {
tr = printDendrogram(dn->right, depth+1);
printClusters(tr, depth);
}
Tree bothTrees = addTree(tl, tr);
return bothTrees;
}
int main(int argc, char* argv[]){
if(argc < 2) {
printf("Usage: ./testLanceWilliamsHAC [file]\n");
return EXIT_FAILURE;
}
Graph g = readGraph(argv[1]);
Dendrogram dn = LanceWilliamsHAC(g, 1);
Tree allTree = printDendrogram(dn, 1);
printClusters(allTree, 0);
freeDendrogram(dn);
}