@tscircuit/capacity-autorouter 0.0.19 → 0.0.21
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 +228 -4
- package/dist/index.js +1313 -802
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -18,6 +18,7 @@ interface SimpleRouteJson {
|
|
|
18
18
|
interface Obstacle {
|
|
19
19
|
type: "rect";
|
|
20
20
|
layers: string[];
|
|
21
|
+
zLayers?: number[];
|
|
21
22
|
center: {
|
|
22
23
|
x: number;
|
|
23
24
|
y: number;
|
|
@@ -72,6 +73,7 @@ interface CapacityMeshNode {
|
|
|
72
73
|
_containsObstacle?: boolean;
|
|
73
74
|
_containsTarget?: boolean;
|
|
74
75
|
_targetConnectionName?: string;
|
|
76
|
+
_shouldBeInGraph?: boolean;
|
|
75
77
|
_parent?: CapacityMeshNode;
|
|
76
78
|
}
|
|
77
79
|
interface CapacityMeshEdge {
|
|
@@ -93,7 +95,9 @@ declare class BaseSolver {
|
|
|
93
95
|
iterations: number;
|
|
94
96
|
progress: number;
|
|
95
97
|
error: string | null;
|
|
98
|
+
activeSubSolver?: BaseSolver | null;
|
|
96
99
|
failedSubSolvers?: BaseSolver[];
|
|
100
|
+
timeToSolve?: number;
|
|
97
101
|
/** DO NOT OVERRIDE! Override _step() instead */
|
|
98
102
|
step(): void;
|
|
99
103
|
_step(): void;
|
|
@@ -108,6 +112,7 @@ declare class CapacityMeshEdgeSolver extends BaseSolver {
|
|
|
108
112
|
getNextCapacityMeshEdgeId(): string;
|
|
109
113
|
step(): void;
|
|
110
114
|
private areNodesBordering;
|
|
115
|
+
private doNodesHaveSharedLayer;
|
|
111
116
|
visualize(): GraphicsObject;
|
|
112
117
|
}
|
|
113
118
|
|
|
@@ -125,7 +130,8 @@ declare class CapacityMeshNodeSolver extends BaseSolver {
|
|
|
125
130
|
opts: CapacityMeshNodeSolverOptions;
|
|
126
131
|
unfinishedNodes: CapacityMeshNode[];
|
|
127
132
|
finishedNodes: CapacityMeshNode[];
|
|
128
|
-
|
|
133
|
+
nodeToXYOverlappingObstaclesMap: Map<CapacityMeshNodeId, Obstacle[]>;
|
|
134
|
+
layerCount: number;
|
|
129
135
|
MAX_DEPTH: number;
|
|
130
136
|
targets: Target[];
|
|
131
137
|
constructor(srj: SimpleRouteJson, opts?: CapacityMeshNodeSolverOptions);
|
|
@@ -133,7 +139,8 @@ declare class CapacityMeshNodeSolver extends BaseSolver {
|
|
|
133
139
|
getNextNodeId(): string;
|
|
134
140
|
getCapacityFromDepth(depth: number): number;
|
|
135
141
|
getTargetIfNodeContainsTarget(node: CapacityMeshNode): Target | null;
|
|
136
|
-
|
|
142
|
+
getXYOverlappingObstacles(node: CapacityMeshNode): Obstacle[];
|
|
143
|
+
getXYZOverlappingObstacles(node: CapacityMeshNode): Obstacle[];
|
|
137
144
|
/**
|
|
138
145
|
* Checks if the given mesh node overlaps with any obstacle.
|
|
139
146
|
* We treat both obstacles and nodes as axis‐aligned rectangles.
|
|
@@ -144,7 +151,7 @@ declare class CapacityMeshNodeSolver extends BaseSolver {
|
|
|
144
151
|
*/
|
|
145
152
|
isNodeCompletelyInsideObstacle(node: CapacityMeshNode): boolean;
|
|
146
153
|
getChildNodes(parent: CapacityMeshNode): CapacityMeshNode[];
|
|
147
|
-
|
|
154
|
+
shouldNodeBeXYSubdivided(node: CapacityMeshNode): boolean;
|
|
148
155
|
_step(): void;
|
|
149
156
|
/**
|
|
150
157
|
* Creates a GraphicsObject to visualize the mesh, its nodes, obstacles, and connection points.
|
|
@@ -889,6 +896,222 @@ declare class MultipleHighDensityRouteStitchSolver extends BaseSolver {
|
|
|
889
896
|
visualize(): GraphicsObject;
|
|
890
897
|
}
|
|
891
898
|
|
|
899
|
+
type SegmentPointId = string;
|
|
900
|
+
type SegmentId = string;
|
|
901
|
+
interface BaseUnravelIssue {
|
|
902
|
+
probabilityOfFailure: number;
|
|
903
|
+
}
|
|
904
|
+
interface UnravelTransitionViaIssue extends BaseUnravelIssue {
|
|
905
|
+
type: "transition_via";
|
|
906
|
+
capacityMeshNodeId: CapacityMeshNodeId;
|
|
907
|
+
segmentPoints: SegmentPointId[];
|
|
908
|
+
}
|
|
909
|
+
interface UnravelSameLayerCrossingIssue extends BaseUnravelIssue {
|
|
910
|
+
type: "same_layer_crossing";
|
|
911
|
+
capacityMeshNodeId: CapacityMeshNodeId;
|
|
912
|
+
crossingLine1: [SegmentPointId, SegmentPointId];
|
|
913
|
+
crossingLine2: [SegmentPointId, SegmentPointId];
|
|
914
|
+
}
|
|
915
|
+
interface UnravelSingleTransitionCrossingIssue extends BaseUnravelIssue {
|
|
916
|
+
type: "single_transition_crossing";
|
|
917
|
+
capacityMeshNodeId: CapacityMeshNodeId;
|
|
918
|
+
sameLayerCrossingLine: [SegmentPointId, SegmentPointId];
|
|
919
|
+
transitionCrossingLine: [SegmentPointId, SegmentPointId];
|
|
920
|
+
}
|
|
921
|
+
interface UnravelDoubleTransitionCrossingIssue extends BaseUnravelIssue {
|
|
922
|
+
type: "double_transition_crossing";
|
|
923
|
+
capacityMeshNodeId: CapacityMeshNodeId;
|
|
924
|
+
crossingLine1: [SegmentPointId, SegmentPointId];
|
|
925
|
+
crossingLine2: [SegmentPointId, SegmentPointId];
|
|
926
|
+
}
|
|
927
|
+
interface UnravelTraceCapacityIssue extends BaseUnravelIssue {
|
|
928
|
+
type: "same_layer_trace_imbalance_with_low_capacity";
|
|
929
|
+
capacityMeshNodeId: CapacityMeshNodeId;
|
|
930
|
+
z: number;
|
|
931
|
+
tracesOnLayer: Array<{
|
|
932
|
+
A: SegmentPointId;
|
|
933
|
+
B: SegmentPointId;
|
|
934
|
+
}>;
|
|
935
|
+
}
|
|
936
|
+
interface SegmentPoint {
|
|
937
|
+
segmentPointId: SegmentPointId;
|
|
938
|
+
directlyConnectedSegmentPointIds: SegmentPointId[];
|
|
939
|
+
connectionName: string;
|
|
940
|
+
segmentId: string;
|
|
941
|
+
capacityMeshNodeIds: CapacityMeshNodeId[];
|
|
942
|
+
x: number;
|
|
943
|
+
y: number;
|
|
944
|
+
z: number;
|
|
945
|
+
}
|
|
946
|
+
type SegmentPointMap = Map<SegmentPointId, SegmentPoint>;
|
|
947
|
+
type UnravelIssue = UnravelTransitionViaIssue | UnravelSameLayerCrossingIssue | UnravelSingleTransitionCrossingIssue | UnravelDoubleTransitionCrossingIssue | UnravelTraceCapacityIssue;
|
|
948
|
+
interface UnravelSection {
|
|
949
|
+
allNodeIds: CapacityMeshNodeId[];
|
|
950
|
+
mutableNodeIds: CapacityMeshNodeId[];
|
|
951
|
+
mutableSegmentIds: Set<string>;
|
|
952
|
+
immutableNodeIds: CapacityMeshNodeId[];
|
|
953
|
+
segmentPointMap: SegmentPointMap;
|
|
954
|
+
segmentPairsInNode: Map<CapacityMeshNodeId, Array<[SegmentPointId, SegmentPointId]>>;
|
|
955
|
+
segmentPointsInNode: Map<CapacityMeshNodeId, SegmentPointId[]>;
|
|
956
|
+
segmentPointsInSegment: Map<SegmentId, SegmentPointId[]>;
|
|
957
|
+
}
|
|
958
|
+
interface UnravelChangeLayerOperation {
|
|
959
|
+
type: "change_layer";
|
|
960
|
+
newZ: number;
|
|
961
|
+
segmentPointIds: SegmentPointId[];
|
|
962
|
+
}
|
|
963
|
+
interface UnravelSwapPositionOnSegmentOperation {
|
|
964
|
+
type: "swap_position_on_segment";
|
|
965
|
+
segmentPointIds: SegmentPointId[];
|
|
966
|
+
}
|
|
967
|
+
interface UnravelCombinedOperation {
|
|
968
|
+
type: "combined";
|
|
969
|
+
operations: Array<UnravelChangeLayerOperation | UnravelSwapPositionOnSegmentOperation>;
|
|
970
|
+
}
|
|
971
|
+
type UnravelOperation = UnravelChangeLayerOperation | UnravelSwapPositionOnSegmentOperation | UnravelCombinedOperation;
|
|
972
|
+
type UnravelCandidate = {
|
|
973
|
+
operationsPerformed: number;
|
|
974
|
+
/**
|
|
975
|
+
* A hash of the pointModifications to know if this candidate has already been
|
|
976
|
+
* explored
|
|
977
|
+
*/
|
|
978
|
+
candidateHash: string;
|
|
979
|
+
/**
|
|
980
|
+
* More expensive hash that includes original positions
|
|
981
|
+
*/
|
|
982
|
+
candidateFullHash?: string;
|
|
983
|
+
pointModifications: Map<SegmentPointId, {
|
|
984
|
+
x?: number;
|
|
985
|
+
y?: number;
|
|
986
|
+
z?: number;
|
|
987
|
+
}>;
|
|
988
|
+
issues: UnravelIssue[];
|
|
989
|
+
/**
|
|
990
|
+
* The cost of this candidate (log probability of failure) considering all of
|
|
991
|
+
* the point modifications
|
|
992
|
+
*/
|
|
993
|
+
g: number;
|
|
994
|
+
/**
|
|
995
|
+
* The estimated cost of this candidate (log probability of failure). We don't
|
|
996
|
+
* currently know how to compute this so it's always 0.
|
|
997
|
+
*/
|
|
998
|
+
h: number;
|
|
999
|
+
/**
|
|
1000
|
+
* Candidate cost ~(g + h)
|
|
1001
|
+
*/
|
|
1002
|
+
f: number;
|
|
1003
|
+
};
|
|
1004
|
+
|
|
1005
|
+
/**
|
|
1006
|
+
* The UntangleSectionSolver optimizes a section of connected capacity nodes
|
|
1007
|
+
* with their deduplicated segments.
|
|
1008
|
+
*
|
|
1009
|
+
* The section always has a "root" node. From the root node, MUTABLE_HOPS are
|
|
1010
|
+
* taken to reach other nodes that are mutable. One additional hop is taken to
|
|
1011
|
+
* have all the impacted nodes in section. So a section is composed of mutable
|
|
1012
|
+
* and immutable nodes.
|
|
1013
|
+
*
|
|
1014
|
+
* The goal of the solver is to perform operations on the mutable nodes of the
|
|
1015
|
+
* section to lower the overall cost of the section.
|
|
1016
|
+
*
|
|
1017
|
+
* The untangle phase will perform "operations" on segments based on "issues"
|
|
1018
|
+
*
|
|
1019
|
+
* An "issue" is anything that increases the cost of the node:
|
|
1020
|
+
* - Anything that causes a via (e.g. layer transition)
|
|
1021
|
+
* - Any time two traces cross on the same layer
|
|
1022
|
+
*
|
|
1023
|
+
* An operation is a change to a segment. There are two main operations:
|
|
1024
|
+
* - Change layer
|
|
1025
|
+
* - Change point order on segment
|
|
1026
|
+
*
|
|
1027
|
+
* This solver works by exploring different paths of operations. When an
|
|
1028
|
+
* operation is performed, new issues are created. Each path has a cost, and
|
|
1029
|
+
* a set of neighbors representing next operations to perform.
|
|
1030
|
+
*
|
|
1031
|
+
*/
|
|
1032
|
+
declare class UnravelSectionSolver extends BaseSolver {
|
|
1033
|
+
nodeMap: Map<CapacityMeshNodeId, CapacityMeshNode>;
|
|
1034
|
+
dedupedSegments: SegmentWithAssignedPoints[];
|
|
1035
|
+
MUTABLE_HOPS: number;
|
|
1036
|
+
unravelSection: UnravelSection;
|
|
1037
|
+
candidates: UnravelCandidate[];
|
|
1038
|
+
lastProcessedCandidate: UnravelCandidate | null;
|
|
1039
|
+
bestCandidate: UnravelCandidate | null;
|
|
1040
|
+
originalCandidate: UnravelCandidate;
|
|
1041
|
+
rootNodeId: CapacityMeshNodeId;
|
|
1042
|
+
nodeIdToSegmentIds: Map<CapacityMeshNodeId, CapacityMeshNodeId[]>;
|
|
1043
|
+
segmentIdToNodeIds: Map<CapacityMeshNodeId, CapacityMeshNodeId[]>;
|
|
1044
|
+
colorMap: Record<string, string>;
|
|
1045
|
+
tunedNodeCapacityMap: Map<CapacityMeshNodeId, number>;
|
|
1046
|
+
MAX_CANDIDATES: number;
|
|
1047
|
+
selectedCandidateIndex: number | "best" | "original" | null;
|
|
1048
|
+
queuedOrExploredCandidatePointModificationHashes: Set<string>;
|
|
1049
|
+
constructor(params: {
|
|
1050
|
+
rootNodeId: CapacityMeshNodeId;
|
|
1051
|
+
colorMap?: Record<string, string>;
|
|
1052
|
+
MUTABLE_HOPS?: number;
|
|
1053
|
+
nodeMap: Map<CapacityMeshNodeId, CapacityMeshNode>;
|
|
1054
|
+
dedupedSegments: SegmentWithAssignedPoints[];
|
|
1055
|
+
nodeIdToSegmentIds: Map<CapacityMeshNodeId, CapacityMeshNodeId[]>;
|
|
1056
|
+
segmentIdToNodeIds: Map<CapacityMeshNodeId, CapacityMeshNodeId[]>;
|
|
1057
|
+
segmentPointMap?: SegmentPointMap;
|
|
1058
|
+
});
|
|
1059
|
+
createUnravelSection(segmentPointMap?: SegmentPointMap): UnravelSection;
|
|
1060
|
+
createInitialCandidate(): UnravelCandidate;
|
|
1061
|
+
get nextCandidate(): UnravelCandidate | null;
|
|
1062
|
+
getPointInCandidate(candidate: UnravelCandidate, segmentPointId: SegmentPointId): {
|
|
1063
|
+
x: number;
|
|
1064
|
+
y: number;
|
|
1065
|
+
z: number;
|
|
1066
|
+
segmentId: string;
|
|
1067
|
+
};
|
|
1068
|
+
getOperationsForIssue(candidate: UnravelCandidate, issue: UnravelIssue): UnravelOperation[];
|
|
1069
|
+
computeG(params: {
|
|
1070
|
+
issues: UnravelIssue[];
|
|
1071
|
+
originalCandidate: UnravelCandidate;
|
|
1072
|
+
operationsPerformed: number;
|
|
1073
|
+
operation: UnravelOperation;
|
|
1074
|
+
}): number;
|
|
1075
|
+
getNeighborByApplyingOperation(currentCandidate: UnravelCandidate, operation: UnravelOperation): UnravelCandidate;
|
|
1076
|
+
getNeighborOperationsForCandidate(candidate: UnravelCandidate): UnravelOperation[];
|
|
1077
|
+
getNeighbors(candidate: UnravelCandidate): UnravelCandidate[];
|
|
1078
|
+
_step(): void;
|
|
1079
|
+
visualize(): GraphicsObject;
|
|
1080
|
+
}
|
|
1081
|
+
|
|
1082
|
+
declare class UnravelMultiSectionSolver extends BaseSolver {
|
|
1083
|
+
nodeMap: Map<CapacityMeshNodeId, CapacityMeshNode>;
|
|
1084
|
+
dedupedSegments: SegmentWithAssignedPoints[];
|
|
1085
|
+
nodeIdToSegmentIds: Map<CapacityMeshNodeId, CapacityMeshNodeId[]>;
|
|
1086
|
+
segmentIdToNodeIds: Map<CapacityMeshNodeId, CapacityMeshNodeId[]>;
|
|
1087
|
+
colorMap: Record<string, string>;
|
|
1088
|
+
tunedNodeCapacityMap: Map<CapacityMeshNodeId, number>;
|
|
1089
|
+
MAX_NODE_ATTEMPTS: number;
|
|
1090
|
+
MUTABLE_HOPS: number;
|
|
1091
|
+
ACCEPTABLE_PF: number;
|
|
1092
|
+
/**
|
|
1093
|
+
* Probability of failure for each node
|
|
1094
|
+
*/
|
|
1095
|
+
nodePfMap: Map<CapacityMeshNodeId, number>;
|
|
1096
|
+
attemptsToFixNode: Map<CapacityMeshNodeId, number>;
|
|
1097
|
+
activeSolver: UnravelSectionSolver | null;
|
|
1098
|
+
segmentPointMap: SegmentPointMap;
|
|
1099
|
+
constructor({ assignedSegments, colorMap, nodes, }: {
|
|
1100
|
+
assignedSegments: NodePortSegment[];
|
|
1101
|
+
colorMap?: Record<string, string>;
|
|
1102
|
+
/**
|
|
1103
|
+
* This isn't used by the algorithm, but allows associating metadata
|
|
1104
|
+
* for the result datatype (the center, width, height of the node)
|
|
1105
|
+
*/
|
|
1106
|
+
nodes: CapacityMeshNode[];
|
|
1107
|
+
});
|
|
1108
|
+
computeInitialPfMap(): Map<string, number>;
|
|
1109
|
+
computeNodePf(node: CapacityMeshNode): number;
|
|
1110
|
+
_step(): void;
|
|
1111
|
+
visualize(): GraphicsObject;
|
|
1112
|
+
getNodesWithPortPoints(): NodeWithPortPoints[];
|
|
1113
|
+
}
|
|
1114
|
+
|
|
892
1115
|
interface CapacityMeshSolverOptions {
|
|
893
1116
|
capacityDepth?: number;
|
|
894
1117
|
targetMinCapacity?: number;
|
|
@@ -910,6 +1133,7 @@ declare class CapacityMeshSolver extends BaseSolver {
|
|
|
910
1133
|
edgeToPortSegmentSolver?: CapacityEdgeToPortSegmentSolver;
|
|
911
1134
|
colorMap: Record<string, string>;
|
|
912
1135
|
segmentToPointSolver?: CapacitySegmentToPointSolver;
|
|
1136
|
+
unravelMultiSectionSolver?: UnravelMultiSectionSolver;
|
|
913
1137
|
segmentToPointOptimizer?: CapacitySegmentPointOptimizer;
|
|
914
1138
|
highDensityRouteSolver?: HighDensitySolver;
|
|
915
1139
|
highDensityStitchSolver?: MultipleHighDensityRouteStitchSolver;
|
|
@@ -919,7 +1143,7 @@ declare class CapacityMeshSolver extends BaseSolver {
|
|
|
919
1143
|
activeSolver?: BaseSolver | null;
|
|
920
1144
|
connMap: ConnectivityMap;
|
|
921
1145
|
srjWithPointPairs?: SimpleRouteJson;
|
|
922
|
-
pipelineDef: (PipelineStep<typeof NetToPointPairsSolver> | PipelineStep<typeof CapacityMeshNodeSolver> | PipelineStep<typeof CapacityNodeTargetMerger> | PipelineStep<typeof CapacityMeshEdgeSolver> | PipelineStep<typeof CapacityPathingSolver4_FlexibleNegativeCapacity> | PipelineStep<typeof CapacityEdgeToPortSegmentSolver> | PipelineStep<typeof CapacitySegmentToPointSolver> | PipelineStep<typeof
|
|
1146
|
+
pipelineDef: (PipelineStep<typeof NetToPointPairsSolver> | PipelineStep<typeof CapacityMeshNodeSolver> | PipelineStep<typeof CapacityNodeTargetMerger> | PipelineStep<typeof CapacityMeshEdgeSolver> | PipelineStep<typeof CapacityPathingSolver4_FlexibleNegativeCapacity> | PipelineStep<typeof CapacityEdgeToPortSegmentSolver> | PipelineStep<typeof CapacitySegmentToPointSolver> | PipelineStep<typeof UnravelMultiSectionSolver> | PipelineStep<typeof HighDensitySolver> | PipelineStep<typeof MultipleHighDensityRouteStitchSolver>)[];
|
|
923
1147
|
constructor(srj: SimpleRouteJson, opts?: CapacityMeshSolverOptions);
|
|
924
1148
|
currentPipelineStepIndex: number;
|
|
925
1149
|
_step(): void;
|