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

@ -1 +1 @@
{"v":1,"key":"2026-W44","rev":3,"theme":"flood","city":"sto","cash":2050000,"days":250,"lvl":4,"rules":{"ddos":true},"mods":[],"goal":{"t":"floods","p":{"n":28,"big":5}},"name":{"l":"wkscn.name_packet_monsoon","p":{}},"desc":{"l":"wkscn.desc_city_hosts_the_internets_favourite","p":{"city":"sto"}},"seed":1559294845,"par":198,"ref":{"home":"sto","bb":true,"ix":true,"steps":[{"k":"hop","v":["sto","tll",1,null]},{"k":"hop","v":["tll","hel",1,null]}],"avoid":[],"tr2":false,"scrub":2}}
{"v":1,"key":"2026-W44","rev":3,"theme":"flood","city":"sto","cash":2050000,"days":250,"lvl":4,"rules":{"ddos":true},"mods":[],"goal":{"t":"floods","p":{"n":28,"big":5}},"name":{"l":"wkscn.name_packet_monsoon","p":{}},"desc":{"l":"wkscn.desc_city_hosts_the_internets_favourite","p":{"city":"sto"}},"seed":1559294845,"par":185,"ref":{"home":"sto","bb":true,"ix":true,"steps":[{"k":"hop","v":["sto","tll",1,null]},{"k":"hop","v":["tll","hel",1,null]}],"avoid":[],"tr2":false,"scrub":2}}

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);

View file

@ -189,7 +189,9 @@ test('a customer dropped while a sales trial routes: the trial runs again on the
p.ev(TICK_ERR);
p.ev("window.__ot=0;const ot=offerTrial;offerTrial=(...a)=>{__ot++;return ot(...a);};");
let found = false;
for (let d = 0; d < 20 && !found; d++) {
// Played until such a trial comes: on the big save that is day 51 (where each city's traffic goes decides which
// offers pass, #48).
for (let d = 0; d < 60 && !found; d++) {
p.ev('rwDay()');
for (let k = 0; k < 400 && p.ev('!!RW.job'); k++) {
if (p.ev('__later.length')) { p.ev('__later.shift()()'); continue; }

View file

@ -27,7 +27,8 @@ function twoPops() {
}
test('at its own POP a carrier\'s port takes the traffic bound for that carrier, not an even split', () => {
const { ev, lvl, tly, errors } = newYork();
// Both ports with room: New York's traffic to the US eyeballs in Level Tree's cone alone would fill its port (#48).
const { ev, lvl, tly, errors } = newYork(1, 150);
assert.ok(via(ev, lvl, 'lvl') > 1, 'Level Tree traffic goes out of the Level Tree port');
assert.equal(via(ev, tly, 'lvl'), 0, 'and none of it out of Tell-Ya');
assert.ok(via(ev, tly, 'tly') > 1 && via(ev, lvl, 'tly') === 0, 'the same for Tell-Ya');