Each city is a node; each road is an undirected weighted edge (km). City coordinates are used to compute the heuristic for A*.
Download the materials below (these files are included in the coursework package).
route_planning.py — code template (you implement DFS/UCS/A*)run_all_tests.py — runs all algorithms on required test queries and writes test_results/cities.txt, roads.txt — dataset
Submitting on Canvas: . In short, you submit
route_planning.py and the entire test_results/ directory, package them together into one zip file to submit.
cities.txt format:
CityName latitude longitude
Beijing 39.9042 116.4074
Shanghai 31.2304 121.4737
XiAn 34.3416 108.9398
roads.txt format (undirected):
CityA CityB distance_km
Beijing Tianjin 120
Nanjing Shanghai 300
Hohhot Shanghai 1500
Design note: the dataset includes distractor branches and an expensive shortcut so BFS/DFS/UCS/A* show clearer differences.
route_planning.py: BFS is already implemented as an example; you implement DFS/UCS/A*run_all_tests.py: runs all algorithms on required queries and writes test_results/dfs(graph, start, goal)ucs(graph, start, goal)astar(graph, coords, start, goal)After each run, the program generates a standalone HTML visualization showing:
Open the HTML file directly in a browser (Windows/macOS/Linux).
Run a single query:
python route_planning.py --algorithm astar --start Beijing --goal Shenzhen
Specify output file:
python route_planning.py --algorithm bfs --start Beijing --goal Shanghai --output outputs/route_result.html
Run all required tests:
python run_all_tests.py --outdir test_results
Check test_results/summary.csv (runtime_ms / expanded_nodes / total_cost) and compare.
The batch runner writes a directory containing per-case result.json and visualization.html, plus summary files. Test cases:
python run_all_tests.py
You must submit the entire test_results/ directory.
route_planning.py (DFS/UCS/A* completed; BFS unchanged)test_results/ directory generated by run_all_tests.pyNo report is required.
| Component | Points |
|---|---|
| DFS implementation | 20 |
| UCS implementation | 30 |
| A* implementation | 35 |
| Running tests + correct outputs directory structure | 10 |
| Code clarity (readable, well-structured) | 5 |
| Total | 100 |