@tscircuit/capacity-autorouter 0.0.19 → 0.0.20
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 +220 -1
- package/dist/index.js +1681 -1231
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -93,7 +93,9 @@ declare class BaseSolver {
|
|
|
93
93
|
iterations: number;
|
|
94
94
|
progress: number;
|
|
95
95
|
error: string | null;
|
|
96
|
+
activeSubSolver?: BaseSolver | null;
|
|
96
97
|
failedSubSolvers?: BaseSolver[];
|
|
98
|
+
timeToSolve?: number;
|
|
97
99
|
/** DO NOT OVERRIDE! Override _step() instead */
|
|
98
100
|
step(): void;
|
|
99
101
|
_step(): void;
|
|
@@ -889,6 +891,222 @@ declare class MultipleHighDensityRouteStitchSolver extends BaseSolver {
|
|
|
889
891
|
visualize(): GraphicsObject;
|
|
890
892
|
}
|
|
891
893
|
|
|
894
|
+
type SegmentPointId = string;
|
|
895
|
+
type SegmentId = string;
|
|
896
|
+
interface BaseUnravelIssue {
|
|
897
|
+
probabilityOfFailure: number;
|
|
898
|
+
}
|
|
899
|
+
interface UnravelTransitionViaIssue extends BaseUnravelIssue {
|
|
900
|
+
type: "transition_via";
|
|
901
|
+
capacityMeshNodeId: CapacityMeshNodeId;
|
|
902
|
+
segmentPoints: SegmentPointId[];
|
|
903
|
+
}
|
|
904
|
+
interface UnravelSameLayerCrossingIssue extends BaseUnravelIssue {
|
|
905
|
+
type: "same_layer_crossing";
|
|
906
|
+
capacityMeshNodeId: CapacityMeshNodeId;
|
|
907
|
+
crossingLine1: [SegmentPointId, SegmentPointId];
|
|
908
|
+
crossingLine2: [SegmentPointId, SegmentPointId];
|
|
909
|
+
}
|
|
910
|
+
interface UnravelSingleTransitionCrossingIssue extends BaseUnravelIssue {
|
|
911
|
+
type: "single_transition_crossing";
|
|
912
|
+
capacityMeshNodeId: CapacityMeshNodeId;
|
|
913
|
+
sameLayerCrossingLine: [SegmentPointId, SegmentPointId];
|
|
914
|
+
transitionCrossingLine: [SegmentPointId, SegmentPointId];
|
|
915
|
+
}
|
|
916
|
+
interface UnravelDoubleTransitionCrossingIssue extends BaseUnravelIssue {
|
|
917
|
+
type: "double_transition_crossing";
|
|
918
|
+
capacityMeshNodeId: CapacityMeshNodeId;
|
|
919
|
+
crossingLine1: [SegmentPointId, SegmentPointId];
|
|
920
|
+
crossingLine2: [SegmentPointId, SegmentPointId];
|
|
921
|
+
}
|
|
922
|
+
interface UnravelTraceCapacityIssue extends BaseUnravelIssue {
|
|
923
|
+
type: "same_layer_trace_imbalance_with_low_capacity";
|
|
924
|
+
capacityMeshNodeId: CapacityMeshNodeId;
|
|
925
|
+
z: number;
|
|
926
|
+
tracesOnLayer: Array<{
|
|
927
|
+
A: SegmentPointId;
|
|
928
|
+
B: SegmentPointId;
|
|
929
|
+
}>;
|
|
930
|
+
}
|
|
931
|
+
interface SegmentPoint {
|
|
932
|
+
segmentPointId: SegmentPointId;
|
|
933
|
+
directlyConnectedSegmentPointIds: SegmentPointId[];
|
|
934
|
+
connectionName: string;
|
|
935
|
+
segmentId: string;
|
|
936
|
+
capacityMeshNodeIds: CapacityMeshNodeId[];
|
|
937
|
+
x: number;
|
|
938
|
+
y: number;
|
|
939
|
+
z: number;
|
|
940
|
+
}
|
|
941
|
+
type SegmentPointMap = Map<SegmentPointId, SegmentPoint>;
|
|
942
|
+
type UnravelIssue = UnravelTransitionViaIssue | UnravelSameLayerCrossingIssue | UnravelSingleTransitionCrossingIssue | UnravelDoubleTransitionCrossingIssue | UnravelTraceCapacityIssue;
|
|
943
|
+
interface UnravelSection {
|
|
944
|
+
allNodeIds: CapacityMeshNodeId[];
|
|
945
|
+
mutableNodeIds: CapacityMeshNodeId[];
|
|
946
|
+
mutableSegmentIds: Set<string>;
|
|
947
|
+
immutableNodeIds: CapacityMeshNodeId[];
|
|
948
|
+
segmentPointMap: SegmentPointMap;
|
|
949
|
+
segmentPairsInNode: Map<CapacityMeshNodeId, Array<[SegmentPointId, SegmentPointId]>>;
|
|
950
|
+
segmentPointsInNode: Map<CapacityMeshNodeId, SegmentPointId[]>;
|
|
951
|
+
segmentPointsInSegment: Map<SegmentId, SegmentPointId[]>;
|
|
952
|
+
}
|
|
953
|
+
interface UnravelChangeLayerOperation {
|
|
954
|
+
type: "change_layer";
|
|
955
|
+
newZ: number;
|
|
956
|
+
segmentPointIds: SegmentPointId[];
|
|
957
|
+
}
|
|
958
|
+
interface UnravelSwapPositionOnSegmentOperation {
|
|
959
|
+
type: "swap_position_on_segment";
|
|
960
|
+
segmentPointIds: SegmentPointId[];
|
|
961
|
+
}
|
|
962
|
+
interface UnravelCombinedOperation {
|
|
963
|
+
type: "combined";
|
|
964
|
+
operations: Array<UnravelChangeLayerOperation | UnravelSwapPositionOnSegmentOperation>;
|
|
965
|
+
}
|
|
966
|
+
type UnravelOperation = UnravelChangeLayerOperation | UnravelSwapPositionOnSegmentOperation | UnravelCombinedOperation;
|
|
967
|
+
type UnravelCandidate = {
|
|
968
|
+
operationsPerformed: number;
|
|
969
|
+
/**
|
|
970
|
+
* A hash of the pointModifications to know if this candidate has already been
|
|
971
|
+
* explored
|
|
972
|
+
*/
|
|
973
|
+
candidateHash: string;
|
|
974
|
+
/**
|
|
975
|
+
* More expensive hash that includes original positions
|
|
976
|
+
*/
|
|
977
|
+
candidateFullHash?: string;
|
|
978
|
+
pointModifications: Map<SegmentPointId, {
|
|
979
|
+
x?: number;
|
|
980
|
+
y?: number;
|
|
981
|
+
z?: number;
|
|
982
|
+
}>;
|
|
983
|
+
issues: UnravelIssue[];
|
|
984
|
+
/**
|
|
985
|
+
* The cost of this candidate (log probability of failure) considering all of
|
|
986
|
+
* the point modifications
|
|
987
|
+
*/
|
|
988
|
+
g: number;
|
|
989
|
+
/**
|
|
990
|
+
* The estimated cost of this candidate (log probability of failure). We don't
|
|
991
|
+
* currently know how to compute this so it's always 0.
|
|
992
|
+
*/
|
|
993
|
+
h: number;
|
|
994
|
+
/**
|
|
995
|
+
* Candidate cost ~(g + h)
|
|
996
|
+
*/
|
|
997
|
+
f: number;
|
|
998
|
+
};
|
|
999
|
+
|
|
1000
|
+
/**
|
|
1001
|
+
* The UntangleSectionSolver optimizes a section of connected capacity nodes
|
|
1002
|
+
* with their deduplicated segments.
|
|
1003
|
+
*
|
|
1004
|
+
* The section always has a "root" node. From the root node, MUTABLE_HOPS are
|
|
1005
|
+
* taken to reach other nodes that are mutable. One additional hop is taken to
|
|
1006
|
+
* have all the impacted nodes in section. So a section is composed of mutable
|
|
1007
|
+
* and immutable nodes.
|
|
1008
|
+
*
|
|
1009
|
+
* The goal of the solver is to perform operations on the mutable nodes of the
|
|
1010
|
+
* section to lower the overall cost of the section.
|
|
1011
|
+
*
|
|
1012
|
+
* The untangle phase will perform "operations" on segments based on "issues"
|
|
1013
|
+
*
|
|
1014
|
+
* An "issue" is anything that increases the cost of the node:
|
|
1015
|
+
* - Anything that causes a via (e.g. layer transition)
|
|
1016
|
+
* - Any time two traces cross on the same layer
|
|
1017
|
+
*
|
|
1018
|
+
* An operation is a change to a segment. There are two main operations:
|
|
1019
|
+
* - Change layer
|
|
1020
|
+
* - Change point order on segment
|
|
1021
|
+
*
|
|
1022
|
+
* This solver works by exploring different paths of operations. When an
|
|
1023
|
+
* operation is performed, new issues are created. Each path has a cost, and
|
|
1024
|
+
* a set of neighbors representing next operations to perform.
|
|
1025
|
+
*
|
|
1026
|
+
*/
|
|
1027
|
+
declare class UnravelSectionSolver extends BaseSolver {
|
|
1028
|
+
nodeMap: Map<CapacityMeshNodeId, CapacityMeshNode>;
|
|
1029
|
+
dedupedSegments: SegmentWithAssignedPoints[];
|
|
1030
|
+
MUTABLE_HOPS: number;
|
|
1031
|
+
unravelSection: UnravelSection;
|
|
1032
|
+
candidates: UnravelCandidate[];
|
|
1033
|
+
lastProcessedCandidate: UnravelCandidate | null;
|
|
1034
|
+
bestCandidate: UnravelCandidate | null;
|
|
1035
|
+
originalCandidate: UnravelCandidate;
|
|
1036
|
+
rootNodeId: CapacityMeshNodeId;
|
|
1037
|
+
nodeIdToSegmentIds: Map<CapacityMeshNodeId, CapacityMeshNodeId[]>;
|
|
1038
|
+
segmentIdToNodeIds: Map<CapacityMeshNodeId, CapacityMeshNodeId[]>;
|
|
1039
|
+
colorMap: Record<string, string>;
|
|
1040
|
+
tunedNodeCapacityMap: Map<CapacityMeshNodeId, number>;
|
|
1041
|
+
MAX_CANDIDATES: number;
|
|
1042
|
+
selectedCandidateIndex: number | "best" | "original" | null;
|
|
1043
|
+
queuedOrExploredCandidatePointModificationHashes: Set<string>;
|
|
1044
|
+
constructor(params: {
|
|
1045
|
+
rootNodeId: CapacityMeshNodeId;
|
|
1046
|
+
colorMap?: Record<string, string>;
|
|
1047
|
+
MUTABLE_HOPS?: number;
|
|
1048
|
+
nodeMap: Map<CapacityMeshNodeId, CapacityMeshNode>;
|
|
1049
|
+
dedupedSegments: SegmentWithAssignedPoints[];
|
|
1050
|
+
nodeIdToSegmentIds: Map<CapacityMeshNodeId, CapacityMeshNodeId[]>;
|
|
1051
|
+
segmentIdToNodeIds: Map<CapacityMeshNodeId, CapacityMeshNodeId[]>;
|
|
1052
|
+
segmentPointMap?: SegmentPointMap;
|
|
1053
|
+
});
|
|
1054
|
+
createUnravelSection(segmentPointMap?: SegmentPointMap): UnravelSection;
|
|
1055
|
+
createInitialCandidate(): UnravelCandidate;
|
|
1056
|
+
get nextCandidate(): UnravelCandidate | null;
|
|
1057
|
+
getPointInCandidate(candidate: UnravelCandidate, segmentPointId: SegmentPointId): {
|
|
1058
|
+
x: number;
|
|
1059
|
+
y: number;
|
|
1060
|
+
z: number;
|
|
1061
|
+
segmentId: string;
|
|
1062
|
+
};
|
|
1063
|
+
getOperationsForIssue(candidate: UnravelCandidate, issue: UnravelIssue): UnravelOperation[];
|
|
1064
|
+
computeG(params: {
|
|
1065
|
+
issues: UnravelIssue[];
|
|
1066
|
+
originalCandidate: UnravelCandidate;
|
|
1067
|
+
operationsPerformed: number;
|
|
1068
|
+
operation: UnravelOperation;
|
|
1069
|
+
}): number;
|
|
1070
|
+
getNeighborByApplyingOperation(currentCandidate: UnravelCandidate, operation: UnravelOperation): UnravelCandidate;
|
|
1071
|
+
getNeighborOperationsForCandidate(candidate: UnravelCandidate): UnravelOperation[];
|
|
1072
|
+
getNeighbors(candidate: UnravelCandidate): UnravelCandidate[];
|
|
1073
|
+
_step(): void;
|
|
1074
|
+
visualize(): GraphicsObject;
|
|
1075
|
+
}
|
|
1076
|
+
|
|
1077
|
+
declare class UnravelMultiSectionSolver extends BaseSolver {
|
|
1078
|
+
nodeMap: Map<CapacityMeshNodeId, CapacityMeshNode>;
|
|
1079
|
+
dedupedSegments: SegmentWithAssignedPoints[];
|
|
1080
|
+
nodeIdToSegmentIds: Map<CapacityMeshNodeId, CapacityMeshNodeId[]>;
|
|
1081
|
+
segmentIdToNodeIds: Map<CapacityMeshNodeId, CapacityMeshNodeId[]>;
|
|
1082
|
+
colorMap: Record<string, string>;
|
|
1083
|
+
tunedNodeCapacityMap: Map<CapacityMeshNodeId, number>;
|
|
1084
|
+
MAX_NODE_ATTEMPTS: number;
|
|
1085
|
+
MUTABLE_HOPS: number;
|
|
1086
|
+
ACCEPTABLE_PF: number;
|
|
1087
|
+
/**
|
|
1088
|
+
* Probability of failure for each node
|
|
1089
|
+
*/
|
|
1090
|
+
nodePfMap: Map<CapacityMeshNodeId, number>;
|
|
1091
|
+
attemptsToFixNode: Map<CapacityMeshNodeId, number>;
|
|
1092
|
+
activeSolver: UnravelSectionSolver | null;
|
|
1093
|
+
segmentPointMap: SegmentPointMap;
|
|
1094
|
+
constructor({ assignedSegments, colorMap, nodes, }: {
|
|
1095
|
+
assignedSegments: NodePortSegment[];
|
|
1096
|
+
colorMap?: Record<string, string>;
|
|
1097
|
+
/**
|
|
1098
|
+
* This isn't used by the algorithm, but allows associating metadata
|
|
1099
|
+
* for the result datatype (the center, width, height of the node)
|
|
1100
|
+
*/
|
|
1101
|
+
nodes: CapacityMeshNode[];
|
|
1102
|
+
});
|
|
1103
|
+
computeInitialPfMap(): Map<string, number>;
|
|
1104
|
+
computeNodePf(node: CapacityMeshNode): number;
|
|
1105
|
+
_step(): void;
|
|
1106
|
+
visualize(): GraphicsObject;
|
|
1107
|
+
getNodesWithPortPoints(): NodeWithPortPoints[];
|
|
1108
|
+
}
|
|
1109
|
+
|
|
892
1110
|
interface CapacityMeshSolverOptions {
|
|
893
1111
|
capacityDepth?: number;
|
|
894
1112
|
targetMinCapacity?: number;
|
|
@@ -910,6 +1128,7 @@ declare class CapacityMeshSolver extends BaseSolver {
|
|
|
910
1128
|
edgeToPortSegmentSolver?: CapacityEdgeToPortSegmentSolver;
|
|
911
1129
|
colorMap: Record<string, string>;
|
|
912
1130
|
segmentToPointSolver?: CapacitySegmentToPointSolver;
|
|
1131
|
+
unravelMultiSectionSolver?: UnravelMultiSectionSolver;
|
|
913
1132
|
segmentToPointOptimizer?: CapacitySegmentPointOptimizer;
|
|
914
1133
|
highDensityRouteSolver?: HighDensitySolver;
|
|
915
1134
|
highDensityStitchSolver?: MultipleHighDensityRouteStitchSolver;
|
|
@@ -919,7 +1138,7 @@ declare class CapacityMeshSolver extends BaseSolver {
|
|
|
919
1138
|
activeSolver?: BaseSolver | null;
|
|
920
1139
|
connMap: ConnectivityMap;
|
|
921
1140
|
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
|
|
1141
|
+
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
1142
|
constructor(srj: SimpleRouteJson, opts?: CapacityMeshSolverOptions);
|
|
924
1143
|
currentPipelineStepIndex: number;
|
|
925
1144
|
_step(): void;
|