Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 20 additions & 8 deletions lib/selective-rerip-tiny-hyper-graph-solver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,22 @@ export function selectOwnerRouteIdsToRip(params: {
return rippedRouteIds
}

export function orderRoutesAfterSelectiveRerip(params: {
failedRouteId: RouteId
pendingRouteIds: readonly RouteId[]
rippedRouteIds: ReadonlySet<RouteId>
}): RouteId[] {
const pendingRouteIds = params.pendingRouteIds.filter(
(routeId) =>
routeId !== params.failedRouteId && !params.rippedRouteIds.has(routeId),
)
const rippedRouteIds = [...params.rippedRouteIds].filter(
(routeId) => routeId !== params.failedRouteId,
)

return [params.failedRouteId, ...pendingRouteIds, ...rippedRouteIds]
}

/**
* Keeps the normal tiny-hypergraph route acceptance policy while replacing a
* full rerip with a minimal, explicit rerip when the exhausted route has a
Expand Down Expand Up @@ -245,10 +261,6 @@ export class SelectiveReripTinyHyperGraphSolver extends DistanceAwareTinyHyperGr
const alternateOnlyOwnerRouteIds = (alternateOwnerRouteIds ?? []).filter(
(ownerRouteId) => !directPath.owners.has(ownerRouteId),
)
const remainingRouteIds = this.state.unroutedRoutes.filter(
(routeId) => routeId !== failedRouteId && !rippedRouteIds.has(routeId),
)

if (
this.selectiveReripCongestionUpdateCount <
MAX_SELECTIVE_RERIP_CONGESTION_UPDATES
Expand All @@ -260,11 +272,11 @@ export class SelectiveReripTinyHyperGraphSolver extends DistanceAwareTinyHyperGr
this.state.ripCount += 1
this.state.currentRouteId = undefined
this.state.currentRouteNetId = undefined
this.state.unroutedRoutes = [
this.state.unroutedRoutes = orderRoutesAfterSelectiveRerip({
failedRouteId,
...rippedRouteIds,
...remainingRouteIds,
]
pendingRouteIds: this.state.unroutedRoutes,
rippedRouteIds,
})
this.state.candidateQueue.clear()
this.resetCandidateBestCosts()
this.state.goalPortId = -1
Expand Down
15 changes: 14 additions & 1 deletion tests/selective-rerip-tiny-hyper-graph-solver.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import { expect, test } from "bun:test"
import { selectOwnerRouteIdsToRip } from "lib/selective-rerip-tiny-hyper-graph-solver"
import {
orderRoutesAfterSelectiveRerip,
selectOwnerRouteIdsToRip,
} from "lib/selective-rerip-tiny-hyper-graph-solver"

test("selects alternate owners and rejects a failed route as its only blocker", () => {
expect([
Expand All @@ -19,3 +22,13 @@ test("selects alternate owners and rejects a failed route as its only blocker",
"SelectiveReripTinyHyperGraphSolver: route 1 has blocker resources but no distinct committed owner can be reripped",
)
})

test("keeps pending routes ahead of newly ripped routes", () => {
expect(
orderRoutesAfterSelectiveRerip({
failedRouteId: 7,
pendingRouteIds: [3, 4, 8, 7, 9],
rippedRouteIds: new Set([4, 2, 7]),
}),
).toEqual([7, 3, 8, 9, 4, 2])
})
Loading