@tscircuit/hypergraph 0.0.13 → 0.0.14
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 +1 -0
- package/dist/index.js +77 -9
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -389,6 +389,7 @@ declare class JumperGraphSolver extends HyperGraphSolver<JRegion, JPort> {
|
|
|
389
389
|
ripCost: number;
|
|
390
390
|
baseMaxIterations: number;
|
|
391
391
|
additionalMaxIterationsPerConnection: number;
|
|
392
|
+
additionalMaxIterationsPerCrossing: number;
|
|
392
393
|
constructor(input: {
|
|
393
394
|
inputGraph: HyperGraph | SerializedHyperGraph;
|
|
394
395
|
inputConnections: (Connection | SerializedConnection)[];
|
package/dist/index.js
CHANGED
|
@@ -2369,24 +2369,88 @@ function computeCrossingAssignments(region, port1, port2) {
|
|
|
2369
2369
|
return crossingAssignments;
|
|
2370
2370
|
}
|
|
2371
2371
|
|
|
2372
|
+
// lib/JumperGraphSolver/countInputConnectionCrossings.ts
|
|
2373
|
+
function countInputConnectionCrossings(graph, connections) {
|
|
2374
|
+
if (connections.length < 2) {
|
|
2375
|
+
return 0;
|
|
2376
|
+
}
|
|
2377
|
+
let minX = Infinity;
|
|
2378
|
+
let maxX = -Infinity;
|
|
2379
|
+
let minY = Infinity;
|
|
2380
|
+
let maxY = -Infinity;
|
|
2381
|
+
for (const region of graph.regions) {
|
|
2382
|
+
const jRegion = region;
|
|
2383
|
+
if (jRegion.d?.bounds) {
|
|
2384
|
+
minX = Math.min(minX, jRegion.d.bounds.minX);
|
|
2385
|
+
maxX = Math.max(maxX, jRegion.d.bounds.maxX);
|
|
2386
|
+
minY = Math.min(minY, jRegion.d.bounds.minY);
|
|
2387
|
+
maxY = Math.max(maxY, jRegion.d.bounds.maxY);
|
|
2388
|
+
} else if (jRegion.d?.center) {
|
|
2389
|
+
minX = Math.min(minX, jRegion.d.center.x);
|
|
2390
|
+
maxX = Math.max(maxX, jRegion.d.center.x);
|
|
2391
|
+
minY = Math.min(minY, jRegion.d.center.y);
|
|
2392
|
+
maxY = Math.max(maxY, jRegion.d.center.y);
|
|
2393
|
+
}
|
|
2394
|
+
}
|
|
2395
|
+
const regionCenterMap = /* @__PURE__ */ new Map();
|
|
2396
|
+
for (const region of graph.regions) {
|
|
2397
|
+
const jRegion = region;
|
|
2398
|
+
if (jRegion.d?.center) {
|
|
2399
|
+
regionCenterMap.set(region.regionId, jRegion.d.center);
|
|
2400
|
+
}
|
|
2401
|
+
}
|
|
2402
|
+
const chords = [];
|
|
2403
|
+
for (const conn of connections) {
|
|
2404
|
+
let startCenter;
|
|
2405
|
+
let endCenter;
|
|
2406
|
+
if ("startRegion" in conn && conn.startRegion) {
|
|
2407
|
+
const startRegion = conn.startRegion;
|
|
2408
|
+
const endRegion = conn.endRegion;
|
|
2409
|
+
startCenter = startRegion.d?.center;
|
|
2410
|
+
endCenter = endRegion.d?.center;
|
|
2411
|
+
} else if ("startRegionId" in conn) {
|
|
2412
|
+
startCenter = regionCenterMap.get(conn.startRegionId);
|
|
2413
|
+
endCenter = regionCenterMap.get(conn.endRegionId);
|
|
2414
|
+
}
|
|
2415
|
+
if (!startCenter || !endCenter) {
|
|
2416
|
+
continue;
|
|
2417
|
+
}
|
|
2418
|
+
const t1 = perimeterT(startCenter, minX, maxX, minY, maxY);
|
|
2419
|
+
const t2 = perimeterT(endCenter, minX, maxX, minY, maxY);
|
|
2420
|
+
chords.push([t1, t2]);
|
|
2421
|
+
}
|
|
2422
|
+
let crossings = 0;
|
|
2423
|
+
for (let i = 0; i < chords.length; i++) {
|
|
2424
|
+
for (let j = i + 1; j < chords.length; j++) {
|
|
2425
|
+
if (chordsCross(chords[i], chords[j])) {
|
|
2426
|
+
crossings++;
|
|
2427
|
+
}
|
|
2428
|
+
}
|
|
2429
|
+
}
|
|
2430
|
+
return crossings;
|
|
2431
|
+
}
|
|
2432
|
+
|
|
2372
2433
|
// lib/JumperGraphSolver/JumperGraphSolver.ts
|
|
2373
2434
|
var JUMPER_GRAPH_SOLVER_DEFAULTS = {
|
|
2374
|
-
portUsagePenalty: 0.
|
|
2375
|
-
portUsagePenaltySq: 0.06194817180037216,
|
|
2376
|
-
|
|
2377
|
-
|
|
2378
|
-
|
|
2379
|
-
|
|
2435
|
+
portUsagePenalty: 0.034685181009478865,
|
|
2436
|
+
// portUsagePenaltySq: 0.06194817180037216,
|
|
2437
|
+
portUsagePenaltySq: 0,
|
|
2438
|
+
crossingPenalty: 4.072520483177124,
|
|
2439
|
+
crossingPenaltySq: 0,
|
|
2440
|
+
// crossingPenaltySq: 0.1315528159128946,
|
|
2441
|
+
ripCost: 35.38577539020022,
|
|
2442
|
+
greedyMultiplier: 0.5518001238069296
|
|
2380
2443
|
};
|
|
2381
2444
|
var JumperGraphSolver = class extends HyperGraphSolver {
|
|
2382
|
-
UNIT_OF_COST = "
|
|
2445
|
+
UNIT_OF_COST = "hops";
|
|
2383
2446
|
portUsagePenalty = JUMPER_GRAPH_SOLVER_DEFAULTS.portUsagePenalty;
|
|
2384
2447
|
portUsagePenaltySq = JUMPER_GRAPH_SOLVER_DEFAULTS.portUsagePenaltySq;
|
|
2385
2448
|
crossingPenalty = JUMPER_GRAPH_SOLVER_DEFAULTS.crossingPenalty;
|
|
2386
2449
|
crossingPenaltySq = JUMPER_GRAPH_SOLVER_DEFAULTS.crossingPenaltySq;
|
|
2387
2450
|
ripCost = JUMPER_GRAPH_SOLVER_DEFAULTS.ripCost;
|
|
2388
2451
|
baseMaxIterations = 4e3;
|
|
2389
|
-
additionalMaxIterationsPerConnection =
|
|
2452
|
+
additionalMaxIterationsPerConnection = 2e3;
|
|
2453
|
+
additionalMaxIterationsPerCrossing = 2e3;
|
|
2390
2454
|
constructor(input) {
|
|
2391
2455
|
super({
|
|
2392
2456
|
greedyMultiplier: JUMPER_GRAPH_SOLVER_DEFAULTS.greedyMultiplier,
|
|
@@ -2398,7 +2462,11 @@ var JumperGraphSolver = class extends HyperGraphSolver {
|
|
|
2398
2462
|
this.crossingPenalty = input.crossingPenalty ?? this.crossingPenalty;
|
|
2399
2463
|
this.baseMaxIterations = input.baseMaxIterations ?? this.baseMaxIterations;
|
|
2400
2464
|
this.additionalMaxIterationsPerConnection = input.additionalMaxIterationsPerConnection ?? this.additionalMaxIterationsPerConnection;
|
|
2401
|
-
|
|
2465
|
+
const crossings = countInputConnectionCrossings(
|
|
2466
|
+
this.graph,
|
|
2467
|
+
input.inputConnections
|
|
2468
|
+
);
|
|
2469
|
+
this.MAX_ITERATIONS = this.baseMaxIterations + input.inputConnections.length * this.additionalMaxIterationsPerConnection + crossings * this.additionalMaxIterationsPerCrossing;
|
|
2402
2470
|
this.populateDistanceToEndMaps();
|
|
2403
2471
|
}
|
|
2404
2472
|
populateDistanceToEndMaps() {
|