-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAction.hpp
More file actions
108 lines (97 loc) · 2.59 KB
/
Action.hpp
File metadata and controls
108 lines (97 loc) · 2.59 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
// Action Class for Task Planner
// Author : Prateek Parmeshwar
#pragma once
using namespace std;
struct ConditionComparator
{
bool operator()(const Condition& lhs, const Condition& rhs) const
{
return lhs == rhs;
}
};
struct ConditionHasher
{
size_t operator()(const Condition& cond) const
{
return hash<string>{}(cond.toString());
}
};
class Action
{
private:
string name;
list<string> args;
unordered_set<Condition, ConditionHasher, ConditionComparator> preconditions;
unordered_set<Condition, ConditionHasher, ConditionComparator> effects;
public:
Action(string name, list<string> args,
unordered_set<Condition, ConditionHasher, ConditionComparator>& preconditions,
unordered_set<Condition, ConditionHasher, ConditionComparator>& effects)
{
this->name = name;
for (string l : args)
{
this->args.push_back(l);
}
for (Condition pc : preconditions)
{
this->preconditions.insert(pc);
}
for (Condition pc : effects)
{
this->effects.insert(pc);
}
}
string get_name() const
{
return this->name;
}
list<string> get_args() const
{
return this->args;
}
int get_args_number() const
{
return (this->args).size();
}
unordered_set<Condition, ConditionHasher, ConditionComparator> get_preconditions() const
{
return this->preconditions;
}
unordered_set<Condition, ConditionHasher, ConditionComparator> get_effects() const
{
return this->effects;
}
bool operator==(const Action& rhs) const
{
if (this->get_name() != rhs.get_name() || this->get_args().size() != rhs.get_args().size())
return false;
return true;
}
friend ostream& operator<<(ostream& os, const Action& ac)
{
os << ac.toString() << endl;
os << "Precondition: ";
for (Condition precond : ac.get_preconditions())
os << precond;
os << endl;
os << "Effect: ";
for (Condition effect : ac.get_effects())
os << effect;
os << endl;
return os;
}
string toString() const
{
string temp = "";
temp += this->get_name();
temp += "(";
for (string l : this->get_args())
{
temp += l + ",";
}
temp = temp.substr(0, temp.length() - 1);
temp += ")";
return temp;
}
};