A real-time taxi booking system that efficiently finds the nearest available taxis using Dynamic KD-Trees and calculates optimal routes using graph-based pathfinding algorithms.
This project implements a spatial indexing system for taxi location management using Dynamic KD-Trees with Red-Black balance strategy. The system efficiently handles:
- Finding k-nearest taxis to a pickup location
- Dynamic taxi position updates (insertions and deletions)
- Optimal route calculation using Dijkstra's algorithm on a road network graph
- Real-time visualization of taxis, routes, and road networks
- Efficient Spatial Queries: O(log n) average case for k-nearest neighbor searches using Dynamic KD-Trees
- Self-Balancing Tree: Maintains balance using Red-Black strategy to ensure optimal performance
- Graph-Based Pathfinding: Uses Dijkstra's algorithm for calculating realistic road distances
- Dynamic Updates: Real-time insertion and deletion of taxi locations
- Interactive Visualization: Web-based UI showing taxis, routes, and road networks
- Persistent State: Taxi positions are saved and restored between sessions
- Full Booking Flow: Find taxi � Book taxi � Complete ride with distance and time estimates
- C++: Core data structures (Dynamic KD-Tree, Graph, Dijkstra's algorithm)
- Node.js: HTTP server acting as a bridge between frontend and C++ backend
- Compiler: g++ (MinGW or GCC)
- React (v19.2.0): UI framework
- Tailwind CSS: Styling
- Lucide React: Icons
- JavaScript/ES6: Business logic
- Node.js (v14 or higher)
- npm (v6 or higher)
- g++ compiler (MinGW on Windows, GCC on Linux/Mac)
- Git
git clone https://github.com/kushagramkhare/Dynamic-KD-Trees-for-Taxi-System
cd Dynamic-KD-Trees-for-Taxi-SystemNavigate to the backend directory and compile:
cd backend
g++ -std=c++17 -I include -o main_graph.exe src/main.cpp src/graph.cpp src/dynamic_kd_tree.cppInstall dependencies for frontend-ui:
cd ../frontend-ui
npm icd backend
node server.jsThe server will start on http://localhost:8002
You should see:
==============================================
Taxi Finder Server - C++ Backend
==============================================
Server running on http://localhost:8002
API endpoint: POST http://localhost:8002/api/route
Backend: C++ KD-Tree (main_graph.exe)
Press Ctrl+C to stop the server
Open a new terminal and run:
cd frontend-ui
npm startThe React app will start on http://localhost:3000 and automatically open in your browser.
- Enter Pickup Location: Enter the coordinates from -100 to 100
- Find Nearest Taxis: The system will show the 5 nearest taxis with routes
- Book a Taxi: Select and book a taxi to move it to your pickup location
- Complete Ride: Enter dropoff location and complete the ride
- Insertion: O(log n) average case
- Deletion: O(log n) average case with lazy rebuilding
- k-NN Search: O(k log n) average case
- Balancing Strategy: Red-Black balance (height difference d 2x)
- Splitting: Alternates between x and y dimensions at each level
- Algorithm: Dijkstra's shortest path
- Time Complexity: O((V + E) log V) using priority queue
- Graph Structure: Sparse road network with Manhattan-style connections
- Distance Metric: Graph distance (number of edges) for realistic road distances
This project is based on the following research papers:
-
Paper 1: [Building a Balanced k-d Tree in O(kn log n) Time]
-
Paper 2: [A Dynamic, Self-balancing k-d Tree]
- Dynamic KD-Tree with Red-Black balancing strategy
- K-Nearest Neighbors (k-NN) search
- Dijkstra's Shortest Path algorithm
- Lazy Rebuilding for tree maintenance
- Priority Queue based search optimization
- Initial Tree Build: O(n log n)
- Find Nearest Taxi: O(log n)
- Book Taxi (update position): O(log n)
- Route Calculation: O((V + E) log V)