Skip to content

Commit 799acad

Browse files
authored
Merge pull request #22 from 0hmX/clean-tiny
add same-net shared bottleneck repro with svg snapshot and cosmos page
2 parents 2947005 + ba0635e commit 799acad

4 files changed

Lines changed: 255 additions & 0 deletions

File tree

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { Debugger } from "./components/Debugger"
2+
import { sameNetSharedBottleneckFixture } from "../tests/fixtures/same-net-shared-bottleneck.fixture"
3+
4+
export default function SameNetSharedBottleneckPage() {
5+
return (
6+
<Debugger serializedHyperGraph={sameNetSharedBottleneckFixture} />
7+
)
8+
}
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
import type { SerializedHyperGraph } from "@tscircuit/hypergraph"
2+
3+
const REGION_SIZE = 1.6
4+
5+
const gridPoint = (x: number, y: number) => ({ x: x * 2, y: y * 2 })
6+
7+
const createRegion = (
8+
regionId: string,
9+
x: number,
10+
y: number,
11+
pointIds: string[],
12+
): NonNullable<SerializedHyperGraph["regions"]>[number] => ({
13+
regionId,
14+
pointIds,
15+
d: {
16+
center: gridPoint(x, y),
17+
width: REGION_SIZE,
18+
height: REGION_SIZE,
19+
},
20+
})
21+
22+
const createPort = (
23+
portId: string,
24+
region1Id: string,
25+
region2Id: string,
26+
x: number,
27+
y: number,
28+
): NonNullable<SerializedHyperGraph["ports"]>[number] => ({
29+
portId,
30+
region1Id,
31+
region2Id,
32+
d: {
33+
...gridPoint(x, y),
34+
z: 0,
35+
},
36+
})
37+
38+
const routeA = {
39+
connectionId: "route-a",
40+
startRegionId: "start-a",
41+
endRegionId: "end-a",
42+
mutuallyConnectedNetworkId: "net-0",
43+
}
44+
45+
const routeB = {
46+
connectionId: "route-b",
47+
startRegionId: "start-b",
48+
endRegionId: "end-b",
49+
mutuallyConnectedNetworkId: "net-0",
50+
}
51+
52+
export const sameNetSharedBottleneckFixture: SerializedHyperGraph = {
53+
regions: [
54+
createRegion("start-a", 0, 2, ["a-in"]),
55+
createRegion("start-b", 0, 1, ["b-in"]),
56+
createRegion("left-shared", 1, 1.5, ["a-in", "b-in", "shared-x"]),
57+
createRegion("right-shared", 2, 1.5, ["shared-x", "a-out", "b-out"]),
58+
createRegion("end-a", 3, 2, ["a-out"]),
59+
createRegion("end-b", 3, 1, ["b-out"]),
60+
],
61+
ports: [
62+
createPort("a-in", "start-a", "left-shared", 0.5, 1.75),
63+
createPort("b-in", "start-b", "left-shared", 0.5, 1.25),
64+
createPort("shared-x", "left-shared", "right-shared", 1.5, 1.5),
65+
createPort("a-out", "right-shared", "end-a", 2.5, 1.75),
66+
createPort("b-out", "right-shared", "end-b", 2.5, 1.25),
67+
],
68+
connections: [routeA, routeB],
69+
}
Lines changed: 148 additions & 0 deletions
Loading
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import "bun-match-svg"
2+
import { expect, test } from "bun:test"
3+
import {
4+
getSvgFromGraphicsObject,
5+
stackGraphicsVertically,
6+
} from "graphics-debug"
7+
import { loadSerializedHyperGraph } from "lib/compat/loadSerializedHyperGraph"
8+
import { TinyHyperGraphSolver } from "lib/index"
9+
import { sameNetSharedBottleneckFixture } from "tests/fixtures/same-net-shared-bottleneck.fixture"
10+
11+
test("repro: two same-net routes must share one bottleneck port to solve", () => {
12+
const { topology, problem } = loadSerializedHyperGraph(
13+
sameNetSharedBottleneckFixture,
14+
)
15+
const solver = new TinyHyperGraphSolver(topology, problem)
16+
const beforeSolveGraphics = solver.visualize()
17+
18+
solver.solve()
19+
const afterSolveGraphics = solver.visualize()
20+
21+
const stagedSvg = getSvgFromGraphicsObject(
22+
stackGraphicsVertically([beforeSolveGraphics, afterSolveGraphics], {
23+
titles: ["before solve", "after solve"],
24+
}),
25+
)
26+
expect(stagedSvg).toMatchSvgSnapshot(import.meta.path)
27+
28+
expect(solver.solved).toBe(false)
29+
expect(solver.failed).toBe(true)
30+
})

0 commit comments

Comments
 (0)