@tscircuit/hypergraph 0.0.69 → 0.0.70
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 +83 -1
- package/dist/index.js +319 -6
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -446,6 +446,88 @@ 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
|
+
};
|
|
468
|
+
type NormalizedHyperGraphSectionOptimizer2Input = {
|
|
469
|
+
inputGraph: SerializedHyperGraph;
|
|
470
|
+
inputConnections: SerializedConnection[];
|
|
471
|
+
inputSolvedRoutes: SerializedSolvedRoute[];
|
|
472
|
+
sectionExpansionHops: number;
|
|
473
|
+
maxTargetRegionAttempts: number;
|
|
474
|
+
maxSectionAttempts: number;
|
|
475
|
+
minCentralRegionCost: number;
|
|
476
|
+
effort: number;
|
|
477
|
+
};
|
|
478
|
+
type SectionSolveAttempt = {
|
|
479
|
+
targetRegionId: RegionId;
|
|
480
|
+
sectionRegionIds: Set<RegionId>;
|
|
481
|
+
fullGraphSnapshot: SerializedHyperGraph;
|
|
482
|
+
blankSectionProblem: SerializedHyperGraph;
|
|
483
|
+
currentSectionCost: number;
|
|
484
|
+
};
|
|
485
|
+
declare class HyperGraphSectionOptimizer2 extends BaseSolver {
|
|
486
|
+
readonly config: NormalizedHyperGraphSectionOptimizer2Input;
|
|
487
|
+
readonly rootSolver: HyperGraphSolver<Region, RegionPort>;
|
|
488
|
+
graph: HyperGraph;
|
|
489
|
+
connections: Connection[];
|
|
490
|
+
solvedRoutes: SolvedRoute[];
|
|
491
|
+
activeAttempt: SectionSolveAttempt | null;
|
|
492
|
+
targetRegionAttemptCounts: Map<string, number>;
|
|
493
|
+
attemptedSectionCount: number;
|
|
494
|
+
activeSubSolver: HyperGraphSolver<Region, RegionPort> | null;
|
|
495
|
+
constructor(input: HyperGraphSectionOptimizer2Input);
|
|
496
|
+
getSolverName(): string;
|
|
497
|
+
getConstructorParams(): {
|
|
498
|
+
inputGraph: SerializedHyperGraph;
|
|
499
|
+
inputConnections: SerializedConnection[];
|
|
500
|
+
inputSolvedRoutes: SerializedSolvedRoute[];
|
|
501
|
+
sectionExpansionHops: number;
|
|
502
|
+
maxTargetRegionAttempts: number;
|
|
503
|
+
maxSectionAttempts: number;
|
|
504
|
+
minCentralRegionCost: number;
|
|
505
|
+
effort: number;
|
|
506
|
+
};
|
|
507
|
+
getOutput(): SolvedRoute[];
|
|
508
|
+
_setup(): void;
|
|
509
|
+
visualize(): GraphicsObject;
|
|
510
|
+
protected createHyperGraphSolver(input: CreateSectionSolverInput): HyperGraphSolver<Region, RegionPort>;
|
|
511
|
+
getCostOfCentralRegion(region: Region): number;
|
|
512
|
+
getSectionCost(input: {
|
|
513
|
+
solvedGraph: SerializedHyperGraph;
|
|
514
|
+
sectionRegionIds: Set<RegionId>;
|
|
515
|
+
}): number;
|
|
516
|
+
_step(): void;
|
|
517
|
+
private startNextSectionAttempt;
|
|
518
|
+
private selectTargetRegion;
|
|
519
|
+
private createSectionSolveAttempt;
|
|
520
|
+
private acceptMergedGraph;
|
|
521
|
+
private rejectActiveAttempt;
|
|
522
|
+
private clearActiveAttempt;
|
|
523
|
+
private bumpTargetRegionAttemptCount;
|
|
524
|
+
private serializeSolvedGraph;
|
|
525
|
+
private deserializeSolvedRoutes;
|
|
526
|
+
private getSectionRegionIds;
|
|
527
|
+
private pruneSectionForBlanking;
|
|
528
|
+
private getRegionSolutionCost;
|
|
529
|
+
}
|
|
530
|
+
|
|
449
531
|
type Bounds$1 = {
|
|
450
532
|
minX: number;
|
|
451
533
|
minY: number;
|
|
@@ -1327,4 +1409,4 @@ declare function generateConvexViaTopologyRegions(opts: {
|
|
|
1327
1409
|
};
|
|
1328
1410
|
};
|
|
1329
1411
|
|
|
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 };
|
|
1412
|
+
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,318 @@ 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
|
+
effort: this.config.effort
|
|
3736
|
+
};
|
|
3737
|
+
}
|
|
3738
|
+
getOutput() {
|
|
3739
|
+
return this.solvedRoutes;
|
|
3740
|
+
}
|
|
3741
|
+
_setup() {
|
|
3742
|
+
this.startNextSectionAttempt();
|
|
3743
|
+
}
|
|
3744
|
+
visualize() {
|
|
3745
|
+
if (this.activeSubSolver) {
|
|
3746
|
+
return this.activeSubSolver.visualize();
|
|
3747
|
+
}
|
|
3748
|
+
return {
|
|
3749
|
+
title: "HyperGraphSectionOptimizer2",
|
|
3750
|
+
points: [],
|
|
3751
|
+
lines: [],
|
|
3752
|
+
rects: [],
|
|
3753
|
+
circles: [],
|
|
3754
|
+
texts: [],
|
|
3755
|
+
polygons: [],
|
|
3756
|
+
arrows: []
|
|
3757
|
+
};
|
|
3758
|
+
}
|
|
3759
|
+
createHyperGraphSolver(input) {
|
|
3760
|
+
const graph = convertSerializedHyperGraphToHyperGraph(input.inputGraph);
|
|
3761
|
+
return new HyperGraphSolver({
|
|
3762
|
+
inputGraph: graph,
|
|
3763
|
+
inputConnections: input.inputConnections,
|
|
3764
|
+
inputSolvedRoutes: convertSerializedSolvedRoutesToSolvedRoutes(
|
|
3765
|
+
input.inputSolvedRoutes,
|
|
3766
|
+
graph
|
|
3767
|
+
)
|
|
3768
|
+
});
|
|
3769
|
+
}
|
|
3770
|
+
getCostOfCentralRegion(region) {
|
|
3771
|
+
const attempts = this.targetRegionAttemptCounts.get(region.regionId) ?? 0;
|
|
3772
|
+
return this.getRegionSolutionCost(this.rootSolver, region) + attempts * 1e4;
|
|
3773
|
+
}
|
|
3774
|
+
getSectionCost(input) {
|
|
3775
|
+
const sectionSolver = this.createHyperGraphSolver({
|
|
3776
|
+
inputGraph: input.solvedGraph,
|
|
3777
|
+
inputConnections: input.solvedGraph.connections ?? [],
|
|
3778
|
+
inputSolvedRoutes: input.solvedGraph.solvedRoutes ?? []
|
|
3779
|
+
});
|
|
3780
|
+
let totalCost = 0;
|
|
3781
|
+
for (const region of sectionSolver.graph.regions) {
|
|
3782
|
+
if (!input.sectionRegionIds.has(region.regionId)) continue;
|
|
3783
|
+
totalCost += this.getRegionSolutionCost(sectionSolver, region);
|
|
3784
|
+
}
|
|
3785
|
+
return totalCost;
|
|
3786
|
+
}
|
|
3787
|
+
_step() {
|
|
3788
|
+
if (!this.activeSubSolver) {
|
|
3789
|
+
this.startNextSectionAttempt();
|
|
3790
|
+
return;
|
|
3791
|
+
}
|
|
3792
|
+
this.activeSubSolver.step();
|
|
3793
|
+
if (!this.activeAttempt) return;
|
|
3794
|
+
if (this.activeSubSolver.failed) {
|
|
3795
|
+
this.rejectActiveAttempt();
|
|
3796
|
+
return;
|
|
3797
|
+
}
|
|
3798
|
+
if (!this.activeSubSolver.solved) return;
|
|
3799
|
+
const solvedBlankSection = {
|
|
3800
|
+
...this.activeAttempt.blankSectionProblem,
|
|
3801
|
+
solvedRoutes: convertSolvedRoutesToSerializedSolvedRoutes(
|
|
3802
|
+
this.activeSubSolver.solvedRoutes
|
|
3803
|
+
)
|
|
3804
|
+
};
|
|
3805
|
+
const mergedGraph = reattachSectionToGraph({
|
|
3806
|
+
fullGraph: this.activeAttempt.fullGraphSnapshot,
|
|
3807
|
+
solvedSectionGraph: solvedBlankSection
|
|
3808
|
+
});
|
|
3809
|
+
const mergedSectionCost = this.getSectionCost({
|
|
3810
|
+
solvedGraph: mergedGraph,
|
|
3811
|
+
sectionRegionIds: this.activeAttempt.sectionRegionIds
|
|
3812
|
+
});
|
|
3813
|
+
if (mergedSectionCost < this.activeAttempt.currentSectionCost) {
|
|
3814
|
+
this.acceptMergedGraph(mergedGraph);
|
|
3815
|
+
return;
|
|
3816
|
+
}
|
|
3817
|
+
this.rejectActiveAttempt();
|
|
3818
|
+
}
|
|
3819
|
+
startNextSectionAttempt() {
|
|
3820
|
+
if (this.attemptedSectionCount >= this.config.maxSectionAttempts) {
|
|
3821
|
+
this.solved = true;
|
|
3822
|
+
return;
|
|
3823
|
+
}
|
|
3824
|
+
const targetRegion = this.selectTargetRegion();
|
|
3825
|
+
if (!targetRegion) {
|
|
3826
|
+
this.solved = true;
|
|
3827
|
+
return;
|
|
3828
|
+
}
|
|
3829
|
+
this.attemptedSectionCount += 1;
|
|
3830
|
+
const nextAttempt = this.createSectionSolveAttempt(targetRegion);
|
|
3831
|
+
if (!nextAttempt) {
|
|
3832
|
+
this.bumpTargetRegionAttemptCount(targetRegion.regionId);
|
|
3833
|
+
return;
|
|
3834
|
+
}
|
|
3835
|
+
this.activeAttempt = nextAttempt;
|
|
3836
|
+
this.activeSubSolver = this.createHyperGraphSolver({
|
|
3837
|
+
inputGraph: nextAttempt.blankSectionProblem,
|
|
3838
|
+
inputConnections: nextAttempt.blankSectionProblem.connections ?? [],
|
|
3839
|
+
inputSolvedRoutes: []
|
|
3840
|
+
});
|
|
3841
|
+
}
|
|
3842
|
+
selectTargetRegion() {
|
|
3843
|
+
let bestRegion = null;
|
|
3844
|
+
let bestCost = Infinity;
|
|
3845
|
+
for (const region of this.graph.regions) {
|
|
3846
|
+
if ((region.assignments?.length ?? 0) === 0) continue;
|
|
3847
|
+
if ((this.targetRegionAttemptCounts.get(region.regionId) ?? 0) >= this.config.maxTargetRegionAttempts) {
|
|
3848
|
+
continue;
|
|
3849
|
+
}
|
|
3850
|
+
const cost = this.getCostOfCentralRegion(region);
|
|
3851
|
+
if (cost <= this.config.minCentralRegionCost) continue;
|
|
3852
|
+
if (cost >= bestCost) continue;
|
|
3853
|
+
bestCost = cost;
|
|
3854
|
+
bestRegion = region;
|
|
3855
|
+
}
|
|
3856
|
+
return bestRegion;
|
|
3857
|
+
}
|
|
3858
|
+
createSectionSolveAttempt(targetRegion) {
|
|
3859
|
+
const fullGraphSnapshot = this.serializeSolvedGraph();
|
|
3860
|
+
const extractedSection = extractSectionOfHyperGraph({
|
|
3861
|
+
graph: fullGraphSnapshot,
|
|
3862
|
+
centralRegionId: targetRegion.regionId,
|
|
3863
|
+
expansionHopsFromCentralRegion: this.config.sectionExpansionHops
|
|
3864
|
+
});
|
|
3865
|
+
const prunedSection = this.pruneSectionForBlanking(extractedSection);
|
|
3866
|
+
if ((prunedSection.connections?.length ?? 0) === 0) {
|
|
3867
|
+
return null;
|
|
3868
|
+
}
|
|
3869
|
+
const sectionRegionIds = this.getSectionRegionIds(extractedSection);
|
|
3870
|
+
return {
|
|
3871
|
+
targetRegionId: targetRegion.regionId,
|
|
3872
|
+
sectionRegionIds,
|
|
3873
|
+
fullGraphSnapshot,
|
|
3874
|
+
blankSectionProblem: createBlankHyperGraph(prunedSection),
|
|
3875
|
+
currentSectionCost: this.getSectionCost({
|
|
3876
|
+
solvedGraph: fullGraphSnapshot,
|
|
3877
|
+
sectionRegionIds
|
|
3878
|
+
})
|
|
3879
|
+
};
|
|
3880
|
+
}
|
|
3881
|
+
acceptMergedGraph(mergedGraph) {
|
|
3882
|
+
this.rootSolver.solvedRoutes = commitSolvedRoutes({
|
|
3883
|
+
graph: this.rootSolver.graph,
|
|
3884
|
+
connections: this.rootSolver.connections,
|
|
3885
|
+
solvedRoutes: this.deserializeSolvedRoutes(mergedGraph)
|
|
3886
|
+
});
|
|
3887
|
+
this.solvedRoutes = this.rootSolver.solvedRoutes;
|
|
3888
|
+
this.graph = this.rootSolver.graph;
|
|
3889
|
+
this.connections = this.rootSolver.connections;
|
|
3890
|
+
for (const regionId of this.activeAttempt?.sectionRegionIds ?? []) {
|
|
3891
|
+
this.targetRegionAttemptCounts.set(regionId, 0);
|
|
3892
|
+
}
|
|
3893
|
+
this.clearActiveAttempt();
|
|
3894
|
+
}
|
|
3895
|
+
rejectActiveAttempt() {
|
|
3896
|
+
if (this.activeSubSolver?.failed) {
|
|
3897
|
+
this.failedSubSolvers ??= [];
|
|
3898
|
+
this.failedSubSolvers.push(this.activeSubSolver);
|
|
3899
|
+
}
|
|
3900
|
+
if (this.activeAttempt) {
|
|
3901
|
+
this.bumpTargetRegionAttemptCount(this.activeAttempt.targetRegionId);
|
|
3902
|
+
}
|
|
3903
|
+
this.clearActiveAttempt();
|
|
3904
|
+
}
|
|
3905
|
+
clearActiveAttempt() {
|
|
3906
|
+
this.activeSubSolver = null;
|
|
3907
|
+
this.activeAttempt = null;
|
|
3908
|
+
}
|
|
3909
|
+
bumpTargetRegionAttemptCount(regionId) {
|
|
3910
|
+
this.targetRegionAttemptCounts.set(
|
|
3911
|
+
regionId,
|
|
3912
|
+
(this.targetRegionAttemptCounts.get(regionId) ?? 0) + 1
|
|
3913
|
+
);
|
|
3914
|
+
}
|
|
3915
|
+
serializeSolvedGraph() {
|
|
3916
|
+
return {
|
|
3917
|
+
...convertHyperGraphToSerializedHyperGraph(this.graph),
|
|
3918
|
+
connections: convertConnectionsToSerializedConnections(this.connections),
|
|
3919
|
+
solvedRoutes: convertSolvedRoutesToSerializedSolvedRoutes(
|
|
3920
|
+
this.solvedRoutes
|
|
3921
|
+
)
|
|
3922
|
+
};
|
|
3923
|
+
}
|
|
3924
|
+
deserializeSolvedRoutes(graph) {
|
|
3925
|
+
if (!graph.solvedRoutes) return [];
|
|
3926
|
+
return convertSerializedSolvedRoutesToSolvedRoutes(
|
|
3927
|
+
graph.solvedRoutes,
|
|
3928
|
+
convertSerializedHyperGraphToHyperGraph(graph)
|
|
3929
|
+
);
|
|
3930
|
+
}
|
|
3931
|
+
getSectionRegionIds(sectionGraph) {
|
|
3932
|
+
const fullRegionIds = new Set(
|
|
3933
|
+
this.graph.regions.map((region) => region.regionId)
|
|
3934
|
+
);
|
|
3935
|
+
return new Set(
|
|
3936
|
+
sectionGraph.regions.map((region) => region.regionId).filter((regionId) => fullRegionIds.has(regionId))
|
|
3937
|
+
);
|
|
3938
|
+
}
|
|
3939
|
+
pruneSectionForBlanking(extractedSection) {
|
|
3940
|
+
const mutableSectionGraph = convertSerializedHyperGraphToHyperGraph(extractedSection);
|
|
3941
|
+
const retainedPortIds = extractedSection.solvedRoutes?.flatMap((solvedRoute) => {
|
|
3942
|
+
const firstPortId = solvedRoute.path[0]?.portId;
|
|
3943
|
+
const lastPortId = solvedRoute.path[solvedRoute.path.length - 1]?.portId;
|
|
3944
|
+
return [firstPortId, lastPortId].filter(
|
|
3945
|
+
(portId) => Boolean(portId)
|
|
3946
|
+
);
|
|
3947
|
+
}) ?? [];
|
|
3948
|
+
pruneDeadEndPorts(mutableSectionGraph, retainedPortIds);
|
|
3949
|
+
return {
|
|
3950
|
+
...convertHyperGraphToSerializedHyperGraph(mutableSectionGraph),
|
|
3951
|
+
connections: extractedSection.connections ? structuredClone(extractedSection.connections) : void 0,
|
|
3952
|
+
solvedRoutes: extractedSection.solvedRoutes ? structuredClone(extractedSection.solvedRoutes) : void 0,
|
|
3953
|
+
_sectionCentralRegionId: extractedSection._sectionCentralRegionId,
|
|
3954
|
+
_sectionRouteBindings: extractedSection._sectionRouteBindings ? structuredClone(extractedSection._sectionRouteBindings) : void 0
|
|
3955
|
+
};
|
|
3956
|
+
}
|
|
3957
|
+
getRegionSolutionCost(solver, region) {
|
|
3958
|
+
const previousConnection = solver.currentConnection;
|
|
3959
|
+
let totalCost = 0;
|
|
3960
|
+
for (const assignment of region.assignments ?? []) {
|
|
3961
|
+
solver.currentConnection = assignment.connection;
|
|
3962
|
+
totalCost += solver.computeIncreasedRegionCostIfPortsAreUsed(
|
|
3963
|
+
region,
|
|
3964
|
+
assignment.regionPort1,
|
|
3965
|
+
assignment.regionPort2
|
|
3966
|
+
);
|
|
3967
|
+
}
|
|
3968
|
+
solver.currentConnection = previousConnection;
|
|
3969
|
+
return totalCost;
|
|
3970
|
+
}
|
|
3971
|
+
};
|
|
3972
|
+
var normalizeInput = (input) => {
|
|
3973
|
+
const inputConnections = input.inputConnections ?? input.inputGraph.connections;
|
|
3974
|
+
const inputSolvedRoutes = input.inputSolvedRoutes ?? input.inputGraph.solvedRoutes;
|
|
3975
|
+
const sectionExpansionHops = input.sectionExpansionHops ?? input.expansionHopsFromCentralRegion;
|
|
3976
|
+
const maxTargetRegionAttempts = input.maxTargetRegionAttempts ?? input.MAX_ATTEMPTS_PER_REGION;
|
|
3977
|
+
if (!inputConnections) {
|
|
3978
|
+
throw new Error("HyperGraphSectionOptimizer2 requires inputConnections");
|
|
3979
|
+
}
|
|
3980
|
+
if (!inputSolvedRoutes) {
|
|
3981
|
+
throw new Error("HyperGraphSectionOptimizer2 requires inputSolvedRoutes");
|
|
3982
|
+
}
|
|
3983
|
+
if (sectionExpansionHops === void 0) {
|
|
3984
|
+
throw new Error("HyperGraphSectionOptimizer2 requires sectionExpansionHops");
|
|
3985
|
+
}
|
|
3986
|
+
if (maxTargetRegionAttempts === void 0) {
|
|
3987
|
+
throw new Error(
|
|
3988
|
+
"HyperGraphSectionOptimizer2 requires maxTargetRegionAttempts"
|
|
3989
|
+
);
|
|
3990
|
+
}
|
|
3991
|
+
return {
|
|
3992
|
+
inputGraph: {
|
|
3993
|
+
...input.inputGraph,
|
|
3994
|
+
connections: void 0,
|
|
3995
|
+
solvedRoutes: void 0
|
|
3996
|
+
},
|
|
3997
|
+
inputConnections: structuredClone(inputConnections),
|
|
3998
|
+
inputSolvedRoutes: structuredClone(inputSolvedRoutes),
|
|
3999
|
+
sectionExpansionHops,
|
|
4000
|
+
maxTargetRegionAttempts,
|
|
4001
|
+
maxSectionAttempts: input.maxSectionAttempts ?? input.MAX_ATTEMPTS_PER_SECTION ?? 500,
|
|
4002
|
+
minCentralRegionCost: input.minCentralRegionCost ?? input.ACCEPTABLE_CENTRAL_REGION_COST ?? 0,
|
|
4003
|
+
effort: input.effort ?? 1
|
|
4004
|
+
};
|
|
4005
|
+
};
|
|
4006
|
+
|
|
3695
4007
|
// node_modules/transformation-matrix/src/applyToPoint.js
|
|
3696
4008
|
function applyToPoint(matrix2, point2) {
|
|
3697
4009
|
return Array.isArray(point2) ? [
|
|
@@ -15617,7 +15929,7 @@ function setStepOfAllObjects(graphics, step) {
|
|
|
15617
15929
|
}
|
|
15618
15930
|
return graphics;
|
|
15619
15931
|
}
|
|
15620
|
-
var
|
|
15932
|
+
var BaseSolver4 = class {
|
|
15621
15933
|
MAX_ITERATIONS = 1e5;
|
|
15622
15934
|
solved = false;
|
|
15623
15935
|
failed = false;
|
|
@@ -15724,7 +16036,7 @@ function definePipelineStep(solverName, solverClass, getConstructorParams, opts
|
|
|
15724
16036
|
onSolved: opts.onSolved
|
|
15725
16037
|
};
|
|
15726
16038
|
}
|
|
15727
|
-
var BasePipelineSolver = class extends
|
|
16039
|
+
var BasePipelineSolver = class extends BaseSolver4 {
|
|
15728
16040
|
startTimeOfStage = {};
|
|
15729
16041
|
endTimeOfStage = {};
|
|
15730
16042
|
timeSpentOnStage = {};
|
|
@@ -15939,7 +16251,7 @@ var clampPointToBounds = (point4, bounds) => ({
|
|
|
15939
16251
|
x: Math.min(bounds.maxX, Math.max(bounds.minX, point4.x)),
|
|
15940
16252
|
y: Math.min(bounds.maxY, Math.max(bounds.minY, point4.y))
|
|
15941
16253
|
});
|
|
15942
|
-
var BuildRegionsSolver = class extends
|
|
16254
|
+
var BuildRegionsSolver = class extends BaseSolver4 {
|
|
15943
16255
|
input;
|
|
15944
16256
|
output = null;
|
|
15945
16257
|
constructor(input) {
|
|
@@ -16360,7 +16672,7 @@ var generateBoundaryPointsWithEdges = (params) => {
|
|
|
16360
16672
|
hadCrossings: resolved.hadCrossings
|
|
16361
16673
|
};
|
|
16362
16674
|
};
|
|
16363
|
-
var GeneratePointsSolver = class extends
|
|
16675
|
+
var GeneratePointsSolver = class extends BaseSolver4 {
|
|
16364
16676
|
input;
|
|
16365
16677
|
output = null;
|
|
16366
16678
|
constructor(input) {
|
|
@@ -16815,7 +17127,7 @@ var mergeCellsPolyanya = (params) => {
|
|
|
16815
17127
|
const depths = liveCells.map(() => 0);
|
|
16816
17128
|
return { cells: liveCells, depths };
|
|
16817
17129
|
};
|
|
16818
|
-
var MergeCellsSolver = class extends
|
|
17130
|
+
var MergeCellsSolver = class extends BaseSolver4 {
|
|
16819
17131
|
input;
|
|
16820
17132
|
output = null;
|
|
16821
17133
|
constructor(input) {
|
|
@@ -17073,7 +17385,7 @@ var filterTris = (params) => {
|
|
|
17073
17385
|
return true;
|
|
17074
17386
|
});
|
|
17075
17387
|
};
|
|
17076
|
-
var TriangulateSolver = class extends
|
|
17388
|
+
var TriangulateSolver = class extends BaseSolver4 {
|
|
17077
17389
|
input;
|
|
17078
17390
|
output = null;
|
|
17079
17391
|
constructor(input) {
|
|
@@ -25031,6 +25343,7 @@ function createConvexViaGraphFromXYConnections(xyConnections, viaTileOrProblem,
|
|
|
25031
25343
|
export {
|
|
25032
25344
|
ConnectBuilder,
|
|
25033
25345
|
HyperGraphSectionOptimizer,
|
|
25346
|
+
HyperGraphSectionOptimizer2,
|
|
25034
25347
|
HyperGraphSolver,
|
|
25035
25348
|
JUMPER_GRAPH_SOLVER_DEFAULTS,
|
|
25036
25349
|
JumperGraphSolver,
|