-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathpredicate_manager.h
140 lines (109 loc) · 3.9 KB
/
predicate_manager.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
#ifndef MYPOPPREDICATE_MANAGER_H
#define MYPOPPREDICATE_MANAGER_H
#include <iostream>
#include <vector>
#include <map>
#include "VALfiles/ptree.h"
#include "VALfiles/TIM.h"
#include "manager.h"
/**
* We assume predicates are unique in a domain. If the name of a predicate is equal than Atoms will
* share the same predicate object. During analysis properties of predicates (e.g. if they are static)
* will be assigned to an object of this class.
*/
namespace MyPOP {
class Type;
class TypeManager;
class ActionManager;
class Predicate : public ManageableObject
{
public:
Predicate(const std::string& name, const std::vector<const Type*>& types, bool is_static);
~Predicate();
/**
* Get the name of the predicate.
*/
const std::string& getName() const { return name_; }
/**
* Get the types of the predicate.
*/
const std::vector<const Type*>& getTypes() const { return *types_; }
/**
* Get the arity of this predicate.
*/
unsigned int getArity() const { return types_->size(); }
/**
* Check if this predicate is static.
*/
bool isStatic() const { return is_static_; }
/**
* Make or unmake this predicate static.
*/
void makeStatic(bool make_static);
/**
* Check if this predicate can substitute for the given predicate.
* Requirements for meeting this:
* - The names must be the same.
* - The arity must be the same.
* - For each type: the type of this predicate must be equal or more general than each type of the given predicate.
* This ensures that all possible assignments of the values of the given predicate can also be made to this predicate.
*
* For example the predicate (at ?object ?location) can substitute for (at ?truck ?location) if truck is a subset of object.
*/
bool canSubstitute(const Predicate& predicate) const;
/**
* Check if two predicates are exactly the same.
* Requirements for meeting this:
* - The names must be the same.
* - The arity must be the same.
* - The types must be exactly the same.
*/
bool operator==(const Predicate& predicate) const;
/**
* Check if two predicates are different.
* Requirements for meeting this are to violate any of the following:
* - The names must be the same.
* - The arity must be the same.
* - The types must be exactly the same.
*/
bool operator!=(const Predicate& predicate) const;
void initCache(const std::vector<Predicate*>& all_predicates);
friend std::ostream& operator<<(std::ostream&, const Predicate& predicate);
private:
// The name of the predicate.
const std::string name_;
// The terms of this predicate.
const std::vector<const Type*>* types_;
// Is this predicate static?
bool is_static_;
// Test.
bool* can_substitute_;
};
std::ostream& operator<<(std::ostream&, const Predicate& predicate);
class PredicateManager : public Manager<Predicate>
{
public:
//PredicateManager(const TermManager& term_manager);
PredicateManager(const TypeManager& type_manager);
virtual ~PredicateManager();
// Process all predicate names.
void processPredicates(const VAL::pred_decl_list& predicates);
// Post process all the predicates after we know all the operators of the domain. Determine which
// predicates are static.
void checkStaticPredicates(const ActionManager& action_manager);
// Get the predicate of the given name and types.
const Predicate* getPredicate(const std::string& name, const std::vector<const Type*>& types) const;
// Get the predicate from the domain with its most general types.
// TODO: remove
const Predicate* getGeneralPredicate(const std::string& name) const;
private:
// The term manager.
const TypeManager* type_manager_;
// We store all found predicates in a table, indexed by the predicate's name and types.
std::map<std::pair<std::string, std::vector<const Type*> >, Predicate*> predicate_map_;
// Store the most general predicate per name.
// TODO: remove
std::map<std::string, std::vector<const Type*>* > general_predicates_;
};
}
#endif