-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgraph.h
62 lines (56 loc) · 1.33 KB
/
graph.h
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
#ifndef GRAPH_H_
#define GRAPH_H_
#include "geometry.h"
#include "constant.h"
#include <vector>
#include <unordered_map>
#include <map>
#include <unordered_set>
#include <iostream>
#include <string>
#include <climits>
#include "robot.h"
using namespace std;
using namespace geometry;
struct Node
{
int id;
array<int, 2> map_index;
Vec2 coordinate;
bool is_obstacle;
bool is_workbench;
int workbench_id;
vector<Node*> neighbors;
//unordered_set<Node*> neighbors;
//unordered_map<int, Node*> neighbors;
bool operator==(const Node& other) const {
return map_index[0] == other.map_index[0] && map_index[1] == other.map_index[1];
}
bool operator!=(const Node& other) const {
return !(*this == other);
}
void print() {
cerr << map_index[0] << ',' << map_index[1] << endl;
}
};
class Graph
{
public:
Graph(char map[MAP_SIZE][MAP_SIZE]);
Graph() {};
void initNodes(char map[MAP_SIZE][MAP_SIZE]);
void initNeighbors();
Node* workbenchToNode(int workbench_id);
Node* coordinateToNode(Vec2 coordinate);
Node* indexToNode(array<int, 2> index);
Node* robotToNode(Robot* robot);
void init(char map[MAP_SIZE][MAP_SIZE]);
void updateObstacle(vector<Vec2> robots_coor);
bool isObstacle(Vec2 coordinate);
private:
vector<Node*> robotNodes;
vector<Node*> nodes;
map<array<int, 2>, Node*> index_to_node;
vector<Vec2> obstacles;
};
#endif