@@ -20,6 +20,7 @@ export interface RegionPathSolverOptions {
2020 USE_TOPOLOGY_CAPACITY ?: boolean
2121 MAX_NEGOTIATION_PASSES ?: number
2222 SKIP_UNROUTABLE_ROUTES ?: boolean
23+ USE_TOPOLOGY_CAPACITY ?: boolean
2324}
2425
2526export interface RegionPathCandidate {
@@ -78,6 +79,7 @@ export class RegionPathSolver extends BaseSolver {
7879 USE_TOPOLOGY_CAPACITY = false
7980 MAX_NEGOTIATION_PASSES = 4
8081 SKIP_UNROUTABLE_ROUTES = false
82+ USE_TOPOLOGY_CAPACITY = false
8183 skippedRouteIds : RouteId [ ] = [ ]
8284 negotiationPass = 0
8385
@@ -108,6 +110,9 @@ export class RegionPathSolver extends BaseSolver {
108110 if ( options ?. SKIP_UNROUTABLE_ROUTES !== undefined ) {
109111 this . SKIP_UNROUTABLE_ROUTES = options . SKIP_UNROUTABLE_ROUTES
110112 }
113+ if ( options ?. USE_TOPOLOGY_CAPACITY !== undefined ) {
114+ this . USE_TOPOLOGY_CAPACITY = options . USE_TOPOLOGY_CAPACITY
115+ }
111116
112117 this . state = {
113118 regionUsage : new Int32Array ( this . regionGraph . regionCount ) ,
@@ -325,7 +330,8 @@ export class RegionPathSolver extends BaseSolver {
325330 ? 0
326331 : 1 )
327332 const regionCapacity = this . regionGraph . regionCapacity [ regionId ]
328- const overflow = Math . max ( 0 , nextUsage - regionCapacity )
333+ const trackCapacity = this . getRegionCapacity ( regionId )
334+ const overflow = Math . max ( 0 , nextUsage - trackCapacity )
329335 return (
330336 ( nextUsage / regionCapacity ) * this . MM_COST_FOR_FULL_REGION +
331337 overflow * this . getOverCapacityCost ( ) +
@@ -334,6 +340,8 @@ export class RegionPathSolver extends BaseSolver {
334340 }
335341
336342 computeEdgeEntryCost ( edgeId : number ) : number {
343+ if ( ! this . USE_TOPOLOGY_CAPACITY ) return 0
344+
337345 const currentNetId = this . state . currentRouteNetId
338346 const nextUsage =
339347 this . state . edgeUsage [ edgeId ] +
@@ -344,23 +352,29 @@ export class RegionPathSolver extends BaseSolver {
344352 const edgeCapacity = this . regionGraph . edges [ edgeId ] ! . portIds . length
345353 const overflow = Math . max ( 0 , nextUsage - edgeCapacity )
346354 return (
347- ( nextUsage / edgeCapacity ) * this . MM_COST_FOR_FULL_REGION +
348355 overflow * this . getOverCapacityCost ( ) +
349356 this . state . edgeHistoricalCost [ edgeId ]
350357 )
351358 }
352359
360+ getRegionCapacity ( regionId : RegionId ) : number {
361+ return this . USE_TOPOLOGY_CAPACITY
362+ ? this . regionGraph . regionTrackCapacity [ regionId ] !
363+ : this . regionGraph . regionCapacity [ regionId ] !
364+ }
365+
353366 getOverCapacityCost ( ) : number {
354367 // A simple path visits at most one region and one boundary per graph hop.
355368 // This makes one overflow more expensive than any capacity-respecting path.
356369 return this . regionGraph . regionCount * this . MM_COST_FOR_FULL_REGION * 2
357370 }
358371
359372 hasOverloadedResources ( ) : boolean {
373+ if ( ! this . USE_TOPOLOGY_CAPACITY ) return false
374+
360375 for ( let regionId = 0 ; regionId < this . regionGraph . regionCount ; regionId ++ ) {
361376 if (
362- this . state . regionUsage [ regionId ] >
363- this . regionGraph . regionCapacity [ regionId ]
377+ this . state . regionUsage [ regionId ] > this . getRegionCapacity ( regionId )
364378 ) {
365379 return true
366380 }
@@ -377,7 +391,7 @@ export class RegionPathSolver extends BaseSolver {
377391 for ( let regionId = 0 ; regionId < regionGraph . regionCount ; regionId ++ ) {
378392 const overflow = Math . max (
379393 0 ,
380- state . regionUsage [ regionId ] - regionGraph . regionCapacity [ regionId ] ,
394+ state . regionUsage [ regionId ] - this . getRegionCapacity ( regionId ) ,
381395 )
382396 state . regionHistoricalCost [ regionId ] += overflow * overCapacityCost
383397 }
@@ -477,7 +491,7 @@ export class RegionPathSolver extends BaseSolver {
477491
478492 for ( let regionId = 0 ; regionId < regionGraph . regionCount ; regionId ++ ) {
479493 const usage = state . regionUsage [ regionId ]
480- const utilization = usage / regionGraph . regionCapacity [ regionId ]
494+ const utilization = usage / this . getRegionCapacity ( regionId )
481495 maxRegionUsage = Math . max ( maxRegionUsage , usage )
482496 maxUtilization = Math . max ( maxUtilization , utilization )
483497 }
0 commit comments