Instead of hardcoding a single graph search algorithm, this project builds a system that predicts which solver (BFS, DFS, or A*) will perform best for a given maze based on structural features.
The goal: treat solver selection as a supervised learning problem.
Different search algorithms behave very differently depending on maze structure.
Sometimes DFS expands fewer nodes.
Sometimes A* dominates in open environments.
BFS guarantees shortest paths but can be inefficient.
Rather than guessing which one to use, I wanted to:
- Generate diverse mazes
- Measure solver performance
- Label the optimal solver
- Train a model to predict it
- Evaluate using regret, not just accuracy
Two maze families:
- Family A (structured generation)
- Family B (open-ratio controlled randomness)
Sweeps over:
- Sizes: 21, 31, 51
- Open ratios: 0.15–0.60
- Multiple seeds
Each maze is described using:
cells_totalopen_ratiodead_end_ratioshortest_path_lengthreachable_ratio
These features capture topology and connectivity.
For each maze, all three solvers are executed.
The “best” solver is selected using:
(path_length, nodes_expanded, runtime_ms)
This becomes the ground-truth label.
- Random Forest (200 trees)
- Stratified train/test split
- Majority baseline comparison
- Regret-based evaluation
Regret is defined as:
nodes_expanded(predicted_solver) − nodes_expanded(oracle_solver)
This measures how much extra work the model caused.
Dataset size: 144 mazes
Class distribution:
- A*: 96
- DFS: 48
Majority baseline: 65.5%
Model accuracy: 100%
Average regret: 0
Median regret: 0
The model perfectly predicted the best solver on the held-out test set.
I also implemented a rule-based heuristic selector.
Heuristic:
- 96.7% accuracy
- Avg regret: 1.3 expanded nodes
The learned model eliminated regret entirely on the test set.
- Feature-driven decision systems
- Structured experiment design
- Regret-based evaluation
- Clean dataset construction
- Reproducible benchmarking
- Moderate dataset size
- No BFS-dominant class observed
- Static mazes only
- Python
- NumPy
- SciPy
- Scikit-learn (Random Forest, evaluation metrics)
- Matplotlib
- Larger parameter sweeps
- Weighted mazes
- More algorithms
- Direct regression on nodes expanded
- Policy-learning approaches
pip install -r requirements.txt
python -m scripts.test_build_dataset
python -m scripts.train_random_forest
python -m scripts.

