From e46c91ab331973aee8415a2b1de8f5e12783a1ca Mon Sep 17 00:00:00 2001 From: llols Date: Tue, 10 Nov 2026 18:42:29 +0000 Subject: [PATCH] fix: stop unchanged empty single-route retries --- lib/core.ts | 15 ++++++++++++++- .../__snapshots__/h3-solo-exhaustion.snap.svg | 2 +- tests/solver/h3-solo-exhaustion.test.ts | 2 ++ 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/lib/core.ts b/lib/core.ts index e1b07ea..b0cf9e6 100644 --- a/lib/core.ts +++ b/lib/core.ts @@ -1919,11 +1919,24 @@ export class TinyHyperGraphSolver extends BaseSolver { }) } - onOutOfCandidates() { + onOutOfCandidates(): void { const { topology, state } = this const currentRouteId = state.currentRouteId const maxRegionCostBeforeRip = this.getMaxRegionCost() + // An empty single-route search has nothing to move out of its way. + if ( + this.problem.routeCount === 1 && + !this.problem.initialAssignments?.length && + maxRegionCostBeforeRip === 0 && + state.portAssignment.every((netId) => netId === -1) && + state.regionSegments.every((segments) => segments.length === 0) + ) { + this.failed = true + this.error = `No path for ${this.getRouteConnectionId(0)}` + return + } + for (let regionId = 0; regionId < topology.regionCount; regionId++) { const regionCost = state.regionIntersectionCaches[regionId]?.existingRegionCost ?? 0 diff --git a/tests/solver/__snapshots__/h3-solo-exhaustion.snap.svg b/tests/solver/__snapshots__/h3-solo-exhaustion.snap.svg index 44f6043..8afcdb8 100644 --- a/tests/solver/__snapshots__/h3-solo-exhaustion.snap.svg +++ b/tests/solver/__snapshots__/h3-solo-exhaustion.snap.svg @@ -88,7 +88,7 @@ bottom" data-x="-4.448000000000001" data-y="-1.4679999999999997" x="256.39138855 bottom" data-x="9.119" data-y="3.4790000000000005" x="489.576227762136" y="312.30895659151713" width="7.734442223179485" height="7.734442223179485" fill="rgba(255,0,0,0.75)" stroke="black" stroke-width="0.05818131249999998"/>H3 SDQS1_N: 2000000 iterations; 49 unchanged retriesTinyHyperGraphSolver ran out of iterationsH3 SDQS1_N: 40278 iterations; 0 unchanged retriesNo path for source_trace_46 expect(solver.solved).toBe(false) expect(solver.failed).toBe(true) + expect(solver.iterations).toBeLessThan(solver.MAX_ITERATIONS) + expect(solver.state.ripCount).toBe(0) const left = Math.min( ...graphics.rects!.map((rect) => rect.center.x - rect.width / 2), )