Routing core made once, list orders kept, and Auto-TE's detour searches cut: same routing, much less work

The game plays exactly as before.

* The core of compute() (rankPass, directPass, sendGroup, send, push, carry, altPath) is ROUTE in 29-route-core.js,
  built once by routeCore(): made inside compute() they were new functions every call and V8 threw away their code.
  Exits are read by number from typed columns (USED, CAPX, CIX, HPX, VISX), each list is an object of one shape.
* The route cache keeps, for each list and source city, the order routing tries it (xOrder()); a list whose exits,
  cities and preferences are unchanged on the same graph keeps its orders when other exits change (rcExitKeep()).
* Auto-TE: pairs with no detour are marked (TEF), exits that cannot help are skipped (dud()), one failed search
  answers the next ones, dijkstraTo() searches in arrays kept between calls, teSearch() runs on the graph as flat
  arrays and picks up where the last search from the same POP stopped.
* The PNI/IX tie-break (#298) reaches the core.

Tests: route-cache, routing-reference, speed (the fast core against the plain path, Auto-TE on crowded meshes with
POPs outside the core, picked-up searches counted).
This commit is contained in:
Antoine 2026-11-07 22:21:23 +01:00
parent d03dde6fcd
commit 1edf0abb54
No known key found for this signature in database
GPG key ID: 728FF1CE15732B05
10 changed files with 409 additions and 159 deletions

View file

@ -86,3 +86,45 @@ test('days in a row reuse the kept tables and route like a fresh start every day
}
assert.deepEqual(errors, []);
});
test('with Auto-TE, kept orders and the no-detour marks route like a fresh start every day', () => {
// The routing core (29-route-core.js) keeps each list's order for each city with the tables, and Auto-TE marks the
// pairs with no detour: both have to give exactly what scanning and searching afresh give. The network is made busy
// (half its link capacity) so that flows spill, detours are searched and many fail.
const { ev, errors } = open();
ev("S.core.run=2;S.te={on:true,day:S.day,script:'spill at 85%'};for(const b of S.biz)if(BIZ_T[b.type].l2&&b.city2)b.route='scenic';for(const l of S.links)if(l.kind==='wave')l.cap=(l.cap||0)/2;compute();compute();");
assert.equal(ev('!!(S.te.on&&coreTE())'), true);
let tried = 0;
for (let d = 0; d < 4; d++) {
ev('dayTick()');
const r = step(ev, '');
assert.ok(r.same, `day ${d}: the same routing with and without the kept tables`);
assert.ok(!r.g && !r.x, `day ${d}: a day of demand only keeps the tables`);
tried = Math.max(tried, ev('R.teMoved'));
}
assert.ok(tried > 0, 'Auto-TE moved traffic onto detours');
assert.deepEqual(errors, []);
});
// When the exits change but the graph does not (a network leaves an exchange because its PNI came up), the lists that
// did not change keep the orders routing worked out for them (the same arrays, used the same day), the ones that did
// start again, and routing is still exactly routing without the kept tables, day after day.
test('lists an exit change leaves alone keep their orders; routing stays the same as without the kept tables', () => {
const { ev, errors } = open();
// Two days on the kept build: the lists get their orders.
ev('compute();compute();');
ev('window.__ords=new Set(RC.x.lists.flatMap(d=>d.cs?d.ord.filter(Boolean):[d.ord]).filter(o=>Object.keys(o).length));');
assert.ok(ev('__ords.size') > 5, `orders worked out: ${ev('__ords.size')}`);
// One network leaves one exchange: the exits key moves, the graph does not.
const r = step(ev, `(()=>{const ix=Object.keys(S.ixp).find(x=>ixSessions(x).size>3),n=[...ixSessions(ix)][0];window.__left=n+'@'+ix;
S.peers[n+'@'+ix]=false;delete S.peers[n+'@'+ix];S.rs[ix]=false;S.pni.push({id:'pk1',net:n,city:ixCity(ix),tier:1,n:1});})()`);
assert.equal(r.g, false, 'same graph');
assert.equal(r.x, true, 'the exits changed');
assert.equal(r.same, true, 'the same routing as without the kept tables');
const kept = ev('RC.x.lists.flatMap(d=>d.cs?d.ord.filter(Boolean):[d.ord]).filter(o=>__ords.has(o)).length');
const all = ev('RC.x.lists.length');
assert.ok(kept > 0 && kept < ev('__ords.size') + 1, `lists that kept their orders: ${kept} of ${all}`);
// And a few more days, with the next change between them.
for (let d = 0; d < 3; d++) assert.equal(step(ev, 'for(const c in S.pops)if(S.pops[c].bb)S.pops[c].bb.d*=1.03').same, true, `day ${d + 1} after`);
assert.deepEqual(errors, []);
});