-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathlandmarks.h
241 lines (185 loc) · 8.08 KB
/
landmarks.h
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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
#ifndef LANDMARK_LANDMARKS_H
#define LANDMARK_LANDMARKS_H
#include <vector>
#include "VALfiles/ptree.h"
#include "VALfiles/SASActions.h"
#include "VALfiles/ToFunction.h"
#include "plan_bindings.h"
#include "plan_orderings.h"
#include "bindings_propagator.h"
namespace MyPOP {
class ActionManager;
class TypeManager;
class Plan;
namespace SAS_Plus {
class DomainTransitionGraphManager;
class CausalGraph;
};
namespace LANDMARKS {
class Landmark;
class PreconditionLandmark;
class LandmarkGraph;
/**
* Adapted orderings class, we do not want to deduce any additional orderings as it will make the graphs very messy!
*/
class LandmarkOrderings : public BinaryOrderings
{
public:
virtual bool addOrdering(const Ordering& ordering);
};
/**
* Process the planning problem and produce landmarks based on the lifted action representation.
*/
class LandmarkManager
{
public:
LandmarkManager(const ActionManager& action_manager, const TypeManager& type_manager, const TermManager& term_manager);
~LandmarkManager();
/**
* Start generating the landmark graph. Internally the SAS+ representation of the actions are mapped in
* SAS::FunctionStructure from the operators to the actual representation. Therefor we need the operator
* list to unearth the SAS+ representation.
*/
//void generateLandmarks(const VAL::operator_list& operators, const VAL::pddl_type_list& types, Plan& initial_plan);
/**
* Find landmarks by regressive search. Start off with the goals as the initial landmarks and find landmarks
* by checking which actions share the same preconditions.
*/
void findLandmarksFromGoal(const VAL::operator_list& operators, const VAL::pddl_type_list& types, MyPOP::Plan& initial_plan, const SAS_Plus::DomainTransitionGraphManager& dtg_manager, const SAS_Plus::CausalGraph& causal_graph);
/**
* Find landmarks by checking the DTG structures and see if any nodes must be present in the graph to traverse
* the graph from the initial state to the goal state.
*/
void findClosestLandmarksInDTG(std::vector<const PreconditionLandmark*>& found_landmarks, const SAS_Plus::DomainTransitionGraphManager& dtg_manager, const Landmark& from_landmark, const Landmark& to_landmark);
//void findLandmarksInDTGs(const SAS_Plus::DomainTransitionGraphManager& dtg_manager, Plan& initial_plan);
//void findLandmarksInDTG(const SAS_Plus::DomainTransitionGraphManager& dtg_manager, const Landmark& from_landmark, const Landmark& to_landmark);
/**
* Get the landmark graph with all landmarks found so far.
*/
const LandmarkGraph& getLandmarkGraph() const { return *landmark_graph_; }
protected:
void getSharedPreconditions(std::vector<const Atom*>& shared_preconditions, const std::vector<StepPtr>& action_steps) const;
void getCommonPreconditions(std::vector<const PreconditionLandmark*>& landmarks, const PreconditionLandmark& landmark, Plan& initial_plan, const SAS_Plus::DomainTransitionGraphManager& dtg_manager) const;
void getFirstAchievers(std::vector<const PreconditionLandmark*>& landmarks, const PreconditionLandmark& landmark, Plan& initial_plan, const SAS_Plus::DomainTransitionGraphManager& dtg_manager) const;
private:
// The action manager contains all information about the action.
const ActionManager* action_manager_;
// The type manager contains all information about the types.
const TypeManager* type_manager_;
// The term manager contains all information about the terms.
const TermManager* term_manager_;
// The landmark graph, all found landmarks will be inserted in this graph.
LandmarkGraph* landmark_graph_;
};
/**
* A landmark is defined as a fact which must be true in any valid solution to a problem. The landmark
* fact is captured in atom_ and it is bound to a specific landmark graph which contains the fact's
* bindings.
*/
class Landmark
{
public:
/**
* Create a new landmark. The landmarks' bindings will be copied to the bindings of the landmark
* graph.
* @param step_id The ID used to bind all te variables of atom in the given bindings.
* @param atom The landmark fact.
* @param bindings Contains the mappings between the fact's variables and its domains.
* @param landmark_graph The landmark grah this landmark will be added to.
*/
Landmark(StepID step_id, const Atom& atom, const Bindings& bindings, LandmarkGraph& landmark_graph);
~Landmark();
const Atom& getAtom() const { return *atom_; }
StepID getStepId() const { return step_id_; }
void setStepId(StepID step_id) { step_id_ = step_id; }
const LandmarkGraph& getLandmarkGraph() const { return *landmark_graph_; }
private:
// The step id under which the variables are bound in the landmark graph's bindings.
StepID step_id_;
// The landmark.
const Atom* atom_;
// The landmark graph it is added to.
const LandmarkGraph* landmark_graph_;
};
std::ostream& operator<<(std::ostream& os, const Landmark& landmark);
/**
* A precondition landmark is a landmark which has been discovered when looking at shared preconditions.
* It contains pointers to the landmarks which are shared preconditions of the same set of actions.
*/
class PreconditionLandmark : public Landmark
{
public:
PreconditionLandmark(StepID step_id, const Atom& atom, const Bindings& bindings, LandmarkGraph& landmark_graph);
void setSharedLandmarks(const std::vector<const PreconditionLandmark*>& landmarks);
const std::vector<const PreconditionLandmark*>& getSharedLandmarks() const { return *shared_landmarks_; }
void setAchievingActions(const std::vector<StepPtr>& achieving_actions);
const std::vector<StepPtr>& getAchievingActions() const { return *achieving_actions_; }
private:
// The common set of preconditions of the set of actions which have these landmarks as their precondition.
const std::vector<const PreconditionLandmark*>* shared_landmarks_;
// The set of actions which achieve this landmark. The shared landmarks are the shared preconditions
// of this set of actions.
const std::vector<StepPtr>* achieving_actions_;
};
/**
* Landmark graph keeps a list of landmarks and the orderings between them.
*/
class LandmarkGraph
{
public:
/**
* Create a landmark graph with no initial bindings.
*/
LandmarkGraph(const TermManager& term_manager);
/**
* Create a landmark graph and copy the bindings from the given one.
*/
LandmarkGraph(const Bindings& bindings);
/**
* Get the bindings of the landmarks.
*/
const Bindings& getBindings() const { return *bindings_; }
Bindings& getBindings() { return *bindings_; }
/**
* Get the orderings between the landmarks.
*/
const Orderings& getOrderings() const { return orderings_; }
Orderings& getOrderings() { return orderings_; }
/**
* Get all the landmarks.
*/
const std::vector<const Landmark*>& getLandmarks() const { return landmarks_; }
/**
* Add a landmark to this graph. The bindings of the variables of the landmark are not necessarily
* bounded by bindings_, another Bindings object might have been used to find the variables. These bindings
* will be copied to this landmark graph's own bindings object. The step id of the given landmark will
* be changed after the bindings have been made.
*/
void addLandmark(Landmark& landmark, const Bindings& atom_bindings);
/**
* Order one landmark before another one, if this ordering fails an exception will be thrown.
*/
void addOrdering(const Landmark& from_landmark, const Landmark& to_landmark);
/**
* Return true if the given landmark is unifiable with the given action and its bindings.
*/
bool isUnifiable(StepPtr initial_step, const Bindings& bindings, const PreconditionLandmark& landmark) const;
private:
// The propagator we use to prune the bindings.
SimpleBindingsPropagator propagator_;
// The bindings of all landmarks' variables.
Bindings* bindings_;
// The orderings between landmarks.
//BinaryOrderings orderings_;
LandmarkOrderings orderings_;
// All landmarks contained in this landmark graph.
std::vector<const Landmark*> landmarks_;
};
std::ostream& operator<<(std::ostream& os, const LandmarkGraph& landmark_graph);
};
namespace Graphviz {
// Utility functions to print landmark graphs to DOT format.
void printToDot(const LANDMARKS::LandmarkGraph& landmark_graph);
};
};
#endif