-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
148 lines (117 loc) · 3.31 KB
/
main.cpp
File metadata and controls
148 lines (117 loc) · 3.31 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
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
/*main.cpp*/
//
// Prof. Joe Hummel
// U. of Illinois, Chicago
// CS 251: Spring 2020
// Project #07: open street maps, graphs, and Dijkstra's alg
//
// References:
// TinyXML: https://github.com/leethomason/tinyxml2
// OpenStreetMap: https://www.openstreetmap.org
// OpenStreetMap docs:
// https://wiki.openstreetmap.org/wiki/Main_Page
// https://wiki.openstreetmap.org/wiki/Map_Features
// https://wiki.openstreetmap.org/wiki/Node
// https://wiki.openstreetmap.org/wiki/Way
// https://wiki.openstreetmap.org/wiki/Relation
//
#include <iostream>
#include <iomanip> /*setprecision*/
#include <string>
#include <vector>
#include <map>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include "tinyxml2.h"
#include "dist.h"
#include "osm.h"
using namespace std;
using namespace tinyxml2;
//////////////////////////////////////////////////////////////////
//
// main
//
int main()
{
map<long long, Coordinates> Nodes; // maps a Node ID to it's coordinates (lat, lon)
vector<FootwayInfo> Footways; // info about each footway, in no particular order
vector<BuildingInfo> Buildings; // info about each building, in no particular order
XMLDocument xmldoc;
cout << "** Navigating UIC open street map **" << endl;
cout << endl;
cout << std::setprecision(8);
string def_filename = "map.osm";
string filename;
cout << "Enter map filename> ";
getline(cin, filename);
if (filename == "")
{
filename = def_filename;
}
//
// Load XML-based map file
//
if (!LoadOpenStreetMap(filename, xmldoc))
{
cout << "**Error: unable to load open street map." << endl;
cout << endl;
return 0;
}
//
// Read the nodes, which are the various known positions on the map:
//
int nodeCount = ReadMapNodes(xmldoc, Nodes);
//
// Read the footways, which are the walking paths:
//
int footwayCount = ReadFootways(xmldoc, Footways);
//
// Read the university buildings:
//
int buildingCount = ReadUniversityBuildings(xmldoc, Nodes, Buildings);
//
// Stats
//
assert(nodeCount == Nodes.size());
assert(footwayCount == Footways.size());
assert(buildingCount == Buildings.size());
cout << endl;
cout << "# of nodes: " << Nodes.size() << endl;
cout << "# of footways: " << Footways.size() << endl;
cout << "# of buildings: " << Buildings.size() << endl;
//
// TODO: build the graph, output stats:
//
//cout << "# of vertices: " << G.NumVertices() << endl;
//cout << "# of edges: " << G.NumEdges() << endl;
cout << endl;
//
// Navigation from building to building
//
string startBuilding, destBuilding;
cout << "Enter start (partial name or abbreviation), or #> ";
getline(cin, startBuilding);
while (startBuilding != "#")
{
cout << "Enter destination (partial name or abbreviation)> ";
getline(cin, destBuilding);
//
// TODO: lookup buildings, find nearest start and dest nodes,
// run Dijkstra's alg, output distance and path to destination:
//
//cout << "Start building not found" << endl;
//cout << "Destination building not found" << endl;
//
// another navigation?
//
cout << endl;
cout << "Enter start (partial name or abbreviation), or #> ";
getline(cin, startBuilding);
}
//
// done:
//
cout << "** Done **" << endl;
return 0;
}