-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmetrosystem.h
More file actions
65 lines (52 loc) · 2.22 KB
/
Copy pathmetrosystem.h
File metadata and controls
65 lines (52 loc) · 2.22 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
#ifndef METROSYSTEM_H
#define METROSYSTEM_H
#include <string>
#include <vector>
#include <unordered_map>
#include <set>
#include <limits>
#include <algorithm>
#include <utility> // For std::move
// #include <tuple> // Not needed if getAllUniqueEdges is removed
#include <QPointF> // For storing geographic coordinates
// PathSegment Struct Definition
struct PathSegment {
std::string stationName;
std::string lineTakenToReach;
int timeForSegment;
int costForSegment;
bool isFirstSegment = false;
PathSegment(std::string name, std::string line = "", int time = 0, int cost = 0, bool first = false)
: stationName(std::move(name)), lineTakenToReach(std::move(line)),
timeForSegment(time), costForSegment(cost), isFirstSegment(first) {}
};
// Edge Struct Definition
struct Edge {
std::string to;
int time;
double distance; // Still present from CSV, though not primary for pathfinding types here
int cost;
std::string line; // This should be the line of the track segment
Edge(const std::string& t, int ti, double d, int c, const std::string& l)
: to(t), time(ti), distance(d), cost(c), line(l) {}
};
// Utility function
std::string trim(const std::string& str);
class MetroSystem {
public:
MetroSystem();
bool loadMetroData(const std::string& filename, std::string& errorMsg);
std::vector<std::string> getStationNames() const;
const std::unordered_map<std::string, QPointF>& getStationCoordinates() const;
// Pathfinding methods remain the same
std::vector<PathSegment> findPathLeastStops(const std::string& start, const std::string& end);
std::vector<PathSegment> findPathByTime(const std::string& start, const std::string& end);
std::vector<PathSegment> findPathByCost(const std::string& start, const std::string& end);
private:
std::unordered_map<std::string, std::vector<Edge>> graph_;
std::set<std::string> stationNames_;
std::unordered_map<std::string, QPointF> stationCoordinates_; // To store station coordinates
const Edge* findEdge(const std::string& from, const std::string& to) const;
std::vector<PathSegment> dijkstra(const std::string& start, const std::string& end, const std::string& criteria);
};
#endif // METROSYSTEM_H