-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwolstack.cpp
76 lines (54 loc) · 1.51 KB
/
wolstack.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
/*
* wolstack.cpp
*
* Created on: Dec 14, 2014
* Author: user
*/
#include "wolstack.h"
#include "wolexp.h"
#include "wolevalfactory.h"
#include "wolmgr.h"
#include <cassert>
namespace wolver {
void
WolStackEntry::populateImplications(nodeL &list) {
for (WolNodeSptr i : list) {
WolValueSptr storedValue = i->getSValue();
i->setSValue(nullptr);
_implications.push_back(nodeValue(i, storedValue));
}
}
void
WolStackEntry::restoreImplications() {
for (nodeValue i : _implications) {
assert(i.first->getSValue() == nullptr);
i.first->setValue(i.second);
}
}
void
WolStack::pushDecisionNode(WolNodeSptr node) {
WolStackEntry newEntry(node->getValue(), node);
_stack.push(newEntry);
}
void
WolStack::storeImplications(nodeL &list) {
_stack.top().populateImplications(list);
}
WolValueSptr
WolStack::backtrackOnCurrentVariable(WolValueSptr adjustValue) {
WolEvalFactory *evalFactory = WolMgr::getInstance().getEvalFactory();
// restore Implications (if done)
_stack.top().restoreImplications();
// subtraction : activeValue = activeValue - adjustValue
WolValueSptr activeValue = _stack.top().getActiveValue();
WolValueSptr newValue = evalFactory->evalDiff(activeValue, adjustValue);
_stack.top().updateActiveValue(newValue);
return newValue;
}
void
WolStack::backtrackToNextVariable() {
WolStackEntry top = _stack.top();
top.getNode()->setValue(top.getSotredValue());
_stack.pop();
}
}