forked from waynebhayes/BLANT
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcompute-alphas-NBE.c
89 lines (78 loc) · 2.3 KB
/
compute-alphas-NBE.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#include "combin.h"
#include "tinygraph.h"
#include "blant.h"
#include "misc.h"
#include <stdio.h>
static int _alphaList[MAX_CANONICALS];
static int _canonList[MAX_CANONICALS];
int CountPath(TINY_GRAPH* g, TSET seen, TSET candidates, int k) {
seen = TSetUnion(seen, candidates);
TSET outset = 0;
int outbound[k], outsetSize = 0;
if (TSetCardinality(seen) == k) return 1;
//Fill outset for seen set
int i, j;
for (i = 0; i < k; i++) {
if (!TSetIn(seen, i)) continue;
for (j = 0; j < k; j++) {
if (i != j && !TSetIn(seen, j) && !TSetIn(outset, j) && TinyGraphAreConnected(g, i, j)) {
outbound[outsetSize++] = j;
TSetAdd(outset, j);
}
}
}
//Recurse through neighbors in outset
int total = 0;
for (i = 0; i < outsetSize; i++) {
TSetEmpty(candidates);
TSetAdd(candidates, outbound[i]);
total += CountPath(g, seen, candidates, k);
}
return total;
}
int ComputeAlphaNode(TINY_GRAPH* g, int k) {
int total = 0, i, j;
TSET seen = 0, candidates;
for (i = 0; i < k; i++) {
for (j = i+1; j < k; j++) {
if (!TinyGraphAreConnected(g, i, j))
continue;
TSetEmpty(candidates);
TSetAdd(candidates, i);
TSetAdd(candidates, j);
total += CountPath(g, seen, candidates, k);
TSetEmpty(candidates);
}
}
return total;
}
int main(int argc, char* argv[]) {
if (argc != 2) {
fprintf(stderr, "USAGE: %s k\n", argv[0]);
exit(-1);
}
int k = atoi(argv[1]);
char BUF[BUFSIZ];
TINY_GRAPH *g = TinyGraphAlloc(k);
int _Bk = (1 <<(k*(k-1)/2));
SET* _connectedCanonicals = SetAlloc(_Bk);
int numCanon = canonListPopulate(BUF, _canonList, _connectedCanonicals, k);
int i;
for (i = 0; i < numCanon; i++) {
BuildGraph(g, _canonList[i]);
if (!TinyGraphDFSConnected(g, 0))
_alphaList[i] = 0;
else
_alphaList[i] = ComputeAlphaNode(g, k);
}
sprintf(BUF, CANON_DIR "/alpha_list_nbe%d.txt", k);
FILE *fp=fopen(BUF, "w");
assert(fp);
fprintf(fp, "%d\n", numCanon);
for (i = 0; i < numCanon; i++) {
fprintf(fp, "%d ", _alphaList[i]);
}
fputc('\n', fp);
fclose(fp);
return 0;
}