-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEnv.hpp
More file actions
111 lines (102 loc) · 2.94 KB
/
Env.hpp
File metadata and controls
111 lines (102 loc) · 2.94 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
// Environment Class file for Task Planner
// Author : Prateek Parmeshwar
#pragma once
using namespace std;
struct ActionComparator
{
bool operator()(const Action& lhs, const Action& rhs) const
{
return lhs == rhs;
}
};
struct ActionHasher
{
size_t operator()(const Action& ac) const
{
return hash<string>{}(ac.get_name());
}
};
class Env
{
private:
unordered_set<GroundedCondition, GroundedConditionHasher, GroundedConditionComparator> initial_conditions;
unordered_set<GroundedCondition, GroundedConditionHasher, GroundedConditionComparator> goal_conditions;
unordered_set<Action, ActionHasher, ActionComparator> actions;
unordered_set<string> symbols;
public:
void remove_initial_condition(GroundedCondition gc)
{
this->initial_conditions.erase(gc);
}
void add_initial_condition(GroundedCondition gc)
{
this->initial_conditions.insert(gc);
}
void add_goal_condition(GroundedCondition gc)
{
this->goal_conditions.insert(gc);
}
void remove_goal_condition(GroundedCondition gc)
{
this->goal_conditions.erase(gc);
}
void add_symbol(string symbol)
{
symbols.insert(symbol);
}
void add_symbols(list<string> symbols)
{
for (string l : symbols)
this->symbols.insert(l);
}
void add_action(Action action)
{
this->actions.insert(action);
}
unordered_set<GroundedCondition, GroundedConditionHasher, GroundedConditionComparator> get_initial_condition()
{
return this->initial_conditions;
}
unordered_set<GroundedCondition, GroundedConditionHasher, GroundedConditionComparator> get_goal_condition()
{
return this->goal_conditions;
}
Action get_action(string name)
{
for (Action a : this->actions)
{
if (a.get_name() == name)
return a;
}
throw runtime_error("Action " + name + " not found!");
}
unordered_set<Action, ActionHasher, ActionComparator> get_actions()
{
return actions;
}
unordered_set<string> get_symbols() const
{
return this->symbols;
}
friend ostream& operator<<(ostream& os, const Env& w)
{
os << "***** Environment *****" << endl << endl;
os << "Symbols: ";
for (string s : w.get_symbols())
os << s + ",";
os << endl;
os << "Initial conditions: ";
for (GroundedCondition s : w.initial_conditions)
os << s;
os << endl;
os << "Goal conditions: ";
for (GroundedCondition g : w.goal_conditions)
os << g;
os << endl;
os << "Actions:" << endl;
for (Action g : w.actions)
os << g << endl;
cout << "***** Environment Created! *****" << endl;
return os;
}
};