@tscircuit/hypergraph 0.0.50 → 0.0.52

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -1050,6 +1050,62 @@ declare function generateDefaultViaTopologyRegions(opts: Parameters<typeof gener
1050
1050
  ports: JPort[];
1051
1051
  };
1052
1052
 
1053
+ type ViaTileRecommendationProblemInput = {
1054
+ graphWidthMm?: number;
1055
+ graphHeightMm?: number;
1056
+ connectionCount?: number;
1057
+ intersectionCount?: number;
1058
+ xyConnections?: XYConnection[];
1059
+ sample?: {
1060
+ config?: {
1061
+ numCrossings?: number;
1062
+ };
1063
+ connections?: Array<{
1064
+ connectionId: string;
1065
+ startRegionId: string;
1066
+ endRegionId: string;
1067
+ }>;
1068
+ connectionRegions?: Array<{
1069
+ regionId: string;
1070
+ d: {
1071
+ center: {
1072
+ x: number;
1073
+ y: number;
1074
+ };
1075
+ bounds: {
1076
+ minX: number;
1077
+ maxX: number;
1078
+ minY: number;
1079
+ maxY: number;
1080
+ };
1081
+ };
1082
+ }>;
1083
+ };
1084
+ };
1085
+ type ViaTileCandidate = {
1086
+ viaRegionName: string;
1087
+ viaTile: ViaTile;
1088
+ };
1089
+ type ViaTileRecommendationCandidate = {
1090
+ viaRegionName: string;
1091
+ predictedReliability: number;
1092
+ estimatedIterationCost: number;
1093
+ capacityScore: number;
1094
+ requiredCapacityScore: number;
1095
+ acceptedAsReliable: boolean;
1096
+ };
1097
+ type ViaTileRecommendation = {
1098
+ recommendedViaRegionName: string;
1099
+ inputFeatures: {
1100
+ graphWidthMm: number;
1101
+ graphHeightMm: number;
1102
+ connectionCount: number;
1103
+ intersectionCount: number;
1104
+ };
1105
+ candidates: ViaTileRecommendationCandidate[];
1106
+ };
1107
+ declare const recommendViaTileFromGraphInput: (problemInput: ViaTileRecommendationProblemInput, fallbackXYConnections?: XYConnection[], viaTileCandidates?: ViaTileCandidate[], _opts?: unknown) => ViaTileRecommendation;
1108
+
1053
1109
  type ConvexViaGraphFromXYConnectionsResult = JumperGraph & {
1054
1110
  connections: Connection[];
1055
1111
  viaTile: ViaTile;
@@ -1072,10 +1128,10 @@ type ConvexViaGraphFromXYConnectionsResult = JumperGraph & {
1072
1128
  * 5. Attaches connection regions to the graph
1073
1129
  *
1074
1130
  * @param xyConnections - Array of connections with start/end XY coordinates
1075
- * @param viaTile - Via tile data (defaults to built-in via-tile.json)
1131
+ * @param viaTileOrProblem - Optional explicit via tile, or one-problem input used to recommend a tile
1076
1132
  * @param opts - Optional configuration
1077
1133
  */
1078
- declare function createConvexViaGraphFromXYConnections(xyConnections: XYConnection[], viaTile?: ViaTile, opts?: {
1134
+ declare function createConvexViaGraphFromXYConnections(xyConnections: XYConnection[], viaTileOrProblem?: ViaTile | ViaTileRecommendationProblemInput, opts?: {
1079
1135
  tileWidth?: number;
1080
1136
  tileHeight?: number;
1081
1137
  tileSize?: number;
@@ -1133,4 +1189,4 @@ declare function generateConvexViaTopologyRegions(opts: {
1133
1189
  };
1134
1190
  };
1135
1191
 
1136
- export { type Bounds$1 as Bounds, type BuildOpts, type Candidate, ConnectBuilder, type ConnectOpts, type Connection, type ConnectionId, type ConvexViaGraphFromXYConnectionsResult, type GScore, type GraphEdgeId, type HyperGraph, HyperGraphSolver, type JPort, type JRegion, JUMPER_GRAPH_SOLVER_DEFAULTS, type JumperGraph, JumperGraphSolver, type JumperGraphWithConnections, type NetworkId, type PortAssignment, PortBuilder, type PortData, type PortId, type PortSpread, type Region, RegionBuilder, type RegionData, type RegionId, type RegionPort, type RegionPortAssignment, type RegionRef, type RouteSegment, type SerializedConnection, type SerializedGraphPort, type SerializedGraphRegion, type SerializedHyperGraph, type SerializedRegionPortAssignment, type SharedBoundary, type SolvedRoute, Topology, TopologyError, VIA_GRAPH_SOLVER_DEFAULTS, type ValidateOpts, type ViaByNet, type ViaData, ViaGraphSolver, type ViaGraphWithConnections, type ViaTile, type XYConnection, applyTransformToGraph, calculateGraphBounds, convertConnectionsToSerializedConnections, convertHyperGraphToSerializedHyperGraph, createConvexViaGraphFromXYConnections, createGraphWithConnectionsFromBaseGraph, createViaGraphWithConnections, generateConvexViaTopologyRegions, generateDefaultViaTopologyRegions, generateJumperGrid, generateJumperX4Grid, generateViaTopologyRegions, rotateGraph90Degrees, viaTile4Regions as viaTile };
1192
+ export { type Bounds$1 as Bounds, type BuildOpts, type Candidate, ConnectBuilder, type ConnectOpts, type Connection, type ConnectionId, type ConvexViaGraphFromXYConnectionsResult, type GScore, type GraphEdgeId, type HyperGraph, HyperGraphSolver, type JPort, type JRegion, JUMPER_GRAPH_SOLVER_DEFAULTS, type JumperGraph, JumperGraphSolver, type JumperGraphWithConnections, type NetworkId, type PortAssignment, PortBuilder, type PortData, type PortId, type PortSpread, type Region, RegionBuilder, type RegionData, type RegionId, type RegionPort, type RegionPortAssignment, type RegionRef, type RouteSegment, type SerializedConnection, type SerializedGraphPort, type SerializedGraphRegion, type SerializedHyperGraph, type SerializedRegionPortAssignment, type SharedBoundary, type SolvedRoute, Topology, TopologyError, VIA_GRAPH_SOLVER_DEFAULTS, type ValidateOpts, type ViaByNet, type ViaData, ViaGraphSolver, type ViaGraphWithConnections, type ViaTile, type ViaTileRecommendation, type ViaTileRecommendationCandidate, type ViaTileRecommendationProblemInput, type XYConnection, applyTransformToGraph, calculateGraphBounds, convertConnectionsToSerializedConnections, convertHyperGraphToSerializedHyperGraph, createConvexViaGraphFromXYConnections, createGraphWithConnectionsFromBaseGraph, createViaGraphWithConnections, generateConvexViaTopologyRegions, generateDefaultViaTopologyRegions, generateJumperGrid, generateJumperX4Grid, generateViaTopologyRegions, recommendViaTileFromGraphInput, rotateGraph90Degrees, viaTile4Regions as viaTile };
package/dist/index.js CHANGED
@@ -16681,8 +16681,1081 @@ function generateConvexViaTopologyRegions(opts) {
16681
16681
  };
16682
16682
  }
16683
16683
 
16684
+ // assets/ViaGraphSolver/via-tile-3-regions.json
16685
+ var via_tile_3_regions_default = {
16686
+ viasByNet: {
16687
+ net1: [
16688
+ {
16689
+ viaId: "1b0111be-ce08-409a-80b7-5006cb5e2c5b",
16690
+ diameter: 0.3,
16691
+ position: {
16692
+ x: -0.396773,
16693
+ y: 0.05144
16694
+ }
16695
+ },
16696
+ {
16697
+ viaId: "2f36dd01-8bf4-49dc-b86b-22c27e4cb7bf",
16698
+ diameter: 0.3,
16699
+ position: {
16700
+ x: -0.04486,
16701
+ y: -0.267596
16702
+ }
16703
+ }
16704
+ ],
16705
+ net2: [
16706
+ {
16707
+ viaId: "51af4ca3-53f4-4a03-914b-6dba63eb8c4a",
16708
+ diameter: 0.3,
16709
+ position: {
16710
+ x: 0.39936,
16711
+ y: 0.600815
16712
+ }
16713
+ },
16714
+ {
16715
+ viaId: "b602bfde-3ed8-4f47-9fa7-5baa7a8a9ec4",
16716
+ diameter: 0.3,
16717
+ position: {
16718
+ x: -0.563329,
16719
+ y: -0.420006
16720
+ }
16721
+ }
16722
+ ],
16723
+ net3: [
16724
+ {
16725
+ viaId: "095a83cb-28a7-472c-95fe-bfb08db097f5",
16726
+ diameter: 0.3,
16727
+ position: {
16728
+ x: -0.070756,
16729
+ y: 0.430539
16730
+ }
16731
+ },
16732
+ {
16733
+ viaId: "e8d75a9d-5b0e-4158-8d39-01b264e49299",
16734
+ diameter: 0.3,
16735
+ position: {
16736
+ x: 0.280866,
16737
+ y: 0.111752
16738
+ }
16739
+ }
16740
+ ]
16741
+ },
16742
+ routeSegments: [
16743
+ {
16744
+ routeId: "net1:route_0",
16745
+ fromPort: "1b0111be-ce08-409a-80b7-5006cb5e2c5b",
16746
+ toPort: "2f36dd01-8bf4-49dc-b86b-22c27e4cb7bf",
16747
+ layer: "bottom",
16748
+ segments: [
16749
+ {
16750
+ x: -0.396773,
16751
+ y: 0.05144
16752
+ },
16753
+ {
16754
+ x: -0.363896,
16755
+ y: 0.05144
16756
+ },
16757
+ {
16758
+ x: -0.04486,
16759
+ y: -0.267596
16760
+ }
16761
+ ]
16762
+ },
16763
+ {
16764
+ routeId: "net2:route_0",
16765
+ fromPort: "51af4ca3-53f4-4a03-914b-6dba63eb8c4a",
16766
+ toPort: "b602bfde-3ed8-4f47-9fa7-5baa7a8a9ec4",
16767
+ layer: "bottom",
16768
+ segments: [
16769
+ {
16770
+ x: 0.39936,
16771
+ y: 0.600815
16772
+ },
16773
+ {
16774
+ x: 0.681866,
16775
+ y: 0.318309
16776
+ },
16777
+ {
16778
+ x: 0.681866,
16779
+ y: -0.10797
16780
+ },
16781
+ {
16782
+ x: 0.12124,
16783
+ y: -0.668596
16784
+ },
16785
+ {
16786
+ x: -0.314739,
16787
+ y: -0.668596
16788
+ },
16789
+ {
16790
+ x: -0.563329,
16791
+ y: -0.420006
16792
+ }
16793
+ ]
16794
+ },
16795
+ {
16796
+ routeId: "net3:route_0",
16797
+ fromPort: "095a83cb-28a7-472c-95fe-bfb08db097f5",
16798
+ toPort: "e8d75a9d-5b0e-4158-8d39-01b264e49299",
16799
+ layer: "bottom",
16800
+ segments: [
16801
+ {
16802
+ x: -0.070756,
16803
+ y: 0.430539
16804
+ },
16805
+ {
16806
+ x: -0.037921,
16807
+ y: 0.430539
16808
+ },
16809
+ {
16810
+ x: 0.280866,
16811
+ y: 0.111752
16812
+ }
16813
+ ]
16814
+ }
16815
+ ],
16816
+ tileWidth: 1.6201949999999998,
16817
+ tileHeight: 1.6444109999999998
16818
+ };
16819
+
16820
+ // assets/ViaGraphSolver/via-tile-5-regions.json
16821
+ var via_tile_5_regions_default = {
16822
+ viasByNet: {
16823
+ net1: [
16824
+ {
16825
+ viaId: "14ee4bf1-e7e7-4351-ad16-ba1a8aac0af3",
16826
+ diameter: 0.3,
16827
+ position: {
16828
+ x: 0.778514,
16829
+ y: -0.012215
16830
+ }
16831
+ },
16832
+ {
16833
+ viaId: "8a898812-db2b-4b81-899d-f953b3222f9a",
16834
+ diameter: 0.3,
16835
+ position: {
16836
+ x: -0.770591,
16837
+ y: 0.97317
16838
+ }
16839
+ }
16840
+ ],
16841
+ net2: [
16842
+ {
16843
+ viaId: "1f552ada-e01a-4230-b5f5-0006595b14d5",
16844
+ diameter: 0.3,
16845
+ position: {
16846
+ x: 1.014826,
16847
+ y: 0.42842
16848
+ }
16849
+ },
16850
+ {
16851
+ viaId: "6987544a-501f-4711-bdff-dc583936a21c",
16852
+ diameter: 0.3,
16853
+ position: {
16854
+ x: -0.854951,
16855
+ y: -0.884286
16856
+ }
16857
+ }
16858
+ ],
16859
+ net3: [
16860
+ {
16861
+ viaId: "13cd75da-d582-4eed-bc2c-fee6fa78bc6a",
16862
+ diameter: 0.3,
16863
+ position: {
16864
+ x: -1.067887,
16865
+ y: -0.431891
16866
+ }
16867
+ },
16868
+ {
16869
+ viaId: "9f188f9d-bce8-46c7-b9e8-542b8599d48d",
16870
+ diameter: 0.3,
16871
+ position: {
16872
+ x: 0.695984,
16873
+ y: 0.813573
16874
+ }
16875
+ }
16876
+ ],
16877
+ net4: [
16878
+ {
16879
+ viaId: "2ef3b96b-58c4-4150-b5d1-e90f74b92b25",
16880
+ diameter: 0.3,
16881
+ position: {
16882
+ x: -0.273716,
16883
+ y: 1.029009
16884
+ }
16885
+ },
16886
+ {
16887
+ viaId: "37a70467-7553-415f-8ad7-8b88a5e56ca8",
16888
+ diameter: 0.3,
16889
+ position: {
16890
+ x: -1.062855,
16891
+ y: 0.56748
16892
+ }
16893
+ },
16894
+ {
16895
+ viaId: "6d182b7d-a260-427b-8c43-a09409422252",
16896
+ diameter: 0.3,
16897
+ position: {
16898
+ x: 0.04738,
16899
+ y: -0.678598
16900
+ }
16901
+ }
16902
+ ],
16903
+ net5: [
16904
+ {
16905
+ viaId: "346c301a-f2b4-44d7-b975-5438ddaa0bde",
16906
+ diameter: 0.3,
16907
+ position: {
16908
+ x: 0.462204,
16909
+ y: -0.39945
16910
+ }
16911
+ },
16912
+ {
16913
+ viaId: "c54b4b94-90e0-4240-97ef-883cf097d79d",
16914
+ diameter: 0.3,
16915
+ position: {
16916
+ x: 0.22363,
16917
+ y: 0.977538
16918
+ }
16919
+ },
16920
+ {
16921
+ viaId: "f3cb916e-b0fd-4c5e-b14b-3779f4f9bd01",
16922
+ diameter: 0.3,
16923
+ position: {
16924
+ x: -1.047736,
16925
+ y: 0.067706
16926
+ }
16927
+ }
16928
+ ]
16929
+ },
16930
+ routeSegments: [
16931
+ {
16932
+ routeId: "net1:route_0",
16933
+ fromPort: "14ee4bf1-e7e7-4351-ad16-ba1a8aac0af3",
16934
+ toPort: "8a898812-db2b-4b81-899d-f953b3222f9a",
16935
+ layer: "bottom",
16936
+ segments: [
16937
+ {
16938
+ x: 0.778514,
16939
+ y: -0.012215
16940
+ },
16941
+ {
16942
+ x: 0.863204,
16943
+ y: -0.096905
16944
+ },
16945
+ {
16946
+ x: 0.863204,
16947
+ y: -0.56555
16948
+ },
16949
+ {
16950
+ x: 0.349156,
16951
+ y: -1.079598
16952
+ },
16953
+ {
16954
+ x: -0.11872,
16955
+ y: -1.079598
16956
+ },
16957
+ {
16958
+ x: -0.35362,
16959
+ y: -0.844698
16960
+ },
16961
+ {
16962
+ x: -0.35362,
16963
+ y: -0.818517
16964
+ },
16965
+ {
16966
+ x: -0.646736,
16967
+ y: -0.525401
16968
+ },
16969
+ {
16970
+ x: -0.646736,
16971
+ y: 0.849315
16972
+ },
16973
+ {
16974
+ x: -0.770591,
16975
+ y: 0.97317
16976
+ }
16977
+ ]
16978
+ },
16979
+ {
16980
+ routeId: "net2:route_0",
16981
+ fromPort: "1f552ada-e01a-4230-b5f5-0006595b14d5",
16982
+ toPort: "6987544a-501f-4711-bdff-dc583936a21c",
16983
+ layer: "bottom",
16984
+ segments: [
16985
+ {
16986
+ x: 1.014826,
16987
+ y: 0.42842
16988
+ },
16989
+ {
16990
+ x: 1.179514,
16991
+ y: 0.263732
16992
+ },
16993
+ {
16994
+ x: 1.179514,
16995
+ y: -0.674918
16996
+ },
16997
+ {
16998
+ x: 0.473834,
16999
+ y: -1.380598
17000
+ },
17001
+ {
17002
+ x: -0.358639,
17003
+ y: -1.380598
17004
+ },
17005
+ {
17006
+ x: -0.854951,
17007
+ y: -0.884286
17008
+ }
17009
+ ]
17010
+ },
17011
+ {
17012
+ routeId: "net3:route_0",
17013
+ fromPort: "13cd75da-d582-4eed-bc2c-fee6fa78bc6a",
17014
+ toPort: "9f188f9d-bce8-46c7-b9e8-542b8599d48d",
17015
+ layer: "bottom",
17016
+ segments: [
17017
+ {
17018
+ x: -1.067887,
17019
+ y: -0.431891
17020
+ },
17021
+ {
17022
+ x: -1.255951,
17023
+ y: -0.619955
17024
+ },
17025
+ {
17026
+ x: -1.255951,
17027
+ y: -1.050386
17028
+ },
17029
+ {
17030
+ x: -0.624739,
17031
+ y: -1.681598
17032
+ },
17033
+ {
17034
+ x: 0.598512,
17035
+ y: -1.681598
17036
+ },
17037
+ {
17038
+ x: 1.480514,
17039
+ y: -0.799596
17040
+ },
17041
+ {
17042
+ x: 1.480514,
17043
+ y: 0.529832
17044
+ },
17045
+ {
17046
+ x: 1.180926,
17047
+ y: 0.82942
17048
+ },
17049
+ {
17050
+ x: 0.711831,
17051
+ y: 0.82942
17052
+ },
17053
+ {
17054
+ x: 0.695984,
17055
+ y: 0.813573
17056
+ }
17057
+ ]
17058
+ },
17059
+ {
17060
+ routeId: "net4:route_0",
17061
+ fromPort: "2ef3b96b-58c4-4150-b5d1-e90f74b92b25",
17062
+ toPort: "37a70467-7553-415f-8ad7-8b88a5e56ca8",
17063
+ layer: "bottom",
17064
+ segments: [
17065
+ {
17066
+ x: -0.273716,
17067
+ y: 1.029009
17068
+ },
17069
+ {
17070
+ x: -0.273716,
17071
+ y: 1.043395
17072
+ },
17073
+ {
17074
+ x: -0.604491,
17075
+ y: 1.37417
17076
+ },
17077
+ {
17078
+ x: -0.936691,
17079
+ y: 1.37417
17080
+ },
17081
+ {
17082
+ x: -1.171591,
17083
+ y: 1.13927
17084
+ },
17085
+ {
17086
+ x: -1.171591,
17087
+ y: 0.676216
17088
+ },
17089
+ {
17090
+ x: -1.062855,
17091
+ y: 0.56748
17092
+ }
17093
+ ]
17094
+ },
17095
+ {
17096
+ routeId: "net4:route_1",
17097
+ fromPort: "2ef3b96b-58c4-4150-b5d1-e90f74b92b25",
17098
+ toPort: "6d182b7d-a260-427b-8c43-a09409422252",
17099
+ layer: "bottom",
17100
+ segments: [
17101
+ {
17102
+ x: -0.273716,
17103
+ y: 1.029009
17104
+ },
17105
+ {
17106
+ x: -0.273716,
17107
+ y: -0.357502
17108
+ },
17109
+ {
17110
+ x: 0.04738,
17111
+ y: -0.678598
17112
+ }
17113
+ ]
17114
+ },
17115
+ {
17116
+ routeId: "net5:route_0",
17117
+ fromPort: "346c301a-f2b4-44d7-b975-5438ddaa0bde",
17118
+ toPort: "c54b4b94-90e0-4240-97ef-883cf097d79d",
17119
+ layer: "bottom",
17120
+ segments: [
17121
+ {
17122
+ x: 0.462204,
17123
+ y: -0.39945
17124
+ },
17125
+ {
17126
+ x: 0.22363,
17127
+ y: -0.160876
17128
+ },
17129
+ {
17130
+ x: 0.22363,
17131
+ y: 0.977538
17132
+ }
17133
+ ]
17134
+ },
17135
+ {
17136
+ routeId: "net5:route_1",
17137
+ fromPort: "c54b4b94-90e0-4240-97ef-883cf097d79d",
17138
+ toPort: "f3cb916e-b0fd-4c5e-b14b-3779f4f9bd01",
17139
+ layer: "bottom",
17140
+ segments: [
17141
+ {
17142
+ x: 0.22363,
17143
+ y: 0.977538
17144
+ },
17145
+ {
17146
+ x: 0.22363,
17147
+ y: 1.098763
17148
+ },
17149
+ {
17150
+ x: -0.352777,
17151
+ y: 1.67517
17152
+ },
17153
+ {
17154
+ x: -1.061369,
17155
+ y: 1.67517
17156
+ },
17157
+ {
17158
+ x: -1.472591,
17159
+ y: 1.263948
17160
+ },
17161
+ {
17162
+ x: -1.472591,
17163
+ y: 0.410116
17164
+ },
17165
+ {
17166
+ x: -1.130181,
17167
+ y: 0.067706
17168
+ },
17169
+ {
17170
+ x: -1.047736,
17171
+ y: 0.067706
17172
+ }
17173
+ ]
17174
+ }
17175
+ ],
17176
+ tileWidth: 3.253105,
17177
+ tileHeight: 3.656768
17178
+ };
17179
+
17180
+ // assets/ViaGraphSolver/via-tile-6-regions.json
17181
+ var via_tile_6_regions_default = {
17182
+ viasByNet: {
17183
+ net1: [
17184
+ {
17185
+ viaId: "afbcad2b-4805-48e1-aa34-1f4472329d76",
17186
+ diameter: 0.3,
17187
+ position: {
17188
+ x: 0.648081,
17189
+ y: -0.653655
17190
+ }
17191
+ },
17192
+ {
17193
+ viaId: "d31e4843-afe8-4699-8221-70cba52d9589",
17194
+ diameter: 0.3,
17195
+ position: {
17196
+ x: 0.082317,
17197
+ y: 0.912692
17198
+ }
17199
+ }
17200
+ ],
17201
+ net2: [
17202
+ {
17203
+ viaId: "096f26d0-a555-4492-94da-865de1f8e6e6",
17204
+ diameter: 0.3,
17205
+ position: {
17206
+ x: 1.336913,
17207
+ y: 0.267523
17208
+ }
17209
+ },
17210
+ {
17211
+ viaId: "71432b8b-1d41-4586-88f8-1dd9c542b47b",
17212
+ diameter: 0.3,
17213
+ position: {
17214
+ x: -0.651699,
17215
+ y: -1.264802
17216
+ }
17217
+ }
17218
+ ],
17219
+ net3: [
17220
+ {
17221
+ viaId: "833f3d74-7403-4d5b-8999-848795f1be47",
17222
+ diameter: 0.3,
17223
+ position: {
17224
+ x: -0.652635,
17225
+ y: -0.2648
17226
+ }
17227
+ },
17228
+ {
17229
+ viaId: "ff5f1055-a4f7-4a85-a790-4769e4eea87b",
17230
+ diameter: 0.3,
17231
+ position: {
17232
+ x: 0.58222,
17233
+ y: 0.92265
17234
+ }
17235
+ }
17236
+ ],
17237
+ net4: [
17238
+ {
17239
+ viaId: "6e2c4dc3-f43d-4f13-bff3-c0e08585ceb1",
17240
+ diameter: 0.3,
17241
+ position: {
17242
+ x: -0.15182,
17243
+ y: -1.253675
17244
+ }
17245
+ },
17246
+ {
17247
+ viaId: "b11b8fa4-a804-42b8-8de3-4416f00feda9",
17248
+ diameter: 0.3,
17249
+ position: {
17250
+ x: -0.650488,
17251
+ y: 0.235198
17252
+ }
17253
+ }
17254
+ ],
17255
+ net5: [
17256
+ {
17257
+ viaId: "bd0008ee-fb87-4f6a-922b-14f6d989ee78",
17258
+ diameter: 0.3,
17259
+ position: {
17260
+ x: -0.305576,
17261
+ y: 0.59719
17262
+ }
17263
+ },
17264
+ {
17265
+ viaId: "cd839c31-ee5e-47be-973e-a4e0fd041bae",
17266
+ diameter: 0.3,
17267
+ position: {
17268
+ x: 0.251735,
17269
+ y: -0.95847
17270
+ }
17271
+ }
17272
+ ],
17273
+ net6: [
17274
+ {
17275
+ viaId: "aa3a0b88-786d-4e3a-9cf4-ab924faca4e9",
17276
+ diameter: 0.3,
17277
+ position: {
17278
+ x: -0.65095,
17279
+ y: -0.7648
17280
+ }
17281
+ },
17282
+ {
17283
+ viaId: "c0f2259e-7d00-43c3-bfa3-183bc4286c46",
17284
+ diameter: 0.3,
17285
+ position: {
17286
+ x: 0.971187,
17287
+ y: 0.608473
17288
+ }
17289
+ }
17290
+ ]
17291
+ },
17292
+ routeSegments: [
17293
+ {
17294
+ routeId: "net1:route_0",
17295
+ fromPort: "afbcad2b-4805-48e1-aa34-1f4472329d76",
17296
+ toPort: "d31e4843-afe8-4699-8221-70cba52d9589",
17297
+ layer: "bottom",
17298
+ segments: [
17299
+ {
17300
+ x: 0.648081,
17301
+ y: -0.653655
17302
+ },
17303
+ {
17304
+ x: 0.648081,
17305
+ y: 0.268604
17306
+ },
17307
+ {
17308
+ x: 0.082317,
17309
+ y: 0.834368
17310
+ },
17311
+ {
17312
+ x: 0.082317,
17313
+ y: 0.912692
17314
+ }
17315
+ ]
17316
+ },
17317
+ {
17318
+ routeId: "net2:route_0",
17319
+ fromPort: "096f26d0-a555-4492-94da-865de1f8e6e6",
17320
+ toPort: "71432b8b-1d41-4586-88f8-1dd9c542b47b",
17321
+ layer: "bottom",
17322
+ segments: [
17323
+ {
17324
+ x: 1.336913,
17325
+ y: 0.267523
17326
+ },
17327
+ {
17328
+ x: 1.336913,
17329
+ y: -0.531923
17330
+ },
17331
+ {
17332
+ x: 0.214161,
17333
+ y: -1.654675
17334
+ },
17335
+ {
17336
+ x: -0.31792,
17337
+ y: -1.654675
17338
+ },
17339
+ {
17340
+ x: -0.651699,
17341
+ y: -1.320896
17342
+ },
17343
+ {
17344
+ x: -0.651699,
17345
+ y: -1.264802
17346
+ }
17347
+ ]
17348
+ },
17349
+ {
17350
+ routeId: "net3:route_0",
17351
+ fromPort: "833f3d74-7403-4d5b-8999-848795f1be47",
17352
+ toPort: "ff5f1055-a4f7-4a85-a790-4769e4eea87b",
17353
+ layer: "bottom",
17354
+ segments: [
17355
+ {
17356
+ x: -0.652635,
17357
+ y: -0.2648
17358
+ },
17359
+ {
17360
+ x: -0.71759,
17361
+ y: -0.2648
17362
+ },
17363
+ {
17364
+ x: -1.051488,
17365
+ y: 0.069098
17366
+ },
17367
+ {
17368
+ x: -1.051488,
17369
+ y: 0.418378
17370
+ },
17371
+ {
17372
+ x: -0.156174,
17373
+ y: 1.313692
17374
+ },
17375
+ {
17376
+ x: 0.248417,
17377
+ y: 1.313692
17378
+ },
17379
+ {
17380
+ x: 0.58222,
17381
+ y: 0.979889
17382
+ },
17383
+ {
17384
+ x: 0.58222,
17385
+ y: 0.92265
17386
+ }
17387
+ ]
17388
+ },
17389
+ {
17390
+ routeId: "net4:route_0",
17391
+ fromPort: "6e2c4dc3-f43d-4f13-bff3-c0e08585ceb1",
17392
+ toPort: "b11b8fa4-a804-42b8-8de3-4416f00feda9",
17393
+ layer: "bottom",
17394
+ segments: [
17395
+ {
17396
+ x: -0.15182,
17397
+ y: -1.253675
17398
+ },
17399
+ {
17400
+ x: -0.15182,
17401
+ y: -0.198515
17402
+ },
17403
+ {
17404
+ x: -0.585533,
17405
+ y: 0.235198
17406
+ },
17407
+ {
17408
+ x: -0.650488,
17409
+ y: 0.235198
17410
+ }
17411
+ ]
17412
+ },
17413
+ {
17414
+ routeId: "net5:route_0",
17415
+ fromPort: "bd0008ee-fb87-4f6a-922b-14f6d989ee78",
17416
+ toPort: "cd839c31-ee5e-47be-973e-a4e0fd041bae",
17417
+ layer: "bottom",
17418
+ segments: [
17419
+ {
17420
+ x: -0.305576,
17421
+ y: 0.59719
17422
+ },
17423
+ {
17424
+ x: 0.14918,
17425
+ y: 0.142434
17426
+ },
17427
+ {
17428
+ x: 0.14918,
17429
+ y: -0.855915
17430
+ },
17431
+ {
17432
+ x: 0.251735,
17433
+ y: -0.95847
17434
+ }
17435
+ ]
17436
+ },
17437
+ {
17438
+ routeId: "net6:route_0",
17439
+ fromPort: "aa3a0b88-786d-4e3a-9cf4-ab924faca4e9",
17440
+ toPort: "c0f2259e-7d00-43c3-bfa3-183bc4286c46",
17441
+ layer: "bottom",
17442
+ segments: [
17443
+ {
17444
+ x: -0.65095,
17445
+ y: -0.7648
17446
+ },
17447
+ {
17448
+ x: -0.75509,
17449
+ y: -0.7648
17450
+ },
17451
+ {
17452
+ x: -1.402488,
17453
+ y: -0.117402
17454
+ },
17455
+ {
17456
+ x: -1.402488,
17457
+ y: 0.563766
17458
+ },
17459
+ {
17460
+ x: -0.301563,
17461
+ y: 1.664692
17462
+ },
17463
+ {
17464
+ x: 0.442633,
17465
+ y: 1.664692
17466
+ },
17467
+ {
17468
+ x: 1.023297,
17469
+ y: 1.084028
17470
+ },
17471
+ {
17472
+ x: 1.023297,
17473
+ y: 0.660583
17474
+ },
17475
+ {
17476
+ x: 0.971187,
17477
+ y: 0.608473
17478
+ }
17479
+ ]
17480
+ }
17481
+ ],
17482
+ tileWidth: 3.1144009999999995,
17483
+ tileHeight: 3.619367
17484
+ };
17485
+
17486
+ // lib/ViaGraphSolver/via-graph-generator/recommendViaTileFromGraphInput.ts
17487
+ var DEFAULT_VIA_TILE_CANDIDATES = [
17488
+ {
17489
+ viaRegionName: "via-tile-3-regions",
17490
+ viaTile: via_tile_3_regions_default
17491
+ },
17492
+ {
17493
+ viaRegionName: "via-tile-4-regions",
17494
+ viaTile: via_tile_4_regions_default
17495
+ },
17496
+ {
17497
+ viaRegionName: "via-tile-5-regions",
17498
+ viaTile: via_tile_5_regions_default
17499
+ },
17500
+ {
17501
+ viaRegionName: "via-tile-6-regions",
17502
+ viaTile: via_tile_6_regions_default
17503
+ }
17504
+ ];
17505
+ var round2 = (value) => Math.round(value * 100) / 100;
17506
+ var clamp4 = (value, min, max) => Math.max(min, Math.min(max, value));
17507
+ var sigmoid = (x) => 1 / (1 + Math.exp(-x));
17508
+ var ccw = (a, b, c) => (c.y - a.y) * (b.x - a.x) > (b.y - a.y) * (c.x - a.x);
17509
+ var segmentsIntersect = (a1, a2, b1, b2) => ccw(a1, b1, b2) !== ccw(a2, b1, b2) && ccw(a1, a2, b1) !== ccw(a1, a2, b2);
17510
+ var countIntersections = (xyConnections) => {
17511
+ let intersections = 0;
17512
+ for (let i = 0; i < xyConnections.length; i++) {
17513
+ for (let j = i + 1; j < xyConnections.length; j++) {
17514
+ if (segmentsIntersect(
17515
+ xyConnections[i].start,
17516
+ xyConnections[i].end,
17517
+ xyConnections[j].start,
17518
+ xyConnections[j].end
17519
+ )) {
17520
+ intersections++;
17521
+ }
17522
+ }
17523
+ }
17524
+ return intersections;
17525
+ };
17526
+ var getBoundsFromSample = (sample) => {
17527
+ const regions = sample.connectionRegions ?? [];
17528
+ if (regions.length === 0) return null;
17529
+ const minX = Math.min(...regions.map((r) => r.d.bounds.minX));
17530
+ const maxX = Math.max(...regions.map((r) => r.d.bounds.maxX));
17531
+ const minY = Math.min(...regions.map((r) => r.d.bounds.minY));
17532
+ const maxY = Math.max(...regions.map((r) => r.d.bounds.maxY));
17533
+ return {
17534
+ widthMm: maxX - minX,
17535
+ heightMm: maxY - minY
17536
+ };
17537
+ };
17538
+ var extractXYConnectionsFromSample = (sample) => {
17539
+ const connections = sample.connections ?? [];
17540
+ const regionMap = new Map(
17541
+ (sample.connectionRegions ?? []).map((r) => [r.regionId, r.d.center])
17542
+ );
17543
+ const xyConnections = [];
17544
+ for (const conn of connections) {
17545
+ const start = regionMap.get(conn.startRegionId);
17546
+ const end = regionMap.get(conn.endRegionId);
17547
+ if (!start || !end) continue;
17548
+ xyConnections.push({
17549
+ connectionId: conn.connectionId,
17550
+ start,
17551
+ end
17552
+ });
17553
+ }
17554
+ return xyConnections;
17555
+ };
17556
+ var predictViaRegionFromGraphPattern = (input) => {
17557
+ const area = Math.max(input.graphWidthMm * input.graphHeightMm, 0.01);
17558
+ const density = input.connectionCount / area;
17559
+ if (density <= 0.032343248633284985) {
17560
+ if (input.connectionCount <= 11.5) {
17561
+ if (input.connectionCount === 8 && input.intersectionCount >= 17 && input.graphWidthMm <= 15 && input.graphHeightMm >= 20) {
17562
+ return "via-tile-5-regions";
17563
+ }
17564
+ return "via-tile-6-regions";
17565
+ }
17566
+ return "via-tile-3-regions";
17567
+ }
17568
+ if (input.graphHeightMm <= 12.600000000000001) {
17569
+ return "via-tile-3-regions";
17570
+ }
17571
+ if (input.graphWidthMm <= 13.41) {
17572
+ return "via-tile-4-regions";
17573
+ }
17574
+ return "via-tile-5-regions";
17575
+ };
17576
+ var getViaTileBounds = (viaTile) => {
17577
+ const points = [];
17578
+ for (const vias of Object.values(viaTile.viasByNet)) {
17579
+ for (const via of vias) points.push(via.position);
17580
+ }
17581
+ for (const route of viaTile.routeSegments) {
17582
+ for (const p of route.segments) points.push(p);
17583
+ }
17584
+ if (points.length === 0) {
17585
+ return { width: 1, height: 1 };
17586
+ }
17587
+ const minX = Math.min(...points.map((p) => p.x));
17588
+ const maxX = Math.max(...points.map((p) => p.x));
17589
+ const minY = Math.min(...points.map((p) => p.y));
17590
+ const maxY = Math.max(...points.map((p) => p.y));
17591
+ return {
17592
+ width: Math.max(maxX - minX, 0.01),
17593
+ height: Math.max(maxY - minY, 0.01)
17594
+ };
17595
+ };
17596
+ var scoreViaTileForProblem = (problem, candidate) => {
17597
+ const viaCount = Object.values(candidate.viaTile.viasByNet).reduce(
17598
+ (sum, vias) => sum + vias.length,
17599
+ 0
17600
+ );
17601
+ const netCount = Object.keys(candidate.viaTile.viasByNet).length;
17602
+ const routeSegmentCount = candidate.viaTile.routeSegments.length;
17603
+ const bounds = getViaTileBounds(candidate.viaTile);
17604
+ const tileArea = Math.max(
17605
+ candidate.viaTile.tileWidth && candidate.viaTile.tileHeight ? candidate.viaTile.tileWidth * candidate.viaTile.tileHeight : bounds.width * bounds.height,
17606
+ 0.01
17607
+ );
17608
+ const graphArea = Math.max(problem.graphWidthMm * problem.graphHeightMm, 0.01);
17609
+ const crossingPerConnection = problem.intersectionCount / Math.max(problem.connectionCount, 1);
17610
+ const density = problem.connectionCount / graphArea;
17611
+ const requiredCapacityScore = problem.connectionCount * 1.2 + problem.intersectionCount * 1.5 + crossingPerConnection * 5 + density * 40;
17612
+ const capacityScore = viaCount * 3.1 + routeSegmentCount * 2.4 + netCount * 4 + 1 / tileArea * 4.5;
17613
+ const predictedReliability = clamp4(
17614
+ sigmoid((capacityScore - requiredCapacityScore) / 3.2),
17615
+ 0,
17616
+ 1
17617
+ );
17618
+ const oversupplyRatio = Math.max(
17619
+ 0,
17620
+ (capacityScore - requiredCapacityScore) / Math.max(requiredCapacityScore, 1)
17621
+ );
17622
+ const undersupplyRatio = Math.max(
17623
+ 0,
17624
+ (requiredCapacityScore - capacityScore) / Math.max(requiredCapacityScore, 1)
17625
+ );
17626
+ const estimatedIterationCost = problem.connectionCount * 120 + problem.intersectionCount * 140 + oversupplyRatio * 900 + undersupplyRatio * 6e3;
17627
+ return {
17628
+ viaRegionName: candidate.viaRegionName,
17629
+ predictedReliability,
17630
+ estimatedIterationCost,
17631
+ capacityScore,
17632
+ requiredCapacityScore,
17633
+ acceptedAsReliable: predictedReliability >= 0.9
17634
+ };
17635
+ };
17636
+ var calculateBoundsFromConnections = (xyConnections) => {
17637
+ if (xyConnections.length === 0) {
17638
+ throw new Error("Cannot calculate bounds from empty connections array");
17639
+ }
17640
+ let minX = Infinity;
17641
+ let maxX = -Infinity;
17642
+ let minY = Infinity;
17643
+ let maxY = -Infinity;
17644
+ for (const conn of xyConnections) {
17645
+ minX = Math.min(minX, conn.start.x, conn.end.x);
17646
+ maxX = Math.max(maxX, conn.start.x, conn.end.x);
17647
+ minY = Math.min(minY, conn.start.y, conn.end.y);
17648
+ maxY = Math.max(maxY, conn.start.y, conn.end.y);
17649
+ }
17650
+ return { minX, maxX, minY, maxY };
17651
+ };
17652
+ var normalizeGraphProblemInput = (input, fallbackXYConnections) => {
17653
+ const xyConnections = (input.xyConnections && input.xyConnections.length > 0 ? input.xyConnections : fallbackXYConnections).slice();
17654
+ let graphWidthMm = input.graphWidthMm;
17655
+ let graphHeightMm = input.graphHeightMm;
17656
+ let connectionCount = input.connectionCount;
17657
+ let intersectionCount = input.intersectionCount;
17658
+ if (input.sample) {
17659
+ const sampleXYConnections = extractXYConnectionsFromSample(input.sample);
17660
+ if (xyConnections.length === 0 && sampleXYConnections.length > 0) {
17661
+ xyConnections.push(...sampleXYConnections);
17662
+ }
17663
+ if (!connectionCount) {
17664
+ connectionCount = input.sample.connections?.length ?? xyConnections.length;
17665
+ }
17666
+ if (intersectionCount == null) {
17667
+ intersectionCount = input.sample.config?.numCrossings ?? (xyConnections.length > 0 ? countIntersections(xyConnections) : 0);
17668
+ }
17669
+ if (graphWidthMm == null || graphHeightMm == null) {
17670
+ const bounds = getBoundsFromSample(input.sample);
17671
+ if (bounds) {
17672
+ graphWidthMm = graphWidthMm ?? bounds.widthMm;
17673
+ graphHeightMm = graphHeightMm ?? bounds.heightMm;
17674
+ }
17675
+ }
17676
+ }
17677
+ if (xyConnections.length > 0) {
17678
+ const bounds = calculateBoundsFromConnections(xyConnections);
17679
+ graphWidthMm = graphWidthMm ?? bounds.maxX - bounds.minX;
17680
+ graphHeightMm = graphHeightMm ?? bounds.maxY - bounds.minY;
17681
+ connectionCount = connectionCount ?? xyConnections.length;
17682
+ intersectionCount = intersectionCount ?? countIntersections(xyConnections);
17683
+ }
17684
+ if (graphWidthMm == null || graphHeightMm == null || connectionCount == null || intersectionCount == null) {
17685
+ throw new Error(
17686
+ "Insufficient graph input. Provide width/height/connections/intersections, or pass xyConnections."
17687
+ );
17688
+ }
17689
+ return {
17690
+ graphWidthMm: round2(graphWidthMm),
17691
+ graphHeightMm: round2(graphHeightMm),
17692
+ connectionCount,
17693
+ intersectionCount
17694
+ };
17695
+ };
17696
+ var recommendViaTileFromGraphInput = (problemInput, fallbackXYConnections = [], viaTileCandidates = DEFAULT_VIA_TILE_CANDIDATES, _opts) => {
17697
+ if (viaTileCandidates.length === 0) {
17698
+ throw new Error("No via-tile candidates provided");
17699
+ }
17700
+ const xyConnections = problemInput.xyConnections && problemInput.xyConnections.length > 0 ? problemInput.xyConnections : fallbackXYConnections;
17701
+ const normalizedInput = normalizeGraphProblemInput(
17702
+ problemInput,
17703
+ xyConnections
17704
+ );
17705
+ const scored = viaTileCandidates.map((candidate) => scoreViaTileForProblem(normalizedInput, candidate)).sort((a, b) => {
17706
+ if (a.acceptedAsReliable !== b.acceptedAsReliable) {
17707
+ return a.acceptedAsReliable ? -1 : 1;
17708
+ }
17709
+ if (a.acceptedAsReliable && b.acceptedAsReliable) {
17710
+ if (a.estimatedIterationCost !== b.estimatedIterationCost) {
17711
+ return a.estimatedIterationCost - b.estimatedIterationCost;
17712
+ }
17713
+ } else if (a.predictedReliability !== b.predictedReliability) {
17714
+ return b.predictedReliability - a.predictedReliability;
17715
+ }
17716
+ return a.estimatedIterationCost - b.estimatedIterationCost;
17717
+ });
17718
+ const predictedViaRegionName = predictViaRegionFromGraphPattern(normalizedInput);
17719
+ if (predictedViaRegionName) {
17720
+ const predictedCandidate = scored.find(
17721
+ (candidate) => candidate.viaRegionName === predictedViaRegionName
17722
+ );
17723
+ if (predictedCandidate) {
17724
+ const reordered = [
17725
+ predictedCandidate,
17726
+ ...scored.filter(
17727
+ (candidate) => candidate.viaRegionName !== predictedViaRegionName
17728
+ )
17729
+ ];
17730
+ return {
17731
+ recommendedViaRegionName: reordered[0].viaRegionName,
17732
+ inputFeatures: normalizedInput,
17733
+ candidates: reordered
17734
+ };
17735
+ }
17736
+ }
17737
+ return {
17738
+ recommendedViaRegionName: scored[0].viaRegionName,
17739
+ inputFeatures: normalizedInput,
17740
+ candidates: scored
17741
+ };
17742
+ };
17743
+ var selectViaTileForProblemInput = (problemInput, xyConnections) => {
17744
+ const recommendation = recommendViaTileFromGraphInput(
17745
+ problemInput,
17746
+ xyConnections
17747
+ );
17748
+ const selectedCandidate = DEFAULT_VIA_TILE_CANDIDATES.find(
17749
+ (candidate) => candidate.viaRegionName === recommendation.recommendedViaRegionName
17750
+ );
17751
+ return selectedCandidate?.viaTile ?? via_tile_4_regions_default;
17752
+ };
17753
+
16684
17754
  // lib/ViaGraphSolver/via-graph-generator/createConvexViaGraphFromXYConnections.ts
16685
- function calculateBoundsFromConnections(xyConnections) {
17755
+ var isViaTile = (input) => Boolean(
17756
+ input && typeof input === "object" && "viasByNet" in input && "routeSegments" in input
17757
+ );
17758
+ function calculateBoundsFromConnections2(xyConnections) {
16686
17759
  if (xyConnections.length === 0) {
16687
17760
  throw new Error("Cannot calculate bounds from empty connections array");
16688
17761
  }
@@ -16698,18 +17771,25 @@ function calculateBoundsFromConnections(xyConnections) {
16698
17771
  }
16699
17772
  return { minX, maxX, minY, maxY };
16700
17773
  }
16701
- function createConvexViaGraphFromXYConnections(xyConnections, viaTile = via_tile_4_regions_default, opts) {
16702
- const bounds = calculateBoundsFromConnections(xyConnections);
17774
+ function createConvexViaGraphFromXYConnections(xyConnections, viaTileOrProblem, opts) {
17775
+ const selectedViaTile = isViaTile(viaTileOrProblem) ? viaTileOrProblem : selectViaTileForProblemInput(
17776
+ {
17777
+ ...viaTileOrProblem ?? {},
17778
+ xyConnections: viaTileOrProblem?.xyConnections ?? xyConnections
17779
+ },
17780
+ xyConnections
17781
+ );
17782
+ const bounds = calculateBoundsFromConnections2(xyConnections);
16703
17783
  const {
16704
17784
  regions,
16705
17785
  ports,
16706
17786
  viaTile: generatedViaTile,
16707
17787
  tileCount
16708
17788
  } = generateConvexViaTopologyRegions({
16709
- viaTile,
17789
+ viaTile: selectedViaTile,
16710
17790
  bounds,
16711
- tileWidth: opts?.tileWidth ?? viaTile.tileWidth,
16712
- tileHeight: opts?.tileHeight ?? viaTile.tileHeight,
17791
+ tileWidth: opts?.tileWidth ?? selectedViaTile.tileWidth,
17792
+ tileHeight: opts?.tileHeight ?? selectedViaTile.tileHeight,
16713
17793
  tileSize: opts?.tileSize,
16714
17794
  portPitch: opts?.portPitch,
16715
17795
  clearance: opts?.clearance,
@@ -16749,6 +17829,7 @@ export {
16749
17829
  generateJumperGrid,
16750
17830
  generateJumperX4Grid,
16751
17831
  generateViaTopologyRegions,
17832
+ recommendViaTileFromGraphInput,
16752
17833
  rotateGraph90Degrees,
16753
17834
  via_tile_4_regions_default as viaTile
16754
17835
  };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@tscircuit/hypergraph",
3
3
  "main": "dist/index.js",
4
- "version": "0.0.50",
4
+ "version": "0.0.52",
5
5
  "type": "module",
6
6
  "scripts": {
7
7
  "start": "cosmos",