-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtrojanmap.h
More file actions
108 lines (82 loc) · 3.71 KB
/
trojanmap.h
File metadata and controls
108 lines (82 loc) · 3.71 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
#ifndef TROJAN_MAP_H
#define TROJAN_MAP_H
#define DOT_SIZE 5
#define LINE_WIDTH 3
#include <iostream>
#include <map>
#include <vector>
// A Node is the location of one point in the map.
class Node {
public:
Node(){};
Node(const Node &n){id = n.id; lat = n.lat; lon = n.lon; name = n.name; neighbors = n.neighbors;};
std::string id; // A unique id assign to each point
double lat; // Latitude
double lon; // Longitude
std::string name; // Name of the location. E.g. "Bank of America".
std::vector<std::string>
neighbors; // List of the ids of all neighbor points.
};
class TrojanMap {
public:
//-----------------------------------------------------
// TODO: You do not and should not change the following functions:
// Create the menu.
void PrintMenu();
// Read in the data
void CreateGraphFromCSVFile();
// Visualization
// Given a location id, plot the point on the map.
void PlotPoint(std::string id);
// Given a lat and lon, plot the point on the map.
void PlotPoint(double lat, double lon);
// Given a vector of location ids draws the path (connects the points)
void PlotPath(std::vector<std::string> &location_ids);
// Given a vector of location ids draws the points on the map (no path).
void PlotPoints(std::vector<std::string> &location_ids);
// Create the videos of the progress to get the path
void CreateAnimation(std::vector<std::vector<std::string>>);
// Transform the location to the position on the map
std::pair<double, double> GetPlotLocation(double lat, double lon);
//-----------------------------------------------------
// TODO: Implement these functions and create unit tests for them:
// Get the Latitude of a Node given its id.
double GetLat(std::string id);
// Get the Longitude of a Node given its id.
double GetLon(std::string id);
// Get the name of a Node given its id.
std::string GetName(std::string id);
// Get the neighbor ids of a Node.
std::vector<std::string> GetNeighborIDs(std::string id);
// Get the distance between 2 nodes.
double CalculateDistance(const Node &a, const Node &b);
// Calculates the total path length for the locations inside the vector.
double CalculatePathLength(const std::vector<std::string> &path);
// Returns a vector of names given a partial name.
std::vector<std::string> Autocomplete(std::string name);
// Returns lat and long of the given the name.
std::pair<double, double> GetPosition(std::string name);
// Given the name of two locations, it should return the **ids** of the nodes
// on the shortest path.
std::vector<std::string> CalculateShortestPath(std::string location1_name,
std::string location2_name);
// Given a vector of location ids, it should reorder them such that the path
// that covers all these points has the minimum length.
// The return value is a pair where the first member is the total_path,
// and the second member is the reordered vector of points.
// (Notice that we don't find the optimal answer. You can return an estimated
// path.)
std::pair<double, std::vector<std::vector<std::string>>> TravellingTrojan(
std::vector<std::string> &location_ids);
std::pair<double, std::vector<std::vector<std::string>>> TravellingTrojan_2opt(
std::vector<std::string> &location_ids);
//-----------------------------------------------------
// DEBUG: Extract data to public
std::map<std::string, Node> data_out();
private:
// A map of ids to Nodes.
std::map<std::string, Node> data;
void printPath(std::vector<int> parent, int j);
void twoOptSwap( const int&i, const int &k, std::vector<std::string> &route, std::vector<std::string> &newRoute);
};
#endif