Latency offers only ask for a ceiling a build can meet (#273)
The ceiling came from the straight-line distance, and nothing checked that a path could reach it: Pevek-Anadyr asked for 4.3 ms over a 7.7 ms sea route. latFloor() is the fastest a build could get, over own fiber on land and the routes of cables that land at both ends; an offer whose ceiling is below that and below what you already have is not made, as diverse offers are not.
This commit is contained in:
parent
24d865aa57
commit
c7fd54b067
4 changed files with 55 additions and 1 deletions
|
|
@ -6,6 +6,7 @@ All notable changes to this project are documented here. The project follows
|
|||
|
||||
## [Unreleased]
|
||||
|
||||
- Latency customers only ask for a ceiling something you can build meets. Before, a Mars ground station could ask for 4.3 ms between Pevek and Anadyr, where the only sea route takes 7.7 ms at best. (#273)
|
||||
- Money now shows billions (`$1.20B`) and bandwidth shows petabits (`1.00 Pbps`) instead of running on in millions and terabits, including on the NOC graph and the fiber labels on the map.
|
||||
- DE-Kicks ports stop getting dearer once they cost four times the list price. Before, the yearly price harmonisation kept compounding, so a long game ended up paying $100k a month for one port at Frankfurt or Mumbai.
|
||||
- An exchange port, a transit port or a PNI can now be stepped down one size from its panel, so shrinking a port no longer means leaving and rejoining (a PNI cannot while an augment is on order).
|
||||
|
|
|
|||
|
|
@ -50,3 +50,15 @@ function viaSeg(a,b){const cabs=cablesOk(a,b),sub=isSub(a,b);if(!cabs.length)ret
|
|||
const opts=(sub?[]:[{v:'land',l:`${tr('common.overland')} <small>${landMult(a,b)>1?landMult(a,b)+'× · ':''}${(kmBetween(a,b)*1.3/200).toFixed(1)} ms</small>`}]).concat(cabs.map(c=>({v:c.cid,l:`${esc(CAB[c.cid].name)} <small>${CAB[c.cid].price}× · ${(c.km*(CAB[c.cid].lat||1)/200).toFixed(1)} ms${CAB[c.cid].age==='old'?' · '+tr('geography_and_latency.old_cuts_often'):''}</small>`})));
|
||||
return `<h4 class="sub4">${tr('common.route')}</h4><div class="seg">${opts.map(o=>btn(o.l,'via',{v:o.v},wr&&wr.via===o.v?'pink':'ghost')).join('')}</div>${wr&&wr.cab?`<p class="note">${esc(CAB[wr.cab].blurb)} ${tr('geography_and_latency.all_your_waves_on_one_cable')}</p>`:''}`;}
|
||||
function bestLat(a,b,f){const ls=S.links.filter(l=>!linkDown(l)&&(!f||f(l)));const dist={[a]:0},done=new Set();for(;;){let u=null,ud=Infinity;for(const k in dist)if(!done.has(k)&&dist[k]<ud){u=k;ud=dist[k];}if(u===null)break;if(u===b)return ud;done.add(u);for(const l of ls){if(l.a!==u&&l.b!==u)continue;const v=l.a===u?l.b:l.a,nd=ud+linkLat(l)+0.05;if(nd<(dist[v]??Infinity))dist[v]=nd;}}return Infinity;}
|
||||
// The lowest one-way latency anything you could build gets between two cities (#273), the way bestLat() adds it up:
|
||||
// your own fiber over land (×1.1), or the route of a cable that lands at both ends (your own cable in the low-latency
|
||||
// design follows it at 0.9 or better). A sea route that no cable takes needs a survey, so it does not count.
|
||||
// Built from the map alone, so it is worked out once per city.
|
||||
const LATF=new Map();let LATC=null;
|
||||
function latFloor(a,b){let D=LATF.get(a);if(!D){LATF.set(a,D=latFloor0(a));}return D[CIDX[b]];}
|
||||
function latFloor0(a){const n=CITIES.length,D=new Float64Array(n).fill(Infinity),done=new Uint8Array(n);
|
||||
if(!LATC){LATC=new Map();for(const c of CABLE_PAIRS){const k=Math.min(CIDX[c.a],CIDX[c.b])*4096+Math.max(CIDX[c.a],CIDX[c.b]),w=c.km*Math.min(0.9,CAB[c.cid].lat||1);if(!(LATC.get(k)<=w))LATC.set(k,w);}}
|
||||
D[CIDX[a]]=0;for(;;){let u=-1,ud=Infinity;for(let i=0;i<n;i++)if(!done[i]&&D[i]<ud){u=i;ud=D[i];}if(u<0)break;done[u]=1;const U=CITIES[u],LU=lands(U);
|
||||
for(let i=0;i<n;i++){if(done[i])continue;const V=CITIES[i],cw=LATC.get(Math.min(u,i)*4096+Math.max(u,i));
|
||||
let w=lands(V).some(x=>LU.includes(x))?kmBetween(U.id,V.id)*1.1:Infinity;if(cw<w)w=cw;if(w<Infinity){const d=ud+w/200+0.05;if(d<D[i])D[i]=d;}}}
|
||||
return D;}
|
||||
|
|
|
|||
|
|
@ -129,5 +129,7 @@ function spawnOffer(){
|
|||
if(Math.random()<(T.lv>=3?0.65:0.3))reqs.push(pick(pool));
|
||||
if(T.lv>=3&&Math.random()<0.35){const more=pool.filter(k=>!reqs.includes(k));if(more.length)reqs.push(pick(more));}
|
||||
const r2=Math.round(rate*(1+reqs.reduce((a,k)=>a+REQS[k].bonus,0)));
|
||||
S.offers.push({id:uid(),city,city2,name,type:t,bw,rate:r2,reqs,latMax:T.lat?+(kmBetween(city,city2)/200*1.35).toFixed(1):null,exp:S.day+40});
|
||||
// A latency ceiling must be one something you can build meets (#273), as diverse paths must be possible.
|
||||
const latMax=T.lat?latMaxOf(city,city2):null;if(T.lat&&!(Math.min(latFloor(city,city2),bestLat(city,city2))<=latMax))return;
|
||||
S.offers.push({id:uid(),city,city2,name,type:t,bw,rate:r2,reqs,latMax,exp:S.day+40});
|
||||
}
|
||||
|
|
|
|||
39
tests/latency-offers.test.js
Normal file
39
tests/latency-offers.test.js
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
// #273: a latency offer only asks for a ceiling something you can build meets. Pevek–Anadyr is 635 km apart as the
|
||||
// crow flies, but only a 1,717 km sea route joins them, so a 4.3 ms ceiling can never be met.
|
||||
const test = require('node:test');
|
||||
const assert = require('node:assert/strict');
|
||||
const { load } = require('./harness');
|
||||
|
||||
// Spawn many mars offers from a network at Pevek and Anadyr only: most are between the two.
|
||||
const marsOnly = "eval('('+spawnOffer.toString().replace('const t=pick(types)',\"const t='mars'\")+')')";
|
||||
const spawn = (ev, n) => ev(`(()=>{S.offers=[];const f=${marsOnly};for(let i=0;i<${n};i++)f();return JSON.stringify(S.offers.map(o=>[o.city,o.city2,o.latMax]));})()`);
|
||||
const start = (ev, cities) => ev(`ACT.start({});S.cash=1e9;S.nextFail=1e9;S.nextEvent=1e9;for(const g of GOALS)S.done[g.id]=0;S.lvl=13;S.pops={};for(const c of ${JSON.stringify(cities)})S.pops[c]={day:0,bb:null,boost:0,down:0,routers:1,gen:false,rgen:0};compute()`);
|
||||
|
||||
test('#273 no latency offer between Pevek and Anadyr: no buildable path meets the straight-line ceiling', () => {
|
||||
const { ev, errors } = load();
|
||||
start(ev, ['pvs', 'dyr']);
|
||||
assert.ok(ev('lvl()') >= 13, 'mars offers are unlocked');
|
||||
assert.equal(ev("latMaxOf('pvs','dyr')"), 4.3);
|
||||
const pair = o => [o[0], o[1]].sort().join('-') === 'dyr-pvs';
|
||||
const offers = JSON.parse(spawn(ev, 60));
|
||||
assert.ok(offers.length > 0, 'mars offers still spawn');
|
||||
assert.deepEqual(offers.filter(pair), [], 'but none asks for 4.3 ms between Pevek and Anadyr');
|
||||
assert.ok(!(ev("latFloor('pvs','dyr')") <= 4.3), 'nothing on the map gets there in 4.3 ms');
|
||||
// Even with the player's own Low latency cable, 7.7 ms is the best there is.
|
||||
ev("S.links.push({id:'own1',a:'pvs',b:'dyr',kind:'df',own:true,sub:true,seaDesign:'express',sys:'roadm',ch:[],km:1717,cable:null,mo:1,trench:'own:own1',cut:0,day:0,ready:0,pairs:1});compute()");
|
||||
assert.ok(ev("bestLat('pvs','dyr')") > 4.3);
|
||||
assert.deepEqual(JSON.parse(spawn(ev, 60)).filter(pair), []);
|
||||
assert.deepEqual(errors, []);
|
||||
});
|
||||
|
||||
test('#273 latency offers still come where a build meets the ceiling', () => {
|
||||
const { ev, errors } = load();
|
||||
start(ev, ['lon', 'nyc']);
|
||||
const offers = JSON.parse(spawn(ev, 60));
|
||||
assert.ok(offers.length > 0, 'London–New York has latency offers');
|
||||
for (const [a, b, max] of offers) assert.ok(ev(`latFloor('${a}','${b}')`) <= max, `${a}–${b} within ${max} ms is buildable`);
|
||||
// The floor is what bestLat() would read on the links it describes: a wave on the fastest London–New York cable.
|
||||
const f = ev("latFloor('lon','nyc')"), c = ev("Math.min(...cablesFor('lon','nyc').map(c=>c.km*Math.min(0.9,CAB[c.cid].lat||1)))/200+0.05");
|
||||
assert.ok(Math.abs(f - c) < 1e-9);
|
||||
assert.deepEqual(errors, []);
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue