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
|
#include "knowledge-base.h"
#include <stdio.h>
#define QUESTION(symbol, label, yes, no) \
[QUESTION_##symbol] = label,
char *question_labels[QUESTION_COUNT] = {
QUESTIONS
};
#undef QUESTION
#define QUESTION(symbol, label, yes, no) \
[QUESTION_##symbol] = { yes, no },
struct question_branch_labels question_branch_labels[QUESTION_COUNT] = {
QUESTIONS
};
#undef QUESTION
#define DECISION(symbol, label, ...) [DECISION_##symbol] = label,
char *decision_labels[DECISION_COUNT] = {
DECISIONS
};
#undef DECISION
#define DECISION(symbol, label, ...) [DECISION_##symbol] = { __VA_ARGS__ },
struct decision_predicates decision_predicates[DECISION_COUNT] = {
DECISIONS
};
#undef DECISION
#define QUESTION(symbol, label, yes, no) \
if (QUESTION_##symbol == question) \
return decision_predicates[decision].symbol;
enum answer
get_decision_predicate (enum decision decision, enum question question)
{
QUESTIONS
return ANSWER_MALFORMED;
}
#undef QUESTION
void
print_knowledge_base (void)
{
puts ("QUESTIONS:");
for (int i = 0; i < QUESTION_COUNT; ++i)
printf ("%2X", i + 1);
putchar ('\n');
for (int i = 0; i < QUESTION_COUNT; ++i) {
printf ("%0*b: %s\n", 2*QUESTION_COUNT,
(1 << ANSWER_COUNT) - 1 << (QUESTION_COUNT - 1 - i)*ANSWER_COUNT, question_labels[i]);
} putchar ('\n');
puts ("DECISIONS:");
for (int i = 0; i < QUESTION_COUNT; ++i)
printf ("%2X", i + 1);
putchar ('\n');
for (int i = 0; i < DECISION_COUNT; ++i) {
for (int j = 0; j < QUESTION_COUNT; ++j) {
printf ("%0*b", ANSWER_COUNT, get_decision_predicate (i, j));
}
printf (": %s\n", decision_labels[i]);
}
}
|