@@ -4,6 +4,10 @@ import {
44 TinyHyperGraphSolver ,
55 type TinyHyperGraphTopology ,
66} from "lib/index"
7+ import {
8+ computeRegionCost ,
9+ isKnownSingleLayerMask ,
10+ } from "lib/computeRegionCost"
711
812const createTopology = (
913 regionAvailableZMask : number ,
@@ -64,9 +68,55 @@ const getCrossingCost = (regionAvailableZMask: number, portZ: number) => {
6468test ( "same-layer crossings in known single-layer regions are rejected as candidates" , ( ) => {
6569 const topLayerCrossingCost = getCrossingCost ( 1 << 0 , 0 )
6670 const bottomLayerCrossingCost = getCrossingCost ( 1 << 1 , 1 )
71+ const innerLayer2CrossingCost = getCrossingCost ( 1 << 2 , 2 )
72+ const innerLayer3CrossingCost = getCrossingCost ( 1 << 3 , 3 )
6773 const multiLayerCrossingCost = getCrossingCost ( ( 1 << 0 ) | ( 1 << 1 ) , 0 )
6874
6975 expect ( topLayerCrossingCost ) . toBe ( Number . POSITIVE_INFINITY )
7076 expect ( bottomLayerCrossingCost ) . toBe ( Number . POSITIVE_INFINITY )
77+ expect ( innerLayer2CrossingCost ) . toBe ( Number . POSITIVE_INFINITY )
78+ expect ( innerLayer3CrossingCost ) . toBe ( Number . POSITIVE_INFINITY )
7179 expect ( multiLayerCrossingCost ) . toBeLessThan ( 0.1 )
7280} )
81+
82+ test ( "single-bit availableZ masks are all treated as known single-layer regions" , ( ) => {
83+ expect ( isKnownSingleLayerMask ( 1 << 0 ) ) . toBe ( true )
84+ expect ( isKnownSingleLayerMask ( 1 << 1 ) ) . toBe ( true )
85+ expect ( isKnownSingleLayerMask ( 1 << 2 ) ) . toBe ( true )
86+ expect ( isKnownSingleLayerMask ( 1 << 3 ) ) . toBe ( true )
87+ expect ( isKnownSingleLayerMask ( ( 1 << 0 ) | ( 1 << 1 ) ) ) . toBe ( false )
88+ expect ( isKnownSingleLayerMask ( 0 ) ) . toBe ( false )
89+ } )
90+
91+ test ( "same-layer crossings incur the impossible single-layer penalty for higher routed layers too" , ( ) => {
92+ const width = 3
93+ const height = 3
94+ const sameLayerIntersections = 1
95+ const crossLayerIntersections = 0
96+ const entryExitChanges = 0
97+ const traceCount = 2
98+
99+ expect (
100+ computeRegionCost (
101+ width ,
102+ height ,
103+ sameLayerIntersections ,
104+ crossLayerIntersections ,
105+ entryExitChanges ,
106+ traceCount ,
107+ 1 << 2 ,
108+ ) ,
109+ ) . toBeGreaterThan ( 10 )
110+
111+ expect (
112+ computeRegionCost (
113+ width ,
114+ height ,
115+ sameLayerIntersections ,
116+ crossLayerIntersections ,
117+ entryExitChanges ,
118+ traceCount ,
119+ 1 << 3 ,
120+ ) ,
121+ ) . toBeGreaterThan ( 10 )
122+ } )
0 commit comments