@tscircuit/capacity-autorouter 0.0.60 → 0.0.62
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 +24 -4
- package/dist/index.js +91 -17
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -101,7 +101,7 @@ declare class BaseSolver {
|
|
|
101
101
|
activeSubSolver?: BaseSolver | null;
|
|
102
102
|
failedSubSolvers?: BaseSolver[];
|
|
103
103
|
timeToSolve?: number;
|
|
104
|
-
stats: Record<string,
|
|
104
|
+
stats: Record<string, any>;
|
|
105
105
|
/**
|
|
106
106
|
* For cached solvers
|
|
107
107
|
**/
|
|
@@ -704,6 +704,7 @@ declare class HyperSingleIntraNodeSolver extends HyperParameterSupervisorSolver<
|
|
|
704
704
|
constructorParams: ConstructorParameters<typeof IntraNodeRouteSolver>[0];
|
|
705
705
|
solvedRoutes: HighDensityIntraNodeRoute$1[];
|
|
706
706
|
nodeWithPortPoints: NodeWithPortPoints;
|
|
707
|
+
connMap?: ConnectivityMap;
|
|
707
708
|
constructor(opts: ConstructorParameters<typeof IntraNodeRouteSolver>[0]);
|
|
708
709
|
getCombinationDefs(): string[][];
|
|
709
710
|
getHyperParameterDefs(): ({
|
|
@@ -1523,18 +1524,37 @@ declare class CapacityPathingMultiSectionSolver extends BaseSolver {
|
|
|
1523
1524
|
nodeOptimizationAttemptCountMap: Map<CapacityMeshNodeId, number>;
|
|
1524
1525
|
currentSection: CapacityPathingSection | null;
|
|
1525
1526
|
sectionSolver?: CapacityPathingSingleSectionSolver | HyperCapacityPathingSingleSectionSolver | null;
|
|
1526
|
-
|
|
1527
|
-
MINIMUM_PROBABILITY_OF_FAILURE_TO_OPTIMIZE: number;
|
|
1528
|
-
MAX_EXPANSION_DEGREES: number;
|
|
1527
|
+
currentScheduleIndex: number;
|
|
1529
1528
|
stats: {
|
|
1530
1529
|
successfulOptimizations: number;
|
|
1531
1530
|
failedOptimizations: number;
|
|
1531
|
+
failedSectionSolvers: number;
|
|
1532
|
+
scheduleScores: Array<{
|
|
1533
|
+
maxExpansionDegrees: number;
|
|
1534
|
+
sectionAttempts: number;
|
|
1535
|
+
endingScore: number;
|
|
1536
|
+
endingHighestNodePf: number;
|
|
1537
|
+
}>;
|
|
1538
|
+
};
|
|
1539
|
+
OPTIMIZATION_SCHEDULE: {
|
|
1540
|
+
MAX_ATTEMPTS_PER_NODE: number;
|
|
1541
|
+
MAX_EXPANSION_DEGREES: number;
|
|
1542
|
+
MINIMUM_PROBABILITY_OF_FAILURE_TO_OPTIMIZE: number;
|
|
1543
|
+
}[];
|
|
1544
|
+
get currentSchedule(): {
|
|
1545
|
+
MAX_ATTEMPTS_PER_NODE: number;
|
|
1546
|
+
MAX_EXPANSION_DEGREES: number;
|
|
1547
|
+
MINIMUM_PROBABILITY_OF_FAILURE_TO_OPTIMIZE: number;
|
|
1532
1548
|
};
|
|
1533
1549
|
constructor(params: ConstructorParameters<typeof CapacityPathingSolver>[0] & {
|
|
1534
1550
|
initialPathingSolver?: CapacityPathingGreedySolver;
|
|
1535
1551
|
});
|
|
1536
1552
|
_stepInitialization(): void;
|
|
1537
1553
|
_getNextNodeToOptimize(): CapacityMeshNodeId | null;
|
|
1554
|
+
getOverallScore(): {
|
|
1555
|
+
highestNodePf: number;
|
|
1556
|
+
score: number;
|
|
1557
|
+
};
|
|
1538
1558
|
_stepSectionOptimization(): void;
|
|
1539
1559
|
/**
|
|
1540
1560
|
* Merges the paths found by a successful section solver back into the main
|
package/dist/index.js
CHANGED
|
@@ -68,7 +68,7 @@ var BaseSolver = class {
|
|
|
68
68
|
throw e;
|
|
69
69
|
}
|
|
70
70
|
if (!this.solved && this.iterations > this.MAX_ITERATIONS) {
|
|
71
|
-
this.error = `${this.constructor.name}
|
|
71
|
+
this.error = `${this.constructor.name} ran out of iterations`;
|
|
72
72
|
console.error(this.error);
|
|
73
73
|
this.failed = true;
|
|
74
74
|
}
|
|
@@ -3897,7 +3897,12 @@ var IntraNodeRouteSolver = class extends BaseSolver {
|
|
|
3897
3897
|
y: points[points.length - 1].y,
|
|
3898
3898
|
z: points[points.length - 1].z
|
|
3899
3899
|
},
|
|
3900
|
-
obstacleRoutes: this.solvedRoutes
|
|
3900
|
+
obstacleRoutes: this.connMap ? this.solvedRoutes.filter(
|
|
3901
|
+
(sr) => !this.connMap.areIdsConnected(
|
|
3902
|
+
sr.connectionName,
|
|
3903
|
+
connectionName
|
|
3904
|
+
)
|
|
3905
|
+
) : this.solvedRoutes,
|
|
3901
3906
|
futureConnections: this.unsolvedConnections,
|
|
3902
3907
|
layerCount: 2,
|
|
3903
3908
|
hyperParameters: this.hyperParameters,
|
|
@@ -8837,9 +8842,11 @@ var HyperSingleIntraNodeSolver = class extends HyperParameterSupervisorSolver {
|
|
|
8837
8842
|
constructorParams;
|
|
8838
8843
|
solvedRoutes = [];
|
|
8839
8844
|
nodeWithPortPoints;
|
|
8845
|
+
connMap;
|
|
8840
8846
|
constructor(opts) {
|
|
8841
8847
|
super();
|
|
8842
8848
|
this.nodeWithPortPoints = opts.nodeWithPortPoints;
|
|
8849
|
+
this.connMap = opts.connMap;
|
|
8843
8850
|
this.constructorParams = opts;
|
|
8844
8851
|
this.MAX_ITERATIONS = 25e4;
|
|
8845
8852
|
this.GREEDY_MULTIPLIER = 5;
|
|
@@ -8983,6 +8990,7 @@ var HyperSingleIntraNodeSolver = class extends HyperParameterSupervisorSolver {
|
|
|
8983
8990
|
if (hyperParameters.MULTI_HEAD_POLYLINE_SOLVER) {
|
|
8984
8991
|
return new MultiHeadPolyLineIntraNodeSolver3({
|
|
8985
8992
|
nodeWithPortPoints: this.nodeWithPortPoints,
|
|
8993
|
+
connMap: this.connMap,
|
|
8986
8994
|
hyperParameters
|
|
8987
8995
|
});
|
|
8988
8996
|
}
|
|
@@ -9071,7 +9079,7 @@ var HighDensitySolver = class extends BaseSolver {
|
|
|
9071
9079
|
if (this.failedSolvers.length > 0) {
|
|
9072
9080
|
this.solved = false;
|
|
9073
9081
|
this.failed = true;
|
|
9074
|
-
this.error = `Failed to solve ${this.failedSolvers.length} nodes, ${this.failedSolvers.slice(0, 5).map((fs) => fs.nodeWithPortPoints.capacityMeshNodeId)}
|
|
9082
|
+
this.error = `Failed to solve ${this.failedSolvers.length} nodes, ${this.failedSolvers.slice(0, 5).map((fs) => fs.nodeWithPortPoints.capacityMeshNodeId)}. err0: ${this.failedSolvers[0].error}.`;
|
|
9075
9083
|
return;
|
|
9076
9084
|
}
|
|
9077
9085
|
this.solved = true;
|
|
@@ -12731,7 +12739,7 @@ ${percent}% (Pf: ${(probabilityOfFailure * 100).toFixed(1)}%)`;
|
|
|
12731
12739
|
return graphics;
|
|
12732
12740
|
}
|
|
12733
12741
|
|
|
12734
|
-
// lib/solvers/CapacityPathingSectionSolver/
|
|
12742
|
+
// lib/solvers/CapacityPathingSectionSolver/CapacityPathingSingleSectionSolver.ts
|
|
12735
12743
|
var CapacityPathingSingleSectionSolver = class extends BaseSolver {
|
|
12736
12744
|
GREEDY_MULTIPLIER = 1.5;
|
|
12737
12745
|
sectionNodes;
|
|
@@ -12758,6 +12766,7 @@ var CapacityPathingSingleSectionSolver = class extends BaseSolver {
|
|
|
12758
12766
|
// Default, similar to CapacityPathingSolver5
|
|
12759
12767
|
constructor(params) {
|
|
12760
12768
|
super();
|
|
12769
|
+
this.MAX_ITERATIONS = 1e4;
|
|
12761
12770
|
this.centerNodeId = params.centerNodeId;
|
|
12762
12771
|
this.sectionNodes = params.sectionNodes;
|
|
12763
12772
|
this.sectionEdges = params.sectionEdges;
|
|
@@ -13066,7 +13075,7 @@ var HyperCapacityPathingSingleSectionSolver = class extends HyperParameterSuperv
|
|
|
13066
13075
|
winningSolver;
|
|
13067
13076
|
constructor(params) {
|
|
13068
13077
|
super();
|
|
13069
|
-
this.MAX_ITERATIONS =
|
|
13078
|
+
this.MAX_ITERATIONS = 1e5;
|
|
13070
13079
|
this.constructorParams = params;
|
|
13071
13080
|
}
|
|
13072
13081
|
computeG(solver) {
|
|
@@ -13230,15 +13239,42 @@ var CapacityPathingMultiSectionSolver = class extends BaseSolver {
|
|
|
13230
13239
|
nodeOptimizationAttemptCountMap = /* @__PURE__ */ new Map();
|
|
13231
13240
|
currentSection = null;
|
|
13232
13241
|
sectionSolver = null;
|
|
13233
|
-
|
|
13234
|
-
MINIMUM_PROBABILITY_OF_FAILURE_TO_OPTIMIZE = 0.05;
|
|
13235
|
-
MAX_EXPANSION_DEGREES = 5;
|
|
13242
|
+
currentScheduleIndex = 0;
|
|
13236
13243
|
stats;
|
|
13244
|
+
OPTIMIZATION_SCHEDULE = [
|
|
13245
|
+
{
|
|
13246
|
+
MAX_ATTEMPTS_PER_NODE: 1,
|
|
13247
|
+
MAX_EXPANSION_DEGREES: 3,
|
|
13248
|
+
MINIMUM_PROBABILITY_OF_FAILURE_TO_OPTIMIZE: 0.05
|
|
13249
|
+
},
|
|
13250
|
+
{
|
|
13251
|
+
MAX_ATTEMPTS_PER_NODE: 2,
|
|
13252
|
+
MAX_EXPANSION_DEGREES: 5,
|
|
13253
|
+
MINIMUM_PROBABILITY_OF_FAILURE_TO_OPTIMIZE: 0.2
|
|
13254
|
+
},
|
|
13255
|
+
{
|
|
13256
|
+
MAX_ATTEMPTS_PER_NODE: 3,
|
|
13257
|
+
MAX_EXPANSION_DEGREES: 7,
|
|
13258
|
+
MINIMUM_PROBABILITY_OF_FAILURE_TO_OPTIMIZE: 0.3
|
|
13259
|
+
}
|
|
13260
|
+
];
|
|
13261
|
+
get currentSchedule() {
|
|
13262
|
+
return this.OPTIMIZATION_SCHEDULE[this.currentScheduleIndex] ?? null;
|
|
13263
|
+
}
|
|
13237
13264
|
constructor(params) {
|
|
13238
13265
|
super();
|
|
13239
13266
|
this.stats = {
|
|
13240
13267
|
successfulOptimizations: 0,
|
|
13241
|
-
failedOptimizations: 0
|
|
13268
|
+
failedOptimizations: 0,
|
|
13269
|
+
failedSectionSolvers: 0,
|
|
13270
|
+
scheduleScores: this.OPTIMIZATION_SCHEDULE.map(
|
|
13271
|
+
({ MAX_EXPANSION_DEGREES }) => ({
|
|
13272
|
+
maxExpansionDegrees: MAX_EXPANSION_DEGREES,
|
|
13273
|
+
endingScore: 0,
|
|
13274
|
+
endingHighestNodePf: 0,
|
|
13275
|
+
sectionAttempts: 0
|
|
13276
|
+
})
|
|
13277
|
+
)
|
|
13242
13278
|
};
|
|
13243
13279
|
this.MAX_ITERATIONS = 1e7;
|
|
13244
13280
|
this.simpleRouteJson = params.simpleRouteJson;
|
|
@@ -13300,7 +13336,7 @@ var CapacityPathingMultiSectionSolver = class extends BaseSolver {
|
|
|
13300
13336
|
node.availableZ.length
|
|
13301
13337
|
);
|
|
13302
13338
|
const nodePfDivAttempts = nodePf / (attemptCount + 1);
|
|
13303
|
-
if (attemptCount < this.MAX_ATTEMPTS_PER_NODE && nodePfDivAttempts > highestNodePfDivAttempts && nodePf > this.MINIMUM_PROBABILITY_OF_FAILURE_TO_OPTIMIZE) {
|
|
13339
|
+
if (attemptCount < this.currentSchedule.MAX_ATTEMPTS_PER_NODE && nodePfDivAttempts > highestNodePfDivAttempts && nodePf > this.currentSchedule.MINIMUM_PROBABILITY_OF_FAILURE_TO_OPTIMIZE) {
|
|
13304
13340
|
highestNodePfDivAttempts = nodePfDivAttempts;
|
|
13305
13341
|
highestNodePf = nodePf;
|
|
13306
13342
|
nodeWithHighestPercentCapacityUsed = node.capacityMeshNodeId;
|
|
@@ -13308,11 +13344,45 @@ var CapacityPathingMultiSectionSolver = class extends BaseSolver {
|
|
|
13308
13344
|
}
|
|
13309
13345
|
return nodeWithHighestPercentCapacityUsed;
|
|
13310
13346
|
}
|
|
13347
|
+
getOverallScore() {
|
|
13348
|
+
let highestNodePf = 0;
|
|
13349
|
+
for (const node of this.nodes) {
|
|
13350
|
+
if (node._containsTarget) continue;
|
|
13351
|
+
const totalCapacity = this.totalNodeCapacityMap.get(
|
|
13352
|
+
node.capacityMeshNodeId
|
|
13353
|
+
);
|
|
13354
|
+
const nodePf = calculateNodeProbabilityOfFailure2(
|
|
13355
|
+
this.usedNodeCapacityMap.get(node.capacityMeshNodeId) ?? 0,
|
|
13356
|
+
totalCapacity,
|
|
13357
|
+
node.availableZ.length
|
|
13358
|
+
);
|
|
13359
|
+
if (nodePf > highestNodePf) {
|
|
13360
|
+
highestNodePf = nodePf;
|
|
13361
|
+
}
|
|
13362
|
+
}
|
|
13363
|
+
return {
|
|
13364
|
+
highestNodePf,
|
|
13365
|
+
score: computeSectionScore({
|
|
13366
|
+
totalNodeCapacityMap: this.totalNodeCapacityMap,
|
|
13367
|
+
usedNodeCapacityMap: this.usedNodeCapacityMap,
|
|
13368
|
+
nodeMap: this.nodeMap,
|
|
13369
|
+
sectionNodeIds: new Set(
|
|
13370
|
+
this.nodes.map((node) => node.capacityMeshNodeId)
|
|
13371
|
+
)
|
|
13372
|
+
})
|
|
13373
|
+
};
|
|
13374
|
+
}
|
|
13311
13375
|
_stepSectionOptimization() {
|
|
13312
13376
|
if (!this.sectionSolver) {
|
|
13313
13377
|
const centerNodeId = this._getNextNodeToOptimize();
|
|
13314
13378
|
if (!centerNodeId) {
|
|
13315
|
-
|
|
13379
|
+
const { highestNodePf, score } = this.getOverallScore();
|
|
13380
|
+
this.stats.scheduleScores[this.currentScheduleIndex].endingHighestNodePf = highestNodePf;
|
|
13381
|
+
this.stats.scheduleScores[this.currentScheduleIndex].endingScore = score;
|
|
13382
|
+
this.currentScheduleIndex++;
|
|
13383
|
+
if (!this.currentSchedule) {
|
|
13384
|
+
this.solved = true;
|
|
13385
|
+
}
|
|
13316
13386
|
return;
|
|
13317
13387
|
}
|
|
13318
13388
|
const section = computeSectionNodesTerminalsAndEdges({
|
|
@@ -13320,16 +13390,18 @@ var CapacityPathingMultiSectionSolver = class extends BaseSolver {
|
|
|
13320
13390
|
connectionsWithNodes: this.connectionsWithNodes,
|
|
13321
13391
|
nodeMap: this.nodeMap,
|
|
13322
13392
|
edges: this.edges,
|
|
13323
|
-
expansionDegrees: this.MAX_EXPANSION_DEGREES,
|
|
13393
|
+
expansionDegrees: this.currentSchedule.MAX_EXPANSION_DEGREES,
|
|
13394
|
+
// Corrected
|
|
13324
13395
|
nodeEdgeMap: this.nodeEdgeMap
|
|
13325
13396
|
});
|
|
13397
|
+
this.stats.scheduleScores[this.currentScheduleIndex].sectionAttempts++;
|
|
13326
13398
|
this.currentSection = section;
|
|
13327
13399
|
this.sectionSolver = new HyperCapacityPathingSingleSectionSolver({
|
|
13328
|
-
|
|
13329
|
-
sectionEdges:
|
|
13330
|
-
|
|
13400
|
+
sectionNodes: this.currentSection.sectionNodes,
|
|
13401
|
+
sectionEdges: this.currentSection.sectionEdges,
|
|
13402
|
+
sectionConnectionTerminals: this.currentSection.sectionConnectionTerminals,
|
|
13331
13403
|
colorMap: this.colorMap,
|
|
13332
|
-
centerNodeId:
|
|
13404
|
+
centerNodeId: this.currentSection.centerNodeId,
|
|
13333
13405
|
nodeEdgeMap: this.nodeEdgeMap
|
|
13334
13406
|
});
|
|
13335
13407
|
this.activeSubSolver = this.sectionSolver;
|
|
@@ -13343,6 +13415,8 @@ var CapacityPathingMultiSectionSolver = class extends BaseSolver {
|
|
|
13343
13415
|
console.warn(
|
|
13344
13416
|
`Section solver failed for node ${this.currentSection.centerNodeId}. Error: ${this.sectionSolver.error}`
|
|
13345
13417
|
);
|
|
13418
|
+
this.stats.failedSectionSolvers++;
|
|
13419
|
+
this.stats.failedOptimizations++;
|
|
13346
13420
|
this.sectionSolver = null;
|
|
13347
13421
|
this.activeSubSolver = null;
|
|
13348
13422
|
return;
|
|
@@ -15771,7 +15845,7 @@ var AutoroutingPipelineSolver = class extends BaseSolver {
|
|
|
15771
15845
|
super();
|
|
15772
15846
|
this.srj = srj;
|
|
15773
15847
|
this.opts = opts;
|
|
15774
|
-
this.MAX_ITERATIONS =
|
|
15848
|
+
this.MAX_ITERATIONS = 1e8;
|
|
15775
15849
|
if (opts.capacityDepth === void 0) {
|
|
15776
15850
|
const boundsWidth = srj.bounds.maxX - srj.bounds.minX;
|
|
15777
15851
|
const boundsHeight = srj.bounds.maxY - srj.bounds.minY;
|