|
| 1 | +import { expect, test } from "bun:test" |
| 2 | +import { |
| 3 | + type TinyHyperGraphProblem, |
| 4 | + TinyHyperGraphSolver, |
| 5 | + type TinyHyperGraphTopology, |
| 6 | +} from "lib/index" |
| 7 | + |
| 8 | +const createTopology = ( |
| 9 | + regionAvailableZMask: number, |
| 10 | + portZ: number, |
| 11 | +): TinyHyperGraphTopology => ({ |
| 12 | + portCount: 4, |
| 13 | + regionCount: 2, |
| 14 | + regionIncidentPorts: [[0, 1, 2, 3], []], |
| 15 | + incidentPortRegion: [ |
| 16 | + [0, 1], |
| 17 | + [0, 1], |
| 18 | + [0, 1], |
| 19 | + [0, 1], |
| 20 | + ], |
| 21 | + regionWidth: new Float64Array([3, 1]), |
| 22 | + regionHeight: new Float64Array([3, 1]), |
| 23 | + regionCenterX: new Float64Array(2).fill(0), |
| 24 | + regionCenterY: new Float64Array(2).fill(0), |
| 25 | + regionAvailableZMask: new Int32Array([regionAvailableZMask, 0]), |
| 26 | + portAngleForRegion1: new Int32Array([0, 9000, 18000, 27000]), |
| 27 | + portAngleForRegion2: new Int32Array(4), |
| 28 | + portX: new Float64Array([1, 0, -1, 0]), |
| 29 | + portY: new Float64Array([0, 1, 0, -1]), |
| 30 | + portZ: new Int32Array([portZ, portZ, portZ, portZ]), |
| 31 | +}) |
| 32 | + |
| 33 | +const createProblem = (): TinyHyperGraphProblem => ({ |
| 34 | + routeCount: 2, |
| 35 | + portSectionMask: new Int8Array(4).fill(1), |
| 36 | + routeStartPort: new Int32Array([0, 1]), |
| 37 | + routeEndPort: new Int32Array([2, 3]), |
| 38 | + routeNet: new Int32Array([0, 1]), |
| 39 | + regionNetId: new Int32Array(2).fill(-1), |
| 40 | +}) |
| 41 | + |
| 42 | +const getCrossingCost = (regionAvailableZMask: number, portZ: number) => { |
| 43 | + const solver = new TinyHyperGraphSolver( |
| 44 | + createTopology(regionAvailableZMask, portZ), |
| 45 | + createProblem(), |
| 46 | + ) |
| 47 | + |
| 48 | + solver.state.currentRouteNetId = 0 |
| 49 | + solver.appendSegmentToRegionCache(0, 0, 2) |
| 50 | + |
| 51 | + solver.state.currentRouteNetId = 1 |
| 52 | + return solver.computeG( |
| 53 | + { |
| 54 | + nextRegionId: 0, |
| 55 | + portId: 1, |
| 56 | + f: 0, |
| 57 | + g: 0, |
| 58 | + h: 0, |
| 59 | + }, |
| 60 | + 3, |
| 61 | + ) |
| 62 | +} |
| 63 | + |
| 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) |
| 68 | + |
| 69 | + expect(topLayerCrossingCost).toBe(Number.POSITIVE_INFINITY) |
| 70 | + expect(bottomLayerCrossingCost).toBe(Number.POSITIVE_INFINITY) |
| 71 | + expect(multiLayerCrossingCost).toBeLessThan(0.1) |
| 72 | +}) |
0 commit comments