-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGroundedAction.hpp
More file actions
119 lines (102 loc) · 3.03 KB
/
GroundedAction.hpp
File metadata and controls
119 lines (102 loc) · 3.03 KB
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
// GroundedAction Class file for Task Planner
// Author : Prateek Parmeshwar
#pragma once
using namespace std;
struct GroundedConditionComparator
{
bool operator()(const GroundedCondition& lhs, const GroundedCondition& rhs) const
{
return lhs == rhs;
}
};
struct GroundedConditionHasher
{
size_t operator()(const GroundedCondition& gcond) const
{
return hash<string>{}(gcond.toString());
}
};
class GroundedAction
{
private:
string name;
list<string> arg_values;
unordered_set<GroundedCondition, GroundedConditionHasher, GroundedConditionComparator> gPreconditions;
unordered_set<GroundedCondition, GroundedConditionHasher, GroundedConditionComparator> gEffects;
public:
GroundedAction(string name, list<string> arg_values)
{
this->name = name;
for (string ar : arg_values)
{
this->arg_values.push_back(ar);
}
}
GroundedAction(string name, list<string> arg_values,
unordered_set<GroundedCondition, GroundedConditionHasher, GroundedConditionComparator> gPreconditions,
unordered_set<GroundedCondition, GroundedConditionHasher, GroundedConditionComparator> gEffects)
{
this->name = name;
for (string ar : arg_values)
{
this->arg_values.push_back(ar);
}
for (GroundedCondition gpc : gPreconditions)
{
this->gPreconditions.insert(gpc);
}
for (GroundedCondition gEf : gEffects)
{
this->gEffects.insert(gEf);
}
}
string get_name() const
{
return this->name;
}
list<string> get_arg_values() const
{
return this->arg_values;
}
unordered_set<GroundedCondition, GroundedConditionHasher, GroundedConditionComparator> get_preconditions()
{
return this->gPreconditions;
}
unordered_set<GroundedCondition, GroundedConditionHasher, GroundedConditionComparator> get_effects()
{
return this->gEffects;
}
bool operator==(const GroundedAction& rhs) const
{
if (this->name != rhs.name || this->arg_values.size() != rhs.arg_values.size())
return false;
auto lhs_it = this->arg_values.begin();
auto rhs_it = rhs.arg_values.begin();
while (lhs_it != this->arg_values.end() && rhs_it != rhs.arg_values.end())
{
if (*lhs_it != *rhs_it)
return false;
++lhs_it;
++rhs_it;
}
return true;
}
friend ostream& operator<<(ostream& os, const GroundedAction& gac)
{
os << gac.toString() << " ";
return os;
}
string toString() const
{
string temp = "";
temp += this->name;
temp += "(";
for (string l : this->arg_values)
{
temp += l + ",";
}
temp = temp.substr(0, temp.length() - 1);
temp += ")";
return temp;
}
};