-
Notifications
You must be signed in to change notification settings - Fork 0
/
WeightedGraph.cpp
36 lines (30 loc) · 1.24 KB
/
WeightedGraph.cpp
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
#include <limits> // Include the limits header for numeric limits
#include "WeightedGraph.h" // Include the declaration of the WeightedGraph class
// Edge class constructor
WeightedGraph::Edge::Edge(int source, int destination, double weight)
: source(source), destination(destination), weight(weight) {}
// Vertex class constructor
WeightedGraph::Vertex::Vertex(int num, char label, int i, int j) : num(num), label(label), i(i), j(j) {
indivTime = std::numeric_limits<double>::infinity();
timeFromSource = std::numeric_limits<double>::infinity();
heuristic = -1;
prev = nullptr;
}
void WeightedGraph::Vertex::addNeighbor(const Edge& e) {
// Add a neighbor (edge) to the vertex
adjacencyList.push_front(e);
}
// Graph class constructor
WeightedGraph::Graph::Graph() = default;
void WeightedGraph::Graph::addVertex(char label, double indivTime, int i, int j) {
// Add a vertex to the graph
Vertex v(num_v, label, i, j);
v.indivTime = indivTime;
vertexList.push_back(v);
num_v = num_v + 1;
}
void WeightedGraph::Graph::addEdge(int source, int destination, double weight) {
// Add a weighted edge between two vertices
Edge edge(source, destination, weight);
vertexList[source].addNeighbor(edge);
}