-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathmultiagent_search_interface.h
More file actions
59 lines (52 loc) · 1.96 KB
/
multiagent_search_interface.h
File metadata and controls
59 lines (52 loc) · 1.96 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
#ifndef MULTIAGENT_SEARCH_INTEFACE_H
#define MULTIAGENT_SEARCH_INTEFACE_H
#include "config.h"
#include "agent_set.h"
#include "map.h"
#include "multiagent_search_result.h"
#include "isearch.h"
#include <vector>
#include <unordered_map>
class MultiagentSearchInterface
{
public:
virtual ~MultiagentSearchInterface(void) {}
virtual MultiagentSearchResult startSearch(const Map &map, const Config &config, AgentSet &AgentSet,
std::chrono::steady_clock::time_point globalBegin = std::chrono::steady_clock::time_point(),
int globalTimeLimit = -1) = 0;
virtual void clear() {
agentsPaths.clear();
perfectHeuristic.clear();
}
void getPerfectHeuristic(const Map &map, const AgentSet &agentSet) {
if (!perfectHeuristic.empty()) {
return;
}
std::unordered_set<int> visited;
ISearch<> search(false);
for (int i = 0; i < agentSet.getAgentCount(); ++i) {
//std::cout << i << std::endl;
visited.clear();
Node goal = Node(agentSet.getAgent(i).getGoal_i(), agentSet.getAgent(i).getGoal_j());
std::queue<Node> queue;
queue.push(goal);
while (!queue.empty()) {
Node cur = queue.front();
queue.pop();
if (visited.find(cur.convolution(map.getMapWidth(), map.getMapHeight())) != visited.end()) {
continue;
}
perfectHeuristic[std::make_pair(cur, goal)] = cur.g;
visited.insert(cur.convolution(map.getMapWidth(), map.getMapHeight()));
std::list<Node> successors = search.findSuccessors(cur, map);
for (auto neigh : successors) {
queue.push(neigh);
}
}
}
}
//protected:
std::vector<std::vector<Node>> agentsPaths;
std::unordered_map<std::pair<Node, Node>, int, NodePairHash> perfectHeuristic;
};
#endif // MULTIAGENT_SEARCH_INTEFACE_H