On this page
All lessons
Anytime Search
Jump Point Search
Temporal Planning
Playground
CPD Search (Anytime A* with Perfect Distances)
CPD Search is an anytime algorithm that runs A* with a precomputed distance table as its heuristic. Before search, a BFS from the target (on an unweighted map) gives a perfect lower-bound distance for every node. This becomes both the heuristic and an initial upper bound — enabling aggressive pruning and fast convergence to optimality.
Statistics
Draw your map above, then click Run A* to generate the step trace.
How CPD Search works
Phase 1 — Preprocessing. A BFS runs backwards from the target on an unweighted copy of the map (all non-wall cells cost 1). This builds a table of perfect distances dist[n] from every node n to the target. Numbers on each cell during this phase are those BFS distances.
Initial upper bound. The unweighted shortest path from start to target is extracted from the BFS. Its actual weighted cost (including terrain) becomes the first upper bound (UB). We have a valid solution before the main search even starts.
Phase 2 — A* with perfect heuristic. Standard A* runs with f(n) = g(n) + dist[n]. Because dist[n] is the exact unweighted distance — always ≤ the true weighted cost — it is admissible, so A* will find the optimal weighted path.
Anytime pruning. Any node whose f(n) > UB is pruned immediately — no path through it can beat the current best. When the lowest f-value in OPEN (the LB) reaches the UB, optimality is proven and search terminates.
CPD Search vs AWA*
Both are anytime algorithms, but they tackle the problem differently. CPD Search (left) gets an immediate upper bound from its precomputed path, then uses perfect distances to prune aggressively. AWA* (right) uses an inflated heuristic (w=10) to rush toward the goal, then backtracks to find cheaper routes. Edit either grid to run both simultaneously.
CPD Search Statistics
AWA* Statistics
Modify the grid above, then click Run animation to compare both algorithms side by side.
Continue your Learning
Read the original CPD Search paper to understand how Compressed Path Databases are constructed and why they produce such tight bounds in practice.
Found this helpful?
These resources are free — if they saved you time, a coffee keeps them going.