-
Notifications
You must be signed in to change notification settings - Fork 0
/
agents.hpp
97 lines (84 loc) · 2.63 KB
/
agents.hpp
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
#ifndef AGENTS_H
#define AGENTS_H
#include <string>
#include <vector>
// external json parser (https://github.com/nlohmann/json)
#include "json.hpp"
using namespace std;
using json = nlohmann::json; // for convenience
/**
* @brief State class for the Pedestrians representation.
* @param[out] name The agent's name
* @param[out] current_config The agent's current "config" (x, y, theta)
* @param[out] radius The radius of the agent
*/
class AgentState
{
public:
AgentState()
{
}
/**
* @brief Constructor for the Pedestrian's AgentState representation.
* @param[out] name The agent's name
* @param[out] current_config The agent's current "config" (x, y, theta)
* @param[out] radius The radius of the agent
*/
AgentState(string &n, vector<float> ¤t_pos3, float r)
{
name = n;
current_config = current_pos3;
radius = r;
}
/** @brief getter for the agent's name */
string get_name() const
{
return name;
}
/** @brief getter for the agent's radius */
float get_radius() const
{
return radius;
}
/* @brief getter for the agent's current config (x, y, theta) */
vector<float> get_current_config() const
{
return current_config;
}
/**
* @brief construct an AgentState out of its serialized json form
* @param[in] data The json object that holds the serialized AgentState info
* @returns AgentState instance containing all the fields from the json
**/
static AgentState construct_from_json(const json &data)
{
string name = data["name"];
vector<float> current_pos3 = data["current_config"];
float radius = data["radius"];
return AgentState(name, current_pos3, radius);
}
/**
* @brief construct a hash map out of a serialized json dictionary
* @param[in] data The json object that holds the serialized AgentState dictionary
* @returns pedestrians The map from name to AgentState of all the pedestrians
**/
static unordered_map<string, AgentState> construct_from_dict(const json &data)
{
unordered_map<string, AgentState> pedestrians;
for (auto &ped : data.items())
{
string name = ped.key(); // indexed by name (string)
auto new_agent = AgentState::construct_from_json(ped.value());
pedestrians.insert({name, new_agent});
}
return pedestrians;
}
private:
/* The agent's name */
string name;
/* The current config of the agent (x, y, theta) */
vector<float> current_config;
/* The radius of the agent */
float radius;
};
#endif