-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.cpp
259 lines (208 loc) · 9.75 KB
/
main.cpp
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
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
#include <iostream>
#include <fstream>
#include <sstream>
#include <vector>
#include <stdlib.h>
#include <time.h>
#include <cmath>
#include <ctime>
#include <chrono>
#include "graph.cpp"
#include "hash.cpp"
using namespace std;
//clock reference https://stackoverflow.com/questions/15235218/c-timer-milliseconds
void getFlightDataFromFile(graph &theGraph);
void getFlightDataFromFile(HashTable &theHash);
int main(){
//hash
//graph
graph ourGraph;
HashTable hash;
auto graphStart = chrono::steady_clock::now();
getFlightDataFromFile(ourGraph);
auto graphEnd = chrono::steady_clock::now();
auto graphElapsed = chrono::duration_cast<std::chrono::microseconds>(graphEnd - graphStart);
cout << "Graph initialization time: " << graphElapsed.count() << " microseconds" << endl;
auto hashStart = chrono::steady_clock::now();
getFlightDataFromFile(hash);
auto hashEnd = chrono::steady_clock::now();
auto hashElapsed = chrono::duration_cast<std::chrono::microseconds>(hashEnd - hashStart);
cout << "HashTable initialization time: " << hashElapsed.count() << " microseconds" << endl;
string userAirport;
int userInput;
cout << "*****************************************************************************************" << endl;
cout << "Welcome to the Flight Delay Calculator" << endl;
cout << "*****************************************************************************************" << endl;
while (userInput != 4){
cout << "What would you like to do?" << endl;
cout << "1. List Available Airports" << endl;
cout << "2. Get Average Delay Time From Airport" << endl;
cout << "3. Get Average Delay Time Between Two Airports" << endl;
cout << "4. Exit" << endl;
cin >> userInput;
if (userInput == 1){
int input;
cout << " " << endl;
cout << "Insert 1 for Graph and 2 for Hashmap" << endl;
cin >> input;
if (input == 1){
auto start = chrono::steady_clock::now();
vector<string> graphOrigins = ourGraph.allOriginAirports();
auto end = chrono::steady_clock::now();
auto elapsed = chrono::duration_cast<std::chrono::microseconds>(end - start);
for (int i = 0; i < graphOrigins.size(); i++){
cout << graphOrigins[i] << endl;
}
cout << "Graph Runtime: " << elapsed.count() << " microseconds" << endl;
}
else if (input == 2){
auto start = chrono::steady_clock::now();
vector<string> hashOrigins = hash.allOriginAirports();
auto end = chrono::steady_clock::now();
auto elapsed = chrono::duration_cast<std::chrono::microseconds>(end - start);
for (int i = 0; i < hashOrigins.size(); i++){
cout << hashOrigins[i] << endl;
}
cout << "Hashmap Runtime: " << elapsed.count() << " microseconds" << endl;
}
}
if (userInput == 2){
cout << "Please input the airport abreviation (ex: MCO, ATL, MIA) that you would like to calculate" << endl;
cin >> userAirport;
auto start = chrono::steady_clock::now();
double averageDelayTime = ourGraph.getAverageDelayTime(userAirport);
auto end = chrono::steady_clock::now();
auto elapsed = chrono::duration_cast<std::chrono::microseconds>(end - start);
if (averageDelayTime == INT32_MAX){
cout << "No Data Found. Airport Does Not Exist" << endl;
}
else
cout << "The average delay for a flight out of " << userAirport << " is: " << averageDelayTime << " minutes (graph)" << endl;
//running with hashmap
start = chrono::steady_clock::now();
double averageDelayTime2 = hash.GetAirportAverageDelay(userAirport);
end = chrono::steady_clock::now();
auto elapsed2 = chrono::duration_cast<std::chrono::microseconds>(end - start);
if (averageDelayTime2 == INT32_MAX){
cout << "No Data Found. Airport Does Not Exist" << endl;
}
else
cout << "The average delay for a flight out of " << userAirport << " is: " << averageDelayTime2 << " minutes (hashmap)" << endl;
cout << "Time Elapsed using Graph: " << elapsed.count() << " microseconds" << endl;
cout << "Time Elapsed using HashMap: " << elapsed2.count() << " microseconds" << endl;
cout << " " << endl;
cout << " " << endl;
}
if (userInput == 3){
cout << "Please input the origin airport's abreviation (ex: MCO, ATL, MIA) that you would like to calculate" << endl;
cin >> userAirport;
string dest;
cout << "Please input the destination airport's abreviation (ex: MCO, ATL, MIA) that you would like to calculate" << endl;
cin >> dest;
auto start = chrono::steady_clock::now();
double averageDelayTime = ourGraph.getAverageDelayTimeGivenTwoAirportInputs(userAirport, dest);
auto end = chrono::steady_clock::now();
auto elapsed = chrono::duration_cast<std::chrono::microseconds>(end - start);
if (averageDelayTime == INT32_MAX){
cout << "No Data Found. Flight Route Does Not Exist" << endl;
}
else
cout << "The average delay for a flight out of " << userAirport << " going to " << dest << " is: " << averageDelayTime << " minutes (graph)" << endl;
//running with hashmap
start = chrono::steady_clock::now();
double averageDelayTime2 = hash.GetAirportDelayBetweenAirports(userAirport, dest);
end = chrono::steady_clock::now();
auto elapsed2 = chrono::duration_cast<std::chrono::microseconds>(end - start);
if (averageDelayTime2 == INT32_MAX){
cout << "No Data Found. Flight Route Does Not Exist" << endl;
}
else
cout << "The average delay for a flight out of " << userAirport << " going to " << dest << " is: " << averageDelayTime << " minutes (hashmap)" << endl;
cout << "Time Elapsed using Graph: " << elapsed.count() << " microseconds" << endl;
cout << "Time Elapsed using HashMap: " << elapsed2.count() << " microseconds" << endl;
cout << " " << endl;
cout << " " << endl;
}
if (userInput == 4){
break;
}
}
return 0;
}
//need to pass in graph and hash data types to initialize the data structures
void getFlightDataFromFile(graph &theGraph){
fstream file("Data/New2008.csv", ios::in);
string entireLine, Month, Day, delayTime, origin, dest, flightNumber, dummy;
string test;
vector<string> holdingValues;
vector<vector<string>> usefulData;
//we want columns 15 (delay time), 17(origin/source), 18(destination)
int i = 0;
if (file.is_open()){
getline(file,entireLine);
while (getline(file, entireLine)){
holdingValues.clear();
stringstream s(entireLine);
while (getline(s, test, ',')){
holdingValues.push_back(test);
}
Month = holdingValues[0];
Day = holdingValues[1];
flightNumber = holdingValues[2];
origin = holdingValues[4];
dest = holdingValues[5];
delayTime = holdingValues[3];
vector<string> holdingValues2;
holdingValues2.push_back(Month);
holdingValues2.push_back(Day);
holdingValues2.push_back(flightNumber);
holdingValues2.push_back(origin);
holdingValues2.push_back(dest);
holdingValues2.push_back(delayTime);
if (!isdigit(delayTime[0]) && delayTime[0] != '-')
continue;
theGraph.addEdge(make_tuple(origin, dest, delayTime, flightNumber));
//used for testing
//cout << "Flight Number: " << flightNumber << " origin: " << origin << " dest: " << dest << " delay: " << delayTime << endl;
usefulData.push_back(holdingValues2);
}
}
}
void getFlightDataFromFile(HashTable &theHash){
fstream file("Data/New2008.csv", ios::in);
string entireLine, Month, Day, delayTime, origin, dest, flightNumber, dummy;
string test;
vector<string> holdingValues;
vector<vector<string>> usefulData;
//we want columns 15 (delay time), 17(origin/source), 18(destination)
int i = 0;
if (file.is_open()){
getline(file,entireLine);
while (getline(file, entireLine)){
holdingValues.clear();
stringstream s(entireLine);
while (getline(s, test, ',')){
holdingValues.push_back(test);
}
Month = holdingValues[0];
Day = holdingValues[1];
flightNumber = holdingValues[2];
origin = holdingValues[4];
dest = holdingValues[5];
delayTime = holdingValues[3];
vector<string> holdingValues2;
holdingValues2.push_back(Month);
holdingValues2.push_back(Day);
holdingValues2.push_back(flightNumber);
holdingValues2.push_back(origin);
holdingValues2.push_back(dest);
holdingValues2.push_back(delayTime);
if (!isdigit(delayTime[0]) && delayTime[0] != '-')
continue;
theHash.NewNode(make_tuple(origin, dest, stoi(delayTime), flightNumber));
//used for testing
//cout << "Flight Number: " << flightNumber << " origin: " << origin << " dest: " << dest << " delay: " << delayTime << endl;
usefulData.push_back(holdingValues2);
}
}
}