-
Notifications
You must be signed in to change notification settings - Fork 1
/
logictree.c
63 lines (49 loc) · 1.56 KB
/
logictree.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
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include "node.h"
#include "graph.h"
#include "logic.h"
#define BSIZE 2
#include <sys/time.h>
struct timeval timeStart, timeEnd;
struct timeval totalStart, totalEnd;
void timerStart(void)
{
gettimeofday(&timeStart, NULL);
}
void timerEnd(const char *tag)
{
gettimeofday(&timeEnd, NULL);
printf("TIMER: %s took %fus\n", tag, ((double)(timeEnd.tv_sec - timeStart.tv_sec) * 1000000.0 + (double)(timeEnd.tv_usec - timeStart.tv_usec)));
}
int main(int argc, char **argv)
{
char bdot[32768];
char itc[NAME_LENGTH];
unsigned int nn;
fix bnull[BSIZE] = {FIX_ZERO, FIX_ZERO};
enum logic operation = AND;
char name [NAME_LENGTH] = "AND";
int numi = 100, nump = 2, numl = 3;
fix input[BSIZE] = {DOUBLE_TO_FIX(0.5), DOUBLE_TO_FIX(0.5)};
printf("Byte Sizes: short=%ld int=%ld long=%ld fix=%ld fixrad=%ld BERR=%d\n",
sizeof(short), sizeof(int), sizeof(long), sizeof(fix), sizeof(fixrad), BERR);
int numnodes = (int)((pow((double)nump, (double)(numl+1))-1.0)/(double)(nump-1));
printf("Tree with %d levels of %d parents (%d nodes) x %d iterations (total %d inferences)\n", numl, nump, numnodes, numi, numi*numnodes);
sprintf(itc, "inference x%d", numi*numnodes);
timerStart();
nn = addBNode(name, bnull, BSIZE);
makeLogicTree(operation, nn, name, input, nump, numl);
timerEnd("initialization");
timerStart();
for(int i = 0; i < numi; i++)
inferBNetwork(nn);
timerEnd(itc);
printBNetwork();
generateDotGraph(bdot, BSIZE);
ExportDotGraph(bdot, "graph.dot");
DisplayDotGraph(bdot);
freeBNetwork();
return 0;
}