Skip to content
Open
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
10 changes: 10 additions & 0 deletions lib/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1361,11 +1361,21 @@ export class TinyHyperGraphSolver extends BaseSolver {
state.currentRouteId = undefined
}

protected isEstablishingInitialSolution(): boolean {
return !this.bestSolvedStateSnapshot
}

computeG(currentCandidate: Candidate, neighborPortId: PortId): number {
const { state } = this

const nextRegionId = currentCandidate.nextRegionId

if (this.isEstablishingInitialSolution()) {
return (
currentCandidate.g + (this.problem.portPenalty?.[neighborPortId] ?? 0)
)
}

const regionCache = state.regionIntersectionCaches[nextRegionId]
const segmentGeometry = this.populateSegmentGeometryScratch(
nextRegionId,
Expand Down
4 changes: 4 additions & 0 deletions lib/section-solver/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -684,6 +684,10 @@ class TinyHyperGraphSectionSearchSolver extends TinyHyperGraphSolver {
return super.getStartingNextRegionId(routeId, startingPortId)
}

protected override isEstablishingInitialSolution(): boolean {
return false
}

override resetRoutingStateForRerip() {
if (!this.fixedSnapshot) {
super.resetRoutingStateForRerip()
Expand Down
15 changes: 14 additions & 1 deletion tests/solver/single-layer-region-cost.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,21 @@ const createProblem = (): TinyHyperGraphProblem => ({
regionNetId: new Int32Array(2).fill(-1),
})

const getCrossingCost = (regionAvailableZMask: number, portZ: number) => {
const getCrossingCost = (
regionAvailableZMask: number,
portZ: number,
hasInitialSolution = true,
) => {
const solver = new TinyHyperGraphSolver(
createTopology(regionAvailableZMask, portZ),
createProblem(),
)

if (hasInitialSolution) {
solver.state.unroutedRoutes = []
solver.onAllRoutesRouted()
}

solver.state.currentRouteNetId = 0
solver.appendSegmentToRegionCache(0, 0, 2)

Expand All @@ -67,6 +76,10 @@ const getCrossingCost = (regionAvailableZMask: number, portZ: number) => {
)
}

test("initial solution routing ignores same-layer crossing costs", () => {
expect(getCrossingCost(1 << 0, 0, false)).toBe(0)
})

test("same-layer crossings in known single-layer regions are rejected as candidates", () => {
const topLayerCrossingCost = getCrossingCost(1 << 0, 0)
const bottomLayerCrossingCost = getCrossingCost(1 << 1, 1)
Expand Down
Loading