-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwolimplengine.cpp
84 lines (61 loc) · 1.66 KB
/
wolimplengine.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
/*
* wolimplengine.cpp
*
* Created on: Sep 24, 2014
* Author: user
*/
#include <cassert>
#include "wolimplengine.h"
#include "wolexp.h"
#include "wolworklist.h"
#include "wollog.h"
#include "wolmgr.h"
namespace wolver {
void
WolImplEngine::revertChanges(nodeL &changes) {
for(WolNodeSptr i : changes) {
WolValueSptr svalue = i->getSValue();
assert(i->getSValue() != nullptr);
i->setValue(svalue);
i->setSValue(nullptr);
}
}
std::pair<bool, nodeL>
WolWLImplEngine::performImplication(WolNodeSptr node) {
//construct the work list
WolWorkList initialNodes;
initialNodes.addNode(node);
// call the internal function
return performImplicationInt(initialNodes);
}
std::pair<bool, nodeL>
WolWLImplEngine::performImplication(nodeL &inputs, nodeL &outputs) {
WolWorkList initialNodes;
initialNodes.addNodes(inputs);
initialNodes.addNodes(outputs);
return performImplicationInt(initialNodes);
}
std::pair<bool, nodeL>
WolWLImplEngine::performImplicationInt(WolWorkList &wl){
nodeL changes;
WolWorkList prev = wl;
WolWorkList curr = prev.getNeighbors();
prev.setImplyFlag();
while(true) {
WolMgr::getInstance().printgv();
WolWorkList next;
DEBUG_MSG << "Performing Implication on " << curr.str();
bool output = curr.performImplication(changes, next);
prev.unsetImplyFlag();
if (!output) {
revertChanges(changes);
return std::make_pair(false, changes);
}
if (next.isEmpty()) break;
curr.setImplyFlag();
prev = curr;
curr = next;
}
return std::make_pair(true, changes);
}
}