-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
67 lines (60 loc) · 2.38 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
#include <iostream>
#include "cs225/PNG.h"
#include "graph.h"
#include "draw.h"
#include "functions.h"
#include <fstream>
#include <sstream>
#include <string>
#include <vector>
using namespace std;
int main()
{
string airportsDir = "data/airports.dat";
string routesDir = "data/routes.dat";
//Create a Graph object
Graph g(routesDir, airportsDir);
//BFS start airport id
string bfsStartId = "1555";
Graph::Vertex bfsStartTemp = g.getVertex(bfsStartId);
Graph::Vertex bfsStart(bfsStartId, bfsStartTemp.latitude, bfsStartTemp.longitude);
Functions func;
//BFS and draw traversed edges and vertices on a map
vector<Graph::Vertex> list = func.BFS(g, bfsStart);
cout << "BFS traversal result:"<<endl;
cout << "first visited: " + (*(list.begin())).vertex_id <<endl;
cout << "last visited: " + (*(list.end() - 1)).vertex_id <<endl;
cout << "BFS size is " << list.size() << endl;
Draw drawBFS;
PNG * all_airlines = drawBFS.open();
for (size_t i = 0; i < list.size() - 1; i++) {
Graph::Vertex first = list[i];
Graph::Vertex second = list[i+1];
double x_1 = first.latitude;
double y_1 = first.longitude;
double x_2 = second.latitude;
double y_2 = second.longitude;
drawBFS.drawpoint(all_airlines, x_1, y_1);
drawBFS.drawpoint(all_airlines, x_2, y_2);
drawBFS.drawline(all_airlines, x_1, y_1, x_2, y_2);
}
all_airlines->writeToFile("all_airlines.png");
cout << "" << endl;
//Find the shortest path between two airports and draw it on a map
Draw drawPath;
PNG * shortestPath = drawPath.open();
//id of the start airport, change this if you want to use other start airport
string startId = "2188";
//id of the end airport, change this if you want to use other start airport
string endId = "3830";
Graph::Vertex startTemp = g.getVertex(startId);
Graph::Vertex endTemp = g.getVertex(endId);
Graph::Vertex start(startId, startTemp.latitude, startTemp.longitude);
Graph::Vertex end(endId, endTemp.latitude, endTemp.longitude);
if (g.getAdjacentVertex(start).size() < 1 || !g.routeToVertex(end)) {
cout<<"invalid airport id, please choose airports that have airline route to other vertex (some airports don't have departure)."<<endl;
return 0;
}
drawPath.drawmap(routesDir, airportsDir, start, end);
return 0;
}