@tscircuit/capacity-autorouter 0.0.52 → 0.0.53

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
@@ -1,3 +1,4 @@
1
+ import * as graphics_debug from 'graphics-debug';
1
2
  import { GraphicsObject } from 'graphics-debug';
2
3
  import { ConnectivityMap } from 'circuit-json-to-connectivity-map';
3
4
 
@@ -242,80 +243,6 @@ declare class CapacityMeshNodeSolver2_NodeUnderObstacle extends CapacityMeshNode
242
243
  _step(): void;
243
244
  }
244
245
 
245
- interface CapacityHyperParameters {
246
- VIA_DIAMETER: number;
247
- TRACE_WIDTH: number;
248
- MAX_CAPACITY_FACTOR: number;
249
- }
250
-
251
- type Candidate = {
252
- prevCandidate: Candidate | null;
253
- node: CapacityMeshNode;
254
- f: number;
255
- g: number;
256
- h: number;
257
- };
258
- declare class CapacityPathingSolver extends BaseSolver {
259
- connectionsWithNodes: Array<{
260
- connection: SimpleRouteConnection;
261
- nodes: CapacityMeshNode[];
262
- path?: CapacityMeshNode[];
263
- straightLineDistance: number;
264
- }>;
265
- usedNodeCapacityMap: Map<CapacityMeshNodeId, number>;
266
- simpleRouteJson: SimpleRouteJson;
267
- nodes: CapacityMeshNode[];
268
- edges: CapacityMeshEdge[];
269
- GREEDY_MULTIPLIER: number;
270
- nodeMap: Map<CapacityMeshNodeId, CapacityMeshNode>;
271
- nodeEdgeMap: Map<CapacityMeshNodeId, CapacityMeshEdge[]>;
272
- connectionNameToGoalNodeIds: Map<string, CapacityMeshNodeId[]>;
273
- colorMap: Record<string, string>;
274
- maxDepthOfNodes: number;
275
- activeCandidateStraightLineDistance?: number;
276
- debug_lastNodeCostMap: Map<CapacityMeshNodeId, {
277
- g: number;
278
- h: number;
279
- f: number;
280
- }>;
281
- hyperParameters: Partial<CapacityHyperParameters>;
282
- constructor({ simpleRouteJson, nodes, edges, colorMap, MAX_ITERATIONS, hyperParameters, }: {
283
- simpleRouteJson: SimpleRouteJson;
284
- nodes: CapacityMeshNode[];
285
- edges: CapacityMeshEdge[];
286
- colorMap?: Record<string, string>;
287
- MAX_ITERATIONS?: number;
288
- hyperParameters?: Partial<CapacityHyperParameters>;
289
- });
290
- getTotalCapacity(node: CapacityMeshNode): number;
291
- getConnectionsWithNodes(): {
292
- connectionsWithNodes: {
293
- connection: SimpleRouteConnection;
294
- nodes: CapacityMeshNode[];
295
- pathFound: boolean;
296
- straightLineDistance: number;
297
- }[];
298
- connectionNameToGoalNodeIds: Map<string, string[]>;
299
- };
300
- currentConnectionIndex: number;
301
- candidates?: Array<Candidate> | null;
302
- visitedNodes?: Set<CapacityMeshNodeId> | null;
303
- computeG(prevCandidate: Candidate, node: CapacityMeshNode, endGoal: CapacityMeshNode): number;
304
- computeH(prevCandidate: Candidate, node: CapacityMeshNode, endGoal: CapacityMeshNode): number;
305
- getBacktrackedPath(candidate: Candidate): CapacityMeshNode[];
306
- getNeighboringNodes(node: CapacityMeshNode): CapacityMeshNode[];
307
- getCapacityPaths(): CapacityPath[];
308
- doesNodeHaveCapacityForTrace(node: CapacityMeshNode, prevNode: CapacityMeshNode): boolean;
309
- canTravelThroughObstacle(node: CapacityMeshNode, connectionName: string): boolean;
310
- getDistanceBetweenNodes(A: CapacityMeshNode, B: CapacityMeshNode): number;
311
- reduceCapacityAlongPath(nextConnection: {
312
- path?: CapacityMeshNode[];
313
- }): void;
314
- isConnectedToEndGoal(node: CapacityMeshNode, endGoal: CapacityMeshNode): boolean;
315
- _step(): void;
316
- visualize(): GraphicsObject;
317
- }
318
-
319
246
  interface NodePortSegment {
320
247
  capacityMeshNodeId: string;
321
248
  nodePortSegmentId?: string;
@@ -700,6 +627,7 @@ declare class TwoCrossingRoutesHighDensitySolver extends BaseSolver {
700
627
  via1: Point$2;
701
628
  via2: Point$2;
702
629
  }[];
630
+ escapeLayer: number;
703
631
  solvedRoutes: HighDensityIntraNodeRoute$1[];
704
632
  bounds: {
705
633
  minX: number;
@@ -727,20 +655,14 @@ declare class TwoCrossingRoutesHighDensitySolver extends BaseSolver {
727
655
  */
728
656
  private doRoutesCross;
729
657
  private calculateViaPositions;
730
- /**
731
- * Create a route with properly placed vias
732
- */
733
- private createRoute;
734
658
  /**
735
659
  * Try to solve with routeA going over and routeB staying on layer 0
736
660
  */
737
661
  private trySolveAOverB;
738
- private optimizeViaPositions;
739
- /**
740
- * Calculate the orthogonal route points for the second route
741
- */
742
- private calculateConservativeOrthogonalRoutePoints;
743
- private calculateShortestOrthogonalRoutePoints;
662
+ private pushViasFromEndpoints;
663
+ private getMinDistanceBetweenViaCenters;
664
+ private moveViasAsCloseAsPossible;
665
+ handleRoutesDontCross(): void;
744
666
  /**
745
667
  * Main step method that attempts to solve the two crossing routes
746
668
  */
@@ -1024,6 +946,7 @@ declare class SingleHighDensityRouteStitchSolver extends BaseSolver {
1024
946
  y: number;
1025
947
  z: number;
1026
948
  };
949
+ colorMap: Record<string, string>;
1027
950
  constructor(opts: {
1028
951
  connectionName?: string;
1029
952
  hdRoutes: HighDensityIntraNodeRoute$1[];
@@ -1037,6 +960,7 @@ declare class SingleHighDensityRouteStitchSolver extends BaseSolver {
1037
960
  y: number;
1038
961
  z: number;
1039
962
  };
963
+ colorMap?: Record<string, string>;
1040
964
  });
1041
965
  _step(): void;
1042
966
  visualize(): GraphicsObject;
@@ -1060,9 +984,11 @@ declare class MultipleHighDensityRouteStitchSolver extends BaseSolver {
1060
984
  unsolvedRoutes: UnsolvedRoute[];
1061
985
  activeSolver: SingleHighDensityRouteStitchSolver | null;
1062
986
  mergedHdRoutes: HighDensityIntraNodeRoute$1[];
987
+ colorMap: Record<string, string>;
1063
988
  constructor(opts: {
1064
989
  connections: SimpleRouteConnection[];
1065
990
  hdRoutes: HighDensityIntraNodeRoute$1[];
991
+ colorMap?: Record<string, string>;
1066
992
  layerCount: number;
1067
993
  });
1068
994
  _step(): void;
@@ -1304,6 +1230,81 @@ declare class UnravelMultiSectionSolver extends BaseSolver {
1304
1230
  getNodesWithPortPoints(): NodeWithPortPoints[];
1305
1231
  }
1306
1232
 
1233
+ interface CapacityHyperParameters {
1234
+ VIA_DIAMETER: number;
1235
+ TRACE_WIDTH: number;
1236
+ MAX_CAPACITY_FACTOR: number;
1237
+ }
1238
+
1239
+ type Candidate$1 = {
1240
+ prevCandidate: Candidate$1 | null;
1241
+ node: CapacityMeshNode;
1242
+ f: number;
1243
+ g: number;
1244
+ h: number;
1245
+ };
1246
+ type ConnectionPathWithNodes = {
1247
+ connection: SimpleRouteConnection;
1248
+ nodes: CapacityMeshNode[];
1249
+ path?: CapacityMeshNode[];
1250
+ straightLineDistance: number;
1251
+ };
1252
+ declare class CapacityPathingSolver extends BaseSolver {
1253
+ connectionsWithNodes: Array<ConnectionPathWithNodes>;
1254
+ usedNodeCapacityMap: Map<CapacityMeshNodeId, number>;
1255
+ simpleRouteJson: SimpleRouteJson;
1256
+ nodes: CapacityMeshNode[];
1257
+ edges: CapacityMeshEdge[];
1258
+ GREEDY_MULTIPLIER: number;
1259
+ nodeMap: Map<CapacityMeshNodeId, CapacityMeshNode>;
1260
+ nodeEdgeMap: Map<CapacityMeshNodeId, CapacityMeshEdge[]>;
1261
+ connectionNameToGoalNodeIds: Map<string, CapacityMeshNodeId[]>;
1262
+ colorMap: Record<string, string>;
1263
+ maxDepthOfNodes: number;
1264
+ activeCandidateStraightLineDistance?: number;
1265
+ debug_lastNodeCostMap: Map<CapacityMeshNodeId, {
1266
+ g: number;
1267
+ h: number;
1268
+ f: number;
1269
+ }>;
1270
+ hyperParameters: Partial<CapacityHyperParameters>;
1271
+ constructor({ simpleRouteJson, nodes, edges, colorMap, MAX_ITERATIONS, hyperParameters, }: {
1272
+ simpleRouteJson: SimpleRouteJson;
1273
+ nodes: CapacityMeshNode[];
1274
+ edges: CapacityMeshEdge[];
1275
+ colorMap?: Record<string, string>;
1276
+ MAX_ITERATIONS?: number;
1277
+ hyperParameters?: Partial<CapacityHyperParameters>;
1278
+ });
1279
+ getTotalCapacity(node: CapacityMeshNode): number;
1280
+ getConnectionsWithNodes(): {
1281
+ connectionsWithNodes: {
1282
+ connection: SimpleRouteConnection;
1283
+ nodes: CapacityMeshNode[];
1284
+ pathFound: boolean;
1285
+ straightLineDistance: number;
1286
+ }[];
1287
+ connectionNameToGoalNodeIds: Map<string, string[]>;
1288
+ };
1289
+ currentConnectionIndex: number;
1290
+ candidates?: Array<Candidate$1> | null;
1291
+ visitedNodes?: Set<CapacityMeshNodeId> | null;
1292
+ computeG(prevCandidate: Candidate$1, node: CapacityMeshNode, endGoal: CapacityMeshNode): number;
1293
+ computeH(prevCandidate: Candidate$1, node: CapacityMeshNode, endGoal: CapacityMeshNode): number;
1294
+ getBacktrackedPath(candidate: Candidate$1): CapacityMeshNode[];
1295
+ getNeighboringNodes(node: CapacityMeshNode): CapacityMeshNode[];
1296
+ getCapacityPaths(): CapacityPath[];
1297
+ doesNodeHaveCapacityForTrace(node: CapacityMeshNode, prevNode: CapacityMeshNode): boolean;
1298
+ canTravelThroughObstacle(node: CapacityMeshNode, connectionName: string): boolean;
1299
+ getDistanceBetweenNodes(A: CapacityMeshNode, B: CapacityMeshNode): number;
1300
+ reduceCapacityAlongPath(nextConnection: {
1301
+ path?: CapacityMeshNode[];
1302
+ }): void;
1303
+ isConnectedToEndGoal(node: CapacityMeshNode, endGoal: CapacityMeshNode): boolean;
1304
+ _step(): void;
1305
+ visualize(): GraphicsObject;
1306
+ }
1307
+
1307
1308
  declare class CapacityPathingSolver5 extends CapacityPathingSolver {
1308
1309
  NEGATIVE_CAPACITY_PENALTY_FACTOR: number;
1309
1310
  REDUCED_CAPACITY_PENALTY_FACTOR: number;
@@ -1320,8 +1321,158 @@ declare class CapacityPathingSolver5 extends CapacityPathingSolver {
1320
1321
  * To minimize shortest path, you'd want to comment this out.
1321
1322
  */
1322
1323
  getDistanceBetweenNodes(A: CapacityMeshNode, B: CapacityMeshNode): number;
1324
+ computeG(prevCandidate: Candidate$1, node: CapacityMeshNode, endGoal: CapacityMeshNode): number;
1325
+ computeH(prevCandidate: Candidate$1, node: CapacityMeshNode, endGoal: CapacityMeshNode): number;
1326
+ }
1327
+
1328
+ declare class CapacityPathingGreedySolver extends CapacityPathingSolver5 {
1329
+ doesNodeHaveCapacityForTrace(node: CapacityMeshNode, prevNode: CapacityMeshNode): boolean;
1330
+ getNodeCapacityPenalty(node: CapacityMeshNode): number;
1331
+ }
1332
+
1333
+ type Candidate = {
1334
+ prevCandidate: Candidate | null;
1335
+ node: CapacityMeshNode;
1336
+ f: number;
1337
+ g: number;
1338
+ h: number;
1339
+ };
1340
+ interface CpssPathingSolverHyperParameters {
1341
+ SHUFFLE_SEED?: number;
1342
+ EXPANSION_DEGREES?: number;
1343
+ }
1344
+ interface CapacityPathingSingleSectionPathingSolverParams {
1345
+ sectionNodes: CapacityMeshNode[];
1346
+ sectionEdges: CapacityMeshEdge[];
1347
+ sectionConnectionTerminals: Array<{
1348
+ connectionName: string;
1349
+ startNodeId: CapacityMeshNodeId;
1350
+ endNodeId: CapacityMeshNodeId;
1351
+ }>;
1352
+ colorMap?: Record<string, string>;
1353
+ hyperParameters?: CpssPathingSolverHyperParameters;
1354
+ }
1355
+ declare class CapacityPathingSingleSectionPathingSolver extends BaseSolver {
1356
+ GREEDY_MULTIPLIER: number;
1357
+ NEGATIVE_CAPACITY_PENALTY_FACTOR: number;
1358
+ REDUCED_CAPACITY_PENALTY_FACTOR: number;
1359
+ sectionNodes: CapacityMeshNode[];
1360
+ sectionEdges: CapacityMeshEdge[];
1361
+ sectionConnectionTerminals: Array<{
1362
+ connectionName: string;
1363
+ startNodeId: CapacityMeshNodeId;
1364
+ endNodeId: CapacityMeshNodeId;
1365
+ path?: CapacityMeshNode[];
1366
+ }>;
1367
+ nodeMap: Map<CapacityMeshNodeId, CapacityMeshNode>;
1368
+ nodeEdgeMap: Map<CapacityMeshNodeId, CapacityMeshEdge[]>;
1369
+ colorMap: Record<string, string>;
1370
+ usedNodeCapacityMap: Map<CapacityMeshNodeId, number>;
1371
+ currentConnectionIndex: number;
1372
+ candidates?: Array<Candidate> | null;
1373
+ visitedNodes?: Set<CapacityMeshNodeId> | null;
1374
+ queuedNodes?: Set<CapacityMeshNodeId> | null;
1375
+ activeCandidateStraightLineDistance?: number;
1376
+ debug_lastNodeCostMap: Map<CapacityMeshNodeId, {
1377
+ g: number;
1378
+ h: number;
1379
+ f: number;
1380
+ }>;
1381
+ maxCapacityFactor: number;
1382
+ constructor(params: CapacityPathingSingleSectionPathingSolverParams);
1383
+ getTotalCapacity(node: CapacityMeshNode): number;
1384
+ getNodeCapacityPenalty(node: CapacityMeshNode): number;
1385
+ getDistanceBetweenNodes(A: CapacityMeshNode, B: CapacityMeshNode): number;
1323
1386
  computeG(prevCandidate: Candidate, node: CapacityMeshNode, endGoal: CapacityMeshNode): number;
1324
- computeH(prevCandidate: Candidate, node: CapacityMeshNode, endGoal: CapacityMeshNode): number;
1387
+ computeH(prevCandidate: Candidate, // prevCandidate not strictly needed here
1388
+ node: CapacityMeshNode, endGoal: CapacityMeshNode): number;
1389
+ getBacktrackedPath(candidate: Candidate): CapacityMeshNode[];
1390
+ getNeighboringNodes(node: CapacityMeshNode): CapacityMeshNode[];
1391
+ isConnectedToEndGoal(node: CapacityMeshNode, endGoal: CapacityMeshNode): boolean;
1392
+ doesNodeHaveCapacityForTrace(node: CapacityMeshNode, prevNode: CapacityMeshNode | null): boolean;
1393
+ reduceCapacityAlongPath(path: CapacityMeshNode[]): void;
1394
+ _step(): void;
1395
+ private _setupAStar;
1396
+ private _handleCandidatesExhausted;
1397
+ private _handleGoalReached;
1398
+ visualize(): GraphicsObject;
1399
+ }
1400
+
1401
+ interface CapacityPathingSingleSectionSolverInput {
1402
+ centerNodeId: CapacityMeshNodeId;
1403
+ connectionsWithNodes: Array<ConnectionPathWithNodes>;
1404
+ nodes: CapacityMeshNode[];
1405
+ edges: CapacityMeshEdge[];
1406
+ colorMap: Record<string, string>;
1407
+ hyperParameters?: CpssPathingSolverHyperParameters;
1408
+ }
1409
+ declare class CapacityPathingSingleSectionSolver extends BaseSolver {
1410
+ centerNodeId: CapacityMeshNodeId;
1411
+ connectionsWithNodes: Array<ConnectionPathWithNodes>;
1412
+ nodes: CapacityMeshNode[];
1413
+ nodeMap: Map<CapacityMeshNodeId, CapacityMeshNode>;
1414
+ edges: CapacityMeshEdge[];
1415
+ nodeEdgeMap: Map<CapacityMeshNodeId, CapacityMeshEdge[]>;
1416
+ expansionDegrees: number;
1417
+ colorMap: Record<string, string>;
1418
+ sectionNodes: CapacityMeshNode[];
1419
+ sectionEdges: CapacityMeshEdge[];
1420
+ sectionConnectionTerminals: Array<{
1421
+ connectionName: string;
1422
+ startNodeId: CapacityMeshNodeId;
1423
+ endNodeId: CapacityMeshNodeId;
1424
+ }>;
1425
+ activeSubSolver?: CapacityPathingSingleSectionPathingSolver | null | undefined;
1426
+ constructor(params: CapacityPathingSingleSectionSolverInput);
1427
+ private computeSectionNodesTerminalsAndEdges;
1428
+ _step(): void;
1429
+ getConstructorParams(): readonly [{
1430
+ readonly centerNodeId: string;
1431
+ readonly connectionsWithNodes: ConnectionPathWithNodes[];
1432
+ readonly nodes: CapacityMeshNode[];
1433
+ readonly edges: CapacityMeshEdge[];
1434
+ readonly expansionDegrees: number;
1435
+ }];
1436
+ visualize(): GraphicsObject;
1437
+ }
1438
+
1439
+ /**
1440
+ * This solver solves for capacity paths by first solving with negative
1441
+ * capacities allowed, then re-solving problematic sections with a section
1442
+ * solver.
1443
+ */
1444
+ declare class CapacityPathingMultiSectionSolver extends BaseSolver {
1445
+ simpleRouteJson: SimpleRouteJson;
1446
+ nodes: CapacityMeshNode[];
1447
+ edges: CapacityMeshEdge[];
1448
+ connectionsWithNodes: Array<ConnectionPathWithNodes>;
1449
+ colorMap: Record<string, string>;
1450
+ initialSolver: CapacityPathingGreedySolver;
1451
+ stage: "initialization" | "section-optimization";
1452
+ nodeMap: Map<CapacityMeshNodeId, CapacityMeshNode>;
1453
+ usedNodeCapacityMap: Map<CapacityMeshNodeId, number>;
1454
+ totalNodeCapacityMap: Map<CapacityMeshNodeId, number>;
1455
+ nodeCapacityPercentMap: Map<CapacityMeshNodeId, number>;
1456
+ nodeOptimizationAttemptCountMap: Map<CapacityMeshNodeId, number>;
1457
+ sectionSolver?: CapacityPathingSingleSectionSolver | null;
1458
+ MAX_ATTEMPTS_PER_NODE: number;
1459
+ constructor(params: ConstructorParameters<typeof CapacityPathingSolver>[0]);
1460
+ _stepInitialization(): void;
1461
+ _getNextNodeToOptimize(): CapacityMeshNodeId | null;
1462
+ _stepSectionOptimization(): void;
1463
+ /**
1464
+ * Merges the paths found by a successful section solver back into the main
1465
+ * connectionsWithNodes list.
1466
+ */
1467
+ private _mergeSolvedSectionPaths;
1468
+ /**
1469
+ * Recalculates node capacity usage based on the current connectionsWithNodes
1470
+ * and updates the nodeCapacityPercentMap.
1471
+ */
1472
+ private _recalculateNodeCapacityUsage;
1473
+ getCapacityPaths(): CapacityPath[];
1474
+ _step(): void;
1475
+ visualize(): graphics_debug.GraphicsObject;
1325
1476
  }
1326
1477
 
1327
1478
  declare class StrawSolver extends BaseSolver {
@@ -1514,6 +1665,11 @@ declare class SingleRouteUselessViaRemovalSolver extends BaseSolver {
1514
1665
  currentSection: RouteSection;
1515
1666
  targetZ: number;
1516
1667
  }): boolean;
1668
+ getConstructorParams(): {
1669
+ obstacleSHI: ObstacleSpatialHashIndex;
1670
+ hdRouteSHI: HighDensityRouteSpatialIndex;
1671
+ unsimplifiedRoute: HighDensityIntraNodeRoute;
1672
+ };
1517
1673
  getOptimizedHdRoute(): HighDensityRoute;
1518
1674
  visualize(): GraphicsObject;
1519
1675
  }
@@ -1555,7 +1711,7 @@ declare class AutoroutingPipelineSolver extends BaseSolver {
1555
1711
  nodeSolver?: CapacityMeshNodeSolver;
1556
1712
  nodeTargetMerger?: CapacityNodeTargetMerger;
1557
1713
  edgeSolver?: CapacityMeshEdgeSolver;
1558
- pathingSolver?: CapacityPathingSolver;
1714
+ pathingSolver?: CapacityPathingMultiSectionSolver;
1559
1715
  edgeToPortSegmentSolver?: CapacityEdgeToPortSegmentSolver;
1560
1716
  colorMap: Record<string, string>;
1561
1717
  segmentToPointSolver?: CapacitySegmentToPointSolver;
@@ -1565,8 +1721,10 @@ declare class AutoroutingPipelineSolver extends BaseSolver {
1565
1721
  highDensityStitchSolver?: MultipleHighDensityRouteStitchSolver;
1566
1722
  singleLayerNodeMerger?: SingleLayerNodeMergerSolver;
1567
1723
  strawSolver?: StrawSolver;
1568
- uselessViaRemovalSolver?: UselessViaRemovalSolver;
1569
- multiSimplifiedPathSolver?: MultiSimplifiedPathSolver;
1724
+ uselessViaRemovalSolver1?: UselessViaRemovalSolver;
1725
+ uselessViaRemovalSolver2?: UselessViaRemovalSolver;
1726
+ multiSimplifiedPathSolver1?: MultiSimplifiedPathSolver;
1727
+ multiSimplifiedPathSolver2?: MultiSimplifiedPathSolver;
1570
1728
  startTimeOfPhase: Record<string, number>;
1571
1729
  endTimeOfPhase: Record<string, number>;
1572
1730
  timeSpentOnPhase: Record<string, number>;
@@ -1620,6 +1778,7 @@ type CapacityMeshSolver = AutoroutingPipelineSolver;
1620
1778
  */
1621
1779
  declare const getTunedTotalCapacity1: (nodeOrWidth: CapacityMeshNode | {
1622
1780
  width: number;
1781
+ availableZ?: number[];
1623
1782
  }, maxCapacityFactor?: number) => number;
1624
1783
  /**
1625
1784
  * Calculate the optimal subdivision depth to reach a target minimum capacity