Make the budget test spend the budget, and bound the probes that earn nothing

The fixture built for "exactly MAX_VISITED stars reachable" was 338 short: its
random cloud leaves clumps the departure never reaches (the LCG gives 12 212
distinct positions for 39 999 stars), so the search settled 39 662 and the
pre-fix code answered `gaveUp: false` too. The test could not fail on the code
it was written to pin — and the mutant that seemed to prove otherwise was
failing to compile, not failing the test. It is now a line of 40 000 a parsec
apart with the island off the line: settled 40 000 exactly, 115 ms, and the
pre-fix code does report a give-up. Both mutants now compile and are caught.

The give-up cap also has to hold while the bisection has earned nothing: the
exception added for that case had no bound at all, so a search could spend the
resolution's own eight full-budget probes — about 17 s of "Plotting…" — where
two used to cost 4 s. Bounded at five. On the repo's crowded-knot fixture:
1.9 s for the unearned ceiling figure with the old cap, 7.2 s for a range the
bisection earned, and five probes is where that lands.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_016jxMkwA2rbicdGxHosecYi
This commit is contained in:
2026-09-18 15:51:38 +02:00
co-authored by Claude Opus 5
parent 1a53f26474
commit 337602f606
2 changed files with 26 additions and 16 deletions
+16 -8
View File
@@ -65,15 +65,21 @@ const MAX_VISITED = 40000;
const RANGE_RESOLUTION_PC = 0.05;
/**
* How many of `minimumRangeBetween`'s probes may give up before it answers with what it has.
* How many of `minimumRangeBetween`'s probes may give up, once it has a range of its own, before it
* answers with what it has — and how many before it has one.
*
* A probe that finds a route is quick — it heads straight for the destination — while one that
* gives up walks the whole search budget, about two seconds on the real catalogue. Those are also
* the probes that buy the least: they cannot rule anything out. Two of them is the difference
* between an answer of 7.96 pc in half a second and 5.76 pc in seventeen, for a star at 236 pc; it
* lands on 5.97 pc in five.
*
* Until a probe succeeds there is nothing to answer with but the ceiling route's own longest hop,
* which is the control's maximum, so the bound is looser there — but a bound, since the search is
* one the panel waits on: five probes, ten seconds, rather than the resolution's own eight.
*/
const MAX_RANGE_GIVE_UPS = 2;
const MAX_UNEARNED_GIVE_UPS = 5;
/** A binary min-heap of star ids by priority. Duplicates are allowed; stale ones are skipped on the way out. */
class Frontier {
@@ -243,9 +249,10 @@ export function routeBetween(index: StarNeighbourhood, fromId: number, toId: num
* nothing. It is still worth carrying on from — the ranges above it are the ones left to try — but
* the result is no longer the least range, only a range that works, and `least` says which. The
* number of steps that may give up is bounded for the same reason: each one walks the whole budget,
* and 11 s of them for a star at 236 pc bought two decimal places nobody reads. Bounded, but not
* before the bisection has found a range of its own: until then the only range it could offer is
* the ceiling's, which is the control's maximum, for crossings that work well below it.
* and 11 s of them for a star at 236 pc bought two decimal places nobody reads. Bounded more
* loosely before the bisection has found a range of its own, since until then the only range it
* could offer is the ceiling's, which is the control's maximum, for crossings that work well below
* it. See {@link MAX_RANGE_GIVE_UPS}.
*/
export function minimumRangeBetween(index: StarNeighbourhood, fromId: number, toId: number, ceilingPc: number): RangeSearch {
const widest = routeBetween(index, fromId, toId, ceilingPc);
@@ -256,10 +263,11 @@ export function minimumRangeBetween(index: StarNeighbourhood, fromId: number, to
let unreachable = 0;
let reachable = ceilingHopPc;
let giveUps = 0;
// The cap cannot fire while `reachable` is still the ceiling route's own longest hop: that is
// the question, not an answer the bisection earned, and offering it sends the control to its
// maximum for a crossing that works well below — 8.00 pc for a star that routes at 6.
while (reachable - unreachable > RANGE_RESOLUTION_PC && (giveUps < MAX_RANGE_GIVE_UPS || reachable === ceilingHopPc)) {
// While `reachable` is still the ceiling route's own longest hop the bisection has nothing of its
// own to answer with, and that figure sends the control to its maximum for a crossing that works
// well below — 8.00 pc for a star that routes at 6. So it is allowed more probes there, not
// unlimited ones: the panel is waiting on this.
while (reachable - unreachable > RANGE_RESOLUTION_PC && giveUps < (reachable === ceilingHopPc ? MAX_UNEARNED_GIVE_UPS : MAX_RANGE_GIVE_UPS)) {
const range = (unreachable + reachable) / 2;
const { route, gaveUp } = routeBetween(index, fromId, toId, range);
if (route) {