-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgraph_formulation.cpp
More file actions
92 lines (81 loc) · 3.39 KB
/
Copy pathgraph_formulation.cpp
File metadata and controls
92 lines (81 loc) · 3.39 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
#include "metro.hpp"
const int total_stations = 57;
string stations[57];
map<string, int> code;
double graph[57][57];
bool station_closed[57] = {false};
bool line_snag[3] = {false, false, false}; // RED, GREEN, BLUE technical-snag flags
void map_code() {
// Initialize empty graph
for(int i=0; i<total_stations; i++) {
for(int j=0; j<total_stations; j++)
graph[i][j] = 0.0;
station_closed[i] = false; // reset disruption state on every (re)load
}
line_snag[0] = line_snag[1] = line_snag[2] = false;
// --- RED LINE (0 to 26) ---
string red_line[] = {"Miyapur", "JNTU_College", "KPHB_Colony", "Kukatpally", "Balanagar", "Moosapet",
"Bharat_Nagar", "Erragadda", "ESI_Hospital", "SR_Nagar", "Ameerpet",
"Punjagutta", "Irrum_Manzil", "Khairatabad", "Lakdikapul", "Assembly",
"Nampally", "Gandhi_Bhavan", "Osmania_Medical", "MGBS",
"Malakpet", "New_Market", "Musarambagh", "Dilsukhnagar", "Chaitanyapuri",
"Victoria_Memorial", "LB_Nagar"};
for(int i=0; i<27; i++) {
stations[i] = red_line[i];
code[red_line[i]] = i;
}
// --- GREEN LINE (27 to 34) ---
string green_line[] = {"JBS_Parade_Ground", "Secunderabad_West", "Gandhi_Hospital",
"Musheerabad", "RTC_X_Roads", "Chikkadpally", "Narayanaguda", "Sultan_Bazar"};
for(int i=0; i<8; i++) {
int id = 27 + i;
stations[id] = green_line[i];
code[green_line[i]] = id;
}
// --- BLUE LINE (35 to 56) ---
string blue_line[] = {"Nagole", "Uppal", "Stadium", "NGRI", "Habsiguda", "Tarnaka",
"Mettuguda", "Secunderabad_East", "Parade_Ground", "Paradise",
"Rasoolpura", "Prakash_Nagar", "Begumpet", "Madhura_Nagar",
"Yusufguda", "Road_No_5", "Jubilee_Hills_Checkpost", "Peddamma_Temple",
"Madhapur", "Durgam_Cheruvu", "HITEC_City", "Raidurg"};
for(int i=0; i<22; i++) {
int id = 35 + i;
stations[id] = blue_line[i];
code[blue_line[i]] = id;
}
// Call the external file to populate the distances
loadDistances();
}
string getLine(int id) {
if (id >= 0 && id <= 26) return "RED Line";
if (id >= 27 && id <= 34) return "GREEN Line";
if (id >= 35 && id <= 56) return "BLUE Line";
return "UNKNOWN";
}
// Numeric line index used to index line_snag[] and for fast comparisons.
int getLineIndex(int id) {
if (id >= 0 && id <= 26) return 0; // RED
if (id >= 27 && id <= 34) return 1; // GREEN
if (id >= 35 && id <= 56) return 2; // BLUE
return -1;
}
double getActualDistance(vector<int>& path) {
// path.size() is unsigned (size_t). If path is empty, path.size() - 1
// underflows to a huge number and the loop below reads out of bounds.
if (path.size() < 2) return 0.0;
double dist = 0.0;
for(size_t i = 0; i < path.size() - 1; i++) {
dist += graph[path[i]][path[i+1]];
}
return dist;
}
// Counts how many line changes occur along a path (used for the
// transfer-walk-time penalty in schedule.cpp).
int countTransfers(vector<int>& path) {
if (path.size() < 2) return 0;
int transfers = 0;
for (size_t i = 0; i + 1 < path.size(); i++) {
if (getLine(path[i]) != getLine(path[i+1])) transfers++;
}
return transfers;
}