Two parameters

A stop that is correct and never sooner

A two-ended search can stop when the two frontiers' keys together reach the best route found, and it can also stop when either frontier's own estimate reaches it alone. Both rules are safe, so a search may use whichever fires first. On forty weighted grids the second never fires: at the moment the first one stops the search, the larger of the two own-keys stands at 64% of the route. The extra rule costs 60% more counted work and a second priority queue to find that out.

Two estimates that must agree ended on a rule it did not build. A search running from both ends with a shared potential stops when the two frontiers’ smallest keys together reach the length of the best route found so far, and that rule is correct because the two keys are lower bounds in one repriced graph. But each search’s own estimate is still a valid lower bound on any route through its own frontier, even when the two cannot be added. So a search could stop on the sum, or on either own-key reaching the route alone, whichever happened first — and the second possibility was left as a measurement.

This page makes it. The rule is correct, it is implemented, and on forty grids the second half of it never once decides anything.

The two rules, stated so they can be checked

Write μ\mu for the length of the best route found so far — a route through some cell both searches have reached — and let the forward search hold distances dfd_f and the backward search dhd_h.

The sum rule. Under the averaged potential both searches are Dijkstra on one repriced graph, so the smallest key in each frontier is a lower bound on how far that frontier can still be extended, and the sum of the two is a lower bound on any route not yet found. When that sum reaches μ\mu, nothing shorter remains.

The averaged potential is what makes that sentence true, and it is not free. Giving each search its own estimate and summing the keys anyway overstates the ground still to cover — the two estimates are about different destinations — and the search can stop too early: on these same forty grids it returns a longer route than the shortest on twelve of them, while expanding 1,002 cells against the averaged potential’s 1,041. Paying 3.8% more cells to be right on all forty is the trade two estimates that must agree settled, and the own-key rule is an attempt to win some of that 3.8% back.

The own-key rule. The forward search’s own estimate gives every open cell vv a value df(v)+hf(v)d_f(v) + h_f(v), which never exceeds the true length of any route through vv. The smallest such value is therefore a lower bound on every route the forward search could still complete. When it reaches μ\mu, the forward search has nothing shorter left — and symmetrically for the backward one.

Both are sound, so a search that stops at whichever fires first returns a shortest route. That is checked rather than assumed: on forty grids the combined rule returns the same length as a one-ended Dijkstra on every one, and a machine that offers the combined rule as an earlier stop is refused by the grids on which it is not.

Mean cells expanded on 40 weighted grids: two A*, averaged potential 1,041, two A*, stop on either key 3,4912 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. two A*, averaged potential: 1,041 on weighted terrain (0 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).steps cost one to ninesteps cost one01,0002,0003,000cells expanded, mean over the gridstwo A*, averaged potentialalways shortestalways shortesttwo A*, stop on either keyalways shortestalways shortest40 grids a bar, 2,500 cellsestimate: straight-line cells
Fig. 1 Mean cells expanded on forty weighted grids of 2,500 cells, for the two-ended search stopped by the sum of the keys and for the same search stopped only when one frontier’s own key reaches the route. The sum rule expands 1,041 cells; the own-key rule alone expands 3,491, three and a third times as many, and both return a shortest route on every grid. On unit-cost terrain, where the straight-line estimate is exact, the two coincide at 469.

That plate is the warning the combined rule is built against. The own-key rule by itself was measured when the shared potential was introduced, and was already known to be slow: 3,491 cells against 1,041. The hope for the combined rule is not that the own-key is generally better, but that it is occasionally earlier — that on some grids one search proves the answer before the two of them jointly do.

The cheapest way to see whether that can happen is to record all three quantities on one grid, at every expansion.

The sum of the two keys reaches the route at expansion 982; the larger of the two searches' own keys is at 224 of 349 when it doesOne weighted grid of 2,500 cells, drawn expansion by expansion. The rising solid line is the sum of the two frontiers' smallest keys, which is the rule that stops the search; the two lower lines are each frontier's own estimate of the whole route, which is what a stop using either key alone would need. The dashed horizontal line is the length of the route found, 349, first seen at expansion 908. The search stops at expansion 982, where the sum is 349, the forward search's own key is 224 and the backward search's is 223 — 64% of what either would have to reach.0921852773700246491737982cells expandedkey valuethe two keys, summedthe route foundforward search's own keybackward search's own keygrid 1, 2,500 cellsthe sum stops it; neither key alone could
Fig. 2 One weighted grid of 2,500 cells, expansion by expansion. The upper solid line is the sum of the two frontiers’ smallest keys; the two lower lines are the forward and backward searches’ own keys. The dashed horizontal line at 349 is the route found, first seen at expansion 908. The search stops at expansion 982, where the sum has reached 349 exactly, the forward search’s own key is 224 and the backward search’s is 223 — 64% of what either would need.

The three lines rise together and stay in the same relation to each other throughout, and the reason is arithmetic rather than accident. Both searches advance into the same terrain at roughly the same rate, so each covers about half the route by the time they meet. Each own-key measures how far its own search has got; the sum measures how far the two of them have got between them. The sum reaches the whole route because the two halves add. Neither half reaches it because neither half is the whole.

The 64% is not 50%, and the gap between those two figures is where the real explanation is. Each own-key is a distance already walked plus an estimate of the distance still to walk, and on this terrain that second part is badly wrong. An estimate borrowed from an easier problem measured why: the straight-line count of cells is admissible on a grid whose steps cost one to nine, because every step costs at least one, and it is nearly useless there, because it believes every step costs one. An own-key therefore charges the walked half at its true price and the unwalked half at about a fifth of it.

That is a testable account rather than a story, because the estimate can be made exact by making every step cost one.

The own-key rule fires on every grid whose estimate is exact and on none whose estimate is weak — and where it fires it fires at the same expansion as the rule it was meant to pre-emptThe larger of the two searches' own keys at the moment the search stopped, as a fraction of the route found, on 40 grids of 2,500 cells under two terrains. With steps costing one to nine the straight-line estimate believes every step costs one: the own-key reaches 0.640 of the route and fires on 0 of 40 grids, at 1040.7 cells. With every step costing one the same estimate is exact: the own-key reaches 1.000 and fires on 40 of 40, at 468.6 cells — the same count as the sum rule alone, 468.6, so nothing stopped earlier.steps cost one to nine(the estimate is weak)0.640 — fired on 0 of 40every step costs one(the estimate is exact)1.000 — fired on 40 of 40what the rule needsown key ÷ route found, at the moment the search stopped40 grids, 2,500 cellsit fires only where it changes nothing
Fig. 3 The larger own-key at the moment the search stopped, as a fraction of the route found, on forty grids under two terrains. With steps costing one to nine the estimate is weak: the own-key reaches 0.640 of the route and fires on none of the forty, at 1,041 cells. With every step costing one the same estimate is exact: the own-key reaches 1.000 and fires on all forty — at 468.6 cells, which is the sum rule’s own count to the tenth, so nothing stopped earlier.

The result is sharper than a negative. On flat terrain the own-key rule fires on every grid and saves nothing, because the two rules become the same rule: when the estimate is exact, a frontier’s own key already accounts for the whole route and reaches μ\mu at precisely the expansion where the two keys’ sum does. On rough terrain the own-key is weakened by the estimate and never fires at all.

So the second half of the combined rule fires exactly where it is redundant and is silent exactly where it would have to help. There is no terrain in between on these maps: the estimate is either exact, in which case the rules coincide, or it is not, in which case one of them is weakened and the other is not. That is the finding, and it is a statement about the relationship between the two rules rather than about forty particular grids.

Forty grids, and the same answer on every one

One grid could be unrepresentative. It is not.

On 20 grids the separate key reaches between 0.62 and 0.66 of the route it would have to certify, and the rule that needs one is never the rule that stops the searchFor each of 20 weighted grids of 2,500 cells, the larger of the two searches' own estimates at the moment the search stopped, divided by the length of the route found. Reaching one is what the separate rule needs to fire; the dashed line is one. Grid 1: 0.642, at 982 cells. Grid 2: 0.632, at 1275 cells. Grid 3: 0.638, at 1091 cells. Grid 4: 0.635, at 1128 cells. Grid 5: 0.645, at 953 cells. Grid 6: 0.648, at 893 cells. Grid 7: 0.636, at 1126 cells. Grid 8: 0.644, at 802 cells. Grid 9: 0.646, at 999 cells. Grid 10: 0.623, at 1234 cells. Grid 11: 0.637, at 1198 cells. Grid 12: 0.633, at 1235 cells. Grid 13: 0.647, at 1008 cells. Grid 14: 0.657, at 1026 cells. Grid 15: 0.641, at 1088 cells. Grid 16: 0.647, at 1099 cells. Grid 17: 0.630, at 1286 cells. Grid 18: 0.663, at 765 cells. Grid 19: 0.638, at 947 cells. Grid 20: 0.628, at 1145 cells.0.000.250.500.751.00gridseparate key ÷ route found1591317how far the separate key gotwhat it would need20 grids, 2,500 cellsone is the stop; nothing reaches it
Fig. 4 For each of twenty weighted grids, the larger of the two searches’ own keys at the moment the search stopped, divided by the length of the route found. The dashed line at one is what the own-key rule would have to reach. The twenty values run from 0.623 to 0.663, on searches expanding between 765 and 1,286 cells.

The band is four hundredths wide. Across forty grids the own-key rule fires on none, and the mean distance from firing is 0.640 — it is not close on the easy grids and far on the hard ones; it is the same distance from firing everywhere. A rule whose margin has that little variance is not a rule that occasionally helps. It is a rule with a structural reason for never helping, and the reason is the one the trace shows: the sum is the sum of two halves and the own-key is one of them.

That is a prediction from an earlier page measured and found wrong in the part that named a mechanism. The proposal was that “on grids where one search’s own estimate proves the answer sooner, the combined rule stops earlier”. No such grid was found, and the plate says why one should not be expected: the quantity that would have to vary between grids — how unevenly the two searches share the route — barely varies at all when they are alternated by key.

The proposal was not careless, and it is worth being precise about which part of it held. Its premise is exactly right: the separate estimates’ keys are valid lower bounds for their own searches even when they cannot be added, and a stop on either of them is sound. That is what makes the combined rule correct, and correctness was never the question. What the premise does not supply is any reason for the two rules to fire in the other order, and the step from “both are sound” to “the disjunction is an improvement” is the step that needed a measurement. A limit is not a prediction is the general form of that gap; here the limit is a stopping condition and the prediction was about when it would bind.

Making it fire, and what that costs

The own-key rule can be made to fire. It requires taking away the thing that stops it: the second frontier’s contribution.

As the two frontiers stop sharing the work the separate key climbs from 0.64 to 1.00 of what it needs — and the search expands 1.68 times as many cells to get it thereMean cells expanded and the larger separate key as a fraction of the route found, over 40 weighted grids of 2,500 cells, as the share of expansions given to the forward search rises from the usual smaller-key rule to all of them. by key: 1040.7 cells, separate key at 0.640 of the route, fired on 0 of 40. 60% forward: 1056.5 cells, separate key at 0.675 of the route, fired on 0 of 40. 70% forward: 1090.1 cells, separate key at 0.714 of the route, fired on 0 of 40. 80% forward: 1169.7 cells, separate key at 0.760 of the route, fired on 0 of 40. 90% forward: 1333.5 cells, separate key at 0.821 of the route, fired on 0 of 40. one-ended: 1745.4 cells, separate key at 1.000 of the route, fired on 40 of 40.0.000.250.500.751.0005001,0001,500by key60% forward70% forward80% forward90% forwardone-endedhow the expansions are sharedcells expandedseparate key ÷ route40 grids, 2,500 cellsdashed: how close the separate key got to firing
Fig. 5 Mean cells expanded, and the larger own-key as a fraction of the route, over forty weighted grids, as the share of expansions given to the forward search rises from the usual smaller-key alternation to all of them. By key: 1,041 cells, own-key at 0.640, fired on none of forty. 70% forward: 1,090 and 0.714. 90% forward: 1,334 and 0.821. One-ended: 1,745 cells, own-key at 1.000, fired on all forty.

The two curves move in step, and they are the same fact twice. Giving the forward search a larger share of the expansions makes its own key a better bound on the whole route, because it is covering more of the route; it also makes the search worse, because a two-ended search is cheaper than a one-ended one for the reason where two searches should stop measured — two frontiers of radius r/2r/2 hold less than one of radius rr. At the far end the forward search is doing everything, the own-key is exactly the stop, and the search expands 1,745 cells where the sum rule expanded 1,041.

So the own-key rule fires precisely when it has been made the only rule available, and the cost of arranging that is 68% more cells. There is no setting of the alternation at which the combined rule is worth having: every step towards making the second rule usable is a larger step away from the search that made it unnecessary.

The two ends of the range, and what is known about the middle

Two cases can be settled without a measurement, and they bracket everything above.

With no estimate at all, both potentials are zero, so a frontier’s own key is the distance already walked and the sum rule’s two keys are the two walked distances. If the forward own-key reaches μ\mu then the sum — that same key plus a second key that cannot be negative — has reached μ\mu too. The sum rule therefore fires no later than the own-key rule, always, on every graph, and the combined rule is exactly the sum rule with extra bookkeeping. That is a proof and not a measurement, and it is why the two-ended Dijkstra where two searches should stop measured has only ever needed the one rule.

With an exact estimate, a frontier’s own key is the true length of the shortest route through that frontier, so it reaches μ\mu at the moment the search has proved the answer — which is the moment the sum reaches μ\mu as well. The two rules coincide, which is what the flat-terrain grids show to the tenth of a cell.

In between, nothing is proved here. A weak estimate weakens each own-key without weakening the sum in the same proportion, and every grid measured on this page has the own-key behind; but “behind on forty grids of one family” is not “behind on every graph”, and no argument above rules out a graph on which one frontier’s estimate is strong, the other’s is weak, and the strong side’s own key arrives first. That graph is what the last section of this page asks for. What can be said is that the two settled cases are the ends of the range and neither of them is a win, so a rule that wins has to be found strictly inside it.

What the second rule costs to have available

The rule that never fires is not free, because the quantity it tests has to be computed.

Under the averaged potential a frontier’s priority queue is ordered by d(v)+p(v)d(v) + p(v), where pp is the shared potential — not by d(v)+h(v)d(v) + h(v), which is what the own-key rule needs. The smallest own-key is therefore not the top of the queue the search already keeps, and finding it means either scanning that queue at every expansion or keeping a second queue ordered the other way. A scan is linear in the frontier at every step; a second queue is what is measured here.

The second set of keys costs 60% more counted work and saves no cell at allMean counted work — relaxation attempts plus priority-queue comparisons — for two stopping rules on 40 weighted grids of 2,500 cells. Both expand 1041 cells a query; the difference is entirely the second heap each direction keeps so that its own estimate can be read. the sum of the two keys: 17,361. either key, whichever first: 27,832.the sum of the two keys17,361either key, whichever first27,832counted work per query, mean40 grids, 2,500 cellssame cells expanded, different bookkeeping
Fig. 6 Mean counted work — relaxation attempts plus priority-queue comparisons — on forty weighted grids, for the search stopped by the sum of the keys and for the same search stopped by either rule. The sum rule costs 17,361; the combined rule costs 27,832, sixty per cent more. Both expand 1,041 cells, so the whole difference is the bookkeeping for a test that never returns true.

Sixty per cent is a large number for a rule that changes nothing, and it is worth seeing where it comes from. Every relaxation that improves a distance pushes the cell onto the search’s queue, and now onto the second queue as well, at a different key; both pushes sift. Every expansion pops stale entries off the second queue before reading its top. The second queue therefore does approximately the same work as the first, and the search’s total heap work roughly doubles, which against the relaxation count gives the sixty per cent.

Reading a second key means holding a second queue, and it reaches the same 46 entries as the firstMean high-water number of entries held, over 40 weighted grids of 2,500 cells, in the larger of the two frontiers' own priority queues and in the larger of the two extra queues kept so that each frontier's own estimate can be read. the frontier's own queue: 45.8. the second queue beside it: 45.7. Every entry in the second queue names a cell the first queue already names, at a different key.the frontier's own queue45.8the second queue beside it45.7entries held at the high-water mark, mean40 grids, 2,500 cellsthe same cells, a second time, at a second key
Fig. 7 Mean high-water entries held on forty weighted grids, in the larger of the two frontiers’ own queues and in the larger of the two second queues: 45.8 and 45.7. Every entry in the second queue names a cell the first already names, at a different key.

The space is the same story in the other currency. Measuring what an algorithm keeps is the argument that this axis has to be counted rather than assumed, and here it doubles the frontier’s storage to hold a second copy of exactly the same cells. A search that scanned the frontier instead would hold nothing extra and would pay the scan at every expansion; neither version is cheap, and both buy the same nothing.

Why an extra correct rule can be a bad rule

There is a habit of reasoning that this result contradicts, and it is worth naming because it is not obviously wrong. Two sound stopping rules can be combined into a third that fires when either does, and the third is sound and never stops later than the better of the two. It looks like a free improvement, in the way that taking the better of two admissible estimates is a free improvement.

It is not free, for two reasons the measurement separates. The first is that “never later” is not “sometimes earlier”: whether the combination gains anything depends entirely on whether the two rules’ firing times are ever in the other order, and that is an empirical question about the searches, not a property of the rules. Here they are never in the other order, and the trace shows a structural reason.

The second is that a rule has to be evaluated to fire, and evaluation is not free when the quantity it tests is not one the algorithm already maintains. An estimate is a reweighting is why the two quantities differ at all: choosing the averaged potential is choosing which key the queue is ordered by, and the own-key is then a quantity about a different ordering of the same cells. A combined rule looks like a disjunction of two tests and is in fact a disjunction of one test and a second data structure.

The same shape appears wherever a guard is added for a case that does not arise. The depth limit that almost never fires measured a guard in real sorting code that fires on almost no input and is worth having anyway, because what it costs to have available is a comparison against a counter the algorithm already keeps. The difference between that guard and this one is not how often each fires; it is what each costs to be able to ask.

What is not measured here

One family of maps, two estimates of one kind. Every grid is 50 × 50 with 28% of cells removed, and both terrains use the straight-line count in both directions. A map on which the forward and backward estimates differ sharply in quality — a hierarchy, where one direction is guided well and the other badly — would unbalance the two searches without unbalancing their alternation, and is the case most likely to make the own-key rule fire. It is not drawn here.

Estimates that are exact or hopeless, and nothing between. The terrain plate compares a weak estimate with an exact one. A landmark estimate on weighted terrain sits between them, and where the landmarks stand measured how far between: four tables cut a search on these grids by a factor of six without making the estimate exact. Where an own-key stalls under an estimate of that intermediate quality is not measured, though the two points here bracket it.

Corner-to-corner queries. Source and goal are the two far corners of every grid, so the two searches face terrain of similar difficulty by construction. The 0.640 figure is a statement about that arrangement.

One alternation family. The sweep takes a fixed share of expansions forward. A rule that alternated on some other quantity — the frontier sizes, the keys’ rate of increase — might produce imbalance where this one produces only waste, and nothing here rules that out.

The second queue, not a frontier scan. The 60% is the cost of one implementation of the test. A scan of the frontier at each expansion would move the cost from heap work to a linear pass and would be cheaper on small frontiers and dearer on large ones; the frontier here reaches 46 entries, so a scan would probably cost less. It would still be paid at every expansion for a test that never returns true.

Still open: an estimate that is good in one direction only

The plate that made the own-key rule fire did it by unbalancing the work, which made the search worse at the same time. There is a way to unbalance the two searches that does not: give them estimates of different quality. A forward search guided by landmark tables and a backward search guided by the straight-line count cover very different shares of the route for the same number of expansions, and the well-guided one’s own key should then be a much better bound on the whole route than half of it.

The measurement that follows runs the two ends with estimates of deliberately different strength — landmark tables one way, straight-line the other, and a sweep of how many landmark tables the strong side gets — and asks whether the own-key rule ever fires then, by how many cells it stops the search early when it does, and whether the asymmetry costs more in expansions than the early stop saves. That is the one arrangement on which an extra correct rule could pay for its own bookkeeping, and neither plate here reaches it.

Named alongside this one

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

The objects this essay names

Each one links to every other essay that touches it.

AdmissibilityBidirectional searchBookkeepingHeuristic searchLower boundPotential functionPriority queueSearch frontierShortest pathSpace time tradeStopping rule