← All projects
Data & analytics · Python
R

routeplanner

Dijkstra, A* and bidirectional search over one shared implementation — pick two nodes and compare them live.

1 Plan a route

A 5×5 road network: local streets at 35 km/h, arterials at 60, a ring motorway at 100. Each edge stores length and speed separately, so shortest and fastest genuinely disagree.

Pick a start and end node, then run the search.

2 Algorithm comparison

Same query, three searches. Expanded / pushed / relaxed are real counters from the runs above — A* expands fewer nodes because its heuristic never overestimates.

algorithmcostexpandedpushedrelaxedpeak frontier
No query yet.

3 Why two cost models

Minimising distance and minimising time are different questions. The same pair of intersections can differ by kilometres and half an hour — which is why length and speed are stored on every edge instead of being collapsed into one number at load time.

A* uses great-circle distance to the goal: no road beats the straight line, so the heuristic is admissible and A* returns the same route Dijkstra does — it just looks at less of the map. The travel-time heuristic divides by the fastest speed anywhere in the graph, not the road you are standing on, or a motorway ahead would make it overestimate.

$ routeplanner compare n0202 n3737 astar, fastest 50.19 km, 34.4 minutes, 22 segments 1,141 expanded, 1,443 pushed, 4,202 relaxed, peak frontier 208

4 Interactive search lab

Drag nodes to reshape the graph, then watch Dijkstra, A* and bidirectional search expand node by node. Nodes are tinted by f(n) = g(n) + h(n) — the priority each algorithm pops from its frontier. Build your own graph with the tools below.

Press Play or Step to animate the search.

Move mode: drag nodes. Edge mode: click two nodes to connect them (weight = euclidean distance × random factor). Delete: click a node or edge. Double-click an edge to set its weight.

5 Path comparison table

Real numbers from the lab run: distance, estimated travel time, nodes expanded and whether each algorithm found the optimal path.

algorithmdistancetime est.nodes expandedfrontier peakoptimal?
Run the lab to fill this table.
69 tests · Python 3.10–3.12 · standard library only · Built by Umer Hashmi