diff --git a/CHANGELOG.md b/CHANGELOG.md index 19b30dd..4a94607 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ All notable changes to this project are documented here. The project follows ## [Unreleased] +- Big networks are snappier again: working out each day's traffic takes about a quarter less time in the browser, so game days and clicks pause for less on phones. Traffic goes exactly where it went before. - Your own subsea cable can no longer be longer than any optic can light (#88). New York to Sydney now says so before you pay, instead of after the ship comes home. Calling off a cable while it is still being laid returns most of the price of the part not laid yet, and an unusable cable from an older save goes back for a full refund. - Your own IX can now live in either building of a two-site metro, or in both with a second switch, so a dark building no longer takes your exchange down (#36). The LAG buttons that did nothing on your own IX are gone. - Upgrading the only router in a POP that has nothing plugged in yet no longer opens a maintenance window or a NOC warning (#105). diff --git a/site/index.html b/site/index.html index a06c35e..794db86 100644 --- a/site/index.html +++ b/site/index.html @@ -2001,9 +2001,12 @@ function compute(){ let f=null,Dv=null,Pv=null,PP=null,vis=0;const walked=[],G=[],NEG=[]; // An exit the flow can still try: not visited yet, not full when the flow started, and reachable from the POP. const usable=e=>e.vis!==vis&&e.useda.hp-b.hp||Dv[a.ci]-Dv[b.ci]; - // Push up to `want` along one path to exit e; returns what fitted. - const push=(e,P,want,keep=0)=>{const path=P.path,ni=P.ni;let amt=want; - for(const l of path)amt=Math.min(amt,l.res-l.cap*keep);for(const i of ni)if(HAS[i])amt=Math.min(amt,NRES[i]); + // Push up to `want` along one path to exit e; returns what fitted. Capacity only shrinks while routing, so a + // path with one full link or node fits nothing for the rest of this pass: mark it, and later tries cost nothing + // (most tries are into paths that filled up earlier). + const push=(e,P,want,keep=0)=>{if(P.dead)return 0;const path=P.path,ni=P.ni;let amt=want; + for(const l of path){const r=l.res;if(r<=1e-6){P.dead=1;return 0;}amt=Math.min(amt,r-l.cap*keep);} + for(const i of ni)if(HAS[i]){const r=NRES[i];if(r<=1e-6){P.dead=1;return 0;}amt=Math.min(amt,r);} if(amt<=1e-6)return 0; for(const i of ni)if(HAS[i])nodeTake(i,amt); const ek=e.ek,nr=f.nr,ci=f.ci;if(!e.told||e.dup){R2.egDesc[ek]=e.desc;e.told=true;} @@ -2040,9 +2043,15 @@ function compute(){ G.length=0; if(!lst.hi&&ALONE[f.ci]){const here=lst.at.get(f.ci);if(here)for(const e of here)if(e.used=e.cap){full++;continue;}const d=Dv[e.ci];if(d===Infinity)continue;const h=e.hp; + if(h=lst.length&&full){let k=0;for(const e of lst)if(e.used1)continue; - for(const e of lst)if(e.hp===bh&&e.used1)G.sort(byDist);} sendGroup(G); if(f.rem<=1e-6)continue; diff --git a/tests/speed.test.js b/tests/speed.test.js index 8469c3e..8475e52 100644 --- a/tests/speed.test.js +++ b/tests/speed.test.js @@ -219,18 +219,21 @@ test('the map is not drawn while the dashboard covers the whole screen', () => { }); // #89's fast paths must route exactly like the plain path. This builds a copy of compute() with every shortcut -// turned off (the POP's-own-exits shortcut, the first-group scan and the per-network exit index) and compares the -// two on a busy network, so it keeps holding when the game's numbers change. +// turned off (the POP's-own-exits shortcut, the first-group scan with its list clean-up, the per-network exit index +// and the full-path mark in push) and compares the two on a busy network, with Auto-TE and then with a RouteScript +// that keeps headroom on every link, so it keeps holding when the game's numbers change. test('fast routing gives exactly the same result as the plain path it replaces', () => { const { ev, errors } = load(); const src = ev('compute.toString()'); const plain = src .replace('if(!lst.hi&&ALONE[f.ci])', 'if(false)') - .replace('if(!G.length){\n let bh=2', 'if(false){\n let bh=2') - .replace('for(const n of e.nets||NET_IDS)', 'for(const n of NET_IDS)'); + .replace('if(!G.length){\n // One scan', 'if(false){\n // One scan') + .replace('for(const n of e.nets||NET_IDS)', 'for(const n of NET_IDS)') + .replace('if(P.dead)return 0;', '').replaceAll('if(r<=1e-6){P.dead=1;return 0;}', ''); for (const [a, b] of [[src, plain]]) assert.notEqual(a, b); assert.equal((plain.match(/if\(false\)/g) || []).length, 2, 'both shortcuts were found and switched off'); assert.ok(!plain.includes('e.nets||NET_IDS'), 'the exit index was switched off'); + assert.ok(!plain.includes('P.dead'), 'the full-path mark was switched off'); ev('window.__plain=' + plain.replace(/^function compute/, 'function')); ev(`ACT.start({});S.cash=1e12;S.lvl=13;S.won=true;for(const g of GOALS)S.done[g.id]=0;ACT.launchBB({city:'fra'}); const cs=ALLC.filter(c=>!CITY[c].cn).slice(0,40);for(const c of cs){if(!S.pops[c])ACT.buildPop({city:c});S.pops[c].rgen=10;S.pops[c].routers=4;if(!S.pops[c].bb)ACT.launchBB({city:c});S.pops[c].bb.d=CITY[c].P*0.7;} @@ -245,7 +248,10 @@ test('fast routing gives exactly the same result as the plain path it replaces', const sig = () => ev(`JSON.stringify({served:R.served,demand:R.demand,reach:R.reach,peered:R.peered,teMoved:R.teMoved,egT:R.egT, srv:Object.keys(R.citySrv).sort().map(c=>[c,R.citySrv[c]]),load:S.links.map(l=>R.load[l.id]||0),node:Object.keys(R.nodeLoad).sort().map(c=>[c,R.nodeLoad[c]]), t:Object.keys(R.useT).sort().map(k=>[k,R.useT[k]]),p:Object.keys(R.usePni).sort().map(k=>[k,R.usePni[k]]),ix:Object.keys(R.useIx).sort().map(k=>[k,R.useIx[k]]),c:Object.keys(R.useCache).sort().map(k=>[k,R.useCache[k]])})`); - for (let day = 0; day < 4; day++) { + for (let day = 0; day < 6; day++) { + // the last days run a RouteScript: spill keeps headroom on every link (push with a reserve), plus preferences + if (day === 4) ev(`S.te.script='spill at 80%\\nprefer transit '+NET[S.transit[0].net].name+'\\nprotect customers';`); + if (day >= 4) assert.ok(ev('!!teRules()&&teRules().spill===0.8'), 'the RouteScript is active'); ev('compute()'); const fast = sig(); ev('__plain()'); const ref = sig(); assert.equal(fast, ref, `day ${day}: the fast and the plain path route the same traffic`);