-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTime_scheduling.cpp
More file actions
68 lines (62 loc) · 2.42 KB
/
Copy pathTime_scheduling.cpp
File metadata and controls
68 lines (62 loc) · 2.42 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
#include "metro.hpp"
// Returns true if, at the given local time, the metro is running.
// HMRL's published operating window is roughly 6:00 AM to 11:00 PM daily.
bool isMetroOpenNow(tm* ltm) {
int hour = ltm->tm_hour;
return (hour >= OPERATING_OPEN_HOUR && hour < OPERATING_CLOSE_HOUR);
}
// Builds a friendly "metro is closed, first train at X" message.
string nextTrainMessage(tm* ltm) {
tm next = *ltm;
if (ltm->tm_hour < OPERATING_OPEN_HOUR) {
// Same day, just hasn't opened yet.
next.tm_hour = OPERATING_OPEN_HOUR;
next.tm_min = 0;
next.tm_sec = 0;
} else {
// Past closing time tonight; first train is 6:00 AM tomorrow.
next.tm_mday += 1;
next.tm_hour = OPERATING_OPEN_HOUR;
next.tm_min = 0;
next.tm_sec = 0;
}
time_t t = mktime(&next);
tm* fixed = localtime(&t);
char buffer[80];
strftime(buffer, sizeof(buffer), "%I:%M %p", fixed);
return string(buffer);
}
// Peak windows: 7-10 AM and 5-8 PM, matching typical HMRL peak commute hours.
bool isPeakHour(tm* ltm) {
int hour = ltm->tm_hour;
bool morning = (hour >= PEAK_MORNING_START && hour < PEAK_MORNING_END);
bool evening = (hour >= PEAK_EVENING_START && hour < PEAK_EVENING_END);
return morning || evening;
}
int getHeadwayMins(tm* ltm) {
return isPeakHour(ltm) ? PEAK_HEADWAY_MINS : OFFPEAK_HEADWAY_MINS;
}
// Flat platform-walk penalty applied once per line change in the path.
// Real interchanges (Ameerpet, MGBS, Parade Ground/JBS) all require a walk
// between platforms; we don't currently model differing walk distances per
// interchange, so this uses one flat value for all of them.
int getTransferDelayMins(vector<int>& path) {
int transfers = countTransfers(path);
return transfers * TRANSFER_WALK_MINS;
}
// Admin-triggered "Technical Snag" delay: if any segment of the path lies on
// a line currently flagged with a snag, add a flat delay. Applied once per
// distinct affected line touched by the path (so a journey crossing two
// snagged lines is delayed twice, not once).
int getLineSnagDelayMins(vector<int>& path) {
bool touched[3] = {false, false, false};
for (size_t i = 0; i < path.size(); i++) {
int li = getLineIndex(path[i]);
if (li >= 0) touched[li] = true;
}
int delay = 0;
for (int i = 0; i < 3; i++) {
if (touched[i] && line_snag[i]) delay += LINE_SNAG_DELAY_MINS;
}
return delay;
}