@tscircuit/capacity-autorouter 0.0.85 → 0.0.87
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 +21 -1
- package/dist/index.js +132 -7
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1581,6 +1581,8 @@ declare class CapacityPathingMultiSectionSolver extends BaseSolver {
|
|
|
1581
1581
|
endingScore: number;
|
|
1582
1582
|
endingHighestNodePf: number;
|
|
1583
1583
|
}>;
|
|
1584
|
+
cacheHits: number;
|
|
1585
|
+
cacheMisses: number;
|
|
1584
1586
|
};
|
|
1585
1587
|
OPTIMIZATION_SCHEDULE: {
|
|
1586
1588
|
MAX_ATTEMPTS_PER_NODE: number;
|
|
@@ -1732,6 +1734,22 @@ declare class CapacityMeshEdgeSolver2_NodeTreeOptimization extends CapacityMeshE
|
|
|
1732
1734
|
_step(): void;
|
|
1733
1735
|
}
|
|
1734
1736
|
|
|
1737
|
+
declare class DeadEndSolver extends BaseSolver {
|
|
1738
|
+
removedNodeIds: Set<string>;
|
|
1739
|
+
private targetNodeIds;
|
|
1740
|
+
private leaves;
|
|
1741
|
+
private leavesIndex;
|
|
1742
|
+
private adjacencyList;
|
|
1743
|
+
private nodes;
|
|
1744
|
+
private edges;
|
|
1745
|
+
constructor({ nodes, edges, }: {
|
|
1746
|
+
nodes: CapacityMeshNode[];
|
|
1747
|
+
edges: CapacityMeshEdge[];
|
|
1748
|
+
});
|
|
1749
|
+
_step(): void;
|
|
1750
|
+
visualize(): GraphicsObject;
|
|
1751
|
+
}
|
|
1752
|
+
|
|
1735
1753
|
interface Point {
|
|
1736
1754
|
x: number;
|
|
1737
1755
|
y: number;
|
|
@@ -1871,6 +1889,7 @@ declare class AutoroutingPipelineSolver extends BaseSolver {
|
|
|
1871
1889
|
highDensityStitchSolver?: MultipleHighDensityRouteStitchSolver;
|
|
1872
1890
|
singleLayerNodeMerger?: SingleLayerNodeMergerSolver;
|
|
1873
1891
|
strawSolver?: StrawSolver;
|
|
1892
|
+
deadEndSolver?: DeadEndSolver;
|
|
1874
1893
|
uselessViaRemovalSolver1?: UselessViaRemovalSolver;
|
|
1875
1894
|
uselessViaRemovalSolver2?: UselessViaRemovalSolver;
|
|
1876
1895
|
multiSimplifiedPathSolver1?: MultiSimplifiedPathSolver;
|
|
@@ -1882,8 +1901,9 @@ declare class AutoroutingPipelineSolver extends BaseSolver {
|
|
|
1882
1901
|
connMap: ConnectivityMap;
|
|
1883
1902
|
srjWithPointPairs?: SimpleRouteJson;
|
|
1884
1903
|
capacityNodes: CapacityMeshNode[] | null;
|
|
1904
|
+
capacityEdges: CapacityMeshEdge[] | null;
|
|
1885
1905
|
cacheProvider: CacheProvider | null;
|
|
1886
|
-
pipelineDef: (PipelineStep<typeof NetToPointPairsSolver> | PipelineStep<typeof CapacityMeshNodeSolver2_NodeUnderObstacle> | PipelineStep<typeof SingleLayerNodeMergerSolver> | PipelineStep<typeof StrawSolver> | PipelineStep<typeof CapacityMeshEdgeSolver2_NodeTreeOptimization> | PipelineStep<typeof CapacityPathingGreedySolver> | PipelineStep<typeof CapacityPathingMultiSectionSolver> | PipelineStep<typeof CapacityEdgeToPortSegmentSolver> | PipelineStep<typeof CapacitySegmentToPointSolver> | PipelineStep<typeof UnravelMultiSectionSolver> | PipelineStep<typeof HighDensitySolver> | PipelineStep<typeof MultipleHighDensityRouteStitchSolver> | PipelineStep<typeof UselessViaRemovalSolver> | PipelineStep<typeof MultiSimplifiedPathSolver>)[];
|
|
1906
|
+
pipelineDef: (PipelineStep<typeof NetToPointPairsSolver> | PipelineStep<typeof CapacityMeshNodeSolver2_NodeUnderObstacle> | PipelineStep<typeof SingleLayerNodeMergerSolver> | PipelineStep<typeof StrawSolver> | PipelineStep<typeof CapacityMeshEdgeSolver2_NodeTreeOptimization> | PipelineStep<typeof DeadEndSolver> | PipelineStep<typeof CapacityPathingGreedySolver> | PipelineStep<typeof CapacityPathingMultiSectionSolver> | PipelineStep<typeof CapacityEdgeToPortSegmentSolver> | PipelineStep<typeof CapacitySegmentToPointSolver> | PipelineStep<typeof UnravelMultiSectionSolver> | PipelineStep<typeof HighDensitySolver> | PipelineStep<typeof MultipleHighDensityRouteStitchSolver> | PipelineStep<typeof UselessViaRemovalSolver> | PipelineStep<typeof MultiSimplifiedPathSolver>)[];
|
|
1887
1907
|
constructor(srj: SimpleRouteJson, opts?: CapacityMeshSolverOptions);
|
|
1888
1908
|
currentPipelineStepIndex: number;
|
|
1889
1909
|
_step(): void;
|
package/dist/index.js
CHANGED
|
@@ -13522,6 +13522,7 @@ var CachedHyperCapacityPathingSingleSectionSolver = class extends HyperCapacityP
|
|
|
13522
13522
|
});
|
|
13523
13523
|
const terminals = {};
|
|
13524
13524
|
const cacheSpaceToRealConnectionId = /* @__PURE__ */ new Map();
|
|
13525
|
+
const connectionPairMap = /* @__PURE__ */ new Map();
|
|
13525
13526
|
for (const conn of this.constructorParams.sectionConnectionTerminals) {
|
|
13526
13527
|
const cacheStartNodeId = realToCacheSpaceNodeIdMap.get(conn.startNodeId);
|
|
13527
13528
|
const cacheEndNodeId = realToCacheSpaceNodeIdMap.get(conn.endNodeId);
|
|
@@ -13529,7 +13530,10 @@ var CachedHyperCapacityPathingSingleSectionSolver = class extends HyperCapacityP
|
|
|
13529
13530
|
cacheStartNodeId,
|
|
13530
13531
|
cacheEndNodeId
|
|
13531
13532
|
].sort();
|
|
13532
|
-
const
|
|
13533
|
+
const pairKey = `${sortedStartId}->${sortedEndId}`;
|
|
13534
|
+
const pairIndex = connectionPairMap.get(pairKey) ?? 0;
|
|
13535
|
+
connectionPairMap.set(pairKey, pairIndex + 1);
|
|
13536
|
+
const cacheSpaceConnectionId = `${sortedStartId}->${sortedEndId}::${pairIndex}`;
|
|
13533
13537
|
terminals[cacheSpaceConnectionId] = {
|
|
13534
13538
|
start: sortedStartId,
|
|
13535
13539
|
end: sortedEndId
|
|
@@ -13796,9 +13800,11 @@ var CapacityPathingMultiSectionSolver = class extends BaseSolver {
|
|
|
13796
13800
|
endingHighestNodePf: 0,
|
|
13797
13801
|
sectionAttempts: 0
|
|
13798
13802
|
})
|
|
13799
|
-
)
|
|
13803
|
+
),
|
|
13804
|
+
cacheHits: 0,
|
|
13805
|
+
cacheMisses: 0
|
|
13800
13806
|
};
|
|
13801
|
-
this.MAX_ITERATIONS = 1e7;
|
|
13807
|
+
this.MAX_ITERATIONS = params.MAX_ITERATIONS ?? 1e7;
|
|
13802
13808
|
this.cacheProvider = params.cacheProvider;
|
|
13803
13809
|
this.simpleRouteJson = params.simpleRouteJson;
|
|
13804
13810
|
this.nodes = params.nodes;
|
|
@@ -13943,6 +13949,13 @@ var CapacityPathingMultiSectionSolver = class extends BaseSolver {
|
|
|
13943
13949
|
);
|
|
13944
13950
|
}
|
|
13945
13951
|
this.sectionSolver.step();
|
|
13952
|
+
if (this.sectionSolver.failed || this.sectionSolver.solved) {
|
|
13953
|
+
if (this.sectionSolver.cacheHit) {
|
|
13954
|
+
this.stats.cacheHits++;
|
|
13955
|
+
} else {
|
|
13956
|
+
this.stats.cacheMisses++;
|
|
13957
|
+
}
|
|
13958
|
+
}
|
|
13946
13959
|
if (this.sectionSolver.failed) {
|
|
13947
13960
|
console.warn(
|
|
13948
13961
|
`Section solver failed for node ${this.currentSection.centerNodeId}. Error: ${this.sectionSolver.error}`
|
|
@@ -15801,6 +15814,93 @@ var CapacityMeshEdgeSolver2_NodeTreeOptimization = class extends CapacityMeshEdg
|
|
|
15801
15814
|
}
|
|
15802
15815
|
};
|
|
15803
15816
|
|
|
15817
|
+
// lib/solvers/DeadEndSolver/DeadEndSolver.ts
|
|
15818
|
+
var DeadEndSolver = class extends BaseSolver {
|
|
15819
|
+
removedNodeIds;
|
|
15820
|
+
targetNodeIds;
|
|
15821
|
+
leaves;
|
|
15822
|
+
leavesIndex;
|
|
15823
|
+
adjacencyList;
|
|
15824
|
+
// Store the nodes and edges just for visualization purposes
|
|
15825
|
+
nodes;
|
|
15826
|
+
edges;
|
|
15827
|
+
constructor({
|
|
15828
|
+
nodes,
|
|
15829
|
+
edges
|
|
15830
|
+
}) {
|
|
15831
|
+
super();
|
|
15832
|
+
this.MAX_ITERATIONS = nodes.length;
|
|
15833
|
+
this.nodes = nodes;
|
|
15834
|
+
this.edges = edges;
|
|
15835
|
+
this.removedNodeIds = /* @__PURE__ */ new Set();
|
|
15836
|
+
this.targetNodeIds = new Set(
|
|
15837
|
+
nodes.filter((n) => n._containsTarget).map((n) => n.capacityMeshNodeId)
|
|
15838
|
+
);
|
|
15839
|
+
this.adjacencyList = new Map(
|
|
15840
|
+
nodes.map(({ capacityMeshNodeId }) => [capacityMeshNodeId, /* @__PURE__ */ new Set()])
|
|
15841
|
+
);
|
|
15842
|
+
for (const {
|
|
15843
|
+
nodeIds: [u, v]
|
|
15844
|
+
} of edges) {
|
|
15845
|
+
this.adjacencyList.get(u).add(v);
|
|
15846
|
+
this.adjacencyList.get(v).add(u);
|
|
15847
|
+
}
|
|
15848
|
+
this.leavesIndex = 0;
|
|
15849
|
+
this.leaves = [...this.adjacencyList.entries()].filter(([_, neighbours]) => neighbours.size === 1).filter(([nodeId, _]) => !this.targetNodeIds.has(nodeId)).map(([nodeId, _]) => nodeId);
|
|
15850
|
+
}
|
|
15851
|
+
_step() {
|
|
15852
|
+
if (this.leavesIndex === this.leaves.length) {
|
|
15853
|
+
this.solved = true;
|
|
15854
|
+
return;
|
|
15855
|
+
}
|
|
15856
|
+
const leaf = this.leaves[this.leavesIndex];
|
|
15857
|
+
const [neighbor] = this.adjacencyList.get(leaf);
|
|
15858
|
+
const neighborsOfLeafNeighbor = this.adjacencyList.get(neighbor);
|
|
15859
|
+
neighborsOfLeafNeighbor.delete(leaf);
|
|
15860
|
+
this.removedNodeIds.add(leaf);
|
|
15861
|
+
if (neighborsOfLeafNeighbor.size === 1 && !this.targetNodeIds.has(neighbor)) {
|
|
15862
|
+
this.leaves.push(neighbor);
|
|
15863
|
+
}
|
|
15864
|
+
this.leavesIndex += 1;
|
|
15865
|
+
if (this.leavesIndex === this.leaves.length) {
|
|
15866
|
+
this.solved = true;
|
|
15867
|
+
}
|
|
15868
|
+
}
|
|
15869
|
+
visualize() {
|
|
15870
|
+
const graphics = {
|
|
15871
|
+
lines: [],
|
|
15872
|
+
points: [],
|
|
15873
|
+
rects: [],
|
|
15874
|
+
circles: []
|
|
15875
|
+
};
|
|
15876
|
+
for (const edge of this.edges) {
|
|
15877
|
+
if (!edge.nodeIds.some((nodeId) => this.removedNodeIds.has(nodeId))) {
|
|
15878
|
+
continue;
|
|
15879
|
+
}
|
|
15880
|
+
const [node1, node2] = edge.nodeIds.map((nodeId) => {
|
|
15881
|
+
return this.nodes.find((node) => node.capacityMeshNodeId === nodeId);
|
|
15882
|
+
});
|
|
15883
|
+
if (node1?.center && node2?.center) {
|
|
15884
|
+
const lowestZ1 = Math.min(...node1.availableZ);
|
|
15885
|
+
const lowestZ2 = Math.min(...node2.availableZ);
|
|
15886
|
+
const nodeCenter1Adj = {
|
|
15887
|
+
x: node1.center.x + lowestZ1 * node1.width * 0.05,
|
|
15888
|
+
y: node1.center.y - lowestZ1 * node1.width * 0.05
|
|
15889
|
+
};
|
|
15890
|
+
const nodeCenter2Adj = {
|
|
15891
|
+
x: node2.center.x + lowestZ2 * node2.width * 0.05,
|
|
15892
|
+
y: node2.center.y - lowestZ2 * node2.width * 0.05
|
|
15893
|
+
};
|
|
15894
|
+
graphics.lines.push({
|
|
15895
|
+
strokeColor: "black",
|
|
15896
|
+
points: [nodeCenter1Adj, nodeCenter2Adj]
|
|
15897
|
+
});
|
|
15898
|
+
}
|
|
15899
|
+
}
|
|
15900
|
+
return graphics;
|
|
15901
|
+
}
|
|
15902
|
+
};
|
|
15903
|
+
|
|
15804
15904
|
// lib/data-structures/HighDensityRouteSpatialIndex.ts
|
|
15805
15905
|
var getSegmentBounds2 = (segment) => {
|
|
15806
15906
|
return {
|
|
@@ -16409,6 +16509,7 @@ var AutoroutingPipelineSolver = class extends BaseSolver {
|
|
|
16409
16509
|
highDensityStitchSolver;
|
|
16410
16510
|
singleLayerNodeMerger;
|
|
16411
16511
|
strawSolver;
|
|
16512
|
+
deadEndSolver;
|
|
16412
16513
|
uselessViaRemovalSolver1;
|
|
16413
16514
|
uselessViaRemovalSolver2;
|
|
16414
16515
|
multiSimplifiedPathSolver1;
|
|
@@ -16420,6 +16521,7 @@ var AutoroutingPipelineSolver = class extends BaseSolver {
|
|
|
16420
16521
|
connMap;
|
|
16421
16522
|
srjWithPointPairs;
|
|
16422
16523
|
capacityNodes = null;
|
|
16524
|
+
capacityEdges = null;
|
|
16423
16525
|
cacheProvider = null;
|
|
16424
16526
|
pipelineDef = [
|
|
16425
16527
|
definePipelineStep(
|
|
@@ -16484,7 +16586,28 @@ var AutoroutingPipelineSolver = class extends BaseSolver {
|
|
|
16484
16586
|
definePipelineStep(
|
|
16485
16587
|
"edgeSolver",
|
|
16486
16588
|
CapacityMeshEdgeSolver2_NodeTreeOptimization,
|
|
16487
|
-
(cms) => [cms.capacityNodes]
|
|
16589
|
+
(cms) => [cms.capacityNodes],
|
|
16590
|
+
{
|
|
16591
|
+
onSolved: (cms) => {
|
|
16592
|
+
cms.capacityEdges = cms.edgeSolver?.edges;
|
|
16593
|
+
}
|
|
16594
|
+
}
|
|
16595
|
+
),
|
|
16596
|
+
definePipelineStep(
|
|
16597
|
+
"deadEndSolver",
|
|
16598
|
+
DeadEndSolver,
|
|
16599
|
+
(cms) => [{ nodes: cms.capacityNodes, edges: cms.capacityEdges }],
|
|
16600
|
+
{
|
|
16601
|
+
onSolved: (cms) => {
|
|
16602
|
+
const removedNodeIds = cms.deadEndSolver?.removedNodeIds;
|
|
16603
|
+
cms.capacityNodes = cms.capacityNodes.filter(
|
|
16604
|
+
(n) => !removedNodeIds.has(n.capacityMeshNodeId)
|
|
16605
|
+
);
|
|
16606
|
+
cms.capacityEdges = cms.capacityEdges.filter(
|
|
16607
|
+
(e) => e.nodeIds.every((nodeId) => !removedNodeIds.has(nodeId))
|
|
16608
|
+
);
|
|
16609
|
+
}
|
|
16610
|
+
}
|
|
16488
16611
|
),
|
|
16489
16612
|
definePipelineStep(
|
|
16490
16613
|
"initialPathingSolver",
|
|
@@ -16493,7 +16616,7 @@ var AutoroutingPipelineSolver = class extends BaseSolver {
|
|
|
16493
16616
|
{
|
|
16494
16617
|
simpleRouteJson: cms.srjWithPointPairs,
|
|
16495
16618
|
nodes: cms.capacityNodes,
|
|
16496
|
-
edges: cms.
|
|
16619
|
+
edges: cms.capacityEdges || [],
|
|
16497
16620
|
colorMap: cms.colorMap,
|
|
16498
16621
|
hyperParameters: {
|
|
16499
16622
|
MAX_CAPACITY_FACTOR: 1
|
|
@@ -16511,7 +16634,7 @@ var AutoroutingPipelineSolver = class extends BaseSolver {
|
|
|
16511
16634
|
initialPathingSolver: cms.initialPathingSolver,
|
|
16512
16635
|
simpleRouteJson: cms.srjWithPointPairs,
|
|
16513
16636
|
nodes: cms.capacityNodes,
|
|
16514
|
-
edges: cms.
|
|
16637
|
+
edges: cms.capacityEdges || [],
|
|
16515
16638
|
colorMap: cms.colorMap,
|
|
16516
16639
|
cacheProvider: cms.cacheProvider,
|
|
16517
16640
|
hyperParameters: {
|
|
@@ -16526,7 +16649,7 @@ var AutoroutingPipelineSolver = class extends BaseSolver {
|
|
|
16526
16649
|
(cms) => [
|
|
16527
16650
|
{
|
|
16528
16651
|
nodes: cms.capacityNodes,
|
|
16529
|
-
edges: cms.
|
|
16652
|
+
edges: cms.capacityEdges || [],
|
|
16530
16653
|
capacityPaths: cms.pathingOptimizer?.getCapacityPaths() || [],
|
|
16531
16654
|
colorMap: cms.colorMap
|
|
16532
16655
|
}
|
|
@@ -16687,6 +16810,7 @@ var AutoroutingPipelineSolver = class extends BaseSolver {
|
|
|
16687
16810
|
const singleLayerNodeMergerViz = this.singleLayerNodeMerger?.visualize();
|
|
16688
16811
|
const strawSolverViz = this.strawSolver?.visualize();
|
|
16689
16812
|
const edgeViz = this.edgeSolver?.visualize();
|
|
16813
|
+
const deadEndViz = this.deadEndSolver?.visualize();
|
|
16690
16814
|
const initialPathingViz = this.initialPathingSolver?.visualize();
|
|
16691
16815
|
const pathingOptimizerViz = this.pathingOptimizer?.visualize();
|
|
16692
16816
|
const edgeToPortSegmentViz = this.edgeToPortSegmentSolver?.visualize();
|
|
@@ -16743,6 +16867,7 @@ var AutoroutingPipelineSolver = class extends BaseSolver {
|
|
|
16743
16867
|
singleLayerNodeMergerViz,
|
|
16744
16868
|
strawSolverViz,
|
|
16745
16869
|
edgeViz,
|
|
16870
|
+
deadEndViz,
|
|
16746
16871
|
initialPathingViz,
|
|
16747
16872
|
pathingOptimizerViz,
|
|
16748
16873
|
edgeToPortSegmentViz,
|