forked from KCL-Planning/L-RPG
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrelaxed_planning_graph.h
149 lines (107 loc) · 4.19 KB
/
relaxed_planning_graph.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
#ifndef MYPOP_RPGRELAXED_PLANNING_GRAPH_H
#define MYPOP_RPGRELAXED_PLANNING_GRAPH_H
#include <utility>
#include <vector>
#include <ostream>
#include "plan_types.h"
#include "plan_bindings.h"
#include "formula.h"
namespace MyPOP {
class PredicateManager;
class BindingsPropagator;
class ActionManager;
class Plan;
class TermManager;
class Atom;
class Step;
namespace SAS_Plus {
class BoundedAtom;
};
namespace REACHABILITY {
class ResolvedBoundedAtom;
class EquivalentObjectGroupManager;
};
namespace RPG {
//typedef std::pair<StepID, const Atom*> BoundedAtom;
class ResolvedAction
{
public:
ResolvedAction(const Action& action, StepID step_id, const Bindings& bindings, const REACHABILITY::EquivalentObjectGroupManager& eog_manager, PredicateManager& predicate_manager);
~ResolvedAction();
const std::vector<const REACHABILITY::ResolvedBoundedAtom*>& getPreconditions() const { return preconditions_; }
const std::vector<const REACHABILITY::ResolvedBoundedAtom*>& getEffects() const { return effects_; }
const StepID getStepID() const { return step_id_; }
const Action& getAction() const { return *action_; }
const Bindings& getBindings() const { return *bindings_; }
private:
const StepID step_id_;
const Action* action_;
const Bindings* bindings_;
std::vector<const REACHABILITY::ResolvedBoundedAtom*> preconditions_;
std::vector<const REACHABILITY::ResolvedBoundedAtom*> effects_;
};
std::ostream& operator<<(std::ostream& os, const ResolvedAction& resolved_action);
/**
* Because we allow no duplicate facts in a layer we first check if the atom can be bounded to an existing
* one already present in the layer. If this is the case it will not be added.
*/
class FactLayer
{
public:
/**
* Create a new empty fact layer.
*/
FactLayer(bool delete_facts = false);
/**
* Copy constructor.
*/
FactLayer(const FactLayer& fact_layer);
~FactLayer();
/**
* Add a fact to this fact layer, this method only succeeds if the bounded atom cannot be unified
* with any atoms already present in this fact layer.
*/
bool addFact(const REACHABILITY::ResolvedBoundedAtom& bounded_atom);
/**
* Return all the facts stored in this fact layer.
*/
const std::vector<const REACHABILITY::ResolvedBoundedAtom*>& getFacts() const { return facts_; }
const std::vector<const REACHABILITY::ResolvedBoundedAtom*>* getFacts(const REACHABILITY::ResolvedBoundedAtom& precondition) const;
private:
bool delete_facts_;
std::string getUniqueName(const REACHABILITY::ResolvedBoundedAtom& atom) const;
// All the facts stored in this fact layer.
std::vector<const REACHABILITY::ResolvedBoundedAtom*> facts_;
std::map<std::string, std::vector<const REACHABILITY::ResolvedBoundedAtom*>* > mapped_facts_;
std::vector<std::vector<const REACHABILITY::ResolvedBoundedAtom*>*> mapped_facts_to_remove_;
};
/**
* A relaxed planning graph is a serries of facts and action layers alternating between the two. Starting at the initial layer
* all actions which can be applied will be added to the next fact layer and its effects (minus the delete effects) will be added
* to the next fact layer in addition to the facts already present (no-ops).
*/
class RelaxedPlanningGraph
{
public:
/**
* Create a relaxed planning graph from the intial state to the goal state. These can be found in the
* initial plan. The relaxed planning graph is only allowed to make use of the lifted actions.
*/
RelaxedPlanningGraph(const ActionManager& action_manager, const Plan& initial_plan, const REACHABILITY::EquivalentObjectGroupManager& eog_manager, PredicateManager& predicate_manager);
~RelaxedPlanningGraph();
const std::vector<std::vector<const ResolvedAction*>* >& getActionLayers() const { return action_layers_; }
const std::vector<FactLayer* >& getFactLayers() const { return fact_layers_; }
private:
// The action layers.
//std::vector<std::vector<const Step*>* > action_layers_;
std::vector<std::vector<const ResolvedAction*>* > action_layers_;
// The fact layers.
std::vector<FactLayer* > fact_layers_;
std::vector<const ResolvedAction*> all_grounded_actions_;
// The bindings of the actions.
Bindings* bindings_;
};
std::ostream& operator<<(std::ostream& os, const RelaxedPlanningGraph& rpg);
}
}
#endif