-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathVertex.hpp
More file actions
105 lines (86 loc) · 2.46 KB
/
Vertex.hpp
File metadata and controls
105 lines (86 loc) · 2.46 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
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
#ifndef VERTEX_HPP
#define VERTEX_HPP
#include <string>
#include <unordered_map>
#include <vector>
#include "Edge.hpp"
//#include "UndirectedGraph.hpp"
/**
* Represents a Vertex in a graph.
*
* Vertices are connected to other Vertices via Edges. Each Vertex
* maintains a collection of all Edges that originate from it.
*/
class Vertex {
// Graph needs access to Edge map for Dijkstra/Prim algorithms.
friend class UndirectedGraph;
public:
/**
* Initialize the Vertex with the given name.
*/
Vertex(const std::string &name);
/**
* Add an edge to this Vertex. If an edge already exists to the given
* vertex, updates the cost and length of the edge to match the
* passed parameters.
*/
void addEdge(Vertex *to, unsigned int cost, unsigned int length);
/**
* Returns the Vertex's name.
*/
const std::string &getName() const;
/**
* Gets the Vertex's distance value.
*/
unsigned int getDistance() const;
/**
* Sets the Vertex's distance value.
*/
void setDistance(unsigned int distance);
/**
* Gets the Vertex's visited state.
*/
bool wasVisited() const;
/**
* Sets the Vertex's visited state.
*/
void setVisited(bool visited);
/**
* Clears all edges from this Vertex.
*/
void clearEdges();
/**
* Gets total cost of all edges terminating at this Vertex.
*/
unsigned int totalEdgeCost() const;
//returns a list of the vertices which are neighbors to the current vertex
//and are unvisited.
//iterate through edges list and check each edge for the vertex it goes to
//and return the pointers to all those vertices to dereference
std::vector< std::pair<Vertex*, Edge> > getUnvisitedNeighbors() const;
private:
/**
* Returns a reference to the internal map of Edges.
* Used by UndirectedGraph for Dijkstra/Prim algorithms.
*/
const std::unordered_map<std::string, Edge> &getEdges() const;
/**
* Name of this Vertex.
*/
std::string name;
/**
* Distance of this Vertex from initial Vertex.
* Used by Dijkstra's algorithm.
*/
unsigned int distance;
/**
* Whether this node has been visited.
* Used by Prim's algorithm.
*/
bool visited;
/**
* Map of adjacent Vertex name to Edge describing the adjacency.
*/
std::unordered_map<std::string, Edge> edges;
};
#endif