-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdijkstra.h
More file actions
47 lines (43 loc) · 1.21 KB
/
dijkstra.h
File metadata and controls
47 lines (43 loc) · 1.21 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
#pragma once
#include <vector>
#include <limits>
#include <unordered_map>
#include <queue>
#include <iostream>
#include <map>
#include "makeGraph.h"
class Dijkstra {
public:
Dijkstra(makeGraph mkg);
// Runs the Dijkstra algorithm with the inputted source airport
std::vector<double> runDijkstra(int source_id);
std::vector<int> getPrev();
std::vector<double> getDist();
// Returns the minimum distance of the path between a source airport and a destination airport as a double
// source_id: The ID of the source airport
// dest_id: The ID of the destination airport
double minDist(int source_id, int dest_id);
private:
makeGraph mkg_;
std::vector<double> dist_;
int source_id_;
std::vector<int> prev_;
std::vector<bool> seen_;
};
struct Vertex {
Vertex(size_t idx, double weight): idx_(idx), weight_(weight) {}
friend bool operator > (const Vertex& lhs, const Vertex& rhs);
int idx_;
double weight_;
};
// Custom comparator for the priority queue
struct Compare
{
bool operator()(const Vertex& lhs, const Vertex& rhs)
{
if (lhs > rhs) {
return true;
}
return false;
}
};