Two parameters

Two estimates that must agree

Run A* from both ends of a query at once, each search guided by its own straight-line estimate, and stop by the rule that is correct for two-ended Dijkstra. On 40 weighted grids it expands 1,002 cells on average and returns a longer path than the shortest on 12 of them. Give both searches one potential, half of one estimate minus half of the other, and the same rule is correct again — on all 40 grids, for 1,041 cells. Two estimates that measure different things cannot share a stopping rule until they are made to measure the same thing.

Two ideas for making a shortest-path query cheaper have been measured separately. The precondition on a function the caller writes added an estimate of the remaining distance to Dijkstra’s priority key and cut a search across a grid from 1,582 expanded cells to 405. Where two searches should stop ran one search forward from the source and one backward from the goal, and found that the obvious rule for stopping them is wrong — stopping at the first cell both have finished returned a longer path on some grids — while the rule that tracks the best route seen across any arc and stops when the two frontiers’ smallest keys together reach it is always right.

The natural combination is two A* searches, one from each end, each guided by an estimate towards the other. That essay closed by predicting why it would break. An estimate is a reweighting had shown that A* is Dijkstra on arcs repriced by the estimate, so a forward A* guided towards the goal and a backward A* guided towards the source are two Dijkstra searches on two different graphs. The stopping rule adds a forward key to a backward key and compares the sum with a route’s cost, which only means something if both keys price the same arcs.

This page measures the naive combination, the rule that is correct whatever the estimates, and the repair — and then checks how much the repair costs.

The rule that was correct, and where it came from

Stopping where the two searches meet returned a longer path on 5 of 40 grids; the correct rule, on none40 grids of 900 cells with 28% removed and steps costing one to nine, each searched from both ends at once. Each column is one grid, and each bar is how much longer than the shortest path the returned path is. Stopping at the first vertex both searches have finished returned a longer path on 5 of them, by 4, 2, 3, 2, 1. Stopping when the two frontiers' smallest keys together reach the best route seen across any arc returned the shortest path on every one, expanding on average 64% of the cells a one-ended search expands.stop where they meetextra path length42321stop when keys reach itextra path length110203040grid, by seedV = 900, 28% blocked, steps cost one to nine5 of 40 wrong under the meeting rule
Fig. 1 The earlier result, for two Dijkstra searches: 40 grids of 900 cells with 28% removed and steps costing one to nine, each searched from both ends. Stopping at the first cell both searches have finished returned a longer path on 5 of the 40, by 4, 2, 3, 2 and 1. Stopping when the two frontiers’ smallest keys together reach the best route seen across any arc returned the shortest path on every grid, expanding on average 64% of what a one-ended search expands.

The correct rule’s argument is short, and the whole of this page turns on one step of it. Let μ\mu be the cheapest route found so far that crosses from a cell the forward search has reached to a cell the backward search has reached. Any route not yet found must leave the forward search’s finished cells through some cell uu still on its frontier and enter the backward search’s finished cells through some vv still on the other frontier, so it costs at least the forward distance to uu plus the backward distance from vv. Those distances are at least the two frontiers’ smallest keys. So once the two smallest keys add up to μ\mu or more, no unfound route can beat μ\mu, and stopping is safe.

The step that matters is “those distances are at least the smallest keys”. For Dijkstra a key is a distance, so it holds trivially.

Why separate estimates break it

Give the forward search the straight-line estimate of the distance to the goal, hth_t, and the backward search the straight-line estimate of the distance from the source, hsh_s. Each is a correct A* on its own: the forward key of a cell uu is its distance from the source plus ht(u)h_t(u), never more than the length of the best route through uu.

Now add a forward key to a backward key. The sum is the forward distance to uu, plus ht(u)h_t(u), plus the backward distance from vv, plus hs(v)h_s(v). The two estimates are estimates of different stretches of the same route — ht(u)h_t(u) of everything after uu, hs(v)h_s(v) of everything before vv — and when uu and vv lie near each other in the middle of the grid, those two stretches overlap almost completely. The sum counts the middle of the route twice. It can reach μ\mu while a cheaper route through the middle still exists, and the search stops before finding it.

Mean cells expanded on 40 weighted grids: A* from one end 1,748, two-ended Dijkstra 1,171, two A*, separate estimates 1,002 (wrong on 12), two A*, stop on either key 3,491, two A*, averaged potential 1,0415 searches from corner to corner of 40 grids of 2,500 cells with 28% removed, once with every step costing one to nine and once with every step costing one; the estimate is the straight-line count of cells in both directions. Each bar is the mean cells expanded, and the count in brackets is the grids on which the path returned was longer than the shortest. A* from one end: 1,748 on weighted terrain (0 wrong), 473 on unit steps (0 wrong). two-ended Dijkstra: 1,171 on weighted terrain (0 wrong), 1,403 on unit steps (0 wrong). two A*, separate estimates: 1,002 on weighted terrain (12 wrong), 469 on unit steps (0 wrong). two A*, stop on either key: 3,491 on weighted terrain (0 wrong), 469 on unit steps (0 wrong). two A*, averaged potential: 1,041 on weighted terrain (0 wrong), 469 on unit steps (0 wrong).steps cost one to ninesteps cost one01,0002,0003,000cells expanded, mean over the gridsA* from one endalways shortestalways shortesttwo-ended Dijkstraalways shortestalways shortesttwo A*, separate estimateswrong on 12always shortesttwo A*, stop on either keyalways shortestalways shortesttwo A*, averaged potentialalways shortestalways shortest40 grids a bar, 2,500 cellsestimate: straight-line cells
Fig. 2 Five searches from corner to corner of 40 grids of 2,500 cells with 28% removed, on weighted terrain and on unit steps, with the straight-line estimate in both directions; each bar is the mean cells expanded. Weighted terrain: A* from one end 1,748; two-ended Dijkstra 1,171; two A* with separate estimates and the sum rule 1,002, returning a longer path on 12 grids; two A* stopped only when either frontier’s key alone reaches the best route, 3,491; two A* with an averaged potential, 1,041. Unit steps: 473, 1,403, 469, 469 and 469, every one always shortest.

On weighted terrain the separate estimates with the sum rule are the cheapest search on the plate at 1,002 cells, and wrong on twelve of the forty grids. The prediction holds, and it holds more often than the meeting rule’s failure did on the earlier plate — twelve in forty against five — because the double-counted middle is a systematic overestimate rather than an occasional unlucky ordering.

On unit steps none of the forty grids goes wrong. That is not a guarantee. On a grid where every step costs one, the straight-line estimate is nearly exact in open ground, and a search guided by a nearly exact estimate from either end walks almost straight to the other end’s frontier; there is little middle for the two estimates to double-count before the searches meet. The rule is still unjustified there, and the plate records that on these forty grids the unjustified rule happened not to fail.

One grid, taken apart

4 searches on one grid: from 1,786 cells expanded down to 941One 50 × 50 grid with 28% of its cells removed, every step costing between one and nine, searched from corner to corner. The shortest path costs 346. No estimate: 1,786 expanded · path 346. Two-ended, correct stop: 1,129 expanded · path 346. Two A*, separate estimates: 941 expanded · path 356, shortest 346. Two A*, averaged potential: 956 expanded · path 346.cells expandedNo estimate1,786 expanded · path 346Two-ended, correct stop1,129 expanded · path 346Two A*, separate estimates941 expanded · path 356, shortest 346Two A*, averaged potential956 expanded · path 346V = 2,500, steps cost one to nine, seed 22shortest path 346
Fig. 3 One weighted grid of 50 by 50 cells, searched from corner to corner, whose shortest path costs 346. Dijkstra: 1,786 cells expanded. Two-ended Dijkstra with the correct stop: 1,129. Two A* searches with separate estimates: 941 cells, and a path costing 356. Two A* searches with the averaged potential: 956 cells, and the path of 346.

On this grid the separate estimates stop fifteen cells sooner than the repaired search and return a path ten units longer than the shortest — about three per cent. The route the early stop missed runs through the middle of the grid, exactly the region where the forward key’s estimate of the rest of the route and the backward key’s estimate of its beginning cover the same ground.

The size of the error is worth keeping in proportion. Three per cent is small, and on the other eleven grids that went wrong the excess ranges from one unit to ten. A search that returns a slightly longer path is not useless. But it is not the search it claims to be — every method on this plate is described as returning a shortest path — and the failure is invisible from the output, which is a path of plausible length that nothing flags.

It would also be hard to catch in testing, for exactly the reason the unit-step grids show. A test suite for a path-finder is usually built on grids where the right answer is easy to check by eye, and those are grids with unit steps, where the straight-line estimate is nearly exact and the double-counted middle almost never matters. On the forty unit grids here the incorrect rule returned the right answer every time. It is on the terrain that a real system is built for — steps of different costs, estimates that understate them — that it fails, and it fails by a few per cent at a time. The adversary who hides the edge makes the general point about arguments of this kind: a procedure that has only been shown easy inputs has been shown nothing about the hard ones, and a check has to be built from the inputs that break the claim.

The rule that is correct whatever the estimates are

There is a stopping rule that survives separate estimates, and it follows from the property that makes each A* correct on its own. The forward key of a frontier cell is at most the length of the best route through that cell. So when the forward frontier’s smallest key reaches μ\mu, every route through any unfinished forward cell costs at least μ\mu, and every route not yet found passes through such a cell. Stopping then is safe. The same holds for the backward frontier.

So stopping when either frontier’s smallest key alone reaches μ\mu is always correct, and the plate shows the price: 3,491 cells on weighted terrain, three times the incorrect search and twice A* from one end. The rule throws away the reason for searching from both ends. It waits until one search, on its own, has covered enough of the grid to prove the answer — which is roughly what a one-ended A* has to do — while the other search expands cells in parallel that contribute nothing to the proof. Two searches doing the work of one, plus a second one.

Making the two estimates agree

The repair is to stop the two searches working on different graphs. Give the forward search the potential

p(v)=12(ht(v)hs(v))p(v) = \tfrac{1}{2}\bigl(h_t(v) - h_s(v)\bigr)

and the backward search its negative. Reprice every arc from uu to vv by w+p(v)p(u)w + p(v) - p(u). The backward search walks arcs in reverse, and repricing a reversed arc by its own potential, p-p, gives w+(p)(u)(p)(v)w + (-p)(u) - (-p)(v), which is the same number. So both searches now run Dijkstra on one repriced graph.

The repriced arcs are never negative when both estimates are consistent — when each estimate changes by no more than an arc’s cost across that arc. Half of ht(v)ht(u)h_t(v) - h_t(u) is at least w/2-w/2, and half of hs(u)hs(v)h_s(u) - h_s(v) is at least w/2-w/2, so w+p(v)p(u)w + p(v) - p(u) is at least ww/2w/2=0w - w/2 - w/2 = 0. Two-ended Dijkstra on a graph with non-negative arcs is exactly the case the correct stopping rule was proved for. And the constant by which repricing shifts every route’s cost cancels in the rule: the forward key carries pp at the goal’s end of the route and the backward key carries p-p at the same place, so the sum rule on the keys is the sum rule on the repriced distances with nothing added.

The cost of the repair is in the strength of the estimate. The forward search is now guided by half the distance-to-goal estimate, offset by half the distance-from-source estimate, which is a weaker pull towards the goal than hth_t alone. Each search is less directed, and should expand more.

Separate estimates stopped by the sum of keys returned a longer path on 12 of 40 grids; the averaged potential on none, for 4% more cells40 weighted grids of 2,500 cells, each searched from corner to corner by two A* searches. The upper strip is how much longer than the shortest path the path returned by separate estimates with the sum stopping rule is: 1 on grid 2, 2 on grid 5, 4 on grid 10, 2 on grid 16, 1 on grid 17, 1 on grid 18, 5 on grid 19, 3 on grid 21, 10 on grid 22, 7 on grid 28, 6 on grid 30, 9 on grid 34. The lower strip is the averaged potential's cells expanded divided by the separate estimates', grid by grid, from 1.01 to 1.08; its paths are the shortest on every grid.separate estimatesextra path length1242115310769averaged potentialcells ÷ separate1.011020304040 weighted grids, 2,500 cellsdashed: equal cells
Fig. 4 The 40 weighted grids one at a time. Upper strip: how much longer than the shortest the separate estimates’ path is — 1 on grid 2, 2 on grid 5, 4 on grid 10, 2 on grid 16, 1 on grids 17 and 18, 5 on grid 19, 3 on grid 21, 10 on grid 22, 7 on grid 28, 6 on grid 30 and 9 on grid 34, and zero on the other 28. Lower strip: cells expanded with the averaged potential divided by cells expanded with the separate estimates, from 1.01 to 1.08; the averaged potential’s path is the shortest on every grid.

The averaged potential never costs more than 8% over the incorrect search on any grid, and 4% on average. Against the correct alternatives it is the cheapest by a wide margin: 1,041 cells against 1,171 for two-ended Dijkstra, which uses no estimate at all, and against 3,491 for the rule that tolerates separate estimates.

That makes the result unusually clean. The incorrect search is only slightly cheaper than the correct one, and the correct one is substantially cheaper than every other correct search on the plate. There is no trade here to agonise over. The four per cent is the price of a guarantee, and it is a small price.

Why the straight-line estimate helps two ends and not one

The weighted plate has a second finding that is not about stopping at all. A* from one end expands 1,748 cells and two-ended Dijkstra 1,171: on weighted terrain, searching from both ends with no estimate beats searching from one end with an estimate.

An estimate borrowed from an easier problem explained the first number. The straight-line estimate counts cells as though every step cost one, and on terrain where steps cost one to nine it underestimates the remaining cost by a factor of about five, so it barely directs the search. Two-ended search helps for a geometric reason that has nothing to do with the estimate: two discs of half the radius hold about half the area of one disc of the whole radius, so two frontiers that meet in the middle have expanded about half the cells one frontier needs.

On unit steps the same comparison runs the other way, 473 cells for one-ended A* against 1,403 for two-ended Dijkstra, because there the estimate is nearly exact and a one-ended search guided by it is already close to a straight line. A second search from the other end adds cells and removes almost none.

The combinations inherit both effects. On weighted terrain the averaged potential, at 1,041, gains from the two ends and a little from the estimate. On unit steps every two-ended A* expands 469 cells, four fewer than one-ended A* — the estimate did the work, and the second end was carried along.

5 searches on one grid: from 1,793 cells expanded down to 370One 50 × 50 grid with 28% of its cells removed, every step costing one, searched from corner to corner. The shortest path costs 98. No estimate: 1,793 expanded · path 98. Straight-line estimate: 372 expanded · path 98. Two-ended, correct stop: 1,397 expanded · path 98. Two A*, separate estimates: 370 expanded · path 98. Two A*, averaged potential: 370 expanded · path 98.cells expandedNo estimate1,793 expanded · path 98Straight-line estimate372 expanded · path 98Two-ended, correct stop1,397 expanded · path 98Two A*, separate estimates370 expanded · path 98Two A*, averaged potential370 expanded · path 98V = 2,500, unit steps, seed 22shortest path 98
Fig. 5 The same grid with every step costing one; the shortest path costs 98. Dijkstra: 1,793 cells. A* from one end: 372. Two-ended Dijkstra: 1,397. Two A* with separate estimates: 370. Two A* with the averaged potential: 370. Every search returns the path of 98.

On unit steps the separate estimates and the averaged potential expand exactly the same cells on this grid, and both find the shortest path. When the estimate is close to exact from both ends, averaging the two potentials loses almost nothing, because each half-estimate still points almost straight at the other end — and the double-counting that broke the sum rule on weighted terrain has almost no middle to act on.

What the three rules teach about combining guarantees

Each of the two techniques combined here came with a guarantee and a condition. A* returns a shortest path if its estimate never overestimates. The two-ended stopping rule returns a shortest path if the keys it adds are distances in one graph. The naive combination kept each technique’s condition satisfied on its own terms — both estimates were admissible, both searches were correct A* searches — and violated the condition of the combination, which neither technique’s statement mentions because neither was written with the other in mind.

That is the general hazard in composing algorithms that carry preconditions, and the bound with a precondition found its simplest form: Dijkstra’s guarantee is conditioned on non-negative arcs, and on four vertices with one negative arc it is wrong. Here the condition that failed is subtler, since every arc was non-negative and every estimate admissible. What failed was an implicit condition of the stopping rule — that the two keys measure the same thing — which only becomes a condition at all once there are two estimates to disagree.

The repair has a shape worth recognising too. Rather than weakening the rule to tolerate the disagreement, which is what the either-key rule does at three times the cost, it removes the disagreement by construction, so the original rule’s proof applies unchanged. An estimate is a reweighting is what made that possible: once an estimate is seen as a potential that reprices arcs, two estimates can be combined into one potential, and the question “do these keys agree” becomes the question “is this one graph”, which has a yes-or-no answer.

The checks hold the combination to both halves: on twenty weighted grids the averaged potential must return the shortest path every time, and the separate estimates with the sum rule, offered as a search that returns shortest paths, must be refused — which they are, on the second grid, with a path of 376 where the shortest is 375.

With a stronger estimate

Every search on this page used the straight-line count of cells, which on weighted terrain is weak enough that most of the saving comes from searching from two ends. Where the landmarks stand measured a much stronger estimate on the same grids — tables of exact distances from a few chosen cells — which cuts a one-ended search by a factor of six or more.

A landmark estimate is consistent, so the averaged potential applies to it unchanged, and the argument above says what should happen. With a strong estimate the forward search alone already runs almost straight to the goal, so a second search from the other end has less to save, and averaging the two estimates halves a pull that was doing most of the work. The prediction is that the two-ended repair loses its advantage over one-ended A* as the estimate strengthens, which the unit-step grids already show in miniature: there the straight-line estimate is nearly exact, and every two-ended search expanded 469 cells to one-ended A*'s 473. The combination of the two techniques is worth most when the estimate is weak and the terrain is hard, which is exactly the case in which the naive combination fails.

What the model leaves out

One estimate family. Every search here uses the straight-line count of cells, which is consistent on these grids. With an admissible estimate that is not consistent, the averaged potential’s arcs can go negative and the repair no longer applies; an estimate is a reweighting measured what an inconsistent estimate does to a single search, and the two-ended case would inherit that failure in both directions.

Corner-to-corner queries only. A query between two cells close together, or between a cell and one behind an obstacle, gives the two searches much less room to overlap, and the separate estimates’ rate of failure would move. Twelve in forty is a figure about long diagonal queries.

Expansions, not time. The averaged potential evaluates two estimates per cell where a separate search evaluates one, which the count of expanded cells does not charge. On straight-line estimates that is two subtractions; on the landmark tables of the earlier essays it is two passes over every table.

Still open: stopping earlier without giving up the guarantee

The averaged potential pays four per cent for correctness because its keys are weaker than the separate estimates’ keys, and the sum rule has to wait for weaker keys to add up to μ\mu. But the separate estimates’ keys are still valid lower bounds for their own searches, even when they cannot be added.

That suggests a rule that uses both. Stop when the averaged keys’ sum reaches μ\mu — which is always safe — or when either separate key alone reaches μ\mu — which is also always safe — whichever happens first. On grids where the averaged search reaches its stop first nothing changes; on grids where one search’s own estimate proves the answer sooner, the combined rule stops earlier and remains correct. The measurement that follows runs both searches’ keys side by side and asks how many of the forty grids stop sooner under the combined rule, by how many cells, and whether the bookkeeping for two sets of keys costs more than the cells it saves.

What this makes readable

Essays that name this one as a prerequisite.

Named alongside this one

Essays reaching for the same objects. Nobody chose these; they are what the concept index makes visible.

What links here

Every essay whose body links to this one.

The objects this essay names

Each one links to every other essay that touches it.

AdmissibilityBidirectional searchCorrectnessCounterexampleDijkstra's algorithmHeuristic searchPotential functionReweightingSearch frontierShortest pathStopping ruleTriangle inequality