-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMetrograph.hpp
More file actions
67 lines (65 loc) · 2.08 KB
/
Metrograph.hpp
File metadata and controls
67 lines (65 loc) · 2.08 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
#ifndef METROGRAPH_H
#define METROGRAPH_H
#include <iostream>
#include <vector>
#include <map>
#include <string>
#include <fstream>
#include <sstream>
#include <queue>
#include <ctime>
#include <cstdlib>
#include "FlowQueue.hpp"
//存图应该考虑 站名1,站名2, 线路,时间,拥挤度
//无向有环带权图
//乘客请求:起点站、终点站、偏好(最快/最少换乘/最舒适)
/*
需要考虑 下一站,上一站
*/
//考虑地铁线路的参数:长度、下一站
//存一条边u
/*邻接表存图*/
struct Edge{
int to;// 连下一站的ID(大学城->番禺)
int line;//几号线
double time;//列车开过这条路需要的时间
double dist;//长度
int crowd;//考虑人流量
bool closed;//是否停运
Edge(int t,int l,double ti,double d,int crd):
to(t),line(l),time(ti),dist(d),crowd(crd),closed(false) {}
};
struct StationCrowd {
int id;
int num;
StationCrowd(int i, int n) : id(i), num(n) {}
//重载小于号,大顶堆
bool operator<(const StationCrowd& other) const {
return this -> num < other.num;
}
};
class MetroGraph{
private:
//映射与逆映射得到站台的序号与名字之间的唯一关系.
std::map<std::string,int> nmtonum;//name to num
std::map<int,std::string> numtonm;// num to name
std::vector<std::vector<Edge>> adj; // 整个图
void AddEdge(int u,int v,int line,double time,double dist,int crowd);//加边
int CreateID(const std::string& name);//对输入的地铁站名设置ID
std::vector<FlowQueue*> queues;
public:
MetroGraph();
~MetroGraph();
bool LoadGraph(const std::string& file);//写入图
const std::vector<std::vector<Edge>>& GetAdj() const;//获取图的数据
int GetID(const std::string& name);
std::string GetName(int id);
int GetTotalStation() const;//返回总的站点数量
// 模拟生成数据
void SimulateFlow();
// 打印某时刻最挤的站
void PrintCrowdTopK(int time, int k);
// 开关线路 (异常处理)
void SetLineStatus(int line, bool open);// true=开通, false=停运
};
#endif