-
Notifications
You must be signed in to change notification settings - Fork 143
/
Copy pathquery_file.py
191 lines (165 loc) · 10.7 KB
/
query_file.py
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
"""
Runs the query algorithm
"""
from Algorithms.CSA.std_csa import std_csa
from Algorithms.RAPTOR.hypraptor import hypraptor
# from RAPTOR.one_to_many_rraptor import onetomany_rraptor
from Algorithms.RAPTOR.rraptor import rraptor
from Algorithms.RAPTOR.std_raptor import raptor
from Algorithms.TBTR.hyptbtr import hyptbtr
from Algorithms.TBTR.one_many_tbtr import onetomany_rtbtr
from Algorithms.TBTR.rtbtr import rtbtr
from Algorithms.TBTR.tbtr import tbtr
from Algorithms.TIME_EXPANDED_DIJKSTRA.TE_DIJ import custom_dij
from Algorithms.TRANSFER_PATTERNS.transferpattens import std_tp
from miscellaneous_func import *
print_logo()
def take_inputs() -> tuple:
"""
defines the use input
Returns:
algorithm (int): algorithm type. 0 for RAPTOR, 1 for TBTR, 2 for Transfer Patterns
variant (int): variant of the algorithm. 0 for normal version,
1 for range version,
2 for One-To-Many version,
3 for Hyper version
3 for Nested Hyper version
Examples:
>>> algorithm, variant = take_inputs()
"""
algorithm = int(input(
"Press 0 to enter RAPTOR environment \nPress 1 to enter TBTR environment\nPress 2 to enter Transfer Patterns environment\nPress 3 to enter CSA environment"
"\nPress 4 to enter Time Expanded Dijkstra\n: "))
variant = 0
print("***************")
if algorithm == 0:
variant = int(input(
"Press 0 for RAPTOR \nPress 1 for rRAPTOR \nPress 2 for One-To-Many rRAPTOR \nPress 3 for HypRAPTOR\nPress 4 for Multilevel-HypRAPTOR\n: "))
elif algorithm == 1:
variant = int(input("Press 0: TBTR \nPress 1: rTBTR \nPress 2: One-To-Many rTBTR \nPress 3: HypTBTR \nPress 4 for Multilevel-HypTBTR \n: "))
print("***************")
return algorithm, variant
def main() -> None:
"""
Runs the test case depending upon the values of algorithm, variant
Examples:
>>> main()
"""
algorithm, variant = take_inputs()
print_query_parameters(NETWORK_NAME, SOURCE, DESTINATION, D_TIME, MAX_TRANSFER, WALKING_FROM_SOURCE, variant, no_of_partitions=4,
weighting_scheme="S2", partitioning_algorithm="KaHyPar")
if algorithm == 0:
if variant == 0:
output = raptor(SOURCE, DESTINATION, D_TIME, MAX_TRANSFER, WALKING_FROM_SOURCE, CHANGE_TIME_SEC, PRINT_ITINERARY,
routes_by_stop_dict, stops_dict, stoptimes_dict, footpath_dict, idx_by_route_stop_dict)
print(f"Optimal arrival time are: {output}")
elif variant == 1:
output = rraptor(SOURCE, DESTINATION, d_time_groups, MAX_TRANSFER, WALKING_FROM_SOURCE, CHANGE_TIME_SEC, PRINT_ITINERARY,
OPTIMIZED, routes_by_stop_dict, stops_dict, stoptimes_dict, footpath_dict, idx_by_route_stop_dict)
if OPTIMIZED == 1:
print(f"Trips required to cover optimal journeys are {output}")
else:
print(f"Routes required to cover optimal journeys are {output}")
elif variant == 2:
pass
# output = onetomany_rraptor(SOURCE, DESTINATION_LIST, d_time_groups, MAX_TRANSFER, WALKING_FROM_SOURCE, CHANGE_TIME_SEC, PRINT_ITINERARY, OPTIMIZED, routes_by_stop_dict, stops_dict, stoptimes_dict, footpath_dict, idx_by_route_stop_dict)
# if OPTIMIZED == 1:
# print(f"Trips required to cover optimal journeys are {output}")
# else:
# print(f"Routes required to cover optimal journeys are {output}")
elif variant == 3:
output = hypraptor(SOURCE, DESTINATION, D_TIME, MAX_TRANSFER, WALKING_FROM_SOURCE, CHANGE_TIME_SEC, PRINT_ITINERARY,
stop_out, route_groups, routes_by_stop_dict, stops_dict, stoptimes_dict, footpath_dict, idx_by_route_stop_dict)
print(f"Optimal arrival time are: {output}")
elif variant == 4:
output = hypraptor(SOURCE, DESTINATION, D_TIME, MAX_TRANSFER, WALKING_FROM_SOURCE, CHANGE_TIME_SEC, PRINT_ITINERARY,
nested_stop_out, nested_route_groups, routes_by_stop_dict, stops_dict, stoptimes_dict, footpath_dict, idx_by_route_stop_dict)
print(f"Optimal arrival time are: {output}")
if algorithm == 1:
if variant == 0:
output = tbtr(SOURCE, DESTINATION, D_TIME, MAX_TRANSFER, WALKING_FROM_SOURCE, PRINT_ITINERARY, routes_by_stop_dict, stops_dict, stoptimes_dict,
footpath_dict, idx_by_route_stop_dict, trip_transfer_dict, trip_set)
print(f"Optimal arrival times are: {output[0]}")
elif variant == 1:
output = rtbtr(SOURCE, DESTINATION, d_time_groups, MAX_TRANSFER, WALKING_FROM_SOURCE, PRINT_ITINERARY, OPTIMIZED,
routes_by_stop_dict, stops_dict, stoptimes_dict, footpath_dict, idx_by_route_stop_dict, trip_transfer_dict, trip_set)
if OPTIMIZED == 1:
print(f"Trips required to cover optimal journeys are {output}")
else:
print(f"Routes required to cover optimal journeys are {output}")
elif variant == 2:
output = onetomany_rtbtr(SOURCE, DESTINATION_LIST, d_time_groups, MAX_TRANSFER, WALKING_FROM_SOURCE, PRINT_ITINERARY,
OPTIMIZED, routes_by_stop_dict, stops_dict, stoptimes_dict, footpath_dict, idx_by_route_stop_dict, trip_transfer_dict,
trip_set)
if OPTIMIZED == 1:
print(f"Trips required to cover optimal journeys are {output}")
else:
print(f"Routes required to cover optimal journeys are {output}")
elif variant == 3:
output = hyptbtr(SOURCE, DESTINATION, D_TIME, MAX_TRANSFER, WALKING_FROM_SOURCE, PRINT_ITINERARY, stop_out, trip_groups,
routes_by_stop_dict, stops_dict, stoptimes_dict, footpath_dict, idx_by_route_stop_dict, trip_transfer_dict, trip_set)
print(f"Optimal arrival times are: {output[0]}")
elif variant == 4:
output = hyptbtr(SOURCE, DESTINATION, D_TIME, MAX_TRANSFER, WALKING_FROM_SOURCE, PRINT_ITINERARY, nested_stop_out, nested_trip_groups,
routes_by_stop_dict, stops_dict, stoptimes_dict, footpath_dict, idx_by_route_stop_dict, trip_transfer_dict, trip_set)
print(f"Optimal arrival times are: {output[0]}")
if algorithm == 2:
if variant == 0:
output = std_tp(SOURCE, DESTINATION, D_TIME, footpath_dict, NETWORK_NAME, routesindx_by_stop_dict, stoptimes_dict, hub_count, hubstops)
print(f"Optimal arrival times are: {output}")
if algorithm == 3:
if variant == 0:
output = std_csa(SOURCE, DESTINATION, D_TIME, connections_list, WALKING_FROM_SOURCE, footpath_dict, PRINT_ITINERARY)
print(f"Optimal arrival times is: {output}")
if algorithm == 4:
if variant == 0:
output = custom_dij(SOURCE, D_TIME, DESTINATION, G, stops_group, stopevent_mapping, stop_times_file)
print(f"Optimal arrival times is: {output}")
return None
if __name__ == "__main__":
# Read network
USE_TESTCASE = int(input("Press 1 to use test case (anaheim), 0 to enter values manually. Example: 1\n: " ))
if USE_TESTCASE == 1:
NETWORK_NAME = './anaheim'
stops_file, trips_file, stop_times_file, transfers_file, stops_dict, stoptimes_dict, footpath_dict, routes_by_stop_dict, idx_by_route_stop_dict, routesindx_by_stop_dict = read_testcase(
NETWORK_NAME)
trip_transfer_dict, trip_set = load_TBTR(NETWORK_NAME)
connections_list = load_CSA(NETWORK_NAME)
G, stops_group, stopevent_mapping = load_TE_graph(NETWORK_NAME, stop_times_file)
print_network_details(transfers_file, trips_file, stops_file)
# Query parameters
SOURCE, DESTINATION, DESTINATION_LIST = 36, 52, [52, 43]
D_TIME = stop_times_file.arrival_time.sort_values().iloc[0]
MAX_TRANSFER, WALKING_FROM_SOURCE, CHANGE_TIME_SEC = 4, 1, 0
hub_count, hubstops = 0, set()
PRINT_ITINERARY, OPTIMIZED = 1, 0
# TODO add partition testcases
# stop_out, route_groups, _, trip_groups = read_partitions(stop_times_file, NETWORK_NAME, no_of_partitions=4, weighting_scheme="S2", partitioning_algorithm="kahypar")
# nested_stop_out, nested_route_groups, _, nested_trip_groups = read_nested_partitions(stop_times_file, NETWORK_NAME, no_of_partitions=4, weighting_scheme="S2")
else:
NETWORK_NAME = input("Enter Network name in small case. Example: anaheim\n: ")
stops_file, trips_file, stop_times_file, transfers_file, stops_dict, stoptimes_dict, footpath_dict, routes_by_stop_dict, idx_by_route_stop_dict, routesindx_by_stop_dict = read_testcase(
NETWORK_NAME)
trip_transfer_dict, trip_set = load_TBTR(NETWORK_NAME)
connections_list = load_CSA(NETWORK_NAME)
G, stops_group, stopevent_mapping = load_TE_graph(NETWORK_NAME, stop_times_file)
print_network_details(transfers_file, trips_file, stops_file)
SOURCE = int(input("Enter source stop id\n: "))
DESTINATION = int(input("Enter destination stop id\n: "))
D_TIME = pd.to_datetime(input("Enter departure time. Format: YYYY-MM-DD HH:MM:SS (24 hour format)\n: "))
MAX_TRANSFER = int(input("Maximum transfer limit\n: "))
WALKING_FROM_SOURCE = int(input("Press 1 to allow walking from source, else 0\n: "))
CHANGE_TIME_SEC = int(input("Enter change time (in seconds) \n: "))
PRINT_ITINERARY, OPTIMIZED = 1, 0
PARTITIONING_PARAMETER = int(input("Press 1 to enter partitioning related parameters. Else press 0\n: "))
if PARTITIONING_PARAMETER == 1:
NO_OF_PARTITION = int(input("Enter number of partitions\n: "))
WEIGHING_SCHEME = str(input("Enter weighing scheme [S1, S2, S3 S4 S5 S6]\n: "))
stop_out, route_groups, _, trip_groups = read_partitions(stop_times_file, NETWORK_NAME, no_of_partitions=NO_OF_PARTITION,
weighting_scheme=WEIGHING_SCHEME, partitioning_algorithm="kahypar")
nested_stop_out, nested_route_groups, _, nested_trip_groups = read_nested_partitions(stop_times_file, NETWORK_NAME,
no_of_partitions=NO_OF_PARTITION,
weighting_scheme=WEIGHING_SCHEME)
# main function
d_time_groups = stop_times_file.groupby("stop_id")
main()