This project is based on the final project of EE538(Computing Principles for Electrical Engineers) in spring 2022 at University of Southern California
Author: Junyu Huang
- Auto Complete location names
- Find Coordinates
- Calcualte Shortest Path with Dijkstra algorithm and Bellman-ford algorithm
- Cycle Detection in a subgraph
- Topological Sort
- Travelling salesman problem with Brute-force, earlybacktracking and 2-opt
Each point on the map is represented by the class Node shown below and defined in trojanmap.h.
class Node {
public:
Node(){};
Node(const Node &n) {
id = n.id;
lat = n.lat;
lon = n.lon;
name = n.name;
neighbors = n.neighbors;
attributes = n.attributes;
};
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.
std::unordered_set<std::string>
attributes; // List of the attributes of the location.
};
main.cc
is the main function.trojanmap.h
,trojanmap.cc
are the source files for the graph algorithms
Time complexity:
This function is implemented to find the latitude and longitude of the location name we enter.
Time complexity:
Here we are using "priority queue" to implement Dijkstra. We should input the source node and destination node and the output should be the shortest path and distance between these two locations.
Time complexity:
Time complexity:
Solving TSP with brute-force is similar to permutation. We need to permutate all possible results. Brute-force algorithm can guarantee the accuracy of the result, but the runtime for it is horrible.
Time complexity:
Solving TSP with earlybacktracking is similar to brute-force. We can skip some cases which do not meet the requirement to speed up the process. But in worst case, the runtime for it is the same as brute-force.
Time complexity:
Solving TSP with 2-opt heuristic algorithm is much more efficient than using brute-force and earlybacktracking. But it would result in less accuracy.
Time complexity: