From 8c2dd05d0ba351250d634bd6a38d259483580a2c Mon Sep 17 00:00:00 2001 From: Wesley Marques <350003694+wesleymarquesnetworks@users.noreply.github.com> Date: Fri, 30 Oct 2026 16:38:30 -0300 Subject: [PATCH 1/2] Skip saturated paths during candidate exit scan to prevent routing freezes (#210) --- CHANGELOG.md | 1 + src/game/80-simulation/30-compute.js | 10 +++++----- tests/issues.test.js | 12 ++++++++++++ 3 files changed, 18 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ac76186..c5de6d5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ All notable changes to this project are documented here. The project follows ## [Unreleased] +- Saturated shortest paths are skipped during the candidate exit scan and usable exit filtering, preventing routing freezes on congested networks (#210). - Premium submarine terminals and Optical engineering can no longer be bought on a cable where they would change nothing (#198). The button now says so, and an upgrade that only helps together with the other one stays available. - A wave size that is sold out on a route can no longer be reached by upgrading a smaller wave on it (#201). The upgrade button says how long it is sold out, just like when buying. - Choosing Both for a PNI with one member now really splits it: the second member arrives in the other building when the augment lands, instead of joining the first (#219). diff --git a/src/game/80-simulation/30-compute.js b/src/game/80-simulation/30-compute.js index eba967a..4c04ae8 100644 --- a/src/game/80-simulation/30-compute.js +++ b/src/game/80-simulation/30-compute.js @@ -182,8 +182,8 @@ function compute(){ let V=L;if(NCOMP>1){const cs=[];for(const e of L){const k=COMP[e.ci];if(k>=0)(cs[k]||(cs[k]=[])).push(e);}for(const s of cs)if(s)idx(s);V={cs};}else idx(L);LIST.set(key,V);m[r]=V;}} // The flow being routed, and from its POP: distances, arriving edges and the paths walked so far, by city index. let f=null,Dv=null,Pv=null,PP=null,vis=0;const walked=[],G=[],REST=[],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]; + // An exit the flow can still try: not visited yet, not full when the flow started, reachable, and not on a saturated path. + 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. 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). @@ -238,7 +238,7 @@ function compute(){ when it does not fit. Most often the group is the POP's own exits: with no preferred exit on the list and no other city at distance 0, the usable ones here are exactly the first group, already in order. */ 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.usede.usede.used=e.cap){full++;continue;}const d=Dv[e.ci];if(d===Infinity)continue;const h=e.hp; + for(let li=0,LN=lst.length;li=e.cap||gone(e)){full++;continue;}const d=Dv[e.ci];if(d===Infinity)continue;const h=e.hp; if(h=lst.length&&full){let k=0;for(let li=0;li { + const { ev, errors } = load(); + ev("ACT.start({});S.cash=1e8;UI.speed=0;for(const g of GOALS)S.done[g.id]=0;"); + ev("ACT.buyTransit({city:'fra',net:'cog',tier:1});"); + ev("ACT.buildPop({city:'par'});ACT.launchBB({city:'par'});"); + ev("S.links.push({id:'x1',a:'fra',b:'par',kind:'wave',tier:0,km:450,mult:1,mo:1000,ready:0,cut:0});"); + ev("compute();"); + assert.ok(ev("R.load['x1'] >= 10 - 1e-6"), 'intercity wave is saturated'); + ev("compute();"); + assert.deepEqual(errors, []); +}); From 928d6f01114d930035405fe0fb110ce33d3b2d2f Mon Sep 17 00:00:00 2001 From: Frederic Jung Date: Sat, 31 Oct 2026 07:10:27 +0100 Subject: [PATCH 2/2] Routing reference skips exits behind a full path too; #210 test checks the answer; CHANGELOG for players The reference loop now states the rule #225 adds to compute(): without Auto-TE an exit whose shortest path is already full fits nothing, like a full exit. With the same rule both match bit for bit; before, only float rounding differed (at most 3.6e-14 relative), because the ECMP split no longer counts a dead exit's room. --- CHANGELOG.md | 2 +- tests/helpers/reference-allocation.js | 4 +++- tests/issues.test.js | 4 ++++ 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c5de6d5..02b2278 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,7 +6,7 @@ All notable changes to this project are documented here. The project follows ## [Unreleased] -- Saturated shortest paths are skipped during the candidate exit scan and usable exit filtering, preventing routing freezes on congested networks (#210). +- Big networks freeze for less on every game day and every click: working out where traffic goes skips exits whose route is already full, so a game day takes about 40% less time (#210). Traffic goes exactly where it went before. - Premium submarine terminals and Optical engineering can no longer be bought on a cable where they would change nothing (#198). The button now says so, and an upgrade that only helps together with the other one stays available. - A wave size that is sold out on a route can no longer be reached by upgrading a smaller wave on it (#201). The upgrade button says how long it is sold out, just like when buying. - Choosing Both for a PNI with one member now really splits it: the second member arrives in the other building when the augment lands, instead of joining the first (#219). diff --git a/tests/helpers/reference-allocation.js b/tests/helpers/reference-allocation.js index a69d199..f9e4e70 100644 --- a/tests/helpers/reference-allocation.js +++ b/tests/helpers/reference-allocation.js @@ -1,12 +1,14 @@ // Deliberately scan all exits for every flow, without byRank, local-city // shortcuts or first-group selection. Stable sorting preserves E order on ties. +// Without Auto-TE, an exit whose shortest path from this POP is already full fits nothing, so it counts as +// unusable, like a full exit (#210). module.exports = ` for(const pass of PASSES||[null])for(const rank of RANKS){ for(f of flows){ if(f.rem<=1e-6||(rank===0&&!f.cache)||(pass&&!pass(f)))continue; Dv=SDi[f.ci];Pv=SPi[f.ci];PP=walked[f.ci]||(walked[f.ci]=[]);vis++; const candidates=E.filter(e=>e.used(a.pref==='high'?0:1)-(b.pref==='high'?0:1)||Dv[CIDX[a.city]]-Dv[CIDX[b.city]]); for(let i=0;i1e-6;){ let j=i+1;while(j= 10 - 1e-6"), 'intercity wave is saturated'); + assert.ok(ev("R.load['x1'] <= 10 + 1e-6"), 'and carries no more than it can'); + // Skipping exits behind the full wave changes nothing: routing again gives the same answer. + const first = ev('JSON.stringify([R.served,R.citySrv,R.load])'); ev("compute();"); + assert.equal(ev('JSON.stringify([R.served,R.citySrv,R.load])'), first); assert.deepEqual(errors, []); });