Routing loop: keep flows in typed-array columns instead of objects, and add up link and transit totals without boxing numbers
Flows are packed into Float64Array/Int32Array columns; R.fl builds the old objects only when read. Edge egress sums keep a slot per egress in a plain array, and R.tNet is added up in a typed array and written out at the end, in the same key order. Results are identical to main.
This commit is contained in:
parent
0355eb4e38
commit
89fc8b8d03
3 changed files with 73 additions and 57 deletions
|
|
@ -6,16 +6,16 @@ module.exports = `
|
|||
// A carrier's own port (dr) is also a plain transit exit. A POP with a Prefer-marked transit port keeps what Prefer
|
||||
// says, and a port not set to carry only takes its own POP's traffic.
|
||||
const PH=new Set(E.filter(x=>x.k==='t'&&x.pref==='high').map(x=>CIDX[x.city]));
|
||||
const dr=(e,f)=>{if(e.k!=='t'||PH.has(f.ci)||eff(e,f.n)!==3)return 0;const t=directTier(e.net,f.n);return t?DIRECT_RANK[t][e.carry?0:1]:0;};
|
||||
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<e.cap&&e.ok(f.n)&&
|
||||
((TR?eff(e,f.n):base(e,f.n))===rank||(dr(e,f)||-1)===rank)&&
|
||||
(rank!==DIRECT_RANK[1][1]&&rank!==DIRECT_RANK[2][1]||CIDX[e.city]===f.ci)&&Dv[CIDX[e.city]]<Infinity&&!gone(e))
|
||||
const dr=(e,ci,n)=>{if(e.k!=='t'||PH.has(ci)||eff(e,n)!==3)return 0;const t=directTier(e.net,n);return t?DIRECT_RANK[t][e.carry?0:1]:0;};
|
||||
for(const pass of PASSES)for(const rank of RANKS){
|
||||
for(F=0;F<NF;F++){fci=FCI[F];fnj=FNJ[F];const n=NET_IDS[fnj];
|
||||
if(FREM[F]<=1e-6||(rank===0&&!FCA[F])||(pass===1&&!FBZ[F])||(pass===2&&FBZ[F]))continue;
|
||||
Dv=SDi[fci];Pv=SPi[fci];PP=walked[fci]||(walked[fci]=[]);vis++;
|
||||
const candidates=E.filter(e=>e.used<e.cap&&e.ok(n)&&
|
||||
((TR?eff(e,n):base(e,n))===rank||(dr(e,fci,n)||-1)===rank)&&
|
||||
(rank!==DIRECT_RANK[1][1]&&rank!==DIRECT_RANK[2][1]||CIDX[e.city]===fci)&&Dv[CIDX[e.city]]<Infinity&&!gone(e))
|
||||
.sort((a,b)=>(a.pref==='high'?0:1)-(b.pref==='high'?0:1)||Dv[CIDX[a.city]]-Dv[CIDX[b.city]]);
|
||||
for(let i=0;i<candidates.length&&f.rem>1e-6;){
|
||||
for(let i=0;i<candidates.length&&FREM[F]>1e-6;){
|
||||
let j=i+1;while(j<candidates.length&&(candidates[j].pref==='high')===(candidates[i].pref==='high')&&
|
||||
Math.abs(Dv[CIDX[candidates[j].city]]-Dv[CIDX[candidates[i].city]])<1e-6)j++;
|
||||
sendGroup(candidates.slice(i,j));i=j;
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ function network(ev) {
|
|||
// Share the model and path sender, but replace indexed exit selection with
|
||||
// the original full scan and stable sort for every flow.
|
||||
const source = ev('compute.toString()');
|
||||
const start = source.indexOf(' for(const pass of PASSES||[null])for(const rank of RANKS){');
|
||||
const start = source.indexOf(' for(const pass of PASSES)for(const rank of RANKS){');
|
||||
const end = source.indexOf(' for(const i of NORD)', start);
|
||||
assert.ok(start >= 0 && end > start, 'allocation loop boundaries must exist');
|
||||
ev(`window.referenceCompute=eval('('+${JSON.stringify(source.slice(0,start)+referenceAllocation+source.slice(end))}+')')`);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue