Expand to view full navigation
Pathfinding Benchmarks is an advanced algorithmic engineering laboratory designed to audit, stress-test, and optimize graph search strategies. Unlike standard visualizers that only show the shortest path, this system focuses on the computational economics of pathfinding: specifically, the trade-off between Time Complexity (CPU cycles) and Space Complexity (RAM usage).
Modern pathfinding faces two critical challenges which this project addresses:
Standard A (A-Star)* is optimally efficient in terms of nodes visited, but it is memory-hungry. On massive grids (game maps, logistics networks), it creates millions of object references, often leading to OutOfMemoryError.
SMA (Simplified Memory-Bounded A)** solves this by fixing a hard memory limit and "pruning" the worst nodes when full. However, if the algorithm later needs those pruned nodes, it must regenerate them. This cycle of forgetting and relearning is called Thrashing. This suite provides the tooling to visualize exactly when and how Thrashing destroys performance.
Mathematical heuristics (Manhattan, Euclidean) are "blind" to terrain costs like mud, traffic, or walls until they touch them. This project implements a Hybrid AI Pipeline that:
- Generates thousands of procedural maps with complex topologies.
- Trains Python-based ML models (Linear Regression, Neural Networks) to predict path costs based on features like
% Wall Density,% Traffic, andGrid Distance. - Injects these learned weights back into the Java engine, allowing the AI to "see" obstacles before exploring them, significantly reducing search space.
This project employs a polyglot architecture to leverage the best tools for each domain:
We treat algorithm performance data like financial analytics. The project includes a dedicated HTML5/JS dashboard that parses the raw CSV logs from the Java engine and visualizes Memory Thrashing, Heuristic Efficiency, and Time-Space Tradeoffs.
The following diagram illustrates the Hybrid AI Pipelineβhow Java generation feeds Python training, which loops back into the Java runtime.
graph LR
subgraph P1["Phase 1: Data Generation (Java)"]
A[Map Generator] -->|1000+ Maps| B(Solved Maps)
B -->|Extract Features| C[training_data.jsonl]
end
subgraph P2["Phase 2: Model Training (Python)"]
C --> D[ML.py]
D -->|Train Model| E{Best Model?}
E -->|Export Weights| F[ml_weights.properties]
end
subgraph P3["Phase 3: Runtime Injection (Java)"]
F -->|Load at Startup| G[MachineLearnedHeuristic.java]
G -->|Predict Cost| H[A* / SMA* Engine]
H -->|Output Logs| I[benchmark_results.csv]
end
I --> J[HTML5 Dashboard]
Follow these steps to set up the environment for both the Java Benchmark Engine and the Python ML Pipeline.
- Java JDK 11+: Required to compile and run the core engine.
- Verify:
java -version
- Verify:
- Python 3.8+: Required only if you intend to retrain the ML models.
- Libraries:
scikit-learn,numpy,pandas
- Libraries:
- Git: To clone the repository.
-
Clone the Repository
git clone https://github.com/amir-hossein-khodaei/ai-pathfinding-benchmarks.git cd ai-pathfinding-benchmarks -
Compile the Java Engine The project uses a standard directory structure. You can compile it using
javac:# Create build directory mkdir -p bin # Compile all sources javac -d bin -sourcepath src src/Main.java
-
Setup Python Environment (Optional for ML) If you plan to run the
ML.pyscript:pip install scikit-learn numpy pandas
The application is driven by an interactive Command Line Interface (CLI).
To launch the main menu, run the compiled Java class:
java -cp bin MainYou will be presented with the Pathfinding Benchmark System v3.0 menu:
==========================================
PATHFINDING BENCHMARK SYSTEM v3.0
==========================================
Select Mode:
[1] Standard Benchmark (A* vs SMA*)
[2] Visualize Trace (Single Map Audit)
[3] Generate Training Data (For Python)
[4] Test Machine Learned Heuristic (Bonus)
[0] Exit
| Option | Description |
|---|---|
[1] Standard |
Runs a massive benchmark suite (Size 20-60, Easy-Hard). Generates benchmark_results.csv. |
[2] Audit |
Runs a single complex map trace. Exports trace_astar.txt and trace_smastar.txt to visualize step-by-step logic. |
[3] Generate |
Creates training_data.jsonl for the Python ML pipeline. You define the number of samples (e.g., 50,000). |
[4] ML Test |
Benchmarks your trained AI model against the standard mathematical heuristics. |
If you want the AI to "learn" a new type of map topology:
-
Run Option
[3]in the Java CLI to generatefinal_output/training_data.jsonl. -
Run the Python training script:
python ML.py
-
The script will output performance metrics (RΒ² Score, RMSE) and save the new weights to:
ml_weights.properties(Linear Regression)ml_weights_mlp.properties(Neural Network)ml_weights_lasso.properties(Feature Selection)
-
Restart the Java application and choose Option
[4]to test your new model!
After running a benchmark (Option 1 or 4), the results are saved to final_output/benchmark_results.csv.
- Navigate to
final_output/in your file explorer. - Open
index.htmlorml_report.htmlin a modern web browser. - Note: If the charts do not load due to local CORS policy (browser security), use the "π Select Data.csv" button in the dashboard UI to manually load your generated CSV file.
This repository implements a wide range of heuristic strategies to test the limits of A* and SMA*.
View Supported Heuristics
These heuristics never overestimate the cost to the goal.
| Heuristic | Formula | Use Case |
|---|---|---|
| Scaled Manhattan | `0.5 * ( | dx |
| Scaled Euclidean | 0.5 * sqrt(dxΒ² + dyΒ²) |
useful for "As the crow flies" distance. |
| Dijkstra (Zero) | h(n) = 0 |
Turns A* into Dijkstra's Algorithm (Uniform Cost Search). |
These may overestimate costs but run significantly faster.
| Heuristic | Formula | Use Case |
|---|---|---|
| Unscaled Manhattan | ` | dx |
| Manhattan Squared | `( | dx |
| Avg Cost Manhattan | `4.1 * ( | dx |
| Model | Description |
|---|---|
| Linear Regression | Learns weights for Mud, Traffic, Walls, and Shortcuts. |
| MLP (Neural Net) | A 3-layer Perceptron (6->8->4->1) that captures non-linear terrain relationships. |
- Core Engine: Robust A* and SMA* implementations.
- Visualizer: Interactive HTML5/JS Dashboard with Plotly.
- ML Integration: Python pipeline for Linear Regression & Neural Networks.
- Advanced Algorithms:
- Bidirectional A*
- IDA* (Iterative Deepening A*)
- JPS (Jump Point Search)
- 3D Support: Moving from 2D grids to 3D voxel maps.
- Docker Support: Containerizing the Java/Python workflow.
See the open issues for a full list of proposed features.
Contributions are what make the open-source community such an amazing place to learn, inspire, and create. Any contributions you make are greatly appreciated.
- Fork the Project
- 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
Distributed under the MIT License. See LICENSE for more information.
Amir Hossein Khodaei - GitHub Profile
Project Link: https://github.com/amir-hossein-khodaei/ai-pathfinding-benchmarks