@tscircuit/hypergraph 0.0.70 → 0.0.71
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 +8 -0
- package/dist/index.js +28 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -464,6 +464,8 @@ type HyperGraphSectionOptimizer2Input = {
|
|
|
464
464
|
MAX_ATTEMPTS_PER_REGION?: number;
|
|
465
465
|
MAX_ATTEMPTS_PER_SECTION?: number;
|
|
466
466
|
ACCEPTABLE_CENTRAL_REGION_COST?: number;
|
|
467
|
+
ACCEPTABLE_CENTRAL_REGION_COST_START?: number;
|
|
468
|
+
ACCEPTABLE_CENTRAL_REGION_COST_END?: number;
|
|
467
469
|
};
|
|
468
470
|
type NormalizedHyperGraphSectionOptimizer2Input = {
|
|
469
471
|
inputGraph: SerializedHyperGraph;
|
|
@@ -473,6 +475,8 @@ type NormalizedHyperGraphSectionOptimizer2Input = {
|
|
|
473
475
|
maxTargetRegionAttempts: number;
|
|
474
476
|
maxSectionAttempts: number;
|
|
475
477
|
minCentralRegionCost: number;
|
|
478
|
+
centralRegionCostStart?: number;
|
|
479
|
+
centralRegionCostEnd?: number;
|
|
476
480
|
effort: number;
|
|
477
481
|
};
|
|
478
482
|
type SectionSolveAttempt = {
|
|
@@ -502,6 +506,8 @@ declare class HyperGraphSectionOptimizer2 extends BaseSolver {
|
|
|
502
506
|
maxTargetRegionAttempts: number;
|
|
503
507
|
maxSectionAttempts: number;
|
|
504
508
|
minCentralRegionCost: number;
|
|
509
|
+
ACCEPTABLE_CENTRAL_REGION_COST_START: number | undefined;
|
|
510
|
+
ACCEPTABLE_CENTRAL_REGION_COST_END: number | undefined;
|
|
505
511
|
effort: number;
|
|
506
512
|
};
|
|
507
513
|
getOutput(): SolvedRoute[];
|
|
@@ -516,6 +522,8 @@ declare class HyperGraphSectionOptimizer2 extends BaseSolver {
|
|
|
516
522
|
_step(): void;
|
|
517
523
|
private startNextSectionAttempt;
|
|
518
524
|
private selectTargetRegion;
|
|
525
|
+
protected getMinCentralRegionCost(): number;
|
|
526
|
+
private interpolateCentralRegionCost;
|
|
519
527
|
private createSectionSolveAttempt;
|
|
520
528
|
private acceptMergedGraph;
|
|
521
529
|
private rejectActiveAttempt;
|
package/dist/index.js
CHANGED
|
@@ -3732,6 +3732,8 @@ var HyperGraphSectionOptimizer2 = class extends BaseSolver3 {
|
|
|
3732
3732
|
maxTargetRegionAttempts: this.config.maxTargetRegionAttempts,
|
|
3733
3733
|
maxSectionAttempts: this.config.maxSectionAttempts,
|
|
3734
3734
|
minCentralRegionCost: this.config.minCentralRegionCost,
|
|
3735
|
+
ACCEPTABLE_CENTRAL_REGION_COST_START: this.config.centralRegionCostStart,
|
|
3736
|
+
ACCEPTABLE_CENTRAL_REGION_COST_END: this.config.centralRegionCostEnd,
|
|
3735
3737
|
effort: this.config.effort
|
|
3736
3738
|
};
|
|
3737
3739
|
}
|
|
@@ -3842,19 +3844,35 @@ var HyperGraphSectionOptimizer2 = class extends BaseSolver3 {
|
|
|
3842
3844
|
selectTargetRegion() {
|
|
3843
3845
|
let bestRegion = null;
|
|
3844
3846
|
let bestCost = Infinity;
|
|
3847
|
+
const minCentralRegionCost = this.getMinCentralRegionCost();
|
|
3845
3848
|
for (const region of this.graph.regions) {
|
|
3846
3849
|
if ((region.assignments?.length ?? 0) === 0) continue;
|
|
3847
3850
|
if ((this.targetRegionAttemptCounts.get(region.regionId) ?? 0) >= this.config.maxTargetRegionAttempts) {
|
|
3848
3851
|
continue;
|
|
3849
3852
|
}
|
|
3850
3853
|
const cost = this.getCostOfCentralRegion(region);
|
|
3851
|
-
if (cost <=
|
|
3854
|
+
if (cost <= minCentralRegionCost) continue;
|
|
3852
3855
|
if (cost >= bestCost) continue;
|
|
3853
3856
|
bestCost = cost;
|
|
3854
3857
|
bestRegion = region;
|
|
3855
3858
|
}
|
|
3856
3859
|
return bestRegion;
|
|
3857
3860
|
}
|
|
3861
|
+
getMinCentralRegionCost() {
|
|
3862
|
+
const { centralRegionCostStart, centralRegionCostEnd } = this.config;
|
|
3863
|
+
if (centralRegionCostStart === void 0 || centralRegionCostEnd === void 0) {
|
|
3864
|
+
return this.config.minCentralRegionCost;
|
|
3865
|
+
}
|
|
3866
|
+
return this.interpolateCentralRegionCost(
|
|
3867
|
+
centralRegionCostStart,
|
|
3868
|
+
centralRegionCostEnd
|
|
3869
|
+
);
|
|
3870
|
+
}
|
|
3871
|
+
interpolateCentralRegionCost(start, end) {
|
|
3872
|
+
const attemptsToMax = Math.max(1, this.config.maxSectionAttempts - 1);
|
|
3873
|
+
const progress = Math.min(1, this.attemptedSectionCount / attemptsToMax);
|
|
3874
|
+
return start + (end - start) * progress;
|
|
3875
|
+
}
|
|
3858
3876
|
createSectionSolveAttempt(targetRegion) {
|
|
3859
3877
|
const fullGraphSnapshot = this.serializeSolvedGraph();
|
|
3860
3878
|
const extractedSection = extractSectionOfHyperGraph({
|
|
@@ -3988,6 +4006,13 @@ var normalizeInput = (input) => {
|
|
|
3988
4006
|
"HyperGraphSectionOptimizer2 requires maxTargetRegionAttempts"
|
|
3989
4007
|
);
|
|
3990
4008
|
}
|
|
4009
|
+
const acceptableCentralRegionCostStart = input.ACCEPTABLE_CENTRAL_REGION_COST_START;
|
|
4010
|
+
const acceptableCentralRegionCostEnd = input.ACCEPTABLE_CENTRAL_REGION_COST_END;
|
|
4011
|
+
if (acceptableCentralRegionCostStart === void 0 !== (acceptableCentralRegionCostEnd === void 0)) {
|
|
4012
|
+
throw new Error(
|
|
4013
|
+
"HyperGraphSectionOptimizer2 requires both ACCEPTABLE_CENTRAL_REGION_COST_START and ACCEPTABLE_CENTRAL_REGION_COST_END"
|
|
4014
|
+
);
|
|
4015
|
+
}
|
|
3991
4016
|
return {
|
|
3992
4017
|
inputGraph: {
|
|
3993
4018
|
...input.inputGraph,
|
|
@@ -4000,6 +4025,8 @@ var normalizeInput = (input) => {
|
|
|
4000
4025
|
maxTargetRegionAttempts,
|
|
4001
4026
|
maxSectionAttempts: input.maxSectionAttempts ?? input.MAX_ATTEMPTS_PER_SECTION ?? 500,
|
|
4002
4027
|
minCentralRegionCost: input.minCentralRegionCost ?? input.ACCEPTABLE_CENTRAL_REGION_COST ?? 0,
|
|
4028
|
+
centralRegionCostStart: acceptableCentralRegionCostStart,
|
|
4029
|
+
centralRegionCostEnd: acceptableCentralRegionCostEnd,
|
|
4003
4030
|
effort: input.effort ?? 1
|
|
4004
4031
|
};
|
|
4005
4032
|
};
|