-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNode.h
189 lines (169 loc) · 4.63 KB
/
Node.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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
/**
* @file Node.h
* @brief Definition of the Node class.
*/
#ifndef DA_PROJECT2_NODE_H
#define DA_PROJECT2_NODE_H
#include <list>
#include <cmath>
#include "Edge.h"
using namespace std;
/**
* @class Node
* @brief Represents a node in a graph.
*/
class Node {
public:
int queueIndex = 0;
/**
* @brief Constructs a Node object with the given ID.
*
* @param id The ID of the node.
*
* Time complexity: O(1)
*/
Node(int id);
/**
* @brief Constructs a Node object with the given ID, latitude, and longitude.
*
* @param id The ID of the node.
* @param latitude The latitude coordinate of the node.
* @param longitude The longitude coordinate of the node.
*
* Time complexity: O(1)
*/
Node(int id, double latitude, double longitude);
/**
* @brief Gets the ID of the node.
*
* @return The ID of the node.
*
* Time complexity: O(1)
*/
int getId() const;
/**
* @brief Gets a list of edges connected to the node.
*
* @return A list of edges connected to the node.
*
* Time complexity: O(1)
*/
list<Edge*> getEdges() const;
/**
* @brief Adds an edge to the node's list of edges.
*
* @param edge The edge to be added.
*
* Time complexity: O(1)
*/
void addEdge(Edge* edge);
/**
* @brief Checks if the node has been visited.
*
* @return True if the node has been visited, false otherwise.
*
* Time complexity: O(1)
*/
bool isVisited() const;
/**
* @brief Sets the visited state of the node.
*
* @param v The visited state to be set.
*
* Time complexity: O(1)
*/
void setVisited(bool v);
/**
* @brief Gets the latitude coordinate of the node.
*
* @return The latitude coordinate of the node.
*
* Time complexity: O(1)
*/
double getLatitude() const;
/**
* @brief Gets the longitude coordinate of the node.
*
* @return The longitude coordinate of the node.
*
* Time complexity: O(1)
*/
double getLongitude() const;
/**
* @brief Gets the distance to another node.
*
* @param other The other node.
* @return The distance to the other node.
*
* Time complexity: O(E), where E is the number of edges connected to the node.
*/
double getDistanceTo(Node* other) const;
/**
* @brief Sets the path (edge) from the previous node to this node.
*
* @param p The path (edge) to be set.
*
* Time complexity: O(1)
*/
void setPath(Edge* p);
/**
* @brief Gets the path (edge) from the previous node to this node.
*
* @return The path (edge) from the previous node to this node.
*
* Time complexity: O(1)
*/
Edge* getPath() const;
/**
* @brief Sets the distance from the starting node to this node.
*
* @param d The distance to be set.
*
* Time complexity: O(1)
*/
void setDistance(double d);
/**
* @brief Gets the distance from the starting node to this node.
*
* @return The distance from the starting node to this node.
*
* Time complexity: O(1)
*/
double getDistance() const;
/**
* @brief Gets the edge between this node and another node.
*
* @param node The other node.
* @return The edge between this node and the other node, or nullptr if no edge exists.
*
* Time complexity: O(E) where E is the number of edges connected to the node.
*/
Edge* getEdgeTo(Node* node) const;
/**
* @brief Calculates the Haversine distance between this node and another node.
*
* @param node The other node.
* @return The Haversine distance between this node and the other node.
*
* Time complexity: O(1)
*/
double getHaversineDistanceTo(Node* node) const;
/**
* @brief Overloaded less-than operator to compare nodes.
*
* @param node The node to compare with.
* @return True if this node is less than the given node, false otherwise.
*
* Time complexity: O(1)
*/
bool operator<(Node& node) const;
private:
int id;/**< The ID of the node. */
double latitude;/**< The latitude coordinate of the node. */
double longitude;/**< The longitude coordinate of the node. */
double distance;/**< The distance from the starting node to this node. */
list<Edge*> edges;/**< A list of edges connected to the node. */
Edge* path;/**< The path (edge) from the previous node to this node. */
bool visited;/**< The visited state of the node. */
};
#endif //DA_PROJECT2_NODE_H