feat(08-02): implement the pure landmark compute core — L-suite GREEN
farthestPointAnchors + landmarkTables + landmarkCoverage over the ĉ metric: edge weights floor-quantized once (Math.floor(seconds/q)), exact integer Dijkstras (Int32 labels, binary heap, lazy deletion), 0xFFFF sentinel, 65000-quantum loud overflow. Traversal law mirrors astar.ts verbatim: bit0 edges never relaxed in EITHER direction. Test-vector corrections caught at GREEN (expectations were wrong, implementation was right): - L4: rows index by anchor POSITION (row-major [l*N+v]), not node id - L6: the c-metric farthest node from corner 0 is interior node 18 (297q: interior hops cost 2x perimeter), not corner 24 (264q) — verified against an independent brute-force Dijkstra
This commit is contained in:
@@ -22,8 +22,8 @@
|
||||
* L4 asymmetry — to/from rows differ on a oneway graph
|
||||
* L5 overflow throws — any label > 65000 quanta throws, naming the
|
||||
* distance and the fix (raise landmarkQuantumS)
|
||||
* L6 5x5 grid shape — anchors [0, 24]; corner->corner 264 quanta
|
||||
* (8 perimeter hops x 33); coverage 1.0
|
||||
* L6 5x5 grid shape — anchors [0, 18] (interior node 18 is the ĉ
|
||||
* farthest at 297 quanta); coverage 1.0
|
||||
*
|
||||
* Run: npm run routing:test (exit 0 = all green)
|
||||
*/
|
||||
@@ -160,11 +160,13 @@ test("L3 sentinel + self-cell — unreachable pairs -> 0xFFFF; the landmark's ow
|
||||
test("L4 asymmetry — reversed vs forward rows differ on an oneway graph", async () => {
|
||||
const { landmarkTables } = await loadLandmark();
|
||||
const { to, from } = landmarkTables(onewayInput(), Uint32Array.of(1));
|
||||
// Anchor at the middle node 1: forward reaches 2 (15 quanta) but the
|
||||
// to-row for 2 is the sentinel (2 cannot get back to 1).
|
||||
assert.equal(from[1 * 4 + 2], 15, "1->2 traverses");
|
||||
assert.equal(to[1 * 4 + 2], 0xffff, "2->1 does not (oneway) — asymmetry is representable");
|
||||
assert.notEqual(to[1 * 4 + 2], from[1 * 4 + 2]);
|
||||
// Rows are indexed by anchor POSITION (row-major [ℓ*N+v], ℓ = 0 here),
|
||||
// not by the anchor's node id. Anchor at the middle node 1: forward
|
||||
// reaches 2 (15 quanta) but the to-row for 2 is the sentinel (2 cannot
|
||||
// get back to 1).
|
||||
assert.equal(from[0 * 4 + 2], 15, "1->2 traverses");
|
||||
assert.equal(to[0 * 4 + 2], 0xffff, "2->1 does not (oneway) — asymmetry is representable");
|
||||
assert.notEqual(to[0 * 4 + 2], from[0 * 4 + 2]);
|
||||
});
|
||||
|
||||
test("L5 overflow throws — any label > 65000 quanta fails loud, naming the fix", async () => {
|
||||
@@ -195,19 +197,21 @@ test("L5 overflow throws — any label > 65000 quanta fails loud, naming the fix
|
||||
);
|
||||
});
|
||||
|
||||
test("L6 5x5 grid shape — anchors [0,24]; corner->corner 264 quanta; coverage 1.0", async () => {
|
||||
test("L6 5x5 grid shape — anchors [0,18]; farthest 297 quanta; coverage 1.0", async () => {
|
||||
const { farthestPointAnchors, landmarkTables, landmarkCoverage } = await loadLandmark();
|
||||
const input = await gridInput();
|
||||
const anchors = farthestPointAnchors(input, 2);
|
||||
assert.deepEqual([...anchors], [0, 24], "first candidate is node 0; farthest is the opposite corner");
|
||||
// Farthest-point over the ĉ metric: interior hops cost 66 quanta (2x the
|
||||
// perimeter's 33), so the farthest node from corner 0 is the INTERIOR
|
||||
// node 18 at 297 quanta — NOT the opposite corner 24 (264). Verified
|
||||
// against an independent brute-force Dijkstra (297 unique max).
|
||||
assert.deepEqual([...anchors], [0, 18], "first candidate is node 0; farthest is node 18");
|
||||
const { to, from } = landmarkTables(input, anchors);
|
||||
assert.equal(to.length, 2 * 25, "L*N cells (L=2, N=25)");
|
||||
assert.equal(to[0 * 25 + 0], 0, "self-cell 0");
|
||||
assert.equal(from[1 * 25 + 24], 0, "anchor 24's own from-cell 0");
|
||||
// Corner->corner: 8 perimeter hops (row 0 then column 4, 33 quanta each;
|
||||
// interior hops cost 66 — strictly worse) = 264 exactly.
|
||||
assert.equal(from[0 * 25 + 24], 264, "0->24 = 8 x 33 perimeter quanta, exact");
|
||||
assert.equal(to[1 * 25 + 0], 264, "the to-row mirrors on the grid");
|
||||
assert.equal(from[1 * 25 + 18], 0, "anchor 18's own from-cell 0 (row = position 1)");
|
||||
assert.equal(from[0 * 25 + 18], 297, "0->18 = 3 perimeter + 3 interior hops = 99+198, exact");
|
||||
assert.equal(to[1 * 25 + 0], 297, "the to-row mirrors on the grid");
|
||||
const coverage = landmarkCoverage(to, anchors, 25);
|
||||
assert.deepEqual(coverage, [1, 1], "the grid is strongly connected — full coverage");
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user