Skip to content

Commit 9e270f5

Browse files
committed
drop candidates that need impossible crossings
1 parent dc4dab1 commit 9e270f5

3 files changed

Lines changed: 27 additions & 11 deletions

File tree

lib/computeRegionCost.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@ const traceWidth = 0.1
44
const IMPOSSIBLE_SINGLE_LAYER_INTERSECTION_COST = 10
55

66
const isKnownSingleLayerMask = (regionAvailableZMask: number) =>
7-
regionAvailableZMask > 0 &&
8-
(regionAvailableZMask & (regionAvailableZMask - 1)) === 0
7+
regionAvailableZMask === 1 || regionAvailableZMask === 2
98

109
export const computeRegionCost = (
1110
regionWidth: number,

lib/core.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,7 @@ export class TinyHyperGraphSolver extends BaseSolver {
398398
if (problem.portSectionMask[neighborPortId] === 0) continue
399399

400400
const g = this.computeG(currentCandidate, neighborPortId)
401+
if (!Number.isFinite(g)) continue
401402
const h = this.computeH(neighborPortId)
402403

403404
const nextRegionId =
@@ -510,6 +511,11 @@ export class TinyHyperGraphSolver extends BaseSolver {
510511
)
511512
}
512513

514+
isKnownSingleLayerRegion(regionId: RegionId): boolean {
515+
const regionAvailableZMask = this.topology.regionAvailableZMask?.[regionId] ?? 0
516+
return regionAvailableZMask === 1 || regionAvailableZMask === 2
517+
}
518+
513519
populateSegmentGeometryScratch(
514520
regionId: RegionId,
515521
port1Id: PortId,
@@ -794,6 +800,13 @@ export class TinyHyperGraphSolver extends BaseSolver {
794800
segmentGeometry.entryExitLayerChanges,
795801
)
796802

803+
if (
804+
newSameLayerIntersections > 0 &&
805+
this.isKnownSingleLayerRegion(nextRegionId)
806+
) {
807+
return Number.POSITIVE_INFINITY
808+
}
809+
797810
const newRegionCost =
798811
computeRegionCost(
799812
topology.regionWidth[nextRegionId],

tests/solver/single-layer-region-cost.test.ts

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@ import {
55
type TinyHyperGraphTopology,
66
} from "lib/index"
77

8-
const createTopology = (regionAvailableZMask: number): TinyHyperGraphTopology => ({
8+
const createTopology = (
9+
regionAvailableZMask: number,
10+
portZ: number,
11+
): TinyHyperGraphTopology => ({
912
portCount: 4,
1013
regionCount: 2,
1114
regionIncidentPorts: [[0, 1, 2, 3], []],
@@ -24,7 +27,7 @@ const createTopology = (regionAvailableZMask: number): TinyHyperGraphTopology =>
2427
portAngleForRegion2: new Int32Array(4),
2528
portX: new Float64Array([1, 0, -1, 0]),
2629
portY: new Float64Array([0, 1, 0, -1]),
27-
portZ: new Int32Array(4),
30+
portZ: new Int32Array([portZ, portZ, portZ, portZ]),
2831
})
2932

3033
const createProblem = (): TinyHyperGraphProblem => ({
@@ -36,9 +39,9 @@ const createProblem = (): TinyHyperGraphProblem => ({
3639
regionNetId: new Int32Array(2).fill(-1),
3740
})
3841

39-
const getCrossingCost = (regionAvailableZMask: number) => {
42+
const getCrossingCost = (regionAvailableZMask: number, portZ: number) => {
4043
const solver = new TinyHyperGraphSolver(
41-
createTopology(regionAvailableZMask),
44+
createTopology(regionAvailableZMask, portZ),
4245
createProblem(),
4346
)
4447

@@ -58,11 +61,12 @@ const getCrossingCost = (regionAvailableZMask: number) => {
5861
)
5962
}
6063

61-
test("same-layer crossings in known single-layer regions get an impossible-level penalty", () => {
62-
const singleLayerCrossingCost = getCrossingCost(1 << 0)
63-
const multiLayerCrossingCost = getCrossingCost((1 << 0) | (1 << 1))
64+
test("same-layer crossings in known single-layer regions are rejected as candidates", () => {
65+
const topLayerCrossingCost = getCrossingCost(1 << 0, 0)
66+
const bottomLayerCrossingCost = getCrossingCost(1 << 1, 1)
67+
const multiLayerCrossingCost = getCrossingCost((1 << 0) | (1 << 1), 0)
6468

65-
expect(singleLayerCrossingCost).toBeGreaterThan(10)
69+
expect(topLayerCrossingCost).toBe(Number.POSITIVE_INFINITY)
70+
expect(bottomLayerCrossingCost).toBe(Number.POSITIVE_INFINITY)
6671
expect(multiLayerCrossingCost).toBeLessThan(0.1)
67-
expect(singleLayerCrossingCost).toBeGreaterThan(multiLayerCrossingCost + 9)
6872
})

0 commit comments

Comments
 (0)