Answer the review: say which search gave up, and let the bisection earn its offer

The panel printed "No route at this range." beside the range it was offering —
which is the sentence this branch exists to stop it printing. It was gated on
there being no offer, and a search that gives up usually has one: Sol to
HD 120147 at 4.5 pc spends the budget, offers 4.83 pc, and says there is no
route where a 71-jump route exists. The wording now follows the search at the
range that was asked for, and nothing else.

That needs the two give-ups kept apart, so `least` travels beside `gaveUp` to
the panel: one says the asked range was not searched out, the other that the
search for a range that would work was. HIP 69445 at 3 pc — asked-range search
exhaustive in 44 ms, ceiling probe out of budget — used to read "Too many stars
to search at this range." and now reads "No route at this range.", with nothing
claimed after it.

Two more from the same review. The budget flag was read off the settled count,
so a search that proved a dead end with the last star it was allowed reported a
give-up; it now records why the loop stopped. And the bisection's cap could fire
before a single probe had narrowed anything, leaving the ceiling route's own
longest hop as the answer: star 1000115173 at 3 pc was told to go to 8.00 pc,
the control's maximum, for a crossing that works at 6. It now offers 6.93.

Measured in the app, all three: "Too many stars to search at this range.
4.90 pc would reach.", "No route at this range." alone, and 7.00 pc in place of
8.00. The duplicated dead-end test now asks the question it was named for —
exactly the budget's worth of stars reaching each other and none of them the
destination — and each fix kills its own mutant.

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 14:46:47 +02:00
co-authored by Claude Opus 5
parent 7ab92e61a1
commit 1a53f26474
10 changed files with 98 additions and 47 deletions
+22 -7
View File
@@ -94,14 +94,13 @@ describe('routeBetween', () => {
expect(search.gaveUp).toBe(true);
});
it('reports a genuine dead end as one, having looked everywhere the range reaches', () => {
const split = index([
{ id: 0, x: 0, y: 0, z: 0 },
{ id: 1, x: 1, y: 0, z: 0 },
{ id: 2, x: 20, y: 0, z: 0 }
]);
it('reports a dead end proved with the last star of the budget as a dead end, not a give-up', { timeout: 30_000 }, () => {
// Exactly the budget's worth of stars reach each other, and the destination is not among them.
// The search does look everywhere the range reaches, so "no chain" is what it found — but the
// set is full at the end of it, and a budget read off the settled count says it gave up.
const search = routeBetween(budgetExactly(), 0, BUDGET_ISLAND, 1.5);
expect(routeBetween(split, 0, 2, 5)).toEqual({ route: null, gaveUp: false });
expect(search).toEqual({ route: null, gaveUp: false });
});
it('heads for the destination rather than exhausting a dense knot around the departure', () => {
@@ -131,6 +130,19 @@ function knotAndChain(cellSizePc?: number): StarNeighbourhood {
return new StarNeighbourhood([{ id: 0, x: 0, y: 0, z: 0 }, ...knot, ...chainOut, { id: ISLAND, x: 500, y: 0, z: 0 }], cellSizePc);
}
/**
* Exactly a search's budget of stars that reach one another — 39 999 through the 30 pc cube around
* the origin, plus the departure — and one at 500 pc that nothing reaches. The dead end is real and
* the search proves it, with the last star it is allowed.
*/
const BUDGET_ISLAND = 99_999;
function budgetExactly(): StarNeighbourhood {
let seed = 13;
const random = () => ((seed = (seed * 1103515245 + 12345) % 2147483648) / 2147483648) * 30 - 15;
const crowd: StarPoint[] = Array.from({ length: 39_999 }, (_, i) => ({ id: 1000 + i, x: random(), y: random(), z: random() }));
return new StarNeighbourhood([{ id: 0, x: 0, y: 0, z: 0 }, ...crowd, { id: BUDGET_ISLAND, x: 500, y: 0, z: 0 }], 1.5);
}
/**
* 45 000 stars in a 10 pc cube — dense enough to stay one connected piece at half a parsec, where
* walking it costs more than a search's budget — with a chain a parsec a hop leaving its edge for
@@ -166,6 +178,9 @@ describe('minimumRangeBetween', () => {
expect(needed.least).toBe(false);
expect(needed.rangePc).not.toBeNull();
expect(routeBetween(knot, 0, CROWD_CHAIN_END, needed.rangePc!).route).not.toBeNull();
// Narrower than the ceiling's own route, too: stopping before the bisection has found a range
// of its own hands back the ceiling, which is the control's maximum — the question, not an answer.
expect(needed.rangePc!).toBeLessThan(routeBetween(knot, 0, CROWD_CHAIN_END, 1.2).route!.longestHopPc);
});
it('names the shortest range that opens a way through', () => {
+19 -6
View File
@@ -180,11 +180,18 @@ export function routeBetween(index: StarNeighbourhood, fromId: number, toId: num
const frontier = new Frontier();
frontier.push(fromId, straightLineOn(origin.x, origin.y, origin.z));
while (frontier.size > 0 && settled.size < MAX_VISITED) {
let gaveUp = false;
while (frontier.size > 0) {
const starId = frontier.pop();
if (settled.has(starId)) {
continue;
}
// Counted against the budget only once the frontier has been drained of stale duplicates, so
// the flag below records why the search stopped rather than how full the set happened to be.
if (settled.size >= MAX_VISITED) {
gaveUp = true;
break;
}
settled.add(starId);
const costHere = travelled.get(starId)!;
@@ -216,7 +223,7 @@ export function routeBetween(index: StarNeighbourhood, fromId: number, toId: num
// An empty frontier means the range reaches nothing further; a spent budget means only that the
// search stopped looking.
return { route: null, gaveUp: settled.size >= MAX_VISITED };
return { route: null, gaveUp };
}
/**
@@ -235,18 +242,24 @@ export function routeBetween(index: StarNeighbourhood, fromId: number, toId: num
* Each step has to answer "is there a chain at this range", and a search that gives up answers
* 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 is bounded for the same reason: each one that gives up walks the whole budget,
* and 11 s of them for a star at 236 pc bought two decimal places nobody reads.
* 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.
*/
export function minimumRangeBetween(index: StarNeighbourhood, fromId: number, toId: number, ceilingPc: number): RangeSearch {
const widest = routeBetween(index, fromId, toId, ceilingPc);
if (!widest.route) {
return { rangePc: null, least: !widest.gaveUp };
}
const ceilingHopPc = widest.route.longestHopPc;
let unreachable = 0;
let reachable = widest.route.longestHopPc;
let reachable = ceilingHopPc;
let giveUps = 0;
while (reachable - unreachable > RANGE_RESOLUTION_PC && giveUps < MAX_RANGE_GIVE_UPS) {
// 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)) {
const range = (unreachable + reachable) / 2;
const { route, gaveUp } = routeBetween(index, fromId, toId, range);
if (route) {
+2 -2
View File
@@ -42,13 +42,13 @@ describe('answerRouting', () => {
it('answers a route the range allows, with nothing to raise it to', () => {
const answer = answerRouting(index, { kind: 'route', requestId: 7, fromId: 10, toId: 14, rangePc: 1.5, ceilingPc: 8 });
expect(answer).toEqual({ kind: 'route', requestId: 7, route: routeBetween(direct, 10, 14, 1.5).route, neededRangePc: null, gaveUp: false });
expect(answer).toEqual({ kind: 'route', requestId: 7, route: routeBetween(direct, 10, 14, 1.5).route, neededRangePc: null, gaveUp: false, least: true });
});
it('answers a route the range does not allow with the range that would', () => {
const answer = answerRouting(index, { kind: 'route', requestId: 8, fromId: 10, toId: 99, rangePc: 1.5, ceilingPc: 8 });
expect(answer).toEqual({ kind: 'route', requestId: 8, route: null, neededRangePc: minimumRangeBetween(direct, 10, 99, 8).rangePc, gaveUp: false });
expect(answer).toEqual({ kind: 'route', requestId: 8, route: null, neededRangePc: minimumRangeBetween(direct, 10, 99, 8).rangePc, gaveUp: false, least: true });
expect(answer.kind === 'route' && answer.neededRangePc).toBeCloseTo(5, 1);
});
+16 -5
View File
@@ -27,10 +27,20 @@ export type RoutingRequest =
export type RoutingResponse =
/**
* `gaveUp` is true when the searches spent their budget rather than looking everywhere: there
* being no route and no range to offer is then what was found, not what exists.
* Two searches, and two things they can fail to prove, kept apart because they are printed as
* different sentences. `gaveUp` is about the range that was asked for: true when that search
* spent its budget rather than looking everywhere the range reaches. `least` is about the search
* for a range that would work: true when it looked everywhere up to the ceiling, so `null` there
* means no chain exists rather than none was found.
*/
| { readonly kind: 'route'; readonly requestId: number; readonly route: Route | null; readonly neededRangePc: number | null; readonly gaveUp: boolean }
| {
readonly kind: 'route';
readonly requestId: number;
readonly route: Route | null;
readonly neededRangePc: number | null;
readonly gaveUp: boolean;
readonly least: boolean;
}
| { readonly kind: 'links'; readonly requestId: number; readonly segments: Float32Array }
/** The question threw in the worker. Sent back so the request settles instead of waiting for good. */
| { readonly kind: 'failed'; readonly requestId: number; readonly message: string };
@@ -56,8 +66,9 @@ export function answerRouting(index: StarNeighbourhood, request: RoutingRequest)
// At the ceiling the question has just been asked: the range search would repeat it, identically
// and at the same cost, before bisecting below it.
if (route || request.rangePc >= request.ceilingPc) {
return { kind: 'route', requestId: request.requestId, route, neededRangePc: null, gaveUp: !route && gaveUp };
// Asked at the ceiling, the one search answers both questions.
return { kind: 'route', requestId: request.requestId, route, neededRangePc: null, gaveUp: !route && gaveUp, least: !gaveUp };
}
const needed = minimumRangeBetween(index, request.fromId, request.toId, request.ceilingPc);
return { kind: 'route', requestId: request.requestId, route: null, neededRangePc: needed.rangePc, gaveUp: gaveUp || !needed.least };
return { kind: 'route', requestId: request.requestId, route: null, neededRangePc: needed.rangePc, gaveUp, least: needed.least };
}