-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdeduction.cpp
64 lines (57 loc) · 1.83 KB
/
deduction.cpp
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 <cassert>
#include "deduction.hpp"
using namespace std;
void fact::justify() const {
assert(is_observation());
bool change = !operator bool();
justification_hook();
if (change) {
justification_propagate();
}
}
void fact::unjustify() const {
assert(is_observation());
unjustification_hook();
if (!operator bool()) {
unjustification_propagate();
}
}
void fact::justification_propagate() const {
vector<fact*>immediate_consequences = get_immediate_consequences();
vector<fact*>propagating_immediate_consequences;
for (fact*immediate_consequence : immediate_consequences) {
assert(!immediate_consequence->is_observation());
bool change = !*immediate_consequence;
immediate_consequence->justification_hook();
if (change) {
propagating_immediate_consequences.push_back(immediate_consequence);
} else {
delete immediate_consequence;
}
}
for (fact*immediate_consequence : propagating_immediate_consequences) {
immediate_consequence->justification_propagate();
delete immediate_consequence;
}
}
void fact::unjustification_propagate() const {
vector<fact*>immediate_consequences = get_immediate_consequences();
vector<fact*>propagating_immediate_consequences;
for (fact*immediate_consequence : immediate_consequences) {
assert(!immediate_consequence->is_observation());
assert(*immediate_consequence);
immediate_consequence->unjustification_hook();
if (!*immediate_consequence) {
propagating_immediate_consequences.push_back(immediate_consequence);
} else {
delete immediate_consequence;
}
}
for (fact*immediate_consequence : propagating_immediate_consequences) {
immediate_consequence->unjustification_propagate();
delete immediate_consequence;
}
}
ostream&operator <<(ostream&out, const ::fact&fact) {
return fact.print(out);
}