@tscircuit/capacity-autorouter 0.0.87 → 0.0.88

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
@@ -114,6 +114,12 @@ declare class BaseSolver {
114
114
  getConstructorParams(): void;
115
115
  solve(): void;
116
116
  visualize(): GraphicsObject;
117
+ /**
118
+ * Called when the solver is about to fail, but we want to see if we have an
119
+ * "acceptable" or "passable" solution. Mostly used for optimizers that
120
+ * have an aggressive early stopping criterion.
121
+ */
122
+ tryFinalAcceptance(): void;
117
123
  /**
118
124
  * A lightweight version of the visualize method that can be used to stream
119
125
  * progress
@@ -422,6 +428,7 @@ interface HighDensityHyperParameters {
422
428
  SEGMENTS_PER_POLYLINE: number;
423
429
  BOUNDARY_PADDING: number;
424
430
  ITERATION_PENALTY: number;
431
+ MINIMUM_FINAL_ACCEPTANCE_GAP?: number;
425
432
  }
426
433
 
427
434
  type Node = {
@@ -762,11 +769,13 @@ declare class HyperSingleIntraNodeSolver extends HyperParameterSupervisorSolver<
762
769
  SEGMENTS_PER_POLYLINE: number;
763
770
  BOUNDARY_PADDING: number;
764
771
  ITERATION_PENALTY?: undefined;
772
+ MINIMUM_FINAL_ACCEPTANCE_GAP?: undefined;
765
773
  } | {
766
774
  MULTI_HEAD_POLYLINE_SOLVER: boolean;
767
775
  SEGMENTS_PER_POLYLINE: number;
768
776
  BOUNDARY_PADDING: number;
769
777
  ITERATION_PENALTY: number;
778
+ MINIMUM_FINAL_ACCEPTANCE_GAP: number;
770
779
  })[];
771
780
  })[];
772
781
  computeG(solver: IntraNodeRouteSolver): number;
package/dist/index.js CHANGED
@@ -67,6 +67,9 @@ var BaseSolver = class {
67
67
  this.failed = true;
68
68
  throw e;
69
69
  }
70
+ if (!this.solved && this.iterations > this.MAX_ITERATIONS) {
71
+ this.tryFinalAcceptance();
72
+ }
70
73
  if (!this.solved && this.iterations > this.MAX_ITERATIONS) {
71
74
  this.error = `${this.constructor.name} ran out of iterations`;
72
75
  console.error(this.error);
@@ -97,6 +100,13 @@ var BaseSolver = class {
97
100
  circles: []
98
101
  };
99
102
  }
103
+ /**
104
+ * Called when the solver is about to fail, but we want to see if we have an
105
+ * "acceptable" or "passable" solution. Mostly used for optimizers that
106
+ * have an aggressive early stopping criterion.
107
+ */
108
+ tryFinalAcceptance() {
109
+ }
100
110
  /**
101
111
  * A lightweight version of the visualize method that can be used to stream
102
112
  * progress
@@ -8172,6 +8182,21 @@ var MultiHeadPolyLineIntraNodeSolver = class extends BaseSolver {
8172
8182
  });
8173
8183
  return minGapsToOtherConnectionsValid && allPointsWithinBounds;
8174
8184
  }
8185
+ // ------------------------------------------------------------------
8186
+ // Try accepting the best candidate even if normal solving failed.
8187
+ // ------------------------------------------------------------------
8188
+ tryFinalAcceptance() {
8189
+ const minGapTarget = this.hyperParameters?.MINIMUM_FINAL_ACCEPTANCE_GAP ?? void 0;
8190
+ if (minGapTarget === void 0 || this.lastCandidate === null || this.lastCandidate.minGaps.length === 0)
8191
+ return;
8192
+ const minGapAchieved = Math.min(...this.lastCandidate.minGaps);
8193
+ if (minGapAchieved >= minGapTarget) {
8194
+ this.solved = true;
8195
+ this._setSolvedRoutes();
8196
+ return;
8197
+ }
8198
+ return;
8199
+ }
8175
8200
  _step() {
8176
8201
  if (this.phase === "setup") {
8177
8202
  this.setupInitialPolyLines();
@@ -8180,6 +8205,8 @@ var MultiHeadPolyLineIntraNodeSolver = class extends BaseSolver {
8180
8205
  }
8181
8206
  const currentCandidate = this.candidates.shift();
8182
8207
  if (!currentCandidate) {
8208
+ this.tryFinalAcceptance();
8209
+ if (this.solved) return;
8183
8210
  this.failed = true;
8184
8211
  this.error = "No candidates left";
8185
8212
  return;
@@ -8413,6 +8440,8 @@ var MultiHeadPolyLineIntraNodeSolver2 = class extends MultiHeadPolyLineIntraNode
8413
8440
  }
8414
8441
  const currentCandidate = this.candidates.shift();
8415
8442
  if (!currentCandidate) {
8443
+ this.tryFinalAcceptance();
8444
+ if (this.solved) return;
8416
8445
  this.failed = true;
8417
8446
  return;
8418
8447
  }
@@ -9063,7 +9092,8 @@ var HyperSingleIntraNodeSolver = class extends HyperParameterSupervisorSolver {
9063
9092
  SEGMENTS_PER_POLYLINE: 6,
9064
9093
  BOUNDARY_PADDING: -0.05,
9065
9094
  // Allow vias/traces outside the boundary
9066
- ITERATION_PENALTY: 1e4
9095
+ ITERATION_PENALTY: 1e4,
9096
+ MINIMUM_FINAL_ACCEPTANCE_GAP: 1e-3
9067
9097
  }
9068
9098
  ]
9069
9099
  }