diff --git a/src/game/80-simulation/30-compute.js b/src/game/80-simulation/30-compute.js index 4ef8bdc..568b6f6 100644 --- a/src/game/80-simulation/30-compute.js +++ b/src/game/80-simulation/30-compute.js @@ -169,8 +169,11 @@ function compute(){ // Each list also knows whether it holds a preferred exit (hi) and its exits by city (at), in list order. // With several islands (POPs no backbone joins), each list is split by island: a flow only scans exits it can reach. const idx=L=>{L.hi=L.some(e=>e.hp===0);L.at=new Map();for(const e of L){const h=L.at.get(e.ci);if(h)h.push(e);else L.at.set(e.ci,[e]);}}; + // Networks with the same exits at a rank share one list (LIST, by content), so what one flow learns serves them all. + const LIST=new Map();for(let i=0;i1){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);m[r]={cs};}else idx(L);}} + for(const r in m){const L=m[r],key=L.map(e=>e.xi).join(','),o=LIST.get(key);if(o){m[r]=o;continue;} + 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;}} // Attack flows pinned to their entry port route at its plain rank, which RouteScript may have left with no list. for(const f of flows)if(f.pin)for(const e of ingressE[f.pin]||[])RSET.add(base(e)); // The flow being routed, and from its POP: distances, arriving edges and the paths walked so far, by city index. @@ -234,13 +237,18 @@ function compute(){ // One scan: the best (preference, distance) so far and, in list order, the exits within 1e-6 of it. The best // distance only goes down, so dropping the ones it leaves behind gives exactly the exits a second scan would. // Exits that are full stay full for this pass: when a quarter of a list is, it is rewritten without them. + /* gc[ci]: the first group this list gave a flow from city ci. Exits only fill up during routing, so while all of + them still have room no other exit can have become better, and the scan would find the same group (an + empty one, no usable exit, stays empty). */ + const gc=lst.gc||(lst.gc=[]),c=gc[f.ci]; + if(c!==undefined&&c.every(e=>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(let li=0;li1)continue; - if(G.length>1)sortD(G);} + if(bh>1){gc[f.ci]=[];continue;} + if(G.length>1)sortD(G);gc[f.ci]=G.slice();}} sendGroup(G,0,G.length); if(f.rem<=1e-6)continue; REST.length=0;for(let li=0;li