RouteFinder is a Java-based pathfinding application that implements Dijkstra's algorithm to find the shortest route between two locations on a weighted graph. The program provides an interactive command-line interface for users to explore various routes and calculate optimal paths based on distance.
- Shortest Path Calculation: Uses Dijkstra's algorithm to compute the optimal route between any two nodes
- Interactive Menu System: User-friendly command-line interface with multiple options
- Weighted Graph Implementation: Supports custom graph structures with weighted edges
- Distance Tracking: Maintains and displays cumulative distances along routes
- Multiple Route Queries: Allows users to find multiple routes in a single session
RouteFinder/ ├── RouteFinder.java # Main application file containing all core functionality └── README.md # Project documentation - Java Development Kit (JDK) 8 or higher
- Command-line terminal or IDE with Java support
-
Clone the repository:
git clone https://github.com/kellyG23/RouteFinder.git cd RouteFinder -
Compile the Java file:
javac RouteFinder.java
-
Run the application:
java RouteFinder
Once you start the application, you'll be presented with a menu:
Option 1: Find Shortest Route
- Enter the starting location
- Enter the destination location
- The program will calculate and display:
- The optimal path from start to destination
- Total distance of the route
- All intermediate stops along the way Option 2: Traverse
- Enter “N”as the starting location and destination.
- Circular graphs will show a circular route. Option 3: Exit
- Closes the application
Enter starting location: A Enter destination: D Shortest Route Found: A -> B -> D Total Distance: 13 Process finished with exit code 0 The program implements Dijkstra's algorithm, a popular graph traversal algorithm for finding the shortest path between nodes:
- Initialization: Sets the distance to the starting node as 0 and all other nodes as infinity
- Priority Queue: Uses a priority queue to efficiently select the next closest unvisited node
- Relaxation: Updates distances to neighboring nodes if a shorter path is found
- Path Reconstruction: Traces back through the path to construct the final route
- Time: O((V + E) log V) where V is the number of vertices and E is the number of edges
- Space: O(V) for storing distances and visited nodes
- Uses adjacency list or matrix to represent the network of locations
- Stores weighted edges representing distances between locations
- Represents individual locations in the graph
- Stores node identifier and associated edge weights
- Implements core Dijkstra's algorithm
- Handles distance calculations and path reconstruction
- Menu-driven command-line interface
- Input validation and error handling
- Formatted output display
To add new locations to the graph, modify the graph initialization section in the RouteFinder.java file:
// Add edges with weights (distances) graph.addEdge("LocationA", "LocationB", distance);Update the weight parameter when adding edges to reflect new distances:
graph.addEdge("CityA", "CityB", newDistance);- HashMap: For storing graph adjacency relationships
- PriorityQueue: For efficient node selection during pathfinding
- ArrayList: For maintaining paths and node lists
findShortestPath(): Main pathfinding method implementing Dijkstra's algorithmdisplayLocations(): Shows all available nodes in the graphreconstructPath(): Builds the final path from start to destinationinitializeGraph(): Sets up the graph structure with nodes and edges
The program includes robust error handling for:
- Invalid location names
- Disconnected graph components (no path exists)
- Invalid menu selections
- Empty or null inputs
Potential improvements for future versions:
- GUI implementation with visual graph representation
- Support for A* algorithm as an alternative pathfinding method
- Import/export graph data from external files (JSON, CSV)
- Multi-criteria routing (time, cost, distance)
- Real-time route updates and dynamic graph modifications
- Support for bidirectional edges with different weights
- Visualization of the pathfinding process
Contributions are welcome! Please feel free to submit a Pull Request. For major changes:
- Fork the repository
- Create your feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
This project is available for educational and personal use.
kellyG23
- Dijkstra's algorithm implementation based on classical computer science principles
- Inspired by real-world navigation and routing problems
Note: This is an educational project demonstrating graph algorithms and pathfinding techniques. For production routing applications, consider using established libraries and frameworks.