Keep puzzles and scenarios on plain shares; per-city share sums; tests follow the new traffic split

Puzzles, Architect runs and scenarios keep the table's split (their references and
pars were made with it). Week 2026-W44's reference now wins on day 185 (offers draw
from the wider campus list). The cache planner sums each city's own split.
This commit is contained in:
Frederic Jung 2026-11-10 08:37:31 +00:00
parent 69cdb3e372
commit a98e34711b
No known key found for this signature in database
6 changed files with 18 additions and 10 deletions

View file

@ -24,3 +24,7 @@ function locSh(T,c){let m=LOC_SH.get(T);if(!m)LOC_SH.set(T,m=new Map());let a=m.
for(let j=0;j<NN;j++){const s=T[NETS[j].id]||0;if(!s)continue;const h=L[j];if(!h){a[j]=s;continue;}const v=s*locW(h,C);g+=s;gw+=v;a[j]=v;}
if(gw>0){const f=g/gw;for(let j=0;j<NN;j++)if(L[j]&&a[j])a[j]*=f;}
m.set(c,a);return a;}
/* Puzzles, Architect runs and scenarios (the weekly one too) are built and scored on the plain world shares: their
reference builds and committed pars were made with them. There a city's split stays the table's. */
const LOC_PLAIN=new Map(),locOn=()=>!(S&&(S.mode==='puzzle'||S.pz||S.ar||S.scn));
function cityShares(T,c){if(locOn())return locSh(T,c);let a=LOC_PLAIN.get(T);if(!a)LOC_PLAIN.set(T,a=Float64Array.from(NETS,n=>T[n.id]||0));return a;}

View file

@ -14,12 +14,13 @@ function utilityCacheMoves(city){if(!S||!S.pops[city])return [];const groups=new
// list of networks, and Goggle is throttled to half in Russia. The world shares (NSH) would size boxes for networks the
// city cannot even reach, and too few for the ones it uses most.
const cityShTab=c=>cnCity(c)?NSH_CN:ruCity(c)?NSH_RU:CITY[c].kr&&S.krExit?NSH_KRX:NSH;
const cityNetSh=(c,id)=>{const j=LOC_NIX.get(id);return (j===undefined?0:locSh(cityShTab(c),c)[j])*(id==='ggl'&&ruCity(c)?0.5:1);};
// A city's total share only depends on its table and on the Russian throttle, and the tables never change after load:
// summed once per kind of city, not once per network asked about (that was cities × networks² every shift).
const CSH_SUM=new Map();
function cityShSum(c){const T=cityShTab(c),k=ruCity(c)?1:0;let m=CSH_SUM.get(T);if(!m)CSH_SUM.set(T,m=[null,null]);
if(m[k]===null){let t=0;for(const id in T)t+=cityNetSh(c,id);m[k]=t;}return m[k];}
const cityNetSh=(c,id)=>{const j=LOC_NIX.get(id);return (j===undefined?0:cityShares(cityShTab(c),c)[j])*(id==='ggl'&&ruCity(c)?0.5:1);};
// A city's total share only depends on its split (its table, localised for the city, #48) and on the Russian throttle,
// and those never change after load: summed once per split, not once per network asked about (that was cities ×
// networks² every shift).
const CSH_SUM=new WeakMap();
function cityShSum(c){const a=cityShares(cityShTab(c),c),k=ruCity(c)?1:0;let m=CSH_SUM.get(a);if(!m)CSH_SUM.set(a,m=[null,null]);
if(m[k]===null){const T=cityShTab(c);let t=0;for(const id in T)t+=cityNetSh(c,id);m[k]=t;}return m[k];}
function cacheDem(c,id){const t=cityShSum(c);return t>0?((R.cityDem&&R.cityDem[c])||0)*cityNetSh(c,id)/t:0;}
// One box per site first, if the city sends the network anything at all; then more boxes while that demand outgrows them
// (100G each, #248).

View file

@ -103,7 +103,7 @@ function compute(){RW.gen++;
// traffic you failed to deliver, and it does not cross your links only to be thrown away.
const ru=ruCity(c),thr=n=>n==='ggl'&&ru?0.5:1;let sa=shArr.get(SH),sm=shSum.get(SH);if(!sa){shArr.set(SH,sa=NETS.map(n=>SH[n.id]||0));shSum.set(SH,sm=[]);}
// This city's own split: its traffic to networks that sell to homes goes mostly to the ones whose users are near (#48).
const ls=locSh(SH,c);
const ls=cityShares(SH,c);
const tt=sm[+ru]||(sm[+ru]=[NETS.reduce((t,n,j)=>t+sa[j]*thr(n.id),0),NETS.reduce((t,n,j)=>t+sa[j],0)]),lf=loc?NETS.reduce((t,n,j)=>t+(R2.reachable[n.id]?ls[j]*thr(n.id):0),0)/(tt[0]||1):1,d=d0*tt[0]/(tt[1]||1)*lf;
R2.cityEye[c]=eye;R2.cityDem[c]=d;R2.citySrv[c]=0;R2.demand+=d;
for(let j=0;j<NN;j++)DEMTO[j]=(DEMTO[j]||0)+d0*ls[j]*thr(NETS[j].id);