@tscircuit/hypergraph 0.0.69 → 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 +91 -1
- package/dist/index.js +346 -6
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -446,6 +446,96 @@ declare class HyperGraphSectionOptimizer extends BaseSolver {
|
|
|
446
446
|
_step(): void;
|
|
447
447
|
}
|
|
448
448
|
|
|
449
|
+
type CreateSectionSolverInput = {
|
|
450
|
+
inputGraph: SerializedHyperGraph;
|
|
451
|
+
inputConnections: SerializedConnection[];
|
|
452
|
+
inputSolvedRoutes: SerializedSolvedRoute[];
|
|
453
|
+
};
|
|
454
|
+
type HyperGraphSectionOptimizer2Input = {
|
|
455
|
+
inputGraph: SerializedHyperGraph;
|
|
456
|
+
inputConnections?: SerializedConnection[];
|
|
457
|
+
inputSolvedRoutes?: SerializedSolvedRoute[];
|
|
458
|
+
sectionExpansionHops?: number;
|
|
459
|
+
maxTargetRegionAttempts?: number;
|
|
460
|
+
maxSectionAttempts?: number;
|
|
461
|
+
minCentralRegionCost?: number;
|
|
462
|
+
effort?: number;
|
|
463
|
+
expansionHopsFromCentralRegion?: number;
|
|
464
|
+
MAX_ATTEMPTS_PER_REGION?: number;
|
|
465
|
+
MAX_ATTEMPTS_PER_SECTION?: number;
|
|
466
|
+
ACCEPTABLE_CENTRAL_REGION_COST?: number;
|
|
467
|
+
ACCEPTABLE_CENTRAL_REGION_COST_START?: number;
|
|
468
|
+
ACCEPTABLE_CENTRAL_REGION_COST_END?: number;
|
|
469
|
+
};
|
|
470
|
+
type NormalizedHyperGraphSectionOptimizer2Input = {
|
|
471
|
+
inputGraph: SerializedHyperGraph;
|
|
472
|
+
inputConnections: SerializedConnection[];
|
|
473
|
+
inputSolvedRoutes: SerializedSolvedRoute[];
|
|
474
|
+
sectionExpansionHops: number;
|
|
475
|
+
maxTargetRegionAttempts: number;
|
|
476
|
+
maxSectionAttempts: number;
|
|
477
|
+
minCentralRegionCost: number;
|
|
478
|
+
centralRegionCostStart?: number;
|
|
479
|
+
centralRegionCostEnd?: number;
|
|
480
|
+
effort: number;
|
|
481
|
+
};
|
|
482
|
+
type SectionSolveAttempt = {
|
|
483
|
+
targetRegionId: RegionId;
|
|
484
|
+
sectionRegionIds: Set<RegionId>;
|
|
485
|
+
fullGraphSnapshot: SerializedHyperGraph;
|
|
486
|
+
blankSectionProblem: SerializedHyperGraph;
|
|
487
|
+
currentSectionCost: number;
|
|
488
|
+
};
|
|
489
|
+
declare class HyperGraphSectionOptimizer2 extends BaseSolver {
|
|
490
|
+
readonly config: NormalizedHyperGraphSectionOptimizer2Input;
|
|
491
|
+
readonly rootSolver: HyperGraphSolver<Region, RegionPort>;
|
|
492
|
+
graph: HyperGraph;
|
|
493
|
+
connections: Connection[];
|
|
494
|
+
solvedRoutes: SolvedRoute[];
|
|
495
|
+
activeAttempt: SectionSolveAttempt | null;
|
|
496
|
+
targetRegionAttemptCounts: Map<string, number>;
|
|
497
|
+
attemptedSectionCount: number;
|
|
498
|
+
activeSubSolver: HyperGraphSolver<Region, RegionPort> | null;
|
|
499
|
+
constructor(input: HyperGraphSectionOptimizer2Input);
|
|
500
|
+
getSolverName(): string;
|
|
501
|
+
getConstructorParams(): {
|
|
502
|
+
inputGraph: SerializedHyperGraph;
|
|
503
|
+
inputConnections: SerializedConnection[];
|
|
504
|
+
inputSolvedRoutes: SerializedSolvedRoute[];
|
|
505
|
+
sectionExpansionHops: number;
|
|
506
|
+
maxTargetRegionAttempts: number;
|
|
507
|
+
maxSectionAttempts: number;
|
|
508
|
+
minCentralRegionCost: number;
|
|
509
|
+
ACCEPTABLE_CENTRAL_REGION_COST_START: number | undefined;
|
|
510
|
+
ACCEPTABLE_CENTRAL_REGION_COST_END: number | undefined;
|
|
511
|
+
effort: number;
|
|
512
|
+
};
|
|
513
|
+
getOutput(): SolvedRoute[];
|
|
514
|
+
_setup(): void;
|
|
515
|
+
visualize(): GraphicsObject;
|
|
516
|
+
protected createHyperGraphSolver(input: CreateSectionSolverInput): HyperGraphSolver<Region, RegionPort>;
|
|
517
|
+
getCostOfCentralRegion(region: Region): number;
|
|
518
|
+
getSectionCost(input: {
|
|
519
|
+
solvedGraph: SerializedHyperGraph;
|
|
520
|
+
sectionRegionIds: Set<RegionId>;
|
|
521
|
+
}): number;
|
|
522
|
+
_step(): void;
|
|
523
|
+
private startNextSectionAttempt;
|
|
524
|
+
private selectTargetRegion;
|
|
525
|
+
protected getMinCentralRegionCost(): number;
|
|
526
|
+
private interpolateCentralRegionCost;
|
|
527
|
+
private createSectionSolveAttempt;
|
|
528
|
+
private acceptMergedGraph;
|
|
529
|
+
private rejectActiveAttempt;
|
|
530
|
+
private clearActiveAttempt;
|
|
531
|
+
private bumpTargetRegionAttemptCount;
|
|
532
|
+
private serializeSolvedGraph;
|
|
533
|
+
private deserializeSolvedRoutes;
|
|
534
|
+
private getSectionRegionIds;
|
|
535
|
+
private pruneSectionForBlanking;
|
|
536
|
+
private getRegionSolutionCost;
|
|
537
|
+
}
|
|
538
|
+
|
|
449
539
|
type Bounds$1 = {
|
|
450
540
|
minX: number;
|
|
451
541
|
minY: number;
|
|
@@ -1327,4 +1417,4 @@ declare function generateConvexViaTopologyRegions(opts: {
|
|
|
1327
1417
|
};
|
|
1328
1418
|
};
|
|
1329
1419
|
|
|
1330
|
-
export { type Bounds$1 as Bounds, type BuildOpts, type Candidate, ConnectBuilder, type ConnectOpts, type Connection, type ConnectionId, type ConvexViaGraphFromXYConnectionsResult, type CreateHyperGraphSolver, type CreateHyperGraphSolverInput, type GScore, type GraphEdgeId, type HyperGraph, type HyperGraphSection, HyperGraphSectionOptimizer, HyperGraphSolver, type JPort, type JRegion, JUMPER_GRAPH_SOLVER_DEFAULTS, type JumperGraph, JumperGraphSolver, type JumperGraphWithConnections, type NetworkId, type PortAssignment, PortBuilder, type PortData, type PortId, type PortSpread, type Region, RegionBuilder, type RegionData, type RegionId, type RegionPort, type RegionPortAssignment, type RegionRef, type RouteSegment, type SectionRoute, type SerializedCandidate, type SerializedConnection, type SerializedGraphPort, type SerializedGraphRegion, type SerializedHyperGraph, type SerializedRegionPortAssignment, type SerializedSectionRouteBinding, type SerializedSolvedRoute, type SharedBoundary, type SolvedRoute, Topology, TopologyError, VIA_GRAPH_SOLVER_DEFAULTS, type ValidateOpts, type ViaByNet, type ViaData, ViaGraphSolver, type ViaGraphWithConnections, type ViaTile, type ViaTileRecommendation, type ViaTileRecommendationCandidate, type ViaTileRecommendationProblemInput, type XYConnection, applyTransformToGraph, calculateGraphBounds, convertConnectionsToSerializedConnections, convertHyperGraphToSerializedHyperGraph, createBlankHyperGraph, createConvexViaGraphFromXYConnections, createGraphWithConnectionsFromBaseGraph, createViaGraphWithConnections, extractSectionOfHyperGraph, generateConvexViaTopologyRegions, generateDefaultViaTopologyRegions, generateJumperGrid, generateJumperX4Grid, generateViaTopologyRegions, pruneDeadEndPorts, reattachSectionToGraph, recommendViaTileFromGraphInput, rotateGraph90Degrees, viaTile4Regions as viaTile };
|
|
1420
|
+
export { type Bounds$1 as Bounds, type BuildOpts, type Candidate, ConnectBuilder, type ConnectOpts, type Connection, type ConnectionId, type ConvexViaGraphFromXYConnectionsResult, type CreateHyperGraphSolver, type CreateHyperGraphSolverInput, type CreateSectionSolverInput, type GScore, type GraphEdgeId, type HyperGraph, type HyperGraphSection, HyperGraphSectionOptimizer, HyperGraphSectionOptimizer2, type HyperGraphSectionOptimizer2Input, HyperGraphSolver, type JPort, type JRegion, JUMPER_GRAPH_SOLVER_DEFAULTS, type JumperGraph, JumperGraphSolver, type JumperGraphWithConnections, type NetworkId, type PortAssignment, PortBuilder, type PortData, type PortId, type PortSpread, type Region, RegionBuilder, type RegionData, type RegionId, type RegionPort, type RegionPortAssignment, type RegionRef, type RouteSegment, type SectionRoute, type SerializedCandidate, type SerializedConnection, type SerializedGraphPort, type SerializedGraphRegion, type SerializedHyperGraph, type SerializedRegionPortAssignment, type SerializedSectionRouteBinding, type SerializedSolvedRoute, type SharedBoundary, type SolvedRoute, Topology, TopologyError, VIA_GRAPH_SOLVER_DEFAULTS, type ValidateOpts, type ViaByNet, type ViaData, ViaGraphSolver, type ViaGraphWithConnections, type ViaTile, type ViaTileRecommendation, type ViaTileRecommendationCandidate, type ViaTileRecommendationProblemInput, type XYConnection, applyTransformToGraph, calculateGraphBounds, convertConnectionsToSerializedConnections, convertHyperGraphToSerializedHyperGraph, createBlankHyperGraph, createConvexViaGraphFromXYConnections, createGraphWithConnectionsFromBaseGraph, createViaGraphWithConnections, extractSectionOfHyperGraph, generateConvexViaTopologyRegions, generateDefaultViaTopologyRegions, generateJumperGrid, generateJumperX4Grid, generateViaTopologyRegions, pruneDeadEndPorts, reattachSectionToGraph, recommendViaTileFromGraphInput, rotateGraph90Degrees, viaTile4Regions as viaTile };
|
package/dist/index.js
CHANGED
|
@@ -3692,6 +3692,345 @@ var HyperGraphSectionOptimizer = class extends BaseSolver2 {
|
|
|
3692
3692
|
}
|
|
3693
3693
|
};
|
|
3694
3694
|
|
|
3695
|
+
// lib/HyperGraphSectionOptimizer/HyperGraphSectionOptimizer2.ts
|
|
3696
|
+
import { BaseSolver as BaseSolver3 } from "@tscircuit/solver-utils";
|
|
3697
|
+
var HyperGraphSectionOptimizer2 = class extends BaseSolver3 {
|
|
3698
|
+
config;
|
|
3699
|
+
rootSolver;
|
|
3700
|
+
graph;
|
|
3701
|
+
connections;
|
|
3702
|
+
solvedRoutes;
|
|
3703
|
+
activeAttempt = null;
|
|
3704
|
+
targetRegionAttemptCounts = /* @__PURE__ */ new Map();
|
|
3705
|
+
attemptedSectionCount = 0;
|
|
3706
|
+
constructor(input) {
|
|
3707
|
+
super();
|
|
3708
|
+
this.config = normalizeInput(input);
|
|
3709
|
+
this.rootSolver = this.createHyperGraphSolver({
|
|
3710
|
+
inputGraph: this.config.inputGraph,
|
|
3711
|
+
inputConnections: this.config.inputConnections,
|
|
3712
|
+
inputSolvedRoutes: this.config.inputSolvedRoutes
|
|
3713
|
+
});
|
|
3714
|
+
this.graph = this.rootSolver.graph;
|
|
3715
|
+
this.connections = this.rootSolver.connections;
|
|
3716
|
+
this.solvedRoutes = this.rootSolver.solvedRoutes;
|
|
3717
|
+
this.MAX_ITERATIONS = Math.ceil(this.MAX_ITERATIONS * this.config.effort);
|
|
3718
|
+
}
|
|
3719
|
+
getSolverName() {
|
|
3720
|
+
return "HyperGraphSectionOptimizer2";
|
|
3721
|
+
}
|
|
3722
|
+
getConstructorParams() {
|
|
3723
|
+
return {
|
|
3724
|
+
inputGraph: convertHyperGraphToSerializedHyperGraph(this.graph),
|
|
3725
|
+
inputConnections: convertConnectionsToSerializedConnections(
|
|
3726
|
+
this.connections
|
|
3727
|
+
),
|
|
3728
|
+
inputSolvedRoutes: convertSolvedRoutesToSerializedSolvedRoutes(
|
|
3729
|
+
this.solvedRoutes
|
|
3730
|
+
),
|
|
3731
|
+
sectionExpansionHops: this.config.sectionExpansionHops,
|
|
3732
|
+
maxTargetRegionAttempts: this.config.maxTargetRegionAttempts,
|
|
3733
|
+
maxSectionAttempts: this.config.maxSectionAttempts,
|
|
3734
|
+
minCentralRegionCost: this.config.minCentralRegionCost,
|
|
3735
|
+
ACCEPTABLE_CENTRAL_REGION_COST_START: this.config.centralRegionCostStart,
|
|
3736
|
+
ACCEPTABLE_CENTRAL_REGION_COST_END: this.config.centralRegionCostEnd,
|
|
3737
|
+
effort: this.config.effort
|
|
3738
|
+
};
|
|
3739
|
+
}
|
|
3740
|
+
getOutput() {
|
|
3741
|
+
return this.solvedRoutes;
|
|
3742
|
+
}
|
|
3743
|
+
_setup() {
|
|
3744
|
+
this.startNextSectionAttempt();
|
|
3745
|
+
}
|
|
3746
|
+
visualize() {
|
|
3747
|
+
if (this.activeSubSolver) {
|
|
3748
|
+
return this.activeSubSolver.visualize();
|
|
3749
|
+
}
|
|
3750
|
+
return {
|
|
3751
|
+
title: "HyperGraphSectionOptimizer2",
|
|
3752
|
+
points: [],
|
|
3753
|
+
lines: [],
|
|
3754
|
+
rects: [],
|
|
3755
|
+
circles: [],
|
|
3756
|
+
texts: [],
|
|
3757
|
+
polygons: [],
|
|
3758
|
+
arrows: []
|
|
3759
|
+
};
|
|
3760
|
+
}
|
|
3761
|
+
createHyperGraphSolver(input) {
|
|
3762
|
+
const graph = convertSerializedHyperGraphToHyperGraph(input.inputGraph);
|
|
3763
|
+
return new HyperGraphSolver({
|
|
3764
|
+
inputGraph: graph,
|
|
3765
|
+
inputConnections: input.inputConnections,
|
|
3766
|
+
inputSolvedRoutes: convertSerializedSolvedRoutesToSolvedRoutes(
|
|
3767
|
+
input.inputSolvedRoutes,
|
|
3768
|
+
graph
|
|
3769
|
+
)
|
|
3770
|
+
});
|
|
3771
|
+
}
|
|
3772
|
+
getCostOfCentralRegion(region) {
|
|
3773
|
+
const attempts = this.targetRegionAttemptCounts.get(region.regionId) ?? 0;
|
|
3774
|
+
return this.getRegionSolutionCost(this.rootSolver, region) + attempts * 1e4;
|
|
3775
|
+
}
|
|
3776
|
+
getSectionCost(input) {
|
|
3777
|
+
const sectionSolver = this.createHyperGraphSolver({
|
|
3778
|
+
inputGraph: input.solvedGraph,
|
|
3779
|
+
inputConnections: input.solvedGraph.connections ?? [],
|
|
3780
|
+
inputSolvedRoutes: input.solvedGraph.solvedRoutes ?? []
|
|
3781
|
+
});
|
|
3782
|
+
let totalCost = 0;
|
|
3783
|
+
for (const region of sectionSolver.graph.regions) {
|
|
3784
|
+
if (!input.sectionRegionIds.has(region.regionId)) continue;
|
|
3785
|
+
totalCost += this.getRegionSolutionCost(sectionSolver, region);
|
|
3786
|
+
}
|
|
3787
|
+
return totalCost;
|
|
3788
|
+
}
|
|
3789
|
+
_step() {
|
|
3790
|
+
if (!this.activeSubSolver) {
|
|
3791
|
+
this.startNextSectionAttempt();
|
|
3792
|
+
return;
|
|
3793
|
+
}
|
|
3794
|
+
this.activeSubSolver.step();
|
|
3795
|
+
if (!this.activeAttempt) return;
|
|
3796
|
+
if (this.activeSubSolver.failed) {
|
|
3797
|
+
this.rejectActiveAttempt();
|
|
3798
|
+
return;
|
|
3799
|
+
}
|
|
3800
|
+
if (!this.activeSubSolver.solved) return;
|
|
3801
|
+
const solvedBlankSection = {
|
|
3802
|
+
...this.activeAttempt.blankSectionProblem,
|
|
3803
|
+
solvedRoutes: convertSolvedRoutesToSerializedSolvedRoutes(
|
|
3804
|
+
this.activeSubSolver.solvedRoutes
|
|
3805
|
+
)
|
|
3806
|
+
};
|
|
3807
|
+
const mergedGraph = reattachSectionToGraph({
|
|
3808
|
+
fullGraph: this.activeAttempt.fullGraphSnapshot,
|
|
3809
|
+
solvedSectionGraph: solvedBlankSection
|
|
3810
|
+
});
|
|
3811
|
+
const mergedSectionCost = this.getSectionCost({
|
|
3812
|
+
solvedGraph: mergedGraph,
|
|
3813
|
+
sectionRegionIds: this.activeAttempt.sectionRegionIds
|
|
3814
|
+
});
|
|
3815
|
+
if (mergedSectionCost < this.activeAttempt.currentSectionCost) {
|
|
3816
|
+
this.acceptMergedGraph(mergedGraph);
|
|
3817
|
+
return;
|
|
3818
|
+
}
|
|
3819
|
+
this.rejectActiveAttempt();
|
|
3820
|
+
}
|
|
3821
|
+
startNextSectionAttempt() {
|
|
3822
|
+
if (this.attemptedSectionCount >= this.config.maxSectionAttempts) {
|
|
3823
|
+
this.solved = true;
|
|
3824
|
+
return;
|
|
3825
|
+
}
|
|
3826
|
+
const targetRegion = this.selectTargetRegion();
|
|
3827
|
+
if (!targetRegion) {
|
|
3828
|
+
this.solved = true;
|
|
3829
|
+
return;
|
|
3830
|
+
}
|
|
3831
|
+
this.attemptedSectionCount += 1;
|
|
3832
|
+
const nextAttempt = this.createSectionSolveAttempt(targetRegion);
|
|
3833
|
+
if (!nextAttempt) {
|
|
3834
|
+
this.bumpTargetRegionAttemptCount(targetRegion.regionId);
|
|
3835
|
+
return;
|
|
3836
|
+
}
|
|
3837
|
+
this.activeAttempt = nextAttempt;
|
|
3838
|
+
this.activeSubSolver = this.createHyperGraphSolver({
|
|
3839
|
+
inputGraph: nextAttempt.blankSectionProblem,
|
|
3840
|
+
inputConnections: nextAttempt.blankSectionProblem.connections ?? [],
|
|
3841
|
+
inputSolvedRoutes: []
|
|
3842
|
+
});
|
|
3843
|
+
}
|
|
3844
|
+
selectTargetRegion() {
|
|
3845
|
+
let bestRegion = null;
|
|
3846
|
+
let bestCost = Infinity;
|
|
3847
|
+
const minCentralRegionCost = this.getMinCentralRegionCost();
|
|
3848
|
+
for (const region of this.graph.regions) {
|
|
3849
|
+
if ((region.assignments?.length ?? 0) === 0) continue;
|
|
3850
|
+
if ((this.targetRegionAttemptCounts.get(region.regionId) ?? 0) >= this.config.maxTargetRegionAttempts) {
|
|
3851
|
+
continue;
|
|
3852
|
+
}
|
|
3853
|
+
const cost = this.getCostOfCentralRegion(region);
|
|
3854
|
+
if (cost <= minCentralRegionCost) continue;
|
|
3855
|
+
if (cost >= bestCost) continue;
|
|
3856
|
+
bestCost = cost;
|
|
3857
|
+
bestRegion = region;
|
|
3858
|
+
}
|
|
3859
|
+
return bestRegion;
|
|
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
|
+
}
|
|
3876
|
+
createSectionSolveAttempt(targetRegion) {
|
|
3877
|
+
const fullGraphSnapshot = this.serializeSolvedGraph();
|
|
3878
|
+
const extractedSection = extractSectionOfHyperGraph({
|
|
3879
|
+
graph: fullGraphSnapshot,
|
|
3880
|
+
centralRegionId: targetRegion.regionId,
|
|
3881
|
+
expansionHopsFromCentralRegion: this.config.sectionExpansionHops
|
|
3882
|
+
});
|
|
3883
|
+
const prunedSection = this.pruneSectionForBlanking(extractedSection);
|
|
3884
|
+
if ((prunedSection.connections?.length ?? 0) === 0) {
|
|
3885
|
+
return null;
|
|
3886
|
+
}
|
|
3887
|
+
const sectionRegionIds = this.getSectionRegionIds(extractedSection);
|
|
3888
|
+
return {
|
|
3889
|
+
targetRegionId: targetRegion.regionId,
|
|
3890
|
+
sectionRegionIds,
|
|
3891
|
+
fullGraphSnapshot,
|
|
3892
|
+
blankSectionProblem: createBlankHyperGraph(prunedSection),
|
|
3893
|
+
currentSectionCost: this.getSectionCost({
|
|
3894
|
+
solvedGraph: fullGraphSnapshot,
|
|
3895
|
+
sectionRegionIds
|
|
3896
|
+
})
|
|
3897
|
+
};
|
|
3898
|
+
}
|
|
3899
|
+
acceptMergedGraph(mergedGraph) {
|
|
3900
|
+
this.rootSolver.solvedRoutes = commitSolvedRoutes({
|
|
3901
|
+
graph: this.rootSolver.graph,
|
|
3902
|
+
connections: this.rootSolver.connections,
|
|
3903
|
+
solvedRoutes: this.deserializeSolvedRoutes(mergedGraph)
|
|
3904
|
+
});
|
|
3905
|
+
this.solvedRoutes = this.rootSolver.solvedRoutes;
|
|
3906
|
+
this.graph = this.rootSolver.graph;
|
|
3907
|
+
this.connections = this.rootSolver.connections;
|
|
3908
|
+
for (const regionId of this.activeAttempt?.sectionRegionIds ?? []) {
|
|
3909
|
+
this.targetRegionAttemptCounts.set(regionId, 0);
|
|
3910
|
+
}
|
|
3911
|
+
this.clearActiveAttempt();
|
|
3912
|
+
}
|
|
3913
|
+
rejectActiveAttempt() {
|
|
3914
|
+
if (this.activeSubSolver?.failed) {
|
|
3915
|
+
this.failedSubSolvers ??= [];
|
|
3916
|
+
this.failedSubSolvers.push(this.activeSubSolver);
|
|
3917
|
+
}
|
|
3918
|
+
if (this.activeAttempt) {
|
|
3919
|
+
this.bumpTargetRegionAttemptCount(this.activeAttempt.targetRegionId);
|
|
3920
|
+
}
|
|
3921
|
+
this.clearActiveAttempt();
|
|
3922
|
+
}
|
|
3923
|
+
clearActiveAttempt() {
|
|
3924
|
+
this.activeSubSolver = null;
|
|
3925
|
+
this.activeAttempt = null;
|
|
3926
|
+
}
|
|
3927
|
+
bumpTargetRegionAttemptCount(regionId) {
|
|
3928
|
+
this.targetRegionAttemptCounts.set(
|
|
3929
|
+
regionId,
|
|
3930
|
+
(this.targetRegionAttemptCounts.get(regionId) ?? 0) + 1
|
|
3931
|
+
);
|
|
3932
|
+
}
|
|
3933
|
+
serializeSolvedGraph() {
|
|
3934
|
+
return {
|
|
3935
|
+
...convertHyperGraphToSerializedHyperGraph(this.graph),
|
|
3936
|
+
connections: convertConnectionsToSerializedConnections(this.connections),
|
|
3937
|
+
solvedRoutes: convertSolvedRoutesToSerializedSolvedRoutes(
|
|
3938
|
+
this.solvedRoutes
|
|
3939
|
+
)
|
|
3940
|
+
};
|
|
3941
|
+
}
|
|
3942
|
+
deserializeSolvedRoutes(graph) {
|
|
3943
|
+
if (!graph.solvedRoutes) return [];
|
|
3944
|
+
return convertSerializedSolvedRoutesToSolvedRoutes(
|
|
3945
|
+
graph.solvedRoutes,
|
|
3946
|
+
convertSerializedHyperGraphToHyperGraph(graph)
|
|
3947
|
+
);
|
|
3948
|
+
}
|
|
3949
|
+
getSectionRegionIds(sectionGraph) {
|
|
3950
|
+
const fullRegionIds = new Set(
|
|
3951
|
+
this.graph.regions.map((region) => region.regionId)
|
|
3952
|
+
);
|
|
3953
|
+
return new Set(
|
|
3954
|
+
sectionGraph.regions.map((region) => region.regionId).filter((regionId) => fullRegionIds.has(regionId))
|
|
3955
|
+
);
|
|
3956
|
+
}
|
|
3957
|
+
pruneSectionForBlanking(extractedSection) {
|
|
3958
|
+
const mutableSectionGraph = convertSerializedHyperGraphToHyperGraph(extractedSection);
|
|
3959
|
+
const retainedPortIds = extractedSection.solvedRoutes?.flatMap((solvedRoute) => {
|
|
3960
|
+
const firstPortId = solvedRoute.path[0]?.portId;
|
|
3961
|
+
const lastPortId = solvedRoute.path[solvedRoute.path.length - 1]?.portId;
|
|
3962
|
+
return [firstPortId, lastPortId].filter(
|
|
3963
|
+
(portId) => Boolean(portId)
|
|
3964
|
+
);
|
|
3965
|
+
}) ?? [];
|
|
3966
|
+
pruneDeadEndPorts(mutableSectionGraph, retainedPortIds);
|
|
3967
|
+
return {
|
|
3968
|
+
...convertHyperGraphToSerializedHyperGraph(mutableSectionGraph),
|
|
3969
|
+
connections: extractedSection.connections ? structuredClone(extractedSection.connections) : void 0,
|
|
3970
|
+
solvedRoutes: extractedSection.solvedRoutes ? structuredClone(extractedSection.solvedRoutes) : void 0,
|
|
3971
|
+
_sectionCentralRegionId: extractedSection._sectionCentralRegionId,
|
|
3972
|
+
_sectionRouteBindings: extractedSection._sectionRouteBindings ? structuredClone(extractedSection._sectionRouteBindings) : void 0
|
|
3973
|
+
};
|
|
3974
|
+
}
|
|
3975
|
+
getRegionSolutionCost(solver, region) {
|
|
3976
|
+
const previousConnection = solver.currentConnection;
|
|
3977
|
+
let totalCost = 0;
|
|
3978
|
+
for (const assignment of region.assignments ?? []) {
|
|
3979
|
+
solver.currentConnection = assignment.connection;
|
|
3980
|
+
totalCost += solver.computeIncreasedRegionCostIfPortsAreUsed(
|
|
3981
|
+
region,
|
|
3982
|
+
assignment.regionPort1,
|
|
3983
|
+
assignment.regionPort2
|
|
3984
|
+
);
|
|
3985
|
+
}
|
|
3986
|
+
solver.currentConnection = previousConnection;
|
|
3987
|
+
return totalCost;
|
|
3988
|
+
}
|
|
3989
|
+
};
|
|
3990
|
+
var normalizeInput = (input) => {
|
|
3991
|
+
const inputConnections = input.inputConnections ?? input.inputGraph.connections;
|
|
3992
|
+
const inputSolvedRoutes = input.inputSolvedRoutes ?? input.inputGraph.solvedRoutes;
|
|
3993
|
+
const sectionExpansionHops = input.sectionExpansionHops ?? input.expansionHopsFromCentralRegion;
|
|
3994
|
+
const maxTargetRegionAttempts = input.maxTargetRegionAttempts ?? input.MAX_ATTEMPTS_PER_REGION;
|
|
3995
|
+
if (!inputConnections) {
|
|
3996
|
+
throw new Error("HyperGraphSectionOptimizer2 requires inputConnections");
|
|
3997
|
+
}
|
|
3998
|
+
if (!inputSolvedRoutes) {
|
|
3999
|
+
throw new Error("HyperGraphSectionOptimizer2 requires inputSolvedRoutes");
|
|
4000
|
+
}
|
|
4001
|
+
if (sectionExpansionHops === void 0) {
|
|
4002
|
+
throw new Error("HyperGraphSectionOptimizer2 requires sectionExpansionHops");
|
|
4003
|
+
}
|
|
4004
|
+
if (maxTargetRegionAttempts === void 0) {
|
|
4005
|
+
throw new Error(
|
|
4006
|
+
"HyperGraphSectionOptimizer2 requires maxTargetRegionAttempts"
|
|
4007
|
+
);
|
|
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
|
+
}
|
|
4016
|
+
return {
|
|
4017
|
+
inputGraph: {
|
|
4018
|
+
...input.inputGraph,
|
|
4019
|
+
connections: void 0,
|
|
4020
|
+
solvedRoutes: void 0
|
|
4021
|
+
},
|
|
4022
|
+
inputConnections: structuredClone(inputConnections),
|
|
4023
|
+
inputSolvedRoutes: structuredClone(inputSolvedRoutes),
|
|
4024
|
+
sectionExpansionHops,
|
|
4025
|
+
maxTargetRegionAttempts,
|
|
4026
|
+
maxSectionAttempts: input.maxSectionAttempts ?? input.MAX_ATTEMPTS_PER_SECTION ?? 500,
|
|
4027
|
+
minCentralRegionCost: input.minCentralRegionCost ?? input.ACCEPTABLE_CENTRAL_REGION_COST ?? 0,
|
|
4028
|
+
centralRegionCostStart: acceptableCentralRegionCostStart,
|
|
4029
|
+
centralRegionCostEnd: acceptableCentralRegionCostEnd,
|
|
4030
|
+
effort: input.effort ?? 1
|
|
4031
|
+
};
|
|
4032
|
+
};
|
|
4033
|
+
|
|
3695
4034
|
// node_modules/transformation-matrix/src/applyToPoint.js
|
|
3696
4035
|
function applyToPoint(matrix2, point2) {
|
|
3697
4036
|
return Array.isArray(point2) ? [
|
|
@@ -15617,7 +15956,7 @@ function setStepOfAllObjects(graphics, step) {
|
|
|
15617
15956
|
}
|
|
15618
15957
|
return graphics;
|
|
15619
15958
|
}
|
|
15620
|
-
var
|
|
15959
|
+
var BaseSolver4 = class {
|
|
15621
15960
|
MAX_ITERATIONS = 1e5;
|
|
15622
15961
|
solved = false;
|
|
15623
15962
|
failed = false;
|
|
@@ -15724,7 +16063,7 @@ function definePipelineStep(solverName, solverClass, getConstructorParams, opts
|
|
|
15724
16063
|
onSolved: opts.onSolved
|
|
15725
16064
|
};
|
|
15726
16065
|
}
|
|
15727
|
-
var BasePipelineSolver = class extends
|
|
16066
|
+
var BasePipelineSolver = class extends BaseSolver4 {
|
|
15728
16067
|
startTimeOfStage = {};
|
|
15729
16068
|
endTimeOfStage = {};
|
|
15730
16069
|
timeSpentOnStage = {};
|
|
@@ -15939,7 +16278,7 @@ var clampPointToBounds = (point4, bounds) => ({
|
|
|
15939
16278
|
x: Math.min(bounds.maxX, Math.max(bounds.minX, point4.x)),
|
|
15940
16279
|
y: Math.min(bounds.maxY, Math.max(bounds.minY, point4.y))
|
|
15941
16280
|
});
|
|
15942
|
-
var BuildRegionsSolver = class extends
|
|
16281
|
+
var BuildRegionsSolver = class extends BaseSolver4 {
|
|
15943
16282
|
input;
|
|
15944
16283
|
output = null;
|
|
15945
16284
|
constructor(input) {
|
|
@@ -16360,7 +16699,7 @@ var generateBoundaryPointsWithEdges = (params) => {
|
|
|
16360
16699
|
hadCrossings: resolved.hadCrossings
|
|
16361
16700
|
};
|
|
16362
16701
|
};
|
|
16363
|
-
var GeneratePointsSolver = class extends
|
|
16702
|
+
var GeneratePointsSolver = class extends BaseSolver4 {
|
|
16364
16703
|
input;
|
|
16365
16704
|
output = null;
|
|
16366
16705
|
constructor(input) {
|
|
@@ -16815,7 +17154,7 @@ var mergeCellsPolyanya = (params) => {
|
|
|
16815
17154
|
const depths = liveCells.map(() => 0);
|
|
16816
17155
|
return { cells: liveCells, depths };
|
|
16817
17156
|
};
|
|
16818
|
-
var MergeCellsSolver = class extends
|
|
17157
|
+
var MergeCellsSolver = class extends BaseSolver4 {
|
|
16819
17158
|
input;
|
|
16820
17159
|
output = null;
|
|
16821
17160
|
constructor(input) {
|
|
@@ -17073,7 +17412,7 @@ var filterTris = (params) => {
|
|
|
17073
17412
|
return true;
|
|
17074
17413
|
});
|
|
17075
17414
|
};
|
|
17076
|
-
var TriangulateSolver = class extends
|
|
17415
|
+
var TriangulateSolver = class extends BaseSolver4 {
|
|
17077
17416
|
input;
|
|
17078
17417
|
output = null;
|
|
17079
17418
|
constructor(input) {
|
|
@@ -25031,6 +25370,7 @@ function createConvexViaGraphFromXYConnections(xyConnections, viaTileOrProblem,
|
|
|
25031
25370
|
export {
|
|
25032
25371
|
ConnectBuilder,
|
|
25033
25372
|
HyperGraphSectionOptimizer,
|
|
25373
|
+
HyperGraphSectionOptimizer2,
|
|
25034
25374
|
HyperGraphSolver,
|
|
25035
25375
|
JUMPER_GRAPH_SOLVER_DEFAULTS,
|
|
25036
25376
|
JumperGraphSolver,
|