-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathbindings_propagator.cpp
156 lines (138 loc) · 5.01 KB
/
bindings_propagator.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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
#include "bindings_propagator.h"
#include "plan_bindings.h"
#include "pointers.h"
#include "plan.h"
#include "term_manager.h"
namespace MyPOP {
bool SimpleBindingsPropagator::removeObjectFromUnequalDomains(Bindings& bindings, VariableDomain& variable_domain, const Object& object) const
{
assert (variable_domain.getDomain().size() == 1);
assert (variable_domain.getDomain()[0] == &object);
const std::vector<VariableDomain*>& unequal_variables = variable_domain.getUnequalVariables();
for (std::vector<VariableDomain*>::const_iterator ci = unequal_variables.begin(); ci != unequal_variables.end(); ci++)
{
const std::vector<std::pair<StepID, const Variable*> >& equal_variables = (*ci)->getEqualVariables();
// ObjectBinding ob(equal_variables[0].first, *equal_variables[0].second, object, false);
if (!equal_variables[0].second->makeDomainUnequalTo(equal_variables[0].first, object, Step::INVALID_STEP, bindings))
{
return false;
}
/* if (!bindings.addBinding(ob))
{
return false;
}
*/
}
return true;
}
bool SimpleBindingsPropagator::propagateAfterMakeEqual(Bindings& bindings, VariableDomain& variable_domain, const VariableDomain& ) const
{
if (variable_domain.getDomain().size() == 0)
{
return false;
}
assert (variable_domain.getDomain().size() != 0);
// If a domain is made unequal, check if either has only a single object in their variable domain and propagate this.
if (variable_domain.getDomain().size() == 1)
{
return propagateAfterMakeEqual(bindings, variable_domain, *variable_domain.getDomain()[0]);
}
return true;
}
bool SimpleBindingsPropagator::propagateAfterMakeEqual(Bindings& bindings, VariableDomain& variable_domain, const Object& object) const
{
if (variable_domain.getDomain().size() == 0)
{
return false;
}
// After a domain is made equal to a single object, remove this value from all variable domains which are unequal to
// this one.
if (!removeObjectFromUnequalDomains(bindings, variable_domain, object))
{
return false;
}
return true;
}
bool SimpleBindingsPropagator::propagateAfterMakeEqual(Bindings& bindings, VariableDomain& variable_domain, const std::vector<const Object*>& objects) const
{
if (variable_domain.getDomain().size() == 0)
{
return false;
}
// After a domain is made equal to a single object, remove this value from all variable domains which are unequal to
// this one.
if ((variable_domain.getDomain().size() == 1))
{
if (!removeObjectFromUnequalDomains(bindings, variable_domain, *variable_domain.getDomain()[0]))
{
return false;
}
}
return true;
}
bool SimpleBindingsPropagator::propagateAfterMakeUnequal(Bindings& bindings, VariableDomain& variable_domain1, VariableDomain& variable_domain2) const
{
if (variable_domain1.getDomain().size() == 0 || variable_domain2.getDomain().size() == 0)
{
return false;
}
// If a domain is made unequal, check if either has only a single object in their variable domain and propagate this.
if (variable_domain1.getDomain().size() == 1)
{
//ObjectBinding ob(variable_domain2.getStep(), variable_domain2.getVariable(), *variable_domain1.getDomain()[0], false);
//if (!bindings.addBinding(ob))
if (!removeObjectFromUnequalDomains(bindings, variable_domain1, *variable_domain1.getDomain()[0]))
{
return false;
}
}
if (variable_domain2.getDomain().size() == 1)
{
// ObjectBinding ob(variable_domain1.getStep(), variable_domain1.getVariable(), *variable_domain2.getDomain()[0], false);
// if (!bindings.addBinding(ob))
if (!removeObjectFromUnequalDomains(bindings, variable_domain2, *variable_domain2.getDomain()[0]))
{
return false;
}
}
return true;
}
bool SimpleBindingsPropagator::propagateAfterMakeUnequal(Bindings& bindings, VariableDomain& variable_domain, const Object& object) const
{
if (variable_domain.getDomain().size() == 0)
{
return false;
}
// If the domain only has a single object remaining, prune this from the variable domains which are unequal to it.
if (variable_domain.getDomain().size() == 1)
{
// ObjectBinding ob(variable_domain.getStep(), variable_domain.getVariable(), object, false);
// if (!bindings.addBinding(ob))
// if (!removeObjectFromUnequalDomains(bindings, variable_domain, object))
if (!removeObjectFromUnequalDomains(bindings, variable_domain, *variable_domain.getDomain()[0]))
{
return false;
}
}
return true;
}
bool SimpleBindingsPropagator::propagateAfterMakeUnequal(Bindings& bindings, VariableDomain& variable_domain, const std::vector<const Object*>& objects) const
{
if (variable_domain.getDomain().size() == 0)
{
return false;
}
// If the domain only has a single object remaining, prune this from the variable domains which are unequal to it.
if (variable_domain.getDomain().size() == 1)
{
// ObjectBinding ob(variable_domain.getStep(), variable_domain.getVariable(), object, false);
// if (!bindings.addBinding(ob))
// if (!removeObjectFromUnequalDomains(bindings, variable_domain, object))
if (!removeObjectFromUnequalDomains(bindings, variable_domain, *variable_domain.getDomain()[0]))
{
return false;
}
}
return true;
}
};