{"id":26993237,"url":"https://github.com/linkoucommander/trojanmap","last_synced_at":"2025-07-07T01:06:15.723Z","repository":{"id":238393283,"uuid":"796458993","full_name":"LinkouCommander/TrojanMap","owner":"LinkouCommander","description":null,"archived":false,"fork":false,"pushed_at":"2024-05-06T01:23:43.000Z","size":83963,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-03T23:17:23.854Z","etag":null,"topics":["cpp","graph-algorithms"],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/LinkouCommander.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-05-06T01:19:33.000Z","updated_at":"2024-05-30T16:39:30.000Z","dependencies_parsed_at":"2024-05-06T02:41:46.895Z","dependency_job_id":null,"html_url":"https://github.com/LinkouCommander/TrojanMap","commit_stats":null,"previous_names":["linkoucommander/trojanmap"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/LinkouCommander/TrojanMap","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LinkouCommander%2FTrojanMap","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LinkouCommander%2FTrojanMap/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LinkouCommander%2FTrojanMap/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LinkouCommander%2FTrojanMap/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/LinkouCommander","download_url":"https://codeload.github.com/LinkouCommander/TrojanMap/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LinkouCommander%2FTrojanMap/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":263996080,"owners_count":23541399,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cpp","graph-algorithms"],"created_at":"2025-04-03T23:17:30.961Z","updated_at":"2025-07-07T01:06:15.706Z","avatar_url":"https://github.com/LinkouCommander.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"**Final Report:** [REPORT.md](REPORT.md)\\\n**Video Presentation Link:** https://www.youtube.com/watch?v=3IhQXKd003I\n\n# EE538 Final Project - Spring 2024 - TrojanMap\n\nThe project is **optional**: you can select one of the following options:\n\n1. Work on the project and submit the reports.\n2. Submit homework assignments (HW4, 5).\n\nIf you choose to work on the project, you don't have to submit the remaining homework assignments. Similarly, if you choose to work on the homework assignment, you do not have to submit the project. \n\nYou should inform us of your choice by the first due date (Tuesday, April 9).\n\n#### Who should work on the project?\nIf you plan to become a software engineer, we recommend working on the project as it will give you more experience coding a real-life project. Otherwise, you can take the homework assignments.\n\nNot everything in the project is covered in the class. The idea is for you to do some quick research and figure them out. For example, you should read about handling regular expressions in C++.\n\n#### Which one is harder?\nWe expect both options to take a similar amount of time. The project, however, might require extra effort from you during the environment setup and installation prerequisites.\n\n#### How many students in each team?\nEach team should consist of one or two students. You can find a teammate who is in other sections of the course. You should select your teammates by the first due date (April 9).\n\n#### What should I submit?\nThe project is submitted in different phases. You are required to submit the following:\n\n1. Phase 1, 2, and 3: these should be submitted on GitHub.\n2. Video presentation: you and your teammate will create a 3-4 minute video, post it as an unlisted video on Youtube and submit the link. The video should include:\n   - Teammates introduction\n   - Demo of the executable\n   - Quick overview of the algorithm and code architecture\n   - Tables, plots and comparisons\n   - No coding details in the video\n\n   Here is a [sample video from a previous semester.](https://www.youtube.com/watch?v=_KDML4Ck3SU\u0026t=4s) \n\n3. A final report in the README file of your GitHub submission. The final report should include the questions that are asked in this README file, your tables and plots for the runtime results, and any other detail of your code.\n\n## Due Dates\n\n- Phase 1: Tuesday, April 9, 23:59\n- Phase 2: Sunday, April 14, 23:59\n- Phase 3: Sunday, April 28, 23:59\n- Video Presentation: Sunday, April 28, 23:59\n- Report: Sunday, May 5, 23:59\n\n## TrojanMap\n\nThis project focuses on using data structures in C++ and implementing various graph algorithms to build a map application.\n\n\u003cp align=\"center\"\u003e\u003cimg src=\"img/TrojanMap.png\" alt=\"Trojan\" width=\"500\" /\u003e\u003c/p\u003e\n\n- Please use the repository generated by GitHub repository, read through [README.md](README.md), and implement the functions of the project.\n- Please make sure that your code can run `bazel run` and `bazel test`.\n- You need to fill in [trojanmap.cc](src/lib/trojanmap.cc), [mapui.cc](src/lib/mapui.cc) and maybe [mapui.h](src/lib/mapui.h), and add unit tests in the `tests` directory.\n- We will use the autograder to grade some of the questions\n- We will compare the code similarity between submissions and the previous semester's submissions. Please complete the project within your group.\n---\n\n## The Data Structure\n\nEach point on the map is represented by the class **Node** shown below and defined in [trojanmap.h](src/lib/trojanmap.h).\n\n```cpp\n// A Node is the location of one point in the map.\nclass Node {\n public:\n  Node(){};\n  Node(const Node \u0026n) {\n    id = n.id;\n    lat = n.lat;\n    lon = n.lon;\n    name = n.name;\n    neighbors = n.neighbors;\n    attributes = n.attributes;\n  };\n  std::string id;    // A unique id assigned to each point.\n  double lat;        // Latitude\n  double lon;        // Longitude\n  std::string name;  // Name of the location. E.g. \"Bank of America\".\n  std::vector\u003cstd::string\u003e\n      neighbors;  // List of the ids of all neighbor points.\n  std::unordered_set\u003cstd::string\u003e\n      attributes;  // List of the attributes of the location.\n};\n```\n\n---\n\n## Prerequisites\nThe details of the environment setup will be reviewed in the discussion session. Please do not miss that class!\n\n### External Libraries Installation\n\nFor visualization, we use `OpenCV` library. You will use this library as a black box and don't need to worry about the graphic details. Use the following commands to install OpenCV and other libraries.\n\n#### For macOS Users\n\nStep 1. Type the following three lines in your terminal.\n```shell\n$ brew install cmake\n$ brew install opencv\n$ brew install ncurses\n```\n\nStep 2. Check the installation paths of opencv and ncurses by\n\n```shell\n$ brew info opencv\n```\n\nand\n\n```shell\n$ brew info ncurses\n```\n\nrespectively, and update their paths in the `WORKSPACE` file of your project root directory with the actual installation paths.\n\n\n\n#### For Ubuntu users\nStep 1. Type the following lines in your terminal.\n\n```shell\n$ cd **your project folder**\n$ git clone https://github.com/opencv/opencv.git\n$ sudo apt update\n$ sudo apt install cmake libgtk2.0-dev pkg-config\n$ sudo apt install libcanberra-gtk-module libcanberra-gtk3-module\n$ sudo apt install libncurses5-dev libncursesw5-dev\n$ cp -r ubuntu/* ./\n```\n\nStep 2. Make sure you set the **path_to_install_folder** to be the absolute path to the **install** folder under opencv when running the following commands.\n\n```shell\n$ cd opencv/\n$ mkdir build install\n$ cd build\n$ cmake -D CMAKE_INSTALL_PREFIX=**path_to_install_folder** -D BUILD_LIST=core,highgui,imgcodecs,imgproc,videoio ..\n$ make -j$(nproc) install\n```\n\nFor example, if cloned this repo under `\"/Users/ari/github/TrojanMap\"`, you should type:\n\n```shell\n$ cd opencv/\n$ mkdir build install\n$ cd build\n$ cmake -D CMAKE_INSTALL_PREFIX=/Users/ari/github/TrojanMap/opencv/install -D BUILD_LIST=core,highgui,imgcodecs,imgproc,videoio ..\n$ make -j$(nproc) install\n```\n\nThe `-j$(nproc)` flag is to use all available CPU threads to speed up the build process. If you notice that your computer runs out of memory, you may remove this flag or set it to a smaller value (i.e. `make -j2 install`).\n\n## Run the program\n\nFor macOS users, run\n\n```shell\n$ bazel run src/main:main\n```\n\nFor Ubuntu users, run\n               \n```shell\n$ bazel run --cxxopt='-std=c++17' src/main:main\n```\n\nIf everything is correct, a menu similar to this will show up.\n\n```shell\nTrojanMap Menu\n**************************************************************\n* Enter the function number (1-11) to start:                  \n* 1. Autocomplete                                             \n* 2. Find the location                                        \n* 3. Find all location categories                             \n* 4. Get all locations of a category                          \n* 5. Get location matching regular expression                 \n* 6. CalculateShortestPath                                    \n* 7. Cycle Detection                                          \n* 8. Topological Sort                                         \n* 9. Traveling salesman problem                              \n* 10. Find Nearby                                              \n* 11. Find Path to Visit All Places\n* 12. Check Exist of Path with Constrain\n* 13. Exit                                                     \n**************************************************************\n```\n\n## Test The Program\n\nWe created some tests for you to test your program, please run\n```shell\n$ bazel test tests:trojanmap_test\n```\n\n\u003e You may also need to add the `--cxxopt='-std=c++17'` flag if you are using Linux.\n\nPlease add you test in the [trojanmap_test_student.cc](tests/trojanmap_test_student.cc) and run\n\n```shell\n$ bazel test tests:trojanmap_test_student\n```\n\n## Item 1: Autocomplete The Location Name (Phase 1)\n\n```c++\nstd::vector\u003cstd::string\u003e Autocomplete(std::string name);\n```\n\nWe consider the names of nodes as the locations. Implement a method to type the partial name of the location and return a list of possible locations with the partial name as the prefix. Please treat uppercase and lowercase as the same character. Please return an empty output if the input string is empty.\n\nExample:\n\nInput: \"Chi\" \\\nOutput: [\"Chick-fil-A\", \"Chipotle\", \"Chinese Street Food\"]\n\nExample:\n\n```shell\n**************************************************************\n* 1. Autocomplete                                             \n**************************************************************\n\nPlease input a partial location:ch\n*************************Results******************************\nChinese Street Food\nCheebos Burger\nChick-fil-A\nChase\nChevron 1\nChipotle\nChase Plaza Heliport\nChevron 2\nChurch of Christ\nChucks Chicken \u0026 Waffles\nChevron\n**************************************************************\nTime taken by function: 2 ms\n```\n\n- What is the runtime of your algorithm? \n- (Optional) Can you do it faster than `O(n)`?\n\n## Item 2-1: Find the place's coordinates in the Map (Phase 1)\n\n```c++\nstd::pair\u003cdouble, double\u003e GetPosition(std::string name);\n```\n\nGiven a location name, return the latitude and longitude. There are no duplicated location names. You should mark the given locations on the map. If the location does not exist, return (-1, -1). The algorithm is case-sensitive.\n\nExample:\n\nInput: \"Target\" \\\nOutput: (34.0257016, -118.2843512)\n\n```shell\n**************************************************************\n* 2. Find the position                                        \n**************************************************************\n\nPlease input a location:Target\n*************************Results******************************\nLatitude: 34.0257 Longitude: -118.284\n**************************************************************\nTime taken by function: 1 ms\n```\n\n\u003cp align=\"center\"\u003e\u003cimg src=\"img/Target.png\" alt=\"Target\" width=\"500\"/\u003e\u003c/p\u003e\n\n## Item 2-2: Check Edit Distance Between Two Location Names (Phase 2)\n\n```c++\nint CalculateEditDistance(std::string name1, std::string name2);\n```\n\nWhen entering a location name that does not exist in the map, your program should determine whether the input can be replaced with a \"similar name\" or not. By \"similar names\" we mean the names that exist in the map with a *smallest distance* from the original input. \n\nThe distance between two names A and B is the minimum number of operations required to convert A to B. There are 3 operations:\n+ Insert a character\n+ Delete a character\n+ Replace a character\n\nIf the exact match is found, it will be shown on the map. Otherwise, the map will show the most similar name by using FindClosestName and print a warning. \n\nFor example, if I type *Rolphs*, I should get a warning like \"Did you mean *Ralphs* instead of *Rolphs*?\". \n\nWrite a dynamic programming solution to calculate edit distance. \n\n```c++\nstd::string FindClosestName(std::string name);\n```\n\nNotes:\n- Space can be treated like other characters.\n- Spell checking part should be case insensitive.\n\nExample:\n\nInput: \"Rolphs\", \"Ralphs\" \\\nOutput: 1\n\n\nIn the user interface of your program, you should show the names that have the minimum edit distance to the name that the user entered.\n\nExample:\n\nInput: \"Rolphs\"\\\nOutput: \"Ralphs\"\n\n```shell\n**************************************************************\n* 2. Find the location                                        \n**************************************************************\n\nPlease input a location:Rolphs\n*************************Results******************************\nNo matched locations.\nDid you mean Ralphs instead of Rolphs? [y/n]y\nLatitude: 34.0318 Longitude: -118.291\n**************************************************************\nTime taken by function: 2 ms\n```\n\n## Item 3: Get All Categories (Phase 2)\n\n```c++\nstd::vector\u003cstd::string\u003e GetAllCategories();\n```\n\nSome of the locations have category types (`attributes` field in `data.csv` file). \n\nIn this section, your program should print all available categories among all existing categories in the map. There should be no duplicates in the output.\n\n## Item 4: Get All Locations In A Category (Phase 2)\n\n```c++\nstd::vector\u003cstd::string\u003e GetAllLocationsFromCategory(std::string category);\n```\n\nIn this section if the user entries a category, the program prints all locations that match that category. For example, if there is a category called \"bank\", your program should print all location ids that match the \"bank\" category. \n\n## Item 5: Get Locations Using A Regular Expression (Phase 2)\n\n```c++\nstd::vector\u003cstd::string\u003e GetLocationRegex(std::regex location);\n```\n\nIn this section if the user enters a [regular expression](https://en.wikipedia.org/wiki/Regular_expression), they should see all location ids that match that regular expression.\n\nYour program should also verify if the input regular expression was correct. Return an empty vector if the regex is not valid or matches no items.\n\n\n## Item 6: CalculateShortestPath between two places (Phase 2)\n\n```c++\nstd::vector\u003cstd::string\u003e CalculateShortestPath_Dijkstra(std::string \u0026location1_name,\n                                               std::string \u0026location2_name);\nstd::vector\u003cstd::string\u003e CalculateShortestPath_Bellman_Ford(std::string \u0026location1_name,\n                                               std::string \u0026location2_name);\n```\n\nGiven 2 locations A and B, find the best route from A to B. The distance between 2 points is the euclidean distance using latitude and longitude. You should use both Dijkstra algorithm and Bellman-Ford algorithm. Compare the time for the different methods. Show the routes on the map. If there is no path, please return empty vector.\n\nPlease report and compare the time spent by these algorithms.\n\n**You should create a table like below, which includes the runtime of the algorithm for several examples.**\n\n| Point A to Point B      | Dijkstra | Bellman Ford| Bellman Ford optimized|\n| -------------------- | ----------- |-------|-----|\n|                      |  t1         | t2    |   t3  |\n\nYour table should show have at least 15 rows.\n\nExample\n```\n**************************************************************\n* 6. CalculateShortestPath                                    \n**************************************************************\n\nPlease input the start location:Ralphs\nPlease input the destination:Target\n*************************Dijkstra*****************************\n*************************Results******************************\n\"2578244375\",\"4380040154\",\"4380040158\",\"4380040167\",\"6805802087\",\"8410938469\",\"6813416131\",\"7645318201\",\"6813416130\",\"6813416129\",\"123318563\",\"452688940\",\"6816193777\",\"123408705\",\"6816193774\",\"452688933\",\"452688931\",\"123230412\",\"6816193770\",\"6787470576\",\"4015442011\",\"6816193692\",\"6816193693\",\"6816193694\",\"4015377691\",\"544693739\",\"6816193696\",\"6804883323\",\"6807937309\",\"6807937306\",\"6816193698\",\"4015377690\",\"4015377689\",\"122814447\",\"6813416159\",\"6813405266\",\"4015372488\",\"4015372487\",\"6813405229\",\"122719216\",\"6813405232\",\"4015372486\",\"7071032399\",\"4015372485\",\"6813379479\",\"6813379584\",\"6814769289\",\"5237417650\",\nThe distance of the path is:0.927969 miles\n**************************************************************\nTime taken by function: 39 ms\n\n*************************Bellman_Ford*************************\n*************************Results******************************\n\"2578244375\",\"4380040154\",\"4380040158\",\"4380040167\",\"6805802087\",\"8410938469\",\"6813416131\",\"7645318201\",\"6813416130\",\"6813416129\",\"123318563\",\"452688940\",\"6816193777\",\"123408705\",\"6816193774\",\"452688933\",\"452688931\",\"123230412\",\"6816193770\",\"6787470576\",\"4015442011\",\"6816193692\",\"6816193693\",\"6816193694\",\"4015377691\",\"544693739\",\"6816193696\",\"6804883323\",\"6807937309\",\"6807937306\",\"6816193698\",\"4015377690\",\"4015377689\",\"122814447\",\"6813416159\",\"6813405266\",\"4015372488\",\"4015372487\",\"6813405229\",\"122719216\",\"6813405232\",\"4015372486\",\"7071032399\",\"4015372485\",\"6813379479\",\"6813379584\",\"6814769289\",\"5237417650\",\nThe distance of the path is:0.927969 miles\n**************************************************************\nTime taken by function: 7084 ms\n```\n\n\u003cp align=\"center\"\u003e\u003cimg src=\"img/Routing.png\" alt=\"Routing\" width=\"500\"/\u003e\u003c/p\u003e\n\n\n## Item 7: Cycle Detection (Phase 2)\n\n```c++\nbool CycleDetection(std::vector\u003cdouble\u003e \u0026square);\n```\n\nIn this section, we use a square-shaped subgraph of the original graph by using four coordinates stored in ```std::vector\u003cdouble\u003e square```, which follows the order of left, right, upper, and lower bounds. \n\nThen try to determine if there is a cycle path in the that subgraph.\nIf it does, return true and report the path of the cycle on the map. Otherwise return false.\n\n**Your report should include at least five examples.**\n\nExample 1:\n```shell\nInput: square = {-118.299, -118.264, 34.032, 34.011}\nOutput: true\n```\nHere we use the whole original graph as our subgraph. \n\u003cp align=\"center\"\u003e\u003cimg src=\"img/cycle1.png\" alt=\"TSP\" width=\"500\"/\u003e\u003c/p\u003e\n\nExample 2:\n```shell\nInput: square = {-118.290, -118.289, 34.030, 34.020}\nOutput: false\n```\nHere we use a square area inside USC campus as our subgraph\n\u003cp align=\"center\"\u003e\u003cimg src=\"img/cycle2.png\" alt=\"TSP\" width=\"500\"/\u003e\u003c/p\u003e\n\n```shell\n5\n**************************************************************\n* 5. Cycle Detection                                          \n**************************************************************\n\nPlease input the left bound longitude(between -118.320 and -118.250):-118.299\nPlease input the right bound longitude(between -118.320 and -118.250):-118.264\nPlease input the upper bound latitude(between 34.000 and 34.040):34.032\nPlease input the lower bound latitude(between 34.000 and 34.040):34.011\n*************************Results******************************\nthere exists a cycle in the subgraph \n**************************************************************\nTime taken by function: 0 ms\n\n5\n**************************************************************\n* 5. Cycle Detection                                          \n**************************************************************\n\nPlease input the left bound longitude(between -118.320 and -118.250):-118.290\nPlease input the right bound longitude(between -118.320 and -118.250):-118.289\nPlease input the upper bound latitude(between 34.000 and 34.040):34.030\nPlease input the lower bound latitude(between 34.000 and 34.040):34.020\n*************************Results******************************\nthere exist no cycle in the subgraph \n**************************************************************\nTime taken by function: 0 ms\n```\n\n## Item 8: Topological Sort (Phase 2)\n\n```c++\nstd::vector\u003cstd::string\u003e DeliveringTrojan(std::vector\u003cstd::string\u003e \u0026location_names,\n                                            std::vector\u003cstd::vector\u003cstd::string\u003e\u003e \u0026dependencies);\n```\nIn this section, we assume that we are using a UAV which means we can fly directly from 1 point to another point. Tommy Trojan got a part-time job from TrojanEats, for which he needs to pick up and deliver food from local restaurants to various location near the campus. Tommy needs to visit a few different location near the campus with certain order, since there are some constraints. For example, he must first get the food from the restaurant before arriving at the delivery point. \n\nThe TrojanEats app will have some instructions about these constraints. So, Tommy asks you to help him figure out the feasible route!\n\nHere we will give you a vector of location names that Tommy needs to visit, and also some dependencies between those locations.\n\n\nFor example, \n\n```shell\nInput: \nlocation_names = {\"Ralphs\", \"Chick-fil-A\", \"KFC\"}\ndependencies = {{\"Ralphs\",\"KFC\"}, {\"Ralphs\",\"Chick-fil-A\"}, {\"Chick-fil-A\", \"KFC\"}}\n```\n\nHere, ```{\"Ralphs\",\"KFC\"}``` means\nthat Tommy must go to `Ralphs` prior to `KFC`.\n\nYour output should be:\n```shell\nOutput: Ralphs  -\u003e Chick-fil-A -\u003e KFC\n```\nAlso, we provide ```PlotPointsOrder``` function that can visualize the results on the map. It will plot each location name and also some arrowed lines to demonstrate a feasible route.\n\nIf no feasible route exists, you could simply return an empty vector.\n\nHint:\n- You also need to finish ```ReadLocationsFromCSVFile``` and ```ReadDependenciesFromCSVFile``` functions, so you could read and parse data from you own CSV files. We also give two sample CSV files under ```input``` folder, which could be a reference. \n- When it asks you filenames, you need to give the absolute path.\n- If you do not have ```ReadLocationsFromCSVFile``` and ```ReadDependenciesFromCSVFile``` functions ready yet, you can just press enter when it asks you filenames. It will call the default locations and dependencies.\n- The locations are actually nodes, and the dependencies could be directed edges. You may want to first construct a DAG and then implement topological sort algorithm to get the route.\n\nNote\n- **Your report should show several examples of topological sort with at least 5 to 10 nodes.**\n\n\nBelow is an example output of 3 nodes\n```shell\n*************************Results******************************\nTopological Sorting Results:\nRalphs\nChick-fil-A\nKFC\n**************************************************************\nTime taken by function: 2 ms\n```\n\u003cp align=\"center\"\u003e\u003cimg src=\"img/TopologicalSort.png\" alt=\"TSP\" width=\"500\"/\u003e\u003c/p\u003e\n\nIn the user interface, we read the locations and dependencies from `topologicalsort_dependencies.csv` and `topologicalsort_locations.csv` to modify your input there.\n\n\n## Item 9: The Traveling Trojan Problem (AKA Traveling Salesman!) (Phase 3)\n\nIn this section, we assume that we are using a UAV which means we can fly directly from 1 point to another point. Given a vector of location ids, assume every location can reach all other locations in the vector (i.e. assume that the vector of location ids is a complete graph).\nFind the shortest route that covers all the locations exactly once and goes back to the start point. \n\nYou will need to return the progress to get the shortest route which will then be converted to an animation.  \n\nWe will use the following algorithms:\n\n- Brute-force (i.e. generating all permutations, and returning the minimum)\n```c++\nstd::pair\u003cdouble, std::vector\u003cstd::vector\u003cstd::string\u003e\u003e\u003e TravelingTrojan_Brute_force(\n      std::vector\u003cstd::string\u003e location_ids);\n```\n- Brute-force enhanced with early backtracking\n```c++\nstd::pair\u003cdouble, std::vector\u003cstd::vector\u003cstd::string\u003e\u003e\u003e TravelingTrojan_Backtracking(\n      std::vector\u003cstd::string\u003e location_ids);\n```\n- [2-opt Heuristic](https://en.wikipedia.org/wiki/2-opt). Also see [this paper](http://cs.indstate.edu/~zeeshan/aman.pdf)\n```c++\nstd::pair\u003cdouble, std::vector\u003cstd::vector\u003cstd::string\u003e\u003e\u003e TravelingTrojan_2opt(\n      std::vector\u003cstd::string\u003e location_ids);\n```\n\nWe use early backtracking when the current cost is higher than current minimum.\n\nPlease report and compare the time spent by these 3 algorithms. 2-opt algorithm may not get the optimal solution. Please show how far your solution is from the optimal solution.\n\nShow the routes on the map. For each intermediate solution, create a new plot. Your final video presentation should include the changes to your solution.\n\nWe will randomly select N points in the map and run your program.\n\n```shell\n**************************************************************\n* 9. Traveling salesman problem                              \n**************************************************************\n\nIn this task, we will select N random points on the map and you need to find the path to travel these points and back to the start point.\n\nPlease input the number of the places:8\n\"8201681442\",\"6197156485\",\"7786565237\",\"6820972477\",\"6807600525\",\"1832234142\",\"6819144993\",\"1873055949\",\nCalculating ...\n*************************Results******************************\nTravelingTrojan_Brute_force\n\"8201681442\",\"1873055949\",\"6197156485\",\"1832234142\",\"6807600525\",\"6819144993\",\"7786565237\",\"6820972477\",\"8201681442\",\nThe distance of the path is:7.94756 miles\n**************************************************************\nYou could find your animation at src/lib/output.avi.          \nTime taken by function: 59 ms\n\nCalculating ...\n*************************Results******************************\nTravelingTrojan_Backtracking\n\"8201681442\",\"6820972477\",\"7786565237\",\"6819144993\",\"6807600525\",\"1832234142\",\"6197156485\",\"1873055949\",\"8201681442\",\nThe distance of the path is:7.94756 miles\n**************************************************************\nYou could find your animation at src/lib/output_backtracking.avi.\nTime taken by function: 20 ms\n\nCalculating ...\n*************************Results******************************\nTravelingTrojan_2opt\n\"8201681442\",\"1873055949\",\"6197156485\",\"1832234142\",\"6807600525\",\"6819144993\",\"7786565237\",\"6820972477\",\"8201681442\",\nThe distance of the path is:7.94756 miles\n**************************************************************\nYou could find your animation at src/lib/output_2opt.avi.     \nTime taken by function: 0 ms\n```\n\n\u003cp align=\"center\"\u003e\u003cimg src=\"img/TSP.png\" alt=\"TSP\" width=\"500\"/\u003e\u003c/p\u003e\n\n\u003cp align=\"center\"\u003e\u003cimg src=\"img/output.gif\" alt=\"TSP videos\" width=\"500\"/\u003e\u003c/p\u003e\n\n\n## Item 10: Find Nearby (Phase 3)\n\nGiven an attribute name `C`, a location name `L` and a number `r` and `k`, find at most `k` locations in attribute `C` on the map near `L`(do not include `L`) with the range of `r` and return a vector of string ids. \n\nThe order of locations should be from\nnearest to farthest, and you should not include the current location. \n\n```c++\nstd::vector\u003cstd::string\u003e TrojanMap::FindNearby(std::string attributesName, std::string name, double r, int k);\n```\n\nAll attributes:\n```\n'artwork', 'attraction', 'bakery', 'bank', 'bar', 'beauty', 'beverages', 'bicycle', 'bicycle_rental', 'bus_station', \n'cafe', 'car', 'car_repair', 'car_wash', 'charging_station', 'childcare', 'clinic', 'clothes', 'confectionery', \n'convenience', 'copyshop', 'dentist', 'department_store', 'driving_school', 'fabric', 'fast_food', 'food_court', \n'fountain', 'fuel', 'gallery', 'hairdresser', 'hospital', 'hotel', 'library', 'marketplace', 'mobile_phone', 'museum', \n'music', 'optician', 'parcel_locker', 'parking', 'pharmacy', 'place_of_worship', 'police', 'post_office', \n'restaurant', 'school', 'shoe_repair', 'shoes', \n'skate', 'social_facility', 'supermarket', 'theatre', \n'tobacco', 'yes', 'yoga'\n```\n\n\nPlease report and compare the time spent by this algorithm and show the points on the map.\n\n```shell\n**************************************************************\n* 10. Find Nearby                                    \n**************************************************************\n\nPlease input the attribute:supermarket\nPlease input the locations:Ralphs\nPlease input radius r:10\nPlease input number k:10\n*************************Results******************************\nFind Nearby Results:\n1 Trader Joes\n2 Cal Mart Beer \u0026 Wine Food Store\n3 Food 4 Less\n**************************************************************\nTime taken by function: 5 ms\n```\n\n\u003cp align=\"center\"\u003e\u003cimg src=\"img/Nearby.png\" alt=\"Nearby\" width=\"500\"/\u003e\u003c/p\u003e\n\n## Item 11: Find the Shortest Path to Visit All locations (Phase 3)\n\nGiven an vector of locations, you need to find the shortest path to visit all the locations.\n\n```c++\nstd::vector\u003cstd::string\u003e TrojanMap::TrojanPath(std::vector\u003cstd::string\u003e \u0026location_names)\n```\n\nPlease report and compare the time spent by this algorithm and show the points on the map.\n\n```shell\n**************************************************************\n* 11. Shortest Path to Visit all Nodes                        \n**************************************************************\n\nPlease input the locations filename:\n*************************Results******************************\n\"3088547686\",\"4835551100\",\"4835551099\",\"4835551098\",\"6813565307\",\"6813565306\",\"6813565305\",\"6813565295\",\"6813565296\",\"3402814832\",\"4835551107\",\"6813379403\",\"6813379533\",\"3402814831\",\"6813379501\",\"3402810298\",\"6813565327\",\"3398574883\",\"6813379494\",\"6813379495\",\"6813379544\",\"6813379545\",\"6813379536\",\"6813379546\",\"6813379547\",\"6814916522\",\"6814916523\",\"1732243620\",\"4015372469\",\"4015372463\",\"6819179749\",\"1732243544\",\"6813405275\",\"348121996\",\"348121864\",\"6813405280\",\"1472141024\",\"6813411590\",\"216155217\",\"6813411589\",\"1837212103\",\"1837212101\",\"6814916516\",\"6814916515\",\"6820935910\",\"4547476733\",\"6820935910\",\"6814916515\",\"6814916516\",\"1837212101\",\"6813411588\",\"4015372458\",\"1837212100\",\"6820935907\",\"2753199985\",\"1837212107\",\"1837212104\",\"4015405543\",\"4015405542\",\"1781230449\",\"1781230450\",\"6820935898\",\"6813379556\",\"6820935901\",\"6820935900\",\"6819179753\",\"4540763379\",\"3233702827\",\"1862347583\",\"5231967015\",\"4399697302\",\"4399697304\",\"6807762271\",\"122728406\",\"6787673296\",\"123209598\",\"6814958391\",\"4399697589\",\"4872897515\",\"602606656\",\"3402887080\",\"6814958394\",\"3402887081\",\"6813379483\",\"6813379589\",\"6352865690\",\"4015203127\",\"4015203129\",\"3195897587\",\"4015203132\",\"6389467809\",\"21098539\",\"4015203133\",\"4015203134\",\"4015203136\",\"123152294\",\"6816193786\",\"6816193785\",\"6808069740\",\"6813416155\",\"6813416151\",\"6813416152\",\"6813416153\",\"6813416154\",\"6813416145\",\"7232024780\",\"6818427916\",\"6818427917\",\"6818427898\",\"6818427892\",\"6818427918\",\"6818427919\",\"6818427920\",\"4380040148\",\"4380040152\",\"4380040153\",\"4380040154\",\"2578244375\",\nThe distance of the path is:2.26759 miles\nTime taken by function: 233 ms\n```\n\n\u003cp align=\"center\"\u003e\u003cimg src=\"img/all.png\" alt=\"All\" width=\"500\"/\u003e\u003c/p\u003e\n\n## Item 12: Check the existence of the path with a constrained gas tank (Phase 3)\n\nGiven a map of nodes, you need to determine if it is possible to travel from a given starting point to a destination point with a car that has a certain size of gas tank. You can refuel at any nodes. If the distance between any two nodes on the path is larger than the size of the gas tank, you cannot travel between those nodes. Assume 1 gallon of gas can travel 1 mile.\n\nYour task is to implement a function that takes in multiple queries and specifies if travelling between the two points of each query with the given gas tank is possible. Each query is a pair, `std::pair\u003cdouble, std::vector\u003cstd::string\u003e\u003e`,  consisting of the size of the gas tank and the starting and destination points as a vector of strings. The function should return a vector of bools indicating whether or not a path exists for each query. If a location specified in a query does not exist in the map, the function should return false.\n\n- If you could implement by [Union Find](https://en.wikipedia.org/wiki/Disjoint-set_data_structure), you could get 10 points.\nOtherwise, you get 8 points.\n- **Hint:**: While you can calculate the result of each query separately, it might be more optimal to use the result of one query to decide about other queries.\n\n\n```c++\n// Takes in a vector of queries. Each query consists of a pair: \u003ctank_capacity, [source, destination]\u003e.\n// Returns the result of each query in a vector.\nstd::vector\u003cbool\u003e Queries(const std::vector\u003cstd::pair\u003cdouble, std::vector\u003cstd::string\u003e\u003e\u003e \u0026q);\n```\n\nPlease report and compare the time spent by this algorithm and show the points on the map.\n\n**Example:**\nSuppose you have a map with the following nodes:\n\n\u003cp align=\"center\"\u003e\u003cimg src=\"img/graph.png\" alt=\"Graph\" width=\"500\"/\u003e\u003c/p\u003e\n\n```css\n1 - 2 (distance = 2)\n1 - 3 (distance = 3)\n2 - 3 (distance = 1)\n2 - 4 (distance = 4)\n3 - 4 (distance = 1)\n```\n\nSuppose the queries are:\n```arduino\n(1.5, {\"1\", \"4\"})\n(2.5, {\"1\", \"4\"})\n(3.5, {\"1\", \"4\"})\n(4.5, {\"1\", \"4\"})\n(3.0, {\"2\", \"3\"})\n(3.0, {\"3\", \"1\"})\n(2.0, {\"1\", \"5\"})\n```\nFor each query, you need to determine whether or not it is possible to travel from the starting point to the destination point using a car with the given gas tank size.\n\nThe expected output for this example is:\n\n```cpp\n{\n false,\n true,\n true,\n true,\n true,\n true,\n false\n}\n```\n\nNote that for the first query, it is not possible to travel from 1 to 4 using a car with a gas tank size of 1.5. There are four paths from 1 to 4: 1-2-4, 1-3-4, 1-2-3-4, and 1-3-2-4. Since the gas tank size is 1.5, you can not travel from 1 to 3 or 1 to 2. Therefore, the function should return false.\n\nFor the second query, if we want to travel from 1 to 4 using a car with a gas tank size of 2.5, we can refuel at 2, 3. Since 1-\u003e2 = 2 \u003c= 2.5,  2-\u003e3 = 1 \u003c= 2.5, 3-\u003e4=1 \u003c= 2.5, we should return true! The problem is to make sure that the maximum distance between any two nodes on the path should be smaller than or equal to the size of the gas tank!\n\nFor the thrid query, it is possible to travel from 1 to 4 using a car with a gas tank size of 3.5. The maximum distance between two nodes on the path 1-3-4 is 3, which is smaller than the gas tank size. For the last query, 5 does not exist in the map, so the function should return false.\n\nAnother example where the inputs are read from your program's UI:\nWe use the whole map near USC as the graph! For example, if we want to start from Target to Ralphs, there are a lot of nodes on the path. We want to make sure that the distance between any two nodes on the path is smaller than the size of the gas tank! For dummy, it means if the location does not exist, we should return false.\n\n```shell\n**************************************************************\n* 12. Check Exist of Path with Constrain                      \n**************************************************************\n\nPlease input the start location:Target\nPlease input the destination:Ralphs\nPlease input the volumn of the gas tank:0.05\nMore Query? (y/n)y\nPlease input the start location:Ralphs\nPlease input the destination:Target \nPlease input the volumn of the gas tank:0.01\nMore Query? (y/n)y\nPlease input the start location:KFC\nPlease input the destination:Target\nPlease input the volumn of the gas tank:0.02\nMore Query? (y/n)y\nPlease input the start location:dummy\nPlease input the destination:dummy\nPlease input the volumn of the gas tank:999\nMore Query? (y/n)n\n*************************Results******************************\nFrom Target to Ralphs with 0.05 gallons of gas tank: Yes\nFrom Ralphs to Target with 0.01 gallons of gas tank: No\nFrom KFC to Target with 0.02 gallons of gas tank: No\nFrom dummy to dummy with 999 gallons of gas tank: No\n**************************************************************\nTime taken by function: 239 ms\n```\n\n## Reporting Runtime:\nFor each menu item, your program should show the time it took to finish each task.\n\nPlease make sure to provide various examples when you report the runtime. For example for topological sort, show an example with few nodes and another example with 10 or more nodes. The idea is to see how your runtime grows as input size grows.\n\n## Runtime Comparison\nFor shortest path algorithms, you should compare solving the same problem with different algorithms (Dijkstra and Bellman-Ford). \nPlease show the results on at least 3 different examples.\n\nSimilarly for the TSP problem, please provide various examples that show the runtime comparison. In particular, you should show at what point using the exhaustive search is not practical and compare the same input with the heuristic implementation.\n\n**Please provide a table like below that compares the runtime of your algorithms for different number of nodes:**\n\n| Number of nodes      | Time with algorithm 1 | Time with algorithm 2|\n| -------------------- | ----------- |----|\n|             |  t1        | t2    |\n\nYour table should show have at least 15 rows.\n\n## Report and Rubrics:\n\nYour final project should be checked into Github. The [README.md](README.md) of your project is your report. \n\n### Report:\n\nYour REPORT.md file should include four sections:\nPlease create a new REPORT.md file and write your report there.\n\n1. High-level overview of your design (Use diagrams and pictures for your data structures).\n2. Detailed description of each function and its time complexity.\n3. Time spent for each function.\n4. Discussion, conclusion, and lessons learned.\n\n### Rubrics:\n\nPhase 1: 2 points\n- Item 1 (AutoComplete): 1 point. (Phase 1)\n- Item 2-1 (GetPosition): 1 point. (Phase 1)\n\nPhase 2: 38 points\n- Item 2-2 (EditDistance): 5 points. (Phase 2)\n- Item 3 (GetAllCategories): 3 Points. (Phase 2)\n- Item 4 (GetAllLocationsFromCategory): 2 Points. (Phase 2)\n- Item 5 (GetLocationRegex): 3 Points. (Phase 2)\n- Item 6 (Shortest path): 15 points. (Phase 2)\n   - Bellman-Ford implementation\n   - Dijkstra implementation\n   - Table/Plot for comparison, and measure and report time spent by two algorithms.\n- Item 7 (Cycle detection): 5 points. (Phase 2)\n   - Boolean value and draw the cycle if there exists one.\n- Item 8 (Topological Sort): 5 points (Phase 2)\n   - Check whether there exist a topological sort or not\n   - Return the correct order and plot those point on the map\n\nPhase 3: 60 points\n- Item 9 (Traveling Trojan) (Phase 3)\n   - Brute-force: 5 points.\n   - Brute-force enhanced with early backtracking: 5 points.\n   - 2-opt: 5 points.\n   - Animated plot in the report.\n- Item 10 (Find Nearby): 5 points. (Phase 3)\n   - Return the correct nearby results.\n- Item 11 (TrojanPath): 10 points. (Phase 3)\n   - Return the correct ids and draw the points.\n- Item 12 (CheckPath): 10 points. (Phase 3)\n   - Return the correct output.\n- Video presentation and report: 10 points. (Phase 3)\n- Creating reasonable unit tests: 10 points.\n      - Three different unit tests for each function.\n## Extra credit items: Maximum of 20 points:\n   1. Implementation of [3-opt](http://cs.indstate.edu/~zeeshan/aman.pdf): 10 points.\n   2. [Genetic algorithm](https://www.geeksforgeeks.org/traveling-salesman-problem-using-genetic-algorithm/) implementation for Traveling Trojan: 10 points\n   3. Create dynamic and animated UI using [ncurses](https://en.wikipedia.org/wiki/Ncurses): 10 points\n      - Uncomment #define NCURSES in main.cc and mapui.h\n      - Create your menu in DynamicPrintMenu().\n      - You could check https://github.com/ourarash/ncurses_bazel\n      - Please develope your own UI.\n      - Example\n         \u003cp align=\"center\"\u003e\u003cimg src=\"img/ncurses example.gif\" alt=\"example\" width=\"500\"/\u003e\u003c/p\u003e\n               \n   4. Accurate measurement of your algorithm runtime using [Google Benchmark](https://www.youtube.com/watch?v=9VKR8u9odrA) while sweeping the input size and providing a diagram of how the runtime grows based on the input size: 10 points.\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flinkoucommander%2Ftrojanmap","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flinkoucommander%2Ftrojanmap","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flinkoucommander%2Ftrojanmap/lists"}