-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathForwardChainer.cpp
More file actions
45 lines (40 loc) · 1.39 KB
/
ForwardChainer.cpp
File metadata and controls
45 lines (40 loc) · 1.39 KB
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
#include "ForwardChainer.h"
using namespace std;
bool ForwardChainer::solve()
{
for(auto it = agenda.begin(); it != agenda.end(); ++it)
{
string p = *it;
if(p==Agenda::negated(ask))
{
cout << "Udowodniono nieprawdziwość tezy." << endl;
return false;
}
else if(p==ask)
return true;
/* cross out p from rules which have p in their premises set */
for(auto i = knowledge.begin(); i!=knowledge.end(); ++i)
{
string q;
int t;
/* if whole premises set was crossed out, rule's conclusion has been inferred */
if((t=i->crossOut(p))==0 && i->applies())
{
/* save rule's premises so that they could be printed later */
set<string> premise = i->getPremise();
entailed.insert(entailed.end(), premise.begin(), premise.end());
q = i->getConclusion();
if(q==Agenda::negated(ask))
{
cout << "Udowodniono nieprawdziwość tezy." << endl;
return false;
}
else if(q==ask)
return true;
if(agenda.add(q) < 0)
cout << "Uwaga: wykryto sprzeczność: " << q << " & " << Agenda::negated(q) << endl;;
}
}
}
return false;
}