-
Notifications
You must be signed in to change notification settings - Fork 2
/
types.h
101 lines (84 loc) · 2.29 KB
/
types.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
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
#ifndef ACO_TSP_TYPES_H
#define ACO_TSP_TYPES_H
#include <vector>
namespace aco
{
/**
* Node used by the graph
*/
struct Node
{
Node(double x, double y, int id);
int id;
double x{};
double y{};
std::vector<std::pair<int, double>> neighbors;
bool operator==(const Node &other) const;
/**
* Get distance between current node and node with node id as node_id
* @param node_id
* @return distance
*/
double get_distance_from_neighbor(int node_id) const;
};
struct Graph
{
private:
/**
* The main graph container (The graph is immutable)
*/
typedef std::vector<Node> NodeList;
NodeList graph_;
/**
* Number of nodes in the graph
*/
int n_nodes_;
/**
* Get node pointer from graph corresponding to the node id
* @param node_id
* @return
*/
aco::Node *get_node_from_graph(int node_id);
public:
Graph();
/**
* Define iterators for using std generic algorithms
*/
typedef NodeList::iterator iterator;
typedef NodeList::const_iterator const_iterator;
iterator begin();
iterator end();
const_iterator cbegin() const;
const_iterator cend() const;
/**
* Get the number of nodes in a graph
* @return
*/
int size() const;
/**
* Get the mean of all edge weights in the graph
* @return
*/
double mean_edge_weight() const;
/**
* Create a new node in Graph with co-ordinates x and y
* @param x - x coordinate
* @param y - y coordinate
* @return
*/
int create_node_in_graph(double x, double y);
/**
* Add edge (onw way) from node_id_from to node_id_to in the graph
* @param node_id_from
* @param node_id_to
*/
void add_edge(int node_id_from, int node_id_to);
/**
* Get node from graph corresponding to the node id
* @param node_id
* @return
*/
aco::Node get_node_from_graph(int node_id) const;
};
} // namespace aco
#endif //ACO_TSP_TYPES_H